summaryrefslogtreecommitdiff
path: root/cras/src/tests/audio_thread_unittest.cc
diff options
context:
space:
mode:
authorHsin-Yu Chao <hychao@chromium.org>2014-05-02 19:34:37 +0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-05-23 04:35:39 +0000
commit5940b29ef9b97cb5e60f861e0b43815d2075d491 (patch)
tree8c9ff9c3101668a6371cea2f508eafe2d43cea0f /cras/src/tests/audio_thread_unittest.cc
parent65a6538a2c47c057d23278df2b504f5c06741d4a (diff)
downloadadhd-5940b29ef9b97cb5e60f861e0b43815d2075d491.tar.gz
CRAS: audio_thread: Refactor functions
Due to the structure change to support multiple active devices of a direction, refactor some function arguments to use direction instead of pointer to cras_iodev. Note that, future changes will actually remove the use of cras_iodev and replace by stream direction. BUG=chromium:360338 TEST=None Change-Id: I5266469d1c2ccde6cd56d3216c3c9ed77aa35b89 Reviewed-on: https://chromium-review.googlesource.com/198200 Reviewed-by: Hsinyu Chao <hychao@chromium.org> Commit-Queue: Hsinyu Chao <hychao@chromium.org> Tested-by: Hsinyu Chao <hychao@chromium.org>
Diffstat (limited to 'cras/src/tests/audio_thread_unittest.cc')
-rw-r--r--cras/src/tests/audio_thread_unittest.cc34
1 files changed, 34 insertions, 0 deletions
diff --git a/cras/src/tests/audio_thread_unittest.cc b/cras/src/tests/audio_thread_unittest.cc
index db98c76a..9f7d94a9 100644
--- a/cras/src/tests/audio_thread_unittest.cc
+++ b/cras/src/tests/audio_thread_unittest.cc
@@ -31,6 +31,7 @@ int thread_remove_stream(audio_thread* thread,
int thread_disconnect_stream(audio_thread* thread,
cras_rstream* stream);
int unified_io(audio_thread* thread, timespec* ts);
+int input_delay_frames(struct active_dev *adevs);
static int cras_mix_add_stream_dont_fill_next;
static unsigned int cras_mix_add_stream_count;
@@ -1604,11 +1605,13 @@ class ActiveDevicesSuite : public testing::Test {
iodev_.close_dev = close_dev;
iodev_.is_open = is_open;
iodev_.open_dev = open_dev;
+ iodev_.delay_frames = delay_frames;
iodev_.format = &fmt_;
iodev_.buffer_size = 2048;
iodev2_.close_dev = close_dev;
iodev2_.is_open = is_open;
iodev2_.open_dev = open_dev;
+ iodev2_.delay_frames = delay_frames;
iodev2_.format = &fmt_;
iodev2_.buffer_size = 2048;
thread_ = audio_thread_create();
@@ -1626,8 +1629,10 @@ class ActiveDevicesSuite : public testing::Test {
is_open_ = 0;
cras_fmt_conversion_needed_return_val = 0;
open_dev_val_idx_ = 0;
+ delay_frames_val_idx_ = 0;
for (int i = 0; i < 8; i++) {
open_dev_val_[i] = 0;
+ delay_frames_[i] = 0;
}
}
@@ -1666,6 +1671,11 @@ class ActiveDevicesSuite : public testing::Test {
return open_dev_val_[open_dev_val_idx_++];
}
+ static int delay_frames(const cras_iodev* iodev) {
+ delay_frames_val_idx_ %= 8;
+ return delay_frames_[delay_frames_val_idx_++];
+ }
+
static int is_open_;
static int open_dev_val_[8];
static int open_dev_val_idx_;
@@ -1678,6 +1688,8 @@ class ActiveDevicesSuite : public testing::Test {
struct cras_rstream *rstream_;
struct cras_rstream *rstream2_;
struct audio_thread *thread_;
+ static int delay_frames_val_idx_;
+ static int delay_frames_[8];
};
int ActiveDevicesSuite::is_open_ = 0;
@@ -1686,6 +1698,8 @@ int ActiveDevicesSuite::cb_threshold_ = 0;
int ActiveDevicesSuite::close_dev_called_ = 0;
int ActiveDevicesSuite::open_dev_val_[8];
int ActiveDevicesSuite::open_dev_val_idx_ = 0;
+int ActiveDevicesSuite::delay_frames_val_idx_ = 0;
+int ActiveDevicesSuite::delay_frames_[8];
TEST_F(ActiveDevicesSuite, AddRemoveActiveDevice) {
struct active_dev *adevs;
@@ -1817,6 +1831,26 @@ TEST_F(ActiveDevicesSuite, CloseActiveDevices) {
EXPECT_EQ(2, ActiveDevicesSuite::close_dev_called_);
}
+TEST_F(ActiveDevicesSuite, InputDelayFrames) {
+ int fr;
+ iodev_.direction = CRAS_STREAM_INPUT;
+ iodev2_.direction = CRAS_STREAM_INPUT;
+
+ thread_add_active_dev(thread_, &iodev_);
+ thread_add_active_dev(thread_, &iodev2_);
+
+ thread_add_stream(thread_, rstream_);
+ delay_frames_[0] = 3;
+ delay_frames_[1] = 33;
+ fr = input_delay_frames(thread_->active_devs[CRAS_STREAM_INPUT]);
+ EXPECT_EQ(33, fr);
+
+ delay_frames_val_idx_ = 0;
+ delay_frames_[1] = -1;
+ fr = input_delay_frames(thread_->active_devs[CRAS_STREAM_INPUT]);
+ EXPECT_EQ(-1, fr);
+}
+
extern "C" {
const char kNoCodecsFoundMetric[] = "Cras.NoCodecsFoundAtBoot";