iodev_unittest.cc revision c732e27a905ddce9ccb4507bec7431b6406fdda4
1838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid// Use of this source code is governed by a BSD-style license that can be
3838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid// found in the LICENSE file.
4838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
5838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid#include <stdio.h>
6838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid#include <gtest/gtest.h>
7838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
8838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reidextern "C" {
9838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid#include "cras_iodev.h"
10838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid#include "cras_rstream.h"
11838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid#include "utlist.h"
12838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid}
13838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
14ea1b78a018d72fd22f5ce5650121f5e4b8325a1dChih-Chung Changstatic int select_node_called;
15ea1b78a018d72fd22f5ce5650121f5e4b8325a1dChih-Chung Changstatic enum CRAS_STREAM_DIRECTION select_node_direction;
16ea1b78a018d72fd22f5ce5650121f5e4b8325a1dChih-Chung Changstatic cras_node_id_t select_node_id;
17f1a7e0c094f29c16f6aa9f97d328a93769e69e5cChih-Chung Changstatic struct cras_ionode *node_selected;
18b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Changstatic size_t notify_nodes_changed_called;
19c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Changstatic size_t notify_active_node_changed_called;
206f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang
216f0a5e6a967558105f37513801af573167890f67Chih-Chung Changvoid ResetStubData() {
22ea1b78a018d72fd22f5ce5650121f5e4b8325a1dChih-Chung Chang  select_node_called = 0;
23b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang  notify_nodes_changed_called = 0;
24c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Chang  notify_active_node_changed_called = 0;
256f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang}
266f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang
27838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reidnamespace {
28838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
29838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reidstatic struct timespec clock_gettime_retspec;
30838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
31838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid//  Test fill_time_from_frames
32838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan ReidTEST(IoDevTestSuite, FillTimeFromFramesNormal) {
33838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  struct timespec ts;
34838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
35f880b868b8da1f20594ff271492f7055d4977bb6Dylan Reid  cras_iodev_fill_time_from_frames(12000, 48000, &ts);
36838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_EQ(0, ts.tv_sec);
37838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_GE(ts.tv_nsec, 249900000);
38838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_LE(ts.tv_nsec, 250100000);
39838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid}
40838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
41838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan ReidTEST(IoDevTestSuite, FillTimeFromFramesLong) {
42838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  struct timespec ts;
43838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
44f880b868b8da1f20594ff271492f7055d4977bb6Dylan Reid  cras_iodev_fill_time_from_frames(120000 - 12000, 48000, &ts);
45838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_EQ(2, ts.tv_sec);
46838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_GE(ts.tv_nsec, 249900000);
47838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_LE(ts.tv_nsec, 250100000);
48838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid}
49838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
50838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan ReidTEST(IoDevTestSuite, FillTimeFromFramesShort) {
51838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  struct timespec ts;
52838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
53f880b868b8da1f20594ff271492f7055d4977bb6Dylan Reid  cras_iodev_fill_time_from_frames(12000 - 12000, 48000, &ts);
54838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_EQ(0, ts.tv_sec);
55838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_EQ(0, ts.tv_nsec);
56838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid}
57838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
58838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid//  Test set_playback_timestamp.
59838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan ReidTEST(IoDevTestSuite, SetPlaybackTimeStampSimple) {
60838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  struct timespec ts;
61838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
62838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  clock_gettime_retspec.tv_sec = 1;
63838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  clock_gettime_retspec.tv_nsec = 0;
64838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  cras_iodev_set_playback_timestamp(48000, 24000, &ts);
65838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_EQ(1, ts.tv_sec);
66838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_GE(ts.tv_nsec, 499900000);
67838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_LE(ts.tv_nsec, 500100000);
68838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid}
69838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
70838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan ReidTEST(IoDevTestSuite, SetPlaybackTimeStampWrap) {
71838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  struct timespec ts;
72838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
73838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  clock_gettime_retspec.tv_sec = 1;
74838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  clock_gettime_retspec.tv_nsec = 750000000;
75838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  cras_iodev_set_playback_timestamp(48000, 24000, &ts);
76838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_EQ(2, ts.tv_sec);
77838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_GE(ts.tv_nsec, 249900000);
78838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_LE(ts.tv_nsec, 250100000);
79838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid}
80838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
81838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan ReidTEST(IoDevTestSuite, SetPlaybackTimeStampWrapTwice) {
82838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  struct timespec ts;
83838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
84838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  clock_gettime_retspec.tv_sec = 1;
85838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  clock_gettime_retspec.tv_nsec = 750000000;
86838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  cras_iodev_set_playback_timestamp(48000, 72000, &ts);
87838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_EQ(3, ts.tv_sec);
88838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_GE(ts.tv_nsec, 249900000);
89838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_LE(ts.tv_nsec, 250100000);
90838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid}
91838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
92838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid//  Test set_capture_timestamp.
93838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan ReidTEST(IoDevTestSuite, SetCaptureTimeStampSimple) {
94838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  struct timespec ts;
95838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
96838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  clock_gettime_retspec.tv_sec = 1;
97838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  clock_gettime_retspec.tv_nsec = 750000000;
98838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  cras_iodev_set_capture_timestamp(48000, 24000, &ts);
99838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_EQ(1, ts.tv_sec);
100838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_GE(ts.tv_nsec, 249900000);
101838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_LE(ts.tv_nsec, 250100000);
102838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid}
103838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
104838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan ReidTEST(IoDevTestSuite, SetCaptureTimeStampWrap) {
105838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  struct timespec ts;
106838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
107838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  clock_gettime_retspec.tv_sec = 1;
108838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  clock_gettime_retspec.tv_nsec = 0;
109838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  cras_iodev_set_capture_timestamp(48000, 24000, &ts);
110838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_EQ(0, ts.tv_sec);
111838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_GE(ts.tv_nsec, 499900000);
112838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_LE(ts.tv_nsec, 500100000);
113838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid}
114838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
115838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan ReidTEST(IoDevTestSuite, SetCaptureTimeStampWrapPartial) {
116838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  struct timespec ts;
117838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
118838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  clock_gettime_retspec.tv_sec = 2;
119838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  clock_gettime_retspec.tv_nsec = 750000000;
120838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  cras_iodev_set_capture_timestamp(48000, 72000, &ts);
121838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_EQ(1, ts.tv_sec);
122838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_GE(ts.tv_nsec, 249900000);
123838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_LE(ts.tv_nsec, 250100000);
124838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid}
125838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
126838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan ReidTEST(IoDevTestSuite, TestConfigParamsOneStream) {
127838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  struct cras_iodev iodev;
128838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
129838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  memset(&iodev, 0, sizeof(iodev));
130838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
13132771830509e3baa322a5746edb3a990ea5d631fDylan Reid  iodev.buffer_size = 1024;
132838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
1332c78ba503e3c97f90d4e8b0171c8e3ac50eada42Dylan Reid  cras_iodev_config_params(&iodev, 10, 3);
134838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_EQ(iodev.used_size, 10);
135838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_EQ(iodev.cb_threshold, 3);
136838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid}
137838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
1380534603ac205e739953e3d100d09d3a93ae93c3dDylan ReidTEST(IoDevTestSuite, TestConfigParamsOneStreamLimitThreshold) {
1390534603ac205e739953e3d100d09d3a93ae93c3dDylan Reid  struct cras_iodev iodev;
1400534603ac205e739953e3d100d09d3a93ae93c3dDylan Reid
1410534603ac205e739953e3d100d09d3a93ae93c3dDylan Reid  memset(&iodev, 0, sizeof(iodev));
1420534603ac205e739953e3d100d09d3a93ae93c3dDylan Reid
1430534603ac205e739953e3d100d09d3a93ae93c3dDylan Reid  iodev.buffer_size = 1024;
1440534603ac205e739953e3d100d09d3a93ae93c3dDylan Reid
1452c78ba503e3c97f90d4e8b0171c8e3ac50eada42Dylan Reid  cras_iodev_config_params(&iodev, 10, 10);
1460534603ac205e739953e3d100d09d3a93ae93c3dDylan Reid  EXPECT_EQ(iodev.used_size, 10);
1470534603ac205e739953e3d100d09d3a93ae93c3dDylan Reid  EXPECT_EQ(iodev.cb_threshold, 5);
1480534603ac205e739953e3d100d09d3a93ae93c3dDylan Reid
1490534603ac205e739953e3d100d09d3a93ae93c3dDylan Reid  iodev.direction = CRAS_STREAM_INPUT;
1502c78ba503e3c97f90d4e8b0171c8e3ac50eada42Dylan Reid  cras_iodev_config_params(&iodev, 10, 10);
1510534603ac205e739953e3d100d09d3a93ae93c3dDylan Reid  EXPECT_EQ(iodev.used_size, 10);
1520534603ac205e739953e3d100d09d3a93ae93c3dDylan Reid  EXPECT_EQ(iodev.cb_threshold, 10);
1530534603ac205e739953e3d100d09d3a93ae93c3dDylan Reid}
1540534603ac205e739953e3d100d09d3a93ae93c3dDylan Reid
15532771830509e3baa322a5746edb3a990ea5d631fDylan ReidTEST(IoDevTestSuite, TestConfigParamsOneStreamUsedGreaterBuffer) {
15632771830509e3baa322a5746edb3a990ea5d631fDylan Reid  struct cras_iodev iodev;
15732771830509e3baa322a5746edb3a990ea5d631fDylan Reid
15832771830509e3baa322a5746edb3a990ea5d631fDylan Reid  memset(&iodev, 0, sizeof(iodev));
15932771830509e3baa322a5746edb3a990ea5d631fDylan Reid
16032771830509e3baa322a5746edb3a990ea5d631fDylan Reid  iodev.buffer_size = 1024;
16132771830509e3baa322a5746edb3a990ea5d631fDylan Reid
1622c78ba503e3c97f90d4e8b0171c8e3ac50eada42Dylan Reid  cras_iodev_config_params(&iodev, 1280, 1400);
16332771830509e3baa322a5746edb3a990ea5d631fDylan Reid  EXPECT_EQ(iodev.used_size, 1024);
16432771830509e3baa322a5746edb3a990ea5d631fDylan Reid  EXPECT_EQ(iodev.cb_threshold, 512);
16532771830509e3baa322a5746edb3a990ea5d631fDylan Reid}
16632771830509e3baa322a5746edb3a990ea5d631fDylan Reid
167045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Changclass IoDevSetFormatTestSuite : public testing::Test {
168045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  protected:
169045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang    virtual void SetUp() {
170045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang      sample_rates_[0] = 44100;
171045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang      sample_rates_[1] = 48000;
172045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang      sample_rates_[2] = 0;
173045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang
174045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang      channel_counts_[0] = 2;
175045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang      channel_counts_[1] = 0;
176045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang
177045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang      memset(&iodev_, 0, sizeof(iodev_));
178045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang      iodev_.supported_rates = sample_rates_;
179045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang      iodev_.supported_channel_counts = channel_counts_;
180045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang    }
181045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang
1825b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Chang    virtual void TearDown() {
1835b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Chang      cras_iodev_free_format(&iodev_);
1845b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Chang    }
1855b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Chang
186045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang    struct cras_iodev iodev_;
187045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang    size_t sample_rates_[3];
188045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang    size_t channel_counts_[2];
189045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang};
190045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang
191045156126f648a9f0910152a66572a13447bfdc6Chih-Chung ChangTEST_F(IoDevSetFormatTestSuite, SupportedFormatSecondary) {
192045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  struct cras_audio_format fmt;
193045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  int rc;
194045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang
195045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  fmt.format = SND_PCM_FORMAT_S16_LE;
196045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  fmt.frame_rate = 48000;
197045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  fmt.num_channels = 2;
198045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  rc = cras_iodev_set_format(&iodev_, &fmt);
199045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  EXPECT_EQ(0, rc);
200045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, fmt.format);
201045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  EXPECT_EQ(48000, fmt.frame_rate);
202045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  EXPECT_EQ(2, fmt.num_channels);
203045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang}
204045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang
205045156126f648a9f0910152a66572a13447bfdc6Chih-Chung ChangTEST_F(IoDevSetFormatTestSuite, SupportedFormatPrimary) {
206045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  struct cras_audio_format fmt;
207045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  int rc;
208045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang
209045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  fmt.format = SND_PCM_FORMAT_S16_LE;
210045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  fmt.frame_rate = 44100;
211045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  fmt.num_channels = 2;
212045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  rc = cras_iodev_set_format(&iodev_, &fmt);
213045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  EXPECT_EQ(0, rc);
214045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, fmt.format);
215045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  EXPECT_EQ(44100, fmt.frame_rate);
216045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  EXPECT_EQ(2, fmt.num_channels);
217045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang}
218045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang
219045156126f648a9f0910152a66572a13447bfdc6Chih-Chung ChangTEST_F(IoDevSetFormatTestSuite, SupportedFormatDivisor) {
220045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  struct cras_audio_format fmt;
221045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  int rc;
222045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang
223045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  fmt.format = SND_PCM_FORMAT_S16_LE;
224045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  fmt.frame_rate = 96000;
225045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  fmt.num_channels = 2;
226045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  rc = cras_iodev_set_format(&iodev_, &fmt);
227045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  EXPECT_EQ(0, rc);
228045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, fmt.format);
229045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  EXPECT_EQ(48000, fmt.frame_rate);
230045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  EXPECT_EQ(2, fmt.num_channels);
231045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang}
232045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang
233045156126f648a9f0910152a66572a13447bfdc6Chih-Chung ChangTEST_F(IoDevSetFormatTestSuite, UnsupportedChannelCount) {
234045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  struct cras_audio_format fmt;
235045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  int rc;
236045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang
237045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  fmt.format = SND_PCM_FORMAT_S16_LE;
238045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  fmt.frame_rate = 96000;
239045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  fmt.num_channels = 1;
240045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  rc = cras_iodev_set_format(&iodev_, &fmt);
241045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  EXPECT_EQ(0, rc);
242045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, fmt.format);
243045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  EXPECT_EQ(48000, fmt.frame_rate);
244045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  EXPECT_EQ(2, fmt.num_channels);
245045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang}
246045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang
247045156126f648a9f0910152a66572a13447bfdc6Chih-Chung ChangTEST_F(IoDevSetFormatTestSuite, SupportedFormatFallbackDefault) {
248045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  struct cras_audio_format fmt;
249045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  int rc;
250045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang
251045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  fmt.format = SND_PCM_FORMAT_S16_LE;
252045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  fmt.frame_rate = 96008;
253045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  fmt.num_channels = 2;
254045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  rc = cras_iodev_set_format(&iodev_, &fmt);
255045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  EXPECT_EQ(0, rc);
256045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, fmt.format);
257045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  EXPECT_EQ(44100, fmt.frame_rate);
258045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  EXPECT_EQ(2, fmt.num_channels);
259045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang}
260045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang
26132a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang// The ionode that is plugged should be chosen over unplugged.
26232a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung ChangTEST(IoNodeBetter, Plugged) {
26332a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  cras_ionode a, b;
26432a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang
26532a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  a.plugged = 0;
26632a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  b.plugged = 1;
26732a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang
268f1a7e0c094f29c16f6aa9f97d328a93769e69e5cChih-Chung Chang  node_selected = &a;
26931426461ec77c5a7ee613d52d0a93db6b68e7b7cChih-Chung Chang
27032a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  a.plugged_time.tv_sec = 0;
27132a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  a.plugged_time.tv_usec = 1;
27232a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  b.plugged_time.tv_sec = 0;
27332a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  b.plugged_time.tv_usec = 0;
27432a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang
27532a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  a.priority = 1;
27632a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  b.priority = 0;
27732a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang
27832a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  EXPECT_FALSE(cras_ionode_better(&a, &b));
27932a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  EXPECT_TRUE(cras_ionode_better(&b, &a));
28032a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang}
28132a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang
28231426461ec77c5a7ee613d52d0a93db6b68e7b7cChih-Chung Chang// The ionode both plugged, tie should be broken by selected.
28331426461ec77c5a7ee613d52d0a93db6b68e7b7cChih-Chung ChangTEST(IoNodeBetter, Selected) {
28432a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  cras_ionode a, b;
28532a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang
28632a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  a.plugged = 1;
28732a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  b.plugged = 1;
28832a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang
289f1a7e0c094f29c16f6aa9f97d328a93769e69e5cChih-Chung Chang  node_selected = &b;
29031426461ec77c5a7ee613d52d0a93db6b68e7b7cChih-Chung Chang
29131426461ec77c5a7ee613d52d0a93db6b68e7b7cChih-Chung Chang  a.priority = 1;
29231426461ec77c5a7ee613d52d0a93db6b68e7b7cChih-Chung Chang  b.priority = 0;
29331426461ec77c5a7ee613d52d0a93db6b68e7b7cChih-Chung Chang
29431426461ec77c5a7ee613d52d0a93db6b68e7b7cChih-Chung Chang  a.plugged_time.tv_sec = 0;
29531426461ec77c5a7ee613d52d0a93db6b68e7b7cChih-Chung Chang  a.plugged_time.tv_usec = 1;
29631426461ec77c5a7ee613d52d0a93db6b68e7b7cChih-Chung Chang  b.plugged_time.tv_sec = 0;
29731426461ec77c5a7ee613d52d0a93db6b68e7b7cChih-Chung Chang  b.plugged_time.tv_usec = 0;
29831426461ec77c5a7ee613d52d0a93db6b68e7b7cChih-Chung Chang
29931426461ec77c5a7ee613d52d0a93db6b68e7b7cChih-Chung Chang  EXPECT_FALSE(cras_ionode_better(&a, &b));
30031426461ec77c5a7ee613d52d0a93db6b68e7b7cChih-Chung Chang  EXPECT_TRUE(cras_ionode_better(&b, &a));
30131426461ec77c5a7ee613d52d0a93db6b68e7b7cChih-Chung Chang}
30231426461ec77c5a7ee613d52d0a93db6b68e7b7cChih-Chung Chang
30331426461ec77c5a7ee613d52d0a93db6b68e7b7cChih-Chung Chang// Two ionode both plugged and selected, tie should be broken by priority.
30431426461ec77c5a7ee613d52d0a93db6b68e7b7cChih-Chung ChangTEST(IoNodeBetter, Priority) {
30531426461ec77c5a7ee613d52d0a93db6b68e7b7cChih-Chung Chang  cras_ionode a, b;
30631426461ec77c5a7ee613d52d0a93db6b68e7b7cChih-Chung Chang
30731426461ec77c5a7ee613d52d0a93db6b68e7b7cChih-Chung Chang  a.plugged = 1;
30831426461ec77c5a7ee613d52d0a93db6b68e7b7cChih-Chung Chang  b.plugged = 1;
30931426461ec77c5a7ee613d52d0a93db6b68e7b7cChih-Chung Chang
310f1a7e0c094f29c16f6aa9f97d328a93769e69e5cChih-Chung Chang  node_selected = NULL;
31131426461ec77c5a7ee613d52d0a93db6b68e7b7cChih-Chung Chang
31232a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  a.priority = 0;
31332a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  b.priority = 1;
31432a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang
31532a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  a.plugged_time.tv_sec = 0;
31632a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  a.plugged_time.tv_usec = 1;
31732a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  b.plugged_time.tv_sec = 0;
31832a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  b.plugged_time.tv_usec = 0;
31932a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang
32032a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  EXPECT_FALSE(cras_ionode_better(&a, &b));
32132a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  EXPECT_TRUE(cras_ionode_better(&b, &a));
32232a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang}
32332a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang
32432a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang// Two ionode both plugged and have the same priority, tie should be broken
32532a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang// by plugged time.
32631426461ec77c5a7ee613d52d0a93db6b68e7b7cChih-Chung ChangTEST(IoNodeBetter, RecentlyPlugged) {
32732a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  cras_ionode a, b;
32832a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang
32932a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  a.plugged = 1;
33032a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  b.plugged = 1;
33132a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang
332f1a7e0c094f29c16f6aa9f97d328a93769e69e5cChih-Chung Chang  node_selected = NULL;
33331426461ec77c5a7ee613d52d0a93db6b68e7b7cChih-Chung Chang
33432a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  a.priority = 1;
33532a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  b.priority = 1;
33632a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang
33732a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  a.plugged_time.tv_sec = 0;
33832a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  a.plugged_time.tv_usec = 0;
33932a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  b.plugged_time.tv_sec = 0;
34032a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  b.plugged_time.tv_usec = 1;
34132a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang
34232a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  EXPECT_FALSE(cras_ionode_better(&a, &b));
34332a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang  EXPECT_TRUE(cras_ionode_better(&b, &a));
34432a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang}
34532a79c991ade23beeb5725ef30ee064d9eccdc07Chih-Chung Chang
3466f0a5e6a967558105f37513801af573167890f67Chih-Chung Changstatic void update_active_node(struct cras_iodev *iodev)
3476f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang{
3486f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang}
3496f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang
3506f0a5e6a967558105f37513801af573167890f67Chih-Chung ChangTEST(IoNodePlug, ClearSelection) {
3516f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang  struct cras_iodev iodev;
3526f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang  struct cras_ionode ionode;
3536f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang
354b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang  memset(&iodev, 0, sizeof(iodev));
355b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang  memset(&ionode, 0, sizeof(ionode));
356786f9d1938966af8e1eb9f60559a3535b5c71ff8Chih-Chung Chang  ionode.dev = &iodev;
3576f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang  iodev.direction = CRAS_STREAM_INPUT;
3586f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang  iodev.update_active_node = update_active_node;
3596f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang  ResetStubData();
360786f9d1938966af8e1eb9f60559a3535b5c71ff8Chih-Chung Chang  cras_iodev_set_node_attr(&ionode, IONODE_ATTR_PLUGGED, 1);
3616f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang
362ea1b78a018d72fd22f5ce5650121f5e4b8325a1dChih-Chung Chang  EXPECT_EQ(1, select_node_called);
363ea1b78a018d72fd22f5ce5650121f5e4b8325a1dChih-Chung Chang  EXPECT_EQ(CRAS_STREAM_INPUT, select_node_direction);
364ea1b78a018d72fd22f5ce5650121f5e4b8325a1dChih-Chung Chang  EXPECT_EQ(0, select_node_id);
3656f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang}
3666f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang
367b2ad33424e21106930eb23db093746dc30926f27Chih-Chung ChangTEST(IoDev, AddRemoveNode) {
368b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang  struct cras_iodev iodev;
369b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang  struct cras_ionode ionode;
370b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang
371b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang  memset(&iodev, 0, sizeof(iodev));
372b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang  memset(&ionode, 0, sizeof(ionode));
373b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang  ResetStubData();
374b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang  EXPECT_EQ(0, notify_nodes_changed_called);
375b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang  cras_iodev_add_node(&iodev, &ionode);
376b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang  EXPECT_EQ(1, notify_nodes_changed_called);
377b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang  cras_iodev_rm_node(&iodev, &ionode);
378b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang  EXPECT_EQ(2, notify_nodes_changed_called);
379b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang}
380b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang
381c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung ChangTEST(IoDev, SetActiveNode) {
382c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Chang  struct cras_iodev iodev;
383c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Chang  struct cras_ionode ionode;
384c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Chang
385c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Chang  memset(&iodev, 0, sizeof(iodev));
386c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Chang  memset(&ionode, 0, sizeof(ionode));
387c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Chang  ResetStubData();
388c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Chang  EXPECT_EQ(0, notify_active_node_changed_called);
389c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Chang  cras_iodev_set_active_node(&iodev, &ionode);
390c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Chang  EXPECT_EQ(1, notify_active_node_changed_called);
391c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Chang}
392c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Chang
393838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reidextern "C" {
394838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
395838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid//  From libpthread.
396838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reidint pthread_create(pthread_t *thread, const pthread_attr_t *attr,
397838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid                   void *(*start_routine)(void*), void *arg) {
398838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  return 0;
399838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid}
400838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
401838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reidint pthread_join(pthread_t thread, void **value_ptr) {
402838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  return 0;
403838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid}
404838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
405838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid//  From librt.
406838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reidint clock_gettime(clockid_t clk_id, struct timespec *tp) {
407838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  tp->tv_sec = clock_gettime_retspec.tv_sec;
408838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  tp->tv_nsec = clock_gettime_retspec.tv_nsec;
409838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  return 0;
410838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid}
411838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
412386ab71e324831d632544f8bcecc8d0ba1890f01Dylan Reid// From cras_system_state.
413386ab71e324831d632544f8bcecc8d0ba1890f01Dylan Reidvoid cras_system_state_stream_added() {
414386ab71e324831d632544f8bcecc8d0ba1890f01Dylan Reid}
415386ab71e324831d632544f8bcecc8d0ba1890f01Dylan Reid
416386ab71e324831d632544f8bcecc8d0ba1890f01Dylan Reidvoid cras_system_state_stream_removed() {
417386ab71e324831d632544f8bcecc8d0ba1890f01Dylan Reid}
418386ab71e324831d632544f8bcecc8d0ba1890f01Dylan Reid
4195b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Chang// From cras_dsp
4205b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Changstruct cras_dsp_context *cras_dsp_context_new(int channels, int sample_rate,
4215b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Chang                                              const char *purpose)
4225b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Chang{
4235b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Chang  return NULL;
4245b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Chang}
4255b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Chang
4265b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Changvoid cras_dsp_context_free(struct cras_dsp_context *ctx)
4275b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Chang{
4285b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Chang}
4295b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Chang
4305b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Changvoid cras_dsp_load_pipeline(struct cras_dsp_context *ctx)
4315b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Chang{
4325b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Chang}
4335b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Chang
4347057df0d12f641d9bd9aad64d3aa09127a4e84a3Chih-Chung Changvoid cras_dsp_set_variable(struct cras_dsp_context *ctx, const char *key,
4357057df0d12f641d9bd9aad64d3aa09127a4e84a3Chih-Chung Chang                           const char *value)
4367057df0d12f641d9bd9aad64d3aa09127a4e84a3Chih-Chung Chang{
4377057df0d12f641d9bd9aad64d3aa09127a4e84a3Chih-Chung Chang}
4387057df0d12f641d9bd9aad64d3aa09127a4e84a3Chih-Chung Chang
439d6957a4d295e22b427af40ff4dd29c4d14514d7fDylan Reid// From audio thread
440d6957a4d295e22b427af40ff4dd29c4d14514d7fDylan Reidint audio_thread_post_message(struct audio_thread *thread,
441d6957a4d295e22b427af40ff4dd29c4d14514d7fDylan Reid                              struct audio_thread_msg *msg) {
442d6957a4d295e22b427af40ff4dd29c4d14514d7fDylan Reid  return 0;
443d6957a4d295e22b427af40ff4dd29c4d14514d7fDylan Reid}
444d6957a4d295e22b427af40ff4dd29c4d14514d7fDylan Reid
445ea1b78a018d72fd22f5ce5650121f5e4b8325a1dChih-Chung Changvoid cras_iodev_list_select_node(enum CRAS_STREAM_DIRECTION direction,
446ea1b78a018d72fd22f5ce5650121f5e4b8325a1dChih-Chung Chang                                 cras_node_id_t node_id)
447f1a7e0c094f29c16f6aa9f97d328a93769e69e5cChih-Chung Chang{
448ea1b78a018d72fd22f5ce5650121f5e4b8325a1dChih-Chung Chang  select_node_called++;
449ea1b78a018d72fd22f5ce5650121f5e4b8325a1dChih-Chung Chang  select_node_direction = direction;
450ea1b78a018d72fd22f5ce5650121f5e4b8325a1dChih-Chung Chang  select_node_id = node_id;
451f1a7e0c094f29c16f6aa9f97d328a93769e69e5cChih-Chung Chang}
452f1a7e0c094f29c16f6aa9f97d328a93769e69e5cChih-Chung Chang
453ea1b78a018d72fd22f5ce5650121f5e4b8325a1dChih-Chung Changint cras_iodev_list_node_selected(struct cras_ionode *node)
4546f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang{
455ea1b78a018d72fd22f5ce5650121f5e4b8325a1dChih-Chung Chang  return node == node_selected;
4566f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang}
4576f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang
458b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Changvoid cras_iodev_list_notify_nodes_changed()
459b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang{
460b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang  notify_nodes_changed_called++;
461b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang}
462b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang
463c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Changvoid cras_iodev_list_notify_active_node_changed()
464c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Chang{
465c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Chang  notify_active_node_changed_called++;
466c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Chang}
467c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Chang
468838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid}  // extern "C"
469838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid}  //  namespace
470838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
471838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reidint main(int argc, char **argv) {
472838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  ::testing::InitGoogleTest(&argc, argv);
473838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  return RUN_ALL_TESTS();
474838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid}
475