iodev_unittest.cc revision 016277914b2ab40298e86145a25f8cb3cd22b790
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"
1124cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao#include "dev_stream.h"
12838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid#include "utlist.h"
13cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang#include "cras_audio_area.h"
145342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang
155342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang// Mock software volume scalers.
165342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiangfloat softvol_scalers[101];
17838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid}
18838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
19cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang#define BUFFER_SIZE 8192
20cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang
21e53b58efa0e284527ed48cd429b6c87c18cfd0bfHsin-Yu Chaostatic int cras_iodev_list_disable_dev_called;
22ea1b78a018d72fd22f5ce5650121f5e4b8325a1dChih-Chung Changstatic int select_node_called;
23ea1b78a018d72fd22f5ce5650121f5e4b8325a1dChih-Chung Changstatic enum CRAS_STREAM_DIRECTION select_node_direction;
24ea1b78a018d72fd22f5ce5650121f5e4b8325a1dChih-Chung Changstatic cras_node_id_t select_node_id;
25f1a7e0c094f29c16f6aa9f97d328a93769e69e5cChih-Chung Changstatic struct cras_ionode *node_selected;
26b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Changstatic size_t notify_nodes_changed_called;
27c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Changstatic size_t notify_active_node_changed_called;
28b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reidstatic size_t notify_node_volume_called;
29b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reidstatic size_t notify_node_capture_gain_called;
30ccff36a4576d4810784f0b0ae5fe32a5fbcbe3c4Chih-Chung Changstatic int dsp_context_new_sample_rate;
31ccff36a4576d4810784f0b0ae5fe32a5fbcbe3c4Chih-Chung Changstatic const char *dsp_context_new_purpose;
325fa790469656d3e093799329f814756600762a71Dylan Reidstatic int dsp_context_free_called;
33663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chaostatic int update_channel_layout_called;
34663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chaostatic int update_channel_layout_return_val;
353285adee4a1cd81b2dbd22a60b15e5fd9bd33304Cheng-Yi Chiangstatic int  set_swap_mode_for_node_called;
363285adee4a1cd81b2dbd22a60b15e5fd9bd33304Cheng-Yi Chiangstatic int  set_swap_mode_for_node_enable;
373ac00e542de73e404423161a412b04b64fe7d847Cheng-Yi Chiangstatic int notify_node_left_right_swapped_called;
38a8a86fe67e3cc98173c9bf4e219262a619c0670aHsin-Yu Chaostatic int cras_audio_format_set_channel_layout_called;
395342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiangstatic unsigned int cras_system_get_volume_return;
40d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reidstatic int cras_dsp_get_pipeline_called;
41d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reidstatic int cras_dsp_get_pipeline_ret;
42d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reidstatic int cras_dsp_put_pipeline_called;
43d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reidstatic int cras_dsp_pipeline_get_source_buffer_called;
44d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reidstatic int cras_dsp_pipeline_get_sink_buffer_called;
45d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reidstatic float cras_dsp_pipeline_source_buffer[2][DSP_BUFFER_SIZE];
46d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reidstatic float cras_dsp_pipeline_sink_buffer[2][DSP_BUFFER_SIZE];
47d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reidstatic int cras_dsp_pipeline_get_delay_called;
48d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reidstatic int cras_dsp_pipeline_apply_called;
49d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reidstatic int cras_dsp_pipeline_apply_sample_count;
50d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reidstatic unsigned int cras_mix_mute_count;
512db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reidstatic unsigned int cras_dsp_num_input_channels_return;
522db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reidstatic unsigned int cras_dsp_num_output_channels_return;
532db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reidstruct cras_dsp_context *cras_dsp_context_new_return;
541c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reidstatic unsigned int rate_estimator_add_frames_num_frames;
551c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reidstatic unsigned int rate_estimator_add_frames_called;
561c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reidstatic int cras_system_get_mute_return;
57249e72919eb928e107d251b262c305a8fe531641Dylan Reidstatic snd_pcm_format_t cras_scale_buffer_fmt;
581c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reidstatic float cras_scale_buffer_scaler;
5937048d8a04b223de7d47d9f049dcede7e5036066Dylan Reidstatic unsigned int pre_dsp_hook_called;
6037048d8a04b223de7d47d9f049dcede7e5036066Dylan Reidstatic const uint8_t *pre_dsp_hook_frames;
61081f69891fbf2ebbdb6b74e6b9ff59cd23f3eea0Chinyue Chenstatic void *pre_dsp_hook_cb_data;
6237048d8a04b223de7d47d9f049dcede7e5036066Dylan Reidstatic unsigned int post_dsp_hook_called;
6337048d8a04b223de7d47d9f049dcede7e5036066Dylan Reidstatic const uint8_t *post_dsp_hook_frames;
64081f69891fbf2ebbdb6b74e6b9ff59cd23f3eea0Chinyue Chenstatic void *post_dsp_hook_cb_data;
6524cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chaostatic int iodev_buffer_size;
66034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiangstatic long cras_system_get_capture_gain_ret_value;
67e91895c69bef2515b60d6e4514a5f8e8c53cb36fCheng-Yi Chiangstatic int is_open_ret;
68cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiangstatic uint8_t audio_buffer[BUFFER_SIZE];
69cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiangstatic struct cras_audio_area *audio_area;
701bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiangstatic int dev_running_ret_value;
711bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiangstatic unsigned int put_buffer_nframes;
72016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiangstatic int output_should_wake_ret;
73016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiangstatic int no_stream_called;
74016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiangstatic int no_stream_enable;
75663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao
76663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao// Iodev callback
77663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chaoint update_channel_layout(struct cras_iodev *iodev) {
78663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao  update_channel_layout_called = 1;
79663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao  return update_channel_layout_return_val;
80663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao}
816f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang
823285adee4a1cd81b2dbd22a60b15e5fd9bd33304Cheng-Yi Chiang// Iodev callback
833285adee4a1cd81b2dbd22a60b15e5fd9bd33304Cheng-Yi Chiangint set_swap_mode_for_node(struct cras_iodev *iodev, struct cras_ionode *node,
843285adee4a1cd81b2dbd22a60b15e5fd9bd33304Cheng-Yi Chiang                           int enable)
853285adee4a1cd81b2dbd22a60b15e5fd9bd33304Cheng-Yi Chiang{
863285adee4a1cd81b2dbd22a60b15e5fd9bd33304Cheng-Yi Chiang  set_swap_mode_for_node_called++;
873285adee4a1cd81b2dbd22a60b15e5fd9bd33304Cheng-Yi Chiang  set_swap_mode_for_node_enable = enable;
883285adee4a1cd81b2dbd22a60b15e5fd9bd33304Cheng-Yi Chiang  return 0;
893285adee4a1cd81b2dbd22a60b15e5fd9bd33304Cheng-Yi Chiang}
903285adee4a1cd81b2dbd22a60b15e5fd9bd33304Cheng-Yi Chiang
916f0a5e6a967558105f37513801af573167890f67Chih-Chung Changvoid ResetStubData() {
92e53b58efa0e284527ed48cd429b6c87c18cfd0bfHsin-Yu Chao  cras_iodev_list_disable_dev_called = 0;
93ea1b78a018d72fd22f5ce5650121f5e4b8325a1dChih-Chung Chang  select_node_called = 0;
94b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang  notify_nodes_changed_called = 0;
95c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Chang  notify_active_node_changed_called = 0;
96b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reid  notify_node_volume_called = 0;
97b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reid  notify_node_capture_gain_called = 0;
98ccff36a4576d4810784f0b0ae5fe32a5fbcbe3c4Chih-Chung Chang  dsp_context_new_sample_rate = 0;
99ccff36a4576d4810784f0b0ae5fe32a5fbcbe3c4Chih-Chung Chang  dsp_context_new_purpose = NULL;
1005fa790469656d3e093799329f814756600762a71Dylan Reid  dsp_context_free_called = 0;
1013285adee4a1cd81b2dbd22a60b15e5fd9bd33304Cheng-Yi Chiang  set_swap_mode_for_node_called = 0;
1023285adee4a1cd81b2dbd22a60b15e5fd9bd33304Cheng-Yi Chiang  set_swap_mode_for_node_enable = 0;
1033ac00e542de73e404423161a412b04b64fe7d847Cheng-Yi Chiang  notify_node_left_right_swapped_called = 0;
104a8a86fe67e3cc98173c9bf4e219262a619c0670aHsin-Yu Chao  cras_audio_format_set_channel_layout_called = 0;
105d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid  cras_dsp_get_pipeline_called = 0;
106d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid  cras_dsp_get_pipeline_ret = 0;
107d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid  cras_dsp_put_pipeline_called = 0;
108d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid  cras_dsp_pipeline_get_source_buffer_called = 0;
109d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid  cras_dsp_pipeline_get_sink_buffer_called = 0;
110d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid  memset(&cras_dsp_pipeline_source_buffer, 0,
111d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid         sizeof(cras_dsp_pipeline_source_buffer));
112d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid  memset(&cras_dsp_pipeline_sink_buffer, 0,
113d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid         sizeof(cras_dsp_pipeline_sink_buffer));
114d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid  cras_dsp_pipeline_get_delay_called = 0;
115d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid  cras_dsp_pipeline_apply_called = 0;
116d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid  cras_dsp_pipeline_apply_sample_count = 0;
1172db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid  cras_dsp_num_input_channels_return = 2;
1182db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid  cras_dsp_num_output_channels_return = 2;
1192db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid  cras_dsp_context_new_return = NULL;
1201c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  rate_estimator_add_frames_num_frames = 0;
1211c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  rate_estimator_add_frames_called = 0;
1221c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  cras_system_get_mute_return = 0;
1231c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  cras_mix_mute_count = 0;
12437048d8a04b223de7d47d9f049dcede7e5036066Dylan Reid  pre_dsp_hook_called = 0;
12537048d8a04b223de7d47d9f049dcede7e5036066Dylan Reid  pre_dsp_hook_frames = NULL;
12637048d8a04b223de7d47d9f049dcede7e5036066Dylan Reid  post_dsp_hook_called = 0;
12737048d8a04b223de7d47d9f049dcede7e5036066Dylan Reid  post_dsp_hook_frames = NULL;
12824cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao  iodev_buffer_size = 0;
129034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang  cras_system_get_capture_gain_ret_value = 0;
130e91895c69bef2515b60d6e4514a5f8e8c53cb36fCheng-Yi Chiang  is_open_ret = 0;
131cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  // Assume there is some data in audio buffer.
132cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  memset(audio_buffer, 0xff, sizeof(audio_buffer));
133cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  if (audio_area) {
134cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang    free(audio_area);
135cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang    audio_area = NULL;
136cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  }
1371bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  dev_running_ret_value = 0;
1381bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  put_buffer_nframes = 0;
139016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  output_should_wake_ret= 0;
140016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  no_stream_called = 0;
141016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  no_stream_enable = 0;
1426f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang}
1436f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang
144838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reidnamespace {
145838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
146838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid//  Test fill_time_from_frames
147838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan ReidTEST(IoDevTestSuite, FillTimeFromFramesNormal) {
148838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  struct timespec ts;
149838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
150f880b868b8da1f20594ff271492f7055d4977bb6Dylan Reid  cras_iodev_fill_time_from_frames(12000, 48000, &ts);
151838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_EQ(0, ts.tv_sec);
152838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_GE(ts.tv_nsec, 249900000);
153838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_LE(ts.tv_nsec, 250100000);
154838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid}
155838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
156838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan ReidTEST(IoDevTestSuite, FillTimeFromFramesLong) {
157838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  struct timespec ts;
158838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
159f880b868b8da1f20594ff271492f7055d4977bb6Dylan Reid  cras_iodev_fill_time_from_frames(120000 - 12000, 48000, &ts);
160838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_EQ(2, ts.tv_sec);
161838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_GE(ts.tv_nsec, 249900000);
162838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_LE(ts.tv_nsec, 250100000);
163838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid}
164838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
165838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan ReidTEST(IoDevTestSuite, FillTimeFromFramesShort) {
166838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  struct timespec ts;
167838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
168f880b868b8da1f20594ff271492f7055d4977bb6Dylan Reid  cras_iodev_fill_time_from_frames(12000 - 12000, 48000, &ts);
169838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_EQ(0, ts.tv_sec);
170838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  EXPECT_EQ(0, ts.tv_nsec);
171838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid}
172838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
173045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Changclass IoDevSetFormatTestSuite : public testing::Test {
174045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  protected:
175045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang    virtual void SetUp() {
1762db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid      ResetStubData();
177045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang      sample_rates_[0] = 44100;
178045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang      sample_rates_[1] = 48000;
179045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang      sample_rates_[2] = 0;
180045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang
181045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang      channel_counts_[0] = 2;
182045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang      channel_counts_[1] = 0;
183663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao      channel_counts_[2] = 0;
184663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao
185a485ac04bdfc71e374a3a5d2fbcf4699999a2939Dylan Reid      pcm_formats_[0] = SND_PCM_FORMAT_S16_LE;
186a485ac04bdfc71e374a3a5d2fbcf4699999a2939Dylan Reid      pcm_formats_[1] = SND_PCM_FORMAT_S32_LE;
187a485ac04bdfc71e374a3a5d2fbcf4699999a2939Dylan Reid      pcm_formats_[2] = static_cast<snd_pcm_format_t>(0);
188a485ac04bdfc71e374a3a5d2fbcf4699999a2939Dylan Reid
189663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao      update_channel_layout_called = 0;
190663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao      update_channel_layout_return_val = 0;
191045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang
192045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang      memset(&iodev_, 0, sizeof(iodev_));
193663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao      iodev_.update_channel_layout = update_channel_layout;
194045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang      iodev_.supported_rates = sample_rates_;
195045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang      iodev_.supported_channel_counts = channel_counts_;
196a485ac04bdfc71e374a3a5d2fbcf4699999a2939Dylan Reid      iodev_.supported_formats = pcm_formats_;
197aa66420d69c297eec83e1b5a17b0b2cf06cddfd5Dylan Reid      iodev_.dsp_context = NULL;
198a8a86fe67e3cc98173c9bf4e219262a619c0670aHsin-Yu Chao
199a8a86fe67e3cc98173c9bf4e219262a619c0670aHsin-Yu Chao      cras_audio_format_set_channel_layout_called  = 0;
200045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang    }
201045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang
2025b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Chang    virtual void TearDown() {
2035b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Chang      cras_iodev_free_format(&iodev_);
2045b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Chang    }
2055b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Chang
206045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang    struct cras_iodev iodev_;
207045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang    size_t sample_rates_[3];
208663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao    size_t channel_counts_[3];
209a485ac04bdfc71e374a3a5d2fbcf4699999a2939Dylan Reid    snd_pcm_format_t pcm_formats_[3];
210045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang};
211045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang
212045156126f648a9f0910152a66572a13447bfdc6Chih-Chung ChangTEST_F(IoDevSetFormatTestSuite, SupportedFormatSecondary) {
213045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  struct cras_audio_format fmt;
214045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  int rc;
215045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang
216045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  fmt.format = SND_PCM_FORMAT_S16_LE;
217045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  fmt.frame_rate = 48000;
218045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  fmt.num_channels = 2;
219ccff36a4576d4810784f0b0ae5fe32a5fbcbe3c4Chih-Chung Chang  iodev_.direction = CRAS_STREAM_OUTPUT;
220ccff36a4576d4810784f0b0ae5fe32a5fbcbe3c4Chih-Chung Chang  ResetStubData();
221045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  rc = cras_iodev_set_format(&iodev_, &fmt);
222045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  EXPECT_EQ(0, rc);
223bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.ext_format->format);
224bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(48000, iodev_.ext_format->frame_rate);
225bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(2, iodev_.ext_format->num_channels);
226ccff36a4576d4810784f0b0ae5fe32a5fbcbe3c4Chih-Chung Chang  EXPECT_EQ(dsp_context_new_sample_rate, 48000);
22729b418afbe347e21bf01e29c235919ed5d3035dbYunlian Jiang  EXPECT_STREQ(dsp_context_new_purpose, "playback");
228045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang}
229045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang
230a485ac04bdfc71e374a3a5d2fbcf4699999a2939Dylan ReidTEST_F(IoDevSetFormatTestSuite, SupportedFormat32bit) {
231a485ac04bdfc71e374a3a5d2fbcf4699999a2939Dylan Reid  struct cras_audio_format fmt;
232a485ac04bdfc71e374a3a5d2fbcf4699999a2939Dylan Reid  int rc;
233a485ac04bdfc71e374a3a5d2fbcf4699999a2939Dylan Reid
234a485ac04bdfc71e374a3a5d2fbcf4699999a2939Dylan Reid  fmt.format = SND_PCM_FORMAT_S32_LE;
235a485ac04bdfc71e374a3a5d2fbcf4699999a2939Dylan Reid  fmt.frame_rate = 48000;
236a485ac04bdfc71e374a3a5d2fbcf4699999a2939Dylan Reid  fmt.num_channels = 2;
237a485ac04bdfc71e374a3a5d2fbcf4699999a2939Dylan Reid  iodev_.direction = CRAS_STREAM_OUTPUT;
238a485ac04bdfc71e374a3a5d2fbcf4699999a2939Dylan Reid  ResetStubData();
239a485ac04bdfc71e374a3a5d2fbcf4699999a2939Dylan Reid  rc = cras_iodev_set_format(&iodev_, &fmt);
240a485ac04bdfc71e374a3a5d2fbcf4699999a2939Dylan Reid  EXPECT_EQ(0, rc);
241bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(SND_PCM_FORMAT_S32_LE, iodev_.ext_format->format);
242bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(48000, iodev_.ext_format->frame_rate);
243bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(2, iodev_.ext_format->num_channels);
244a485ac04bdfc71e374a3a5d2fbcf4699999a2939Dylan Reid  EXPECT_EQ(dsp_context_new_sample_rate, 48000);
245a485ac04bdfc71e374a3a5d2fbcf4699999a2939Dylan Reid  EXPECT_STREQ(dsp_context_new_purpose, "playback");
246a485ac04bdfc71e374a3a5d2fbcf4699999a2939Dylan Reid}
247a485ac04bdfc71e374a3a5d2fbcf4699999a2939Dylan Reid
248045156126f648a9f0910152a66572a13447bfdc6Chih-Chung ChangTEST_F(IoDevSetFormatTestSuite, SupportedFormatPrimary) {
249045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  struct cras_audio_format fmt;
250045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  int rc;
251045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang
252045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  fmt.format = SND_PCM_FORMAT_S16_LE;
253045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  fmt.frame_rate = 44100;
254045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  fmt.num_channels = 2;
255ccff36a4576d4810784f0b0ae5fe32a5fbcbe3c4Chih-Chung Chang  iodev_.direction = CRAS_STREAM_INPUT;
256ccff36a4576d4810784f0b0ae5fe32a5fbcbe3c4Chih-Chung Chang  ResetStubData();
257045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  rc = cras_iodev_set_format(&iodev_, &fmt);
258045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  EXPECT_EQ(0, rc);
259bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.ext_format->format);
260bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(44100, iodev_.ext_format->frame_rate);
261bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(2, iodev_.ext_format->num_channels);
262ccff36a4576d4810784f0b0ae5fe32a5fbcbe3c4Chih-Chung Chang  EXPECT_EQ(dsp_context_new_sample_rate, 44100);
26329b418afbe347e21bf01e29c235919ed5d3035dbYunlian Jiang  EXPECT_STREQ(dsp_context_new_purpose, "capture");
264045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang}
265045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang
266045156126f648a9f0910152a66572a13447bfdc6Chih-Chung ChangTEST_F(IoDevSetFormatTestSuite, SupportedFormatDivisor) {
267045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  struct cras_audio_format fmt;
268045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  int rc;
269045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang
270045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  fmt.format = SND_PCM_FORMAT_S16_LE;
271045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  fmt.frame_rate = 96000;
272045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  fmt.num_channels = 2;
273045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  rc = cras_iodev_set_format(&iodev_, &fmt);
274045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  EXPECT_EQ(0, rc);
275bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.ext_format->format);
276bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(48000, iodev_.ext_format->frame_rate);
277bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(2, iodev_.ext_format->num_channels);
278045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang}
279045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang
28097d26e1687da4f38da88b868b6b827aeea50871aDylan ReidTEST_F(IoDevSetFormatTestSuite, Supported96k) {
28197d26e1687da4f38da88b868b6b827aeea50871aDylan Reid  struct cras_audio_format fmt;
28297d26e1687da4f38da88b868b6b827aeea50871aDylan Reid  int rc;
28397d26e1687da4f38da88b868b6b827aeea50871aDylan Reid
28497d26e1687da4f38da88b868b6b827aeea50871aDylan Reid  sample_rates_[0] = 48000;
28597d26e1687da4f38da88b868b6b827aeea50871aDylan Reid  sample_rates_[1] = 96000;
28697d26e1687da4f38da88b868b6b827aeea50871aDylan Reid  sample_rates_[2] = 0;
28797d26e1687da4f38da88b868b6b827aeea50871aDylan Reid
28897d26e1687da4f38da88b868b6b827aeea50871aDylan Reid  fmt.format = SND_PCM_FORMAT_S16_LE;
28997d26e1687da4f38da88b868b6b827aeea50871aDylan Reid  fmt.frame_rate = 96000;
29097d26e1687da4f38da88b868b6b827aeea50871aDylan Reid  fmt.num_channels = 2;
29197d26e1687da4f38da88b868b6b827aeea50871aDylan Reid  rc = cras_iodev_set_format(&iodev_, &fmt);
29297d26e1687da4f38da88b868b6b827aeea50871aDylan Reid  EXPECT_EQ(0, rc);
293bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.ext_format->format);
294bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(96000, iodev_.ext_format->frame_rate);
295bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(2, iodev_.ext_format->num_channels);
29697d26e1687da4f38da88b868b6b827aeea50871aDylan Reid}
29797d26e1687da4f38da88b868b6b827aeea50871aDylan Reid
29897d26e1687da4f38da88b868b6b827aeea50871aDylan ReidTEST_F(IoDevSetFormatTestSuite, LimitLowRate) {
29997d26e1687da4f38da88b868b6b827aeea50871aDylan Reid  struct cras_audio_format fmt;
30097d26e1687da4f38da88b868b6b827aeea50871aDylan Reid  int rc;
30197d26e1687da4f38da88b868b6b827aeea50871aDylan Reid
30297d26e1687da4f38da88b868b6b827aeea50871aDylan Reid  sample_rates_[0] = 48000;
30397d26e1687da4f38da88b868b6b827aeea50871aDylan Reid  sample_rates_[1] = 8000;
30497d26e1687da4f38da88b868b6b827aeea50871aDylan Reid  sample_rates_[2] = 0;
30597d26e1687da4f38da88b868b6b827aeea50871aDylan Reid
30697d26e1687da4f38da88b868b6b827aeea50871aDylan Reid  fmt.format = SND_PCM_FORMAT_S16_LE;
30797d26e1687da4f38da88b868b6b827aeea50871aDylan Reid  fmt.frame_rate = 8000;
30897d26e1687da4f38da88b868b6b827aeea50871aDylan Reid  fmt.num_channels = 2;
30997d26e1687da4f38da88b868b6b827aeea50871aDylan Reid  rc = cras_iodev_set_format(&iodev_, &fmt);
31097d26e1687da4f38da88b868b6b827aeea50871aDylan Reid  EXPECT_EQ(0, rc);
311bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.ext_format->format);
312bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(48000, iodev_.ext_format->frame_rate);
313bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(2, iodev_.ext_format->num_channels);
31497d26e1687da4f38da88b868b6b827aeea50871aDylan Reid}
31597d26e1687da4f38da88b868b6b827aeea50871aDylan Reid
316045156126f648a9f0910152a66572a13447bfdc6Chih-Chung ChangTEST_F(IoDevSetFormatTestSuite, UnsupportedChannelCount) {
317045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  struct cras_audio_format fmt;
318045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  int rc;
319045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang
320045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  fmt.format = SND_PCM_FORMAT_S16_LE;
321045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  fmt.frame_rate = 96000;
322045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  fmt.num_channels = 1;
323045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  rc = cras_iodev_set_format(&iodev_, &fmt);
324045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  EXPECT_EQ(0, rc);
325bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.ext_format->format);
326bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(48000, iodev_.ext_format->frame_rate);
327bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(2, iodev_.ext_format->num_channels);
328045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang}
329045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang
330045156126f648a9f0910152a66572a13447bfdc6Chih-Chung ChangTEST_F(IoDevSetFormatTestSuite, SupportedFormatFallbackDefault) {
331045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  struct cras_audio_format fmt;
332045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  int rc;
333045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang
334045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  fmt.format = SND_PCM_FORMAT_S16_LE;
335045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  fmt.frame_rate = 96008;
336045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  fmt.num_channels = 2;
337045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  rc = cras_iodev_set_format(&iodev_, &fmt);
338045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang  EXPECT_EQ(0, rc);
339bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.ext_format->format);
340bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(44100, iodev_.ext_format->frame_rate);
341bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(2, iodev_.ext_format->num_channels);
342045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang}
343045156126f648a9f0910152a66572a13447bfdc6Chih-Chung Chang
3442db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan ReidTEST_F(IoDevSetFormatTestSuite, OutputDSPChannleReduction) {
3452db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid  struct cras_audio_format fmt;
3462db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid  int rc;
3472db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid
3482db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid  fmt.format = SND_PCM_FORMAT_S16_LE;
3492db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid  fmt.frame_rate = 48000;
3502db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid  fmt.num_channels = 2;
3512db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid
3522db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid  iodev_.direction = CRAS_STREAM_OUTPUT;
3532db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid  iodev_.supported_channel_counts[0] = 1;
3542db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid  iodev_.supported_channel_counts[1] = 0;
3552db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid  cras_dsp_context_new_return = reinterpret_cast<cras_dsp_context *>(0xf00);
3562db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid  cras_dsp_get_pipeline_ret =  0xf01;
3572db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid  cras_dsp_num_input_channels_return = 2;
3582db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid  cras_dsp_num_output_channels_return = 1;
3592db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid  rc = cras_iodev_set_format(&iodev_, &fmt);
3602db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid  EXPECT_EQ(0, rc);
361bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.ext_format->format);
362bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(48000, iodev_.ext_format->frame_rate);
363bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(2, iodev_.ext_format->num_channels);
3642db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid}
3652db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid
3662db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan ReidTEST_F(IoDevSetFormatTestSuite, InputDSPChannleReduction) {
3672db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid  struct cras_audio_format fmt;
3682db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid  int rc;
3692db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid
3702db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid  fmt.format = SND_PCM_FORMAT_S16_LE;
3712db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid  fmt.frame_rate = 48000;
3722db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid  fmt.num_channels = 2;
3732db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid
3742db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid  iodev_.direction = CRAS_STREAM_INPUT;
3752db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid  iodev_.supported_channel_counts[0] = 10;
3762db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid  iodev_.supported_channel_counts[1] = 0;
3772db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid  cras_dsp_context_new_return = reinterpret_cast<cras_dsp_context *>(0xf00);
3782db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid  cras_dsp_get_pipeline_ret =  0xf01;
3792db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid  cras_dsp_num_input_channels_return = 10;
3802db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid  cras_dsp_num_output_channels_return = 2;
3812db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid  rc = cras_iodev_set_format(&iodev_, &fmt);
3822db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid  EXPECT_EQ(0, rc);
383bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.ext_format->format);
384bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(48000, iodev_.ext_format->frame_rate);
385bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(2, iodev_.ext_format->num_channels);
3862db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid}
3872db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid
388663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu ChaoTEST_F(IoDevSetFormatTestSuite, UpdateChannelLayoutSuccess) {
389663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao  struct cras_audio_format fmt;
390663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao  int rc;
391663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao
392663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao  fmt.format = SND_PCM_FORMAT_S16_LE;
393663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao  fmt.frame_rate = 48000;
394663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao  fmt.num_channels = 6;
395663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao
396663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao  iodev_.supported_channel_counts[0] = 6;
397663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao  iodev_.supported_channel_counts[1] = 2;
398663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao
399663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao  rc = cras_iodev_set_format(&iodev_, &fmt);
400663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao  EXPECT_EQ(0, rc);
401bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.ext_format->format);
402bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(48000, iodev_.ext_format->frame_rate);
403bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(6, iodev_.ext_format->num_channels);
404663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao}
405663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao
406663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu ChaoTEST_F(IoDevSetFormatTestSuite, UpdateChannelLayoutFail) {
407a8a86fe67e3cc98173c9bf4e219262a619c0670aHsin-Yu Chao  static const int8_t stereo_layout[] =
408a8a86fe67e3cc98173c9bf4e219262a619c0670aHsin-Yu Chao      {0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
409663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao  struct cras_audio_format fmt;
410a8a86fe67e3cc98173c9bf4e219262a619c0670aHsin-Yu Chao  int rc, i;
411663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao
412663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao  fmt.format = SND_PCM_FORMAT_S16_LE;
413663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao  fmt.frame_rate = 48000;
4141609667463605b64a0849f6ae7f26adf698cf5b3Ben Zhang  fmt.num_channels = 2;
415663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao
4165fa790469656d3e093799329f814756600762a71Dylan Reid  cras_dsp_context_new_return = reinterpret_cast<cras_dsp_context *>(0xf0f);
4175fa790469656d3e093799329f814756600762a71Dylan Reid
418663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao  update_channel_layout_return_val = -1;
419663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao  iodev_.supported_channel_counts[0] = 6;
420663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao  iodev_.supported_channel_counts[1] = 2;
421663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao
422663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao  rc = cras_iodev_set_format(&iodev_, &fmt);
423663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao  EXPECT_EQ(0, rc);
424bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.ext_format->format);
425bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(48000, iodev_.ext_format->frame_rate);
426bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(2, iodev_.ext_format->num_channels);
427bba7a4b0d07dbdc77f209025a032ce4c791e650aHsin-Yu Chao  EXPECT_EQ(2, cras_audio_format_set_channel_layout_called);
4285fa790469656d3e093799329f814756600762a71Dylan Reid  EXPECT_EQ(0, dsp_context_free_called);
429a8a86fe67e3cc98173c9bf4e219262a619c0670aHsin-Yu Chao  for (i = 0; i < CRAS_CH_MAX; i++)
430a8a86fe67e3cc98173c9bf4e219262a619c0670aHsin-Yu Chao    EXPECT_EQ(iodev_.format->channel_layout[i], stereo_layout[i]);
431663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao}
432663a962502c7587d464fe555e836c5d70e1c7194Hsin-Yu Chao
4331609667463605b64a0849f6ae7f26adf698cf5b3Ben ZhangTEST_F(IoDevSetFormatTestSuite, UpdateChannelLayoutFail6ch) {
4341609667463605b64a0849f6ae7f26adf698cf5b3Ben Zhang  static const int8_t default_6ch_layout[] =
4351609667463605b64a0849f6ae7f26adf698cf5b3Ben Zhang      {0, 1, 2, 3, 4, 5, -1, -1, -1, -1, -1};
4361609667463605b64a0849f6ae7f26adf698cf5b3Ben Zhang  struct cras_audio_format fmt;
4371609667463605b64a0849f6ae7f26adf698cf5b3Ben Zhang  int rc, i;
4381609667463605b64a0849f6ae7f26adf698cf5b3Ben Zhang
4391609667463605b64a0849f6ae7f26adf698cf5b3Ben Zhang  fmt.format = SND_PCM_FORMAT_S16_LE;
4401609667463605b64a0849f6ae7f26adf698cf5b3Ben Zhang  fmt.frame_rate = 48000;
4411609667463605b64a0849f6ae7f26adf698cf5b3Ben Zhang  fmt.num_channels = 6;
4421609667463605b64a0849f6ae7f26adf698cf5b3Ben Zhang
4431609667463605b64a0849f6ae7f26adf698cf5b3Ben Zhang  cras_dsp_context_new_return = reinterpret_cast<cras_dsp_context *>(0xf0f);
4441609667463605b64a0849f6ae7f26adf698cf5b3Ben Zhang
4451609667463605b64a0849f6ae7f26adf698cf5b3Ben Zhang  update_channel_layout_return_val = -1;
4461609667463605b64a0849f6ae7f26adf698cf5b3Ben Zhang  iodev_.supported_channel_counts[0] = 6;
4471609667463605b64a0849f6ae7f26adf698cf5b3Ben Zhang  iodev_.supported_channel_counts[1] = 2;
4481609667463605b64a0849f6ae7f26adf698cf5b3Ben Zhang
4491609667463605b64a0849f6ae7f26adf698cf5b3Ben Zhang  rc = cras_iodev_set_format(&iodev_, &fmt);
4501609667463605b64a0849f6ae7f26adf698cf5b3Ben Zhang  EXPECT_EQ(0, rc);
4511609667463605b64a0849f6ae7f26adf698cf5b3Ben Zhang  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.ext_format->format);
4521609667463605b64a0849f6ae7f26adf698cf5b3Ben Zhang  EXPECT_EQ(48000, iodev_.ext_format->frame_rate);
4531609667463605b64a0849f6ae7f26adf698cf5b3Ben Zhang  EXPECT_EQ(6, iodev_.ext_format->num_channels);
4541609667463605b64a0849f6ae7f26adf698cf5b3Ben Zhang  EXPECT_EQ(2, cras_audio_format_set_channel_layout_called);
4551609667463605b64a0849f6ae7f26adf698cf5b3Ben Zhang  EXPECT_EQ(0, dsp_context_free_called);
4561609667463605b64a0849f6ae7f26adf698cf5b3Ben Zhang  for (i = 0; i < CRAS_CH_MAX; i++)
4571609667463605b64a0849f6ae7f26adf698cf5b3Ben Zhang    EXPECT_EQ(iodev_.format->channel_layout[i], default_6ch_layout[i]);
4581609667463605b64a0849f6ae7f26adf698cf5b3Ben Zhang}
4591609667463605b64a0849f6ae7f26adf698cf5b3Ben Zhang
4601c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid// Put buffer tests
4611c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid
462cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiangstatic int get_buffer(cras_iodev* iodev, struct cras_audio_area** area,
463cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang               unsigned int* num) {
464cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  size_t sz = sizeof(*audio_area) + sizeof(struct cras_channel_area) * 2;
465cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang
466cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  audio_area = (cras_audio_area*)calloc(1, sz);
467cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  audio_area->frames = *num;
468cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  audio_area->num_channels = 2;
469cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  audio_area->channels[0].buf = audio_buffer;
470cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  channel_area_set_channel(&audio_area->channels[0], CRAS_CH_FL);
471cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  audio_area->channels[0].step_bytes = 4;
472cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  audio_area->channels[1].buf = audio_buffer + 2;
473cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  channel_area_set_channel(&audio_area->channels[1], CRAS_CH_FR);
474cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  audio_area->channels[1].step_bytes = 4;
475cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang
476cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  *area = audio_area;
477cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  return 0;
478cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang}
479cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang
4801c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reidstatic int put_buffer(struct cras_iodev *iodev, unsigned int nframes)
4811c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid{
4821c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  put_buffer_nframes = nframes;
483cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  if (audio_area) {
484cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang    free(audio_area);
485cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang    audio_area = NULL;
486cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  }
4871c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  return 0;
4881c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid}
4891c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid
490016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiangstatic int no_stream(struct cras_iodev *odev, int enable)
491016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang{
492016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  no_stream_called++;
493016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  no_stream_enable = enable;
494016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  // Use default no stream playback to test default behavior.
495016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  return cras_iodev_default_no_stream_playback(odev, enable);
496016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang}
497016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang
498016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiangstatic int output_should_wake(const struct cras_iodev *odev)
499016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang{
500016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  return output_should_wake_ret;
501016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang}
502016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang
50337048d8a04b223de7d47d9f049dcede7e5036066Dylan Reidstatic int pre_dsp_hook(const uint8_t *frames, unsigned int nframes,
504081f69891fbf2ebbdb6b74e6b9ff59cd23f3eea0Chinyue Chen			const struct cras_audio_format *fmt, void *cb_data)
50537048d8a04b223de7d47d9f049dcede7e5036066Dylan Reid{
50637048d8a04b223de7d47d9f049dcede7e5036066Dylan Reid  pre_dsp_hook_called++;
50737048d8a04b223de7d47d9f049dcede7e5036066Dylan Reid  pre_dsp_hook_frames = frames;
508081f69891fbf2ebbdb6b74e6b9ff59cd23f3eea0Chinyue Chen  pre_dsp_hook_cb_data = cb_data;
50937048d8a04b223de7d47d9f049dcede7e5036066Dylan Reid  return 0;
51037048d8a04b223de7d47d9f049dcede7e5036066Dylan Reid}
51137048d8a04b223de7d47d9f049dcede7e5036066Dylan Reid
51237048d8a04b223de7d47d9f049dcede7e5036066Dylan Reidstatic int post_dsp_hook(const uint8_t *frames, unsigned int nframes,
513081f69891fbf2ebbdb6b74e6b9ff59cd23f3eea0Chinyue Chen			 const struct cras_audio_format *fmt, void *cb_data)
51437048d8a04b223de7d47d9f049dcede7e5036066Dylan Reid{
51537048d8a04b223de7d47d9f049dcede7e5036066Dylan Reid  post_dsp_hook_called++;
51637048d8a04b223de7d47d9f049dcede7e5036066Dylan Reid  post_dsp_hook_frames = frames;
517081f69891fbf2ebbdb6b74e6b9ff59cd23f3eea0Chinyue Chen  post_dsp_hook_cb_data = cb_data;
51837048d8a04b223de7d47d9f049dcede7e5036066Dylan Reid  return 0;
51937048d8a04b223de7d47d9f049dcede7e5036066Dylan Reid}
52037048d8a04b223de7d47d9f049dcede7e5036066Dylan Reid
5211bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiangstatic int dev_running(const struct cras_iodev *iodev)
5221bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang{
5231bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  return dev_running_ret_value;
5241bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang}
5251bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang
5261c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan ReidTEST(IoDevPutOutputBuffer, SystemMuted) {
5271c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  struct cras_audio_format fmt;
5281c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  struct cras_iodev iodev;
5291c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  uint8_t *frames = reinterpret_cast<uint8_t*>(0x44);
5301c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  int rc;
5311c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid
5321c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  ResetStubData();
5331c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  memset(&iodev, 0, sizeof(iodev));
5341c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  cras_system_get_mute_return = 1;
5351c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid
5361c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  fmt.format = SND_PCM_FORMAT_S16_LE;
5371c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  fmt.frame_rate = 48000;
5381c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  fmt.num_channels = 2;
5391c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  iodev.format = &fmt;
5401c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  iodev.put_buffer = put_buffer;
5411c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid
5421c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  rc = cras_iodev_put_output_buffer(&iodev, frames, 20);
5431c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  EXPECT_EQ(0, rc);
5441c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  EXPECT_EQ(20, cras_mix_mute_count);
5451c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  EXPECT_EQ(20, put_buffer_nframes);
5461c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  EXPECT_EQ(20, rate_estimator_add_frames_num_frames);
5471c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid}
5481c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid
5491c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan ReidTEST(IoDevPutOutputBuffer, NoDSP) {
5501c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  struct cras_audio_format fmt;
5511c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  struct cras_iodev iodev;
5521c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  uint8_t *frames = reinterpret_cast<uint8_t*>(0x44);
5531c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  int rc;
5541c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid
5551c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  ResetStubData();
5561c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  memset(&iodev, 0, sizeof(iodev));
5571c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid
5581c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  fmt.format = SND_PCM_FORMAT_S16_LE;
5591c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  fmt.frame_rate = 48000;
5601c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  fmt.num_channels = 2;
5611c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  iodev.format = &fmt;
5621c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  iodev.put_buffer = put_buffer;
5631c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid
5641c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  rc = cras_iodev_put_output_buffer(&iodev, frames, 22);
5651c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  EXPECT_EQ(0, rc);
5661c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  EXPECT_EQ(0, cras_mix_mute_count);
5671c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  EXPECT_EQ(22, put_buffer_nframes);
5681c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  EXPECT_EQ(22, rate_estimator_add_frames_num_frames);
5691c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid}
5701c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid
5711c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan ReidTEST(IoDevPutOutputBuffer, DSP) {
5721c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  struct cras_audio_format fmt;
5731c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  struct cras_iodev iodev;
5741c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  uint8_t *frames = reinterpret_cast<uint8_t*>(0x44);
5751c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  int rc;
5761c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid
5771c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  ResetStubData();
5781c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  memset(&iodev, 0, sizeof(iodev));
5791c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  iodev.dsp_context = reinterpret_cast<cras_dsp_context*>(0x15);
5801c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  cras_dsp_get_pipeline_ret = 0x25;
5811c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid
5821c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  fmt.format = SND_PCM_FORMAT_S16_LE;
5831c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  fmt.frame_rate = 48000;
5841c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  fmt.num_channels = 2;
5851c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  iodev.format = &fmt;
5861c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  iodev.put_buffer = put_buffer;
587081f69891fbf2ebbdb6b74e6b9ff59cd23f3eea0Chinyue Chen  cras_iodev_register_pre_dsp_hook(&iodev, pre_dsp_hook, (void *)0x1234);
588081f69891fbf2ebbdb6b74e6b9ff59cd23f3eea0Chinyue Chen  cras_iodev_register_post_dsp_hook(&iodev, post_dsp_hook, (void *)0x5678);
5891c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid
5901c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  rc = cras_iodev_put_output_buffer(&iodev, frames, 32);
5911c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  EXPECT_EQ(0, rc);
5921c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  EXPECT_EQ(0, cras_mix_mute_count);
59337048d8a04b223de7d47d9f049dcede7e5036066Dylan Reid  EXPECT_EQ(1, pre_dsp_hook_called);
59437048d8a04b223de7d47d9f049dcede7e5036066Dylan Reid  EXPECT_EQ(frames, pre_dsp_hook_frames);
595081f69891fbf2ebbdb6b74e6b9ff59cd23f3eea0Chinyue Chen  EXPECT_EQ((void *)0x1234, pre_dsp_hook_cb_data);
59637048d8a04b223de7d47d9f049dcede7e5036066Dylan Reid  EXPECT_EQ(1, post_dsp_hook_called);
597081f69891fbf2ebbdb6b74e6b9ff59cd23f3eea0Chinyue Chen  EXPECT_EQ((void *)0x5678, post_dsp_hook_cb_data);
5981c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  EXPECT_EQ(32, put_buffer_nframes);
5991c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  EXPECT_EQ(32, rate_estimator_add_frames_num_frames);
6001c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  EXPECT_EQ(32, cras_dsp_pipeline_apply_sample_count);
6011c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  EXPECT_EQ(cras_dsp_get_pipeline_called, cras_dsp_put_pipeline_called);
6021c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid}
6031c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid
6041c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan ReidTEST(IoDevPutOutputBuffer, SoftVol) {
6051c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  struct cras_audio_format fmt;
6061c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  struct cras_iodev iodev;
6071c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  uint8_t *frames = reinterpret_cast<uint8_t*>(0x44);
6081c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  int rc;
6091c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid
6101c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  ResetStubData();
6111c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  memset(&iodev, 0, sizeof(iodev));
6121c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  iodev.software_volume_needed = 1;
6131c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid
6141c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  fmt.format = SND_PCM_FORMAT_S16_LE;
6151c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  fmt.frame_rate = 48000;
6161c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  fmt.num_channels = 2;
6171c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  iodev.format = &fmt;
6181c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  iodev.put_buffer = put_buffer;
6191c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid
6201c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  cras_system_get_volume_return = 13;
6211c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  softvol_scalers[13] = 0.435;
6221c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid
6231c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  rc = cras_iodev_put_output_buffer(&iodev, frames, 53);
6241c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  EXPECT_EQ(0, rc);
6251c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  EXPECT_EQ(0, cras_mix_mute_count);
6261c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  EXPECT_EQ(53, put_buffer_nframes);
6271c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  EXPECT_EQ(53, rate_estimator_add_frames_num_frames);
6281c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  EXPECT_EQ(softvol_scalers[13], cras_scale_buffer_scaler);
629249e72919eb928e107d251b262c305a8fe531641Dylan Reid  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, cras_scale_buffer_fmt);
630249e72919eb928e107d251b262c305a8fe531641Dylan Reid}
631249e72919eb928e107d251b262c305a8fe531641Dylan Reid
632249e72919eb928e107d251b262c305a8fe531641Dylan ReidTEST(IoDevPutOutputBuffer, Scale32Bit) {
633249e72919eb928e107d251b262c305a8fe531641Dylan Reid  struct cras_audio_format fmt;
634249e72919eb928e107d251b262c305a8fe531641Dylan Reid  struct cras_iodev iodev;
635249e72919eb928e107d251b262c305a8fe531641Dylan Reid  uint8_t *frames = reinterpret_cast<uint8_t*>(0x44);
636249e72919eb928e107d251b262c305a8fe531641Dylan Reid  int rc;
637249e72919eb928e107d251b262c305a8fe531641Dylan Reid
638249e72919eb928e107d251b262c305a8fe531641Dylan Reid  ResetStubData();
639249e72919eb928e107d251b262c305a8fe531641Dylan Reid  memset(&iodev, 0, sizeof(iodev));
640249e72919eb928e107d251b262c305a8fe531641Dylan Reid  iodev.software_volume_needed = 1;
641249e72919eb928e107d251b262c305a8fe531641Dylan Reid
642249e72919eb928e107d251b262c305a8fe531641Dylan Reid  cras_system_get_volume_return = 13;
643249e72919eb928e107d251b262c305a8fe531641Dylan Reid  softvol_scalers[13] = 0.435;
644249e72919eb928e107d251b262c305a8fe531641Dylan Reid
645249e72919eb928e107d251b262c305a8fe531641Dylan Reid  fmt.format = SND_PCM_FORMAT_S32_LE;
646249e72919eb928e107d251b262c305a8fe531641Dylan Reid  fmt.frame_rate = 48000;
647249e72919eb928e107d251b262c305a8fe531641Dylan Reid  fmt.num_channels = 2;
648249e72919eb928e107d251b262c305a8fe531641Dylan Reid  iodev.format = &fmt;
649249e72919eb928e107d251b262c305a8fe531641Dylan Reid  iodev.put_buffer = put_buffer;
650249e72919eb928e107d251b262c305a8fe531641Dylan Reid
651249e72919eb928e107d251b262c305a8fe531641Dylan Reid  rc = cras_iodev_put_output_buffer(&iodev, frames, 53);
652249e72919eb928e107d251b262c305a8fe531641Dylan Reid  EXPECT_EQ(0, rc);
653249e72919eb928e107d251b262c305a8fe531641Dylan Reid  EXPECT_EQ(0, cras_mix_mute_count);
654249e72919eb928e107d251b262c305a8fe531641Dylan Reid  EXPECT_EQ(53, put_buffer_nframes);
655249e72919eb928e107d251b262c305a8fe531641Dylan Reid  EXPECT_EQ(53, rate_estimator_add_frames_num_frames);
656249e72919eb928e107d251b262c305a8fe531641Dylan Reid  EXPECT_EQ(SND_PCM_FORMAT_S32_LE, cras_scale_buffer_fmt);
6571c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid}
6581c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid
659cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao// frames queued/avail tests
660cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao
661cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chaostatic unsigned fr_queued = 0;
662cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao
663cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chaostatic int frames_queued(const struct cras_iodev *iodev)
664cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao{
665cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  return fr_queued;
666cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao}
667cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao
668cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu ChaoTEST(IoDevQueuedBuffer, ZeroMinBufferLevel) {
669cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  struct cras_iodev iodev;
670cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  int rc;
671cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao
672cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  ResetStubData();
673cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  memset(&iodev, 0, sizeof(iodev));
674cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  iodev.direction = CRAS_STREAM_OUTPUT;
675cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  iodev.frames_queued = frames_queued;
676cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  iodev.min_buffer_level = 0;
677cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  iodev.buffer_size = 200;
678cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  fr_queued = 50;
679cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao
680cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  rc = cras_iodev_frames_queued(&iodev);
681cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  EXPECT_EQ(50, rc);
682cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  rc = cras_iodev_buffer_avail(&iodev, rc);
683cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  EXPECT_EQ(150, rc);
684cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao}
685cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao
686cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu ChaoTEST(IoDevQueuedBuffer, NonZeroMinBufferLevel) {
687cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  struct cras_iodev iodev;
688cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  int rc;
689cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao
690cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  ResetStubData();
691cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  memset(&iodev, 0, sizeof(iodev));
692cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  iodev.direction = CRAS_STREAM_OUTPUT;
693cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  iodev.frames_queued = frames_queued;
694cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  iodev.min_buffer_level = 100;
695cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  iodev.buffer_size = 200;
696cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  fr_queued = 180;
697cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao
698cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  rc = cras_iodev_frames_queued(&iodev);
699cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  EXPECT_EQ(80, rc);
700cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  rc = cras_iodev_buffer_avail(&iodev, rc);
701cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  EXPECT_EQ(20, rc);
702cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao
703cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  /* When fr_queued < min_buffer_level*/
704cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  fr_queued = 80;
705cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  rc = cras_iodev_frames_queued(&iodev);
706cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  EXPECT_EQ(0, rc);
707cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  rc = cras_iodev_buffer_avail(&iodev, rc);
708cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao  EXPECT_EQ(100, rc);
709cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao}
710cda2e426ddf2c20dddfdfa0e972a0963b3dc1d0bHsin-Yu Chao
711bb28140f38fdf6627ec26696c943dfa4f9188450Hsin-Yu Chaostatic void update_active_node(struct cras_iodev *iodev,
7120def72b968591065f56e88d67e5c83234184811bHsin-Yu Chao                               unsigned node_idx,
7130def72b968591065f56e88d67e5c83234184811bHsin-Yu Chao                               unsigned dev_enabled)
7146f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang{
7156f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang}
7166f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang
717b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reidstatic void dev_set_volume(struct cras_iodev *iodev)
718b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reid{
719b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reid}
720b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reid
721b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reidstatic void dev_set_capture_gain(struct cras_iodev *iodev)
722b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reid{
723b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reid}
724b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reid
725e53b58efa0e284527ed48cd429b6c87c18cfd0bfHsin-Yu ChaoTEST(IoNodePlug, PlugUnplugNode) {
7266f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang  struct cras_iodev iodev;
7273b90b36068e31abae3bd4a10ace86861c11c18b0Hsin-Yu Chao  struct cras_ionode ionode, ionode2;
7286f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang
729b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang  memset(&iodev, 0, sizeof(iodev));
730b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang  memset(&ionode, 0, sizeof(ionode));
7313b90b36068e31abae3bd4a10ace86861c11c18b0Hsin-Yu Chao  memset(&ionode2, 0, sizeof(ionode2));
7326f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang  iodev.direction = CRAS_STREAM_INPUT;
7336f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang  iodev.update_active_node = update_active_node;
7343b90b36068e31abae3bd4a10ace86861c11c18b0Hsin-Yu Chao  ionode.dev = &iodev;
7353b90b36068e31abae3bd4a10ace86861c11c18b0Hsin-Yu Chao  cras_iodev_add_node(&iodev, &ionode);
7363b90b36068e31abae3bd4a10ace86861c11c18b0Hsin-Yu Chao  ionode2.dev = &iodev;
7373b90b36068e31abae3bd4a10ace86861c11c18b0Hsin-Yu Chao  cras_iodev_add_node(&iodev, &ionode2);
7383b90b36068e31abae3bd4a10ace86861c11c18b0Hsin-Yu Chao  cras_iodev_set_active_node(&iodev, &ionode);
7396f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang  ResetStubData();
740786f9d1938966af8e1eb9f60559a3535b5c71ff8Chih-Chung Chang  cras_iodev_set_node_attr(&ionode, IONODE_ATTR_PLUGGED, 1);
741e53b58efa0e284527ed48cd429b6c87c18cfd0bfHsin-Yu Chao  EXPECT_EQ(0, cras_iodev_list_disable_dev_called);
742e53b58efa0e284527ed48cd429b6c87c18cfd0bfHsin-Yu Chao  cras_iodev_set_node_attr(&ionode, IONODE_ATTR_PLUGGED, 0);
743e53b58efa0e284527ed48cd429b6c87c18cfd0bfHsin-Yu Chao  EXPECT_EQ(1, cras_iodev_list_disable_dev_called);
7443b90b36068e31abae3bd4a10ace86861c11c18b0Hsin-Yu Chao
7453b90b36068e31abae3bd4a10ace86861c11c18b0Hsin-Yu Chao  /* Unplug non-active node shouldn't disable iodev. */
7463b90b36068e31abae3bd4a10ace86861c11c18b0Hsin-Yu Chao  cras_iodev_set_node_attr(&ionode2, IONODE_ATTR_PLUGGED, 1);
7473b90b36068e31abae3bd4a10ace86861c11c18b0Hsin-Yu Chao  EXPECT_EQ(1, cras_iodev_list_disable_dev_called);
7483b90b36068e31abae3bd4a10ace86861c11c18b0Hsin-Yu Chao  cras_iodev_set_node_attr(&ionode2, IONODE_ATTR_PLUGGED, 0);
7493b90b36068e31abae3bd4a10ace86861c11c18b0Hsin-Yu Chao  EXPECT_EQ(1, cras_iodev_list_disable_dev_called);
7506f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang}
7516f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang
752b2ad33424e21106930eb23db093746dc30926f27Chih-Chung ChangTEST(IoDev, AddRemoveNode) {
753b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang  struct cras_iodev iodev;
754b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang  struct cras_ionode ionode;
755b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang
756b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang  memset(&iodev, 0, sizeof(iodev));
757b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang  memset(&ionode, 0, sizeof(ionode));
758b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang  ResetStubData();
759b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang  EXPECT_EQ(0, notify_nodes_changed_called);
760b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang  cras_iodev_add_node(&iodev, &ionode);
761b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang  EXPECT_EQ(1, notify_nodes_changed_called);
762b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang  cras_iodev_rm_node(&iodev, &ionode);
763b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang  EXPECT_EQ(2, notify_nodes_changed_called);
764b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang}
765b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang
766c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung ChangTEST(IoDev, SetActiveNode) {
767c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Chang  struct cras_iodev iodev;
768c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Chang  struct cras_ionode ionode;
769c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Chang
770c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Chang  memset(&iodev, 0, sizeof(iodev));
771c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Chang  memset(&ionode, 0, sizeof(ionode));
772c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Chang  ResetStubData();
773c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Chang  EXPECT_EQ(0, notify_active_node_changed_called);
774c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Chang  cras_iodev_set_active_node(&iodev, &ionode);
775c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Chang  EXPECT_EQ(1, notify_active_node_changed_called);
776c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Chang}
777c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Chang
778b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan ReidTEST(IoDev, SetNodeVolume) {
779b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reid  struct cras_iodev iodev;
780b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reid  struct cras_ionode ionode;
781b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reid
782b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reid  memset(&iodev, 0, sizeof(iodev));
783b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reid  memset(&ionode, 0, sizeof(ionode));
784b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reid  iodev.set_volume = dev_set_volume;
785b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reid  iodev.set_capture_gain = dev_set_capture_gain;
786b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reid  ionode.dev = &iodev;
787b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reid  ResetStubData();
788b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reid  cras_iodev_set_node_attr(&ionode, IONODE_ATTR_VOLUME, 10);
789b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reid  EXPECT_EQ(1, notify_node_volume_called);
790b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reid  iodev.direction = CRAS_STREAM_INPUT;
791b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reid  cras_iodev_set_node_attr(&ionode, IONODE_ATTR_CAPTURE_GAIN, 10);
792b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reid  EXPECT_EQ(1, notify_node_capture_gain_called);
793b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reid}
794b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reid
7953285adee4a1cd81b2dbd22a60b15e5fd9bd33304Cheng-Yi ChiangTEST(IoDev, SetNodeSwapLeftRight) {
7963285adee4a1cd81b2dbd22a60b15e5fd9bd33304Cheng-Yi Chiang  struct cras_iodev iodev;
7973285adee4a1cd81b2dbd22a60b15e5fd9bd33304Cheng-Yi Chiang  struct cras_ionode ionode;
7983285adee4a1cd81b2dbd22a60b15e5fd9bd33304Cheng-Yi Chiang
7993285adee4a1cd81b2dbd22a60b15e5fd9bd33304Cheng-Yi Chiang  memset(&iodev, 0, sizeof(iodev));
8003285adee4a1cd81b2dbd22a60b15e5fd9bd33304Cheng-Yi Chiang  memset(&ionode, 0, sizeof(ionode));
8013285adee4a1cd81b2dbd22a60b15e5fd9bd33304Cheng-Yi Chiang  iodev.set_swap_mode_for_node = set_swap_mode_for_node;
8023285adee4a1cd81b2dbd22a60b15e5fd9bd33304Cheng-Yi Chiang  ionode.dev = &iodev;
8033285adee4a1cd81b2dbd22a60b15e5fd9bd33304Cheng-Yi Chiang  ResetStubData();
8043285adee4a1cd81b2dbd22a60b15e5fd9bd33304Cheng-Yi Chiang  cras_iodev_set_node_attr(&ionode, IONODE_ATTR_SWAP_LEFT_RIGHT, 1);
8053285adee4a1cd81b2dbd22a60b15e5fd9bd33304Cheng-Yi Chiang  EXPECT_EQ(1, set_swap_mode_for_node_called);
8063285adee4a1cd81b2dbd22a60b15e5fd9bd33304Cheng-Yi Chiang  EXPECT_EQ(1, set_swap_mode_for_node_enable);
8073285adee4a1cd81b2dbd22a60b15e5fd9bd33304Cheng-Yi Chiang  EXPECT_EQ(1, ionode.left_right_swapped);
8083ac00e542de73e404423161a412b04b64fe7d847Cheng-Yi Chiang  EXPECT_EQ(1, notify_node_left_right_swapped_called);
8093285adee4a1cd81b2dbd22a60b15e5fd9bd33304Cheng-Yi Chiang  cras_iodev_set_node_attr(&ionode, IONODE_ATTR_SWAP_LEFT_RIGHT, 0);
8103285adee4a1cd81b2dbd22a60b15e5fd9bd33304Cheng-Yi Chiang  EXPECT_EQ(2, set_swap_mode_for_node_called);
8113285adee4a1cd81b2dbd22a60b15e5fd9bd33304Cheng-Yi Chiang  EXPECT_EQ(0, set_swap_mode_for_node_enable);
8123285adee4a1cd81b2dbd22a60b15e5fd9bd33304Cheng-Yi Chiang  EXPECT_EQ(0, ionode.left_right_swapped);
8133ac00e542de73e404423161a412b04b64fe7d847Cheng-Yi Chiang  EXPECT_EQ(2, notify_node_left_right_swapped_called);
8143285adee4a1cd81b2dbd22a60b15e5fd9bd33304Cheng-Yi Chiang}
8153285adee4a1cd81b2dbd22a60b15e5fd9bd33304Cheng-Yi Chiang
8165342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang
8175342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang// Test software volume changes for default output.
8185342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi ChiangTEST(IoDev, SoftwareVolume) {
8195342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang  struct cras_iodev iodev;
8205342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang  struct cras_ionode ionode;
8215342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang
8225342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang  memset(&iodev, 0, sizeof(iodev));
8235342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang  memset(&ionode, 0, sizeof(ionode));
8245342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang  ResetStubData();
8255342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang
8265342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang  iodev.nodes = &ionode;
8275342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang  iodev.active_node = &ionode;
8285342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang  iodev.active_node->dev = &iodev;
8295342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang
8305342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang  iodev.active_node->volume = 100;
8315342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang  iodev.software_volume_needed = 0;
8325342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang
8335342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang
8345342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang  softvol_scalers[80] = 0.5;
8355342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang  softvol_scalers[70] = 0.3;
8365342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang
8375342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang  // Check that system volume changes software volume if needed.
8385342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang  cras_system_get_volume_return = 80;
8395342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang  // system_volume - 100 + node_volume = 80 - 100 + 100 = 80
8405342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang  EXPECT_FLOAT_EQ(0.5, cras_iodev_get_software_volume_scaler(&iodev));
8415342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang
8425342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang  // Check that node volume changes software volume if needed.
8435342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang  iodev.active_node->volume = 90;
8445342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang  // system_volume - 100 + node_volume = 80 - 100 + 90 = 70
8455342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang  EXPECT_FLOAT_EQ(0.3, cras_iodev_get_software_volume_scaler(&iodev));
8465342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang}
8475342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang
848034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang// Test software gain scaler.
849034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi ChiangTEST(IoDev, SoftwareGain) {
850034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang  struct cras_iodev iodev;
851034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang  struct cras_ionode ionode;
852034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang
853034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang  memset(&iodev, 0, sizeof(iodev));
854034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang  memset(&ionode, 0, sizeof(ionode));
855034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang  ResetStubData();
856034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang
857034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang  iodev.nodes = &ionode;
858034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang  iodev.active_node = &ionode;
859034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang  iodev.active_node->dev = &iodev;
860034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang
861034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang  ionode.capture_gain= 400;
862034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang  ionode.software_volume_needed = 1;
863034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang  ionode.max_software_gain = 3000;
864034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang
865034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang  // Check that system volume changes software volume if needed.
866034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang  cras_system_get_capture_gain_ret_value = 2000;
867034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang  // system_gain + node_gain = 2000 + 400  = 2400
868034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang  // 2400 dBm is 15.848931
869034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang  EXPECT_FLOAT_EQ(15.848931, cras_iodev_get_software_gain_scaler(&iodev));
870034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang  EXPECT_FLOAT_EQ(3000, cras_iodev_maximum_software_gain(&iodev));
871034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang
872034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang  // Software gain scaler should be 1.0 if software gain is not needed.
873034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang  ionode.software_volume_needed = 0;
874034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang  EXPECT_FLOAT_EQ(1.0, cras_iodev_get_software_gain_scaler(&iodev));
875034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang  EXPECT_FLOAT_EQ(0, cras_iodev_maximum_software_gain(&iodev));
876034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang}
877034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang
87824cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chaostatic int open_dev(struct cras_iodev *iodev) {
87924cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao  iodev->buffer_size = iodev_buffer_size;
88024cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao  return 0;
88124cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao}
88224cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao
883016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi ChiangTEST(IoDev, OpenDevice) {
884016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  struct cras_iodev iodev;
885016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang
886016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  memset(&iodev, 0, sizeof(iodev));
887016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  iodev.open_dev = open_dev;
888016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  ResetStubData();
889016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang
890016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  // Test that this flag is cleared after cras_iodev_open.
891016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  iodev.no_stream_state = 1;
892016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang
893016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  iodev_buffer_size = 1024;
894016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  cras_iodev_open(&iodev, 240);
895016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  EXPECT_EQ(0, iodev.max_cb_level);
896016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  EXPECT_EQ(240, iodev.min_cb_level);
897016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  EXPECT_EQ(0, iodev.no_stream_state);
898016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang}
899016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang
90024cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu ChaoTEST(IoDev, AddRmStream) {
90124cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao  struct cras_iodev iodev;
90224cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao  struct cras_rstream rstream1, rstream2;
90324cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao  struct dev_stream stream1, stream2;
90424cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao
90524cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao  memset(&iodev, 0, sizeof(iodev));
90624cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao  iodev.open_dev = open_dev;
90724cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao  rstream1.cb_threshold = 800;
90824cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao  stream1.stream = &rstream1;
90924cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao  rstream2.cb_threshold = 400;
91024cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao  stream2.stream = &rstream2;
91124cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao  ResetStubData();
91224cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao
91324cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao  iodev_buffer_size = 1024;
91424cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao  cras_iodev_open(&iodev, rstream1.cb_threshold);
91524cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao  EXPECT_EQ(0, iodev.max_cb_level);
91624cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao  EXPECT_EQ(512, iodev.min_cb_level);
91724cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao
91824cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao  /* min_cb_level should not exceed half the buffer size. */
91924cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao  cras_iodev_add_stream(&iodev, &stream1);
92024cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao  EXPECT_EQ(800, iodev.max_cb_level);
92124cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao  EXPECT_EQ(512, iodev.min_cb_level);
92224cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao
92324cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao  cras_iodev_add_stream(&iodev, &stream2);
92424cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao  EXPECT_EQ(800, iodev.max_cb_level);
92524cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao  EXPECT_EQ(400, iodev.min_cb_level);
92624cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao
92724cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao  cras_iodev_rm_stream(&iodev, &rstream1);
92824cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao  EXPECT_EQ(400, iodev.max_cb_level);
92924cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao  EXPECT_EQ(400, iodev.min_cb_level);
93024cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao
93124cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao  /* When all streams are removed, keep the last min_cb_level for draining. */
93224cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao  cras_iodev_rm_stream(&iodev, &rstream2);
93324cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao  EXPECT_EQ(0, iodev.max_cb_level);
93424cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao  EXPECT_EQ(400, iodev.min_cb_level);
93524cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao}
9365342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang
937e91895c69bef2515b60d6e4514a5f8e8c53cb36fCheng-Yi Chiangstatic int start(const struct cras_iodev *iodev) {
938e91895c69bef2515b60d6e4514a5f8e8c53cb36fCheng-Yi Chiang  return 0;
939e91895c69bef2515b60d6e4514a5f8e8c53cb36fCheng-Yi Chiang}
940e91895c69bef2515b60d6e4514a5f8e8c53cb36fCheng-Yi Chiang
941e91895c69bef2515b60d6e4514a5f8e8c53cb36fCheng-Yi Chiangstatic int is_open(const struct cras_iodev *iodev) {
942e91895c69bef2515b60d6e4514a5f8e8c53cb36fCheng-Yi Chiang  return is_open_ret;
943e91895c69bef2515b60d6e4514a5f8e8c53cb36fCheng-Yi Chiang}
944e91895c69bef2515b60d6e4514a5f8e8c53cb36fCheng-Yi Chiang
945e91895c69bef2515b60d6e4514a5f8e8c53cb36fCheng-Yi ChiangTEST(IoDev, StartDevice) {
946e91895c69bef2515b60d6e4514a5f8e8c53cb36fCheng-Yi Chiang  struct cras_iodev iodev;
947e91895c69bef2515b60d6e4514a5f8e8c53cb36fCheng-Yi Chiang
948e91895c69bef2515b60d6e4514a5f8e8c53cb36fCheng-Yi Chiang  memset(&iodev, 0, sizeof(iodev));
949e91895c69bef2515b60d6e4514a5f8e8c53cb36fCheng-Yi Chiang  iodev.is_open = is_open;
950e91895c69bef2515b60d6e4514a5f8e8c53cb36fCheng-Yi Chiang  iodev.start = start;
951e91895c69bef2515b60d6e4514a5f8e8c53cb36fCheng-Yi Chiang
952e91895c69bef2515b60d6e4514a5f8e8c53cb36fCheng-Yi Chiang  // Start fails if it is called in closed state.
953e91895c69bef2515b60d6e4514a5f8e8c53cb36fCheng-Yi Chiang  is_open_ret = 0;
954e91895c69bef2515b60d6e4514a5f8e8c53cb36fCheng-Yi Chiang  ASSERT_TRUE(cras_iodev_start(&iodev));
955e91895c69bef2515b60d6e4514a5f8e8c53cb36fCheng-Yi Chiang
956e91895c69bef2515b60d6e4514a5f8e8c53cb36fCheng-Yi Chiang  // Start can only be called in open state.
957e91895c69bef2515b60d6e4514a5f8e8c53cb36fCheng-Yi Chiang  is_open_ret = 1;
958e91895c69bef2515b60d6e4514a5f8e8c53cb36fCheng-Yi Chiang  EXPECT_EQ(0, cras_iodev_start(&iodev));
959e91895c69bef2515b60d6e4514a5f8e8c53cb36fCheng-Yi Chiang}
960e91895c69bef2515b60d6e4514a5f8e8c53cb36fCheng-Yi Chiang
961cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi ChiangTEST(IoDev, FillZeros) {
962cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  struct cras_iodev iodev;
963cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  struct cras_audio_format fmt;
964cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  unsigned int frames = 50;
965cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  int16_t *zeros;
966cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  int rc;
967cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang
968cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  ResetStubData();
969cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang
970cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  memset(&iodev, 0, sizeof(iodev));
971cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  fmt.format = SND_PCM_FORMAT_S16_LE;
972cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  fmt.frame_rate = 48000;
973cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  fmt.num_channels = 2;
974cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  iodev.ext_format = &fmt;
975cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  iodev.get_buffer = get_buffer;
976cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  iodev.put_buffer = put_buffer;
977cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang
978cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  iodev.direction = CRAS_STREAM_INPUT;
979cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  rc = cras_iodev_fill_odev_zeros(&iodev, frames);
980cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  EXPECT_EQ(-EINVAL, rc);
981cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang
982cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  iodev.direction = CRAS_STREAM_OUTPUT;
983cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  rc = cras_iodev_fill_odev_zeros(&iodev, frames);
984cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang
985cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  EXPECT_EQ(0, rc);
986cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  EXPECT_EQ(frames, put_buffer_nframes);
987cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  zeros = (int16_t *)calloc(frames * 2, sizeof(*zeros));
988cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  rc = memcmp(audio_buffer, zeros, frames * 2 * 2);
989cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  free(zeros);
990cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang  EXPECT_EQ(0, rc);
991cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang}
992cb9882489e765b30ee5318689b51f86648dfd5afCheng-Yi Chiang
9931bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi ChiangTEST(IoDev, NoStreamPlaybackNotRunning) {
9941bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  struct cras_iodev iodev;
9951bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  int rc;
9961bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang
9971bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  memset(&iodev, 0, sizeof(iodev));
9981bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang
9991bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  ResetStubData();
10001bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang
10011bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  iodev.dev_running = dev_running;
10021bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang
10031bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  // Device is not running. No need to fill zeros.
1004016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  rc = cras_iodev_no_stream_playback(&iodev, 1);
10051bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  EXPECT_EQ(0, rc);
10061bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  EXPECT_EQ(0, put_buffer_nframes);
10071bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang}
10081bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang
10091bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi ChiangTEST(IoDev, NoStreamPlaybackRunning) {
10101bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  struct cras_iodev iodev;
10111bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  struct cras_audio_format fmt;
10121bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  unsigned int hw_level = 50;
10131bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  unsigned int min_cb_level = 240;
10141bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  unsigned int zeros_to_fill;
10151bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  int16_t *zeros;
10161bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  int rc;
10171bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang
10181bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  memset(&iodev, 0, sizeof(iodev));
10191bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang
10201bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  fmt.format = SND_PCM_FORMAT_S16_LE;
10211bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  fmt.frame_rate = 48000;
10221bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  fmt.num_channels = 2;
10231bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  iodev.ext_format = &fmt;
10241bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  iodev.min_cb_level = min_cb_level;
10251bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  iodev.get_buffer = get_buffer;
10261bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  iodev.put_buffer = put_buffer;
10271bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  iodev.dev_running = dev_running;
10281bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  iodev.frames_queued = frames_queued;
10291bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  iodev.min_buffer_level = 0;
10301bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  iodev.direction = CRAS_STREAM_OUTPUT;
10311bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  iodev.buffer_size = BUFFER_SIZE;
1032016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  iodev.no_stream = no_stream;
1033016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang
1034016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  ResetStubData();
10351bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang
10361bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  // Device is running. hw_level is less than target.
10371bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  // Need to fill to callback level * 2;
10381bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  dev_running_ret_value = 1;
10391bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  fr_queued = hw_level;
10401bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  zeros_to_fill = min_cb_level * 2 - hw_level;
10411bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang
1042016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  rc = cras_iodev_no_stream_playback(&iodev, 1);
10431bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang
10441bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  EXPECT_EQ(0, rc);
1045016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  EXPECT_EQ(1, no_stream_called);
1046016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  EXPECT_EQ(1, no_stream_enable);
1047016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  EXPECT_EQ(1, iodev.no_stream_state);
10481bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  EXPECT_EQ(zeros_to_fill, put_buffer_nframes);
10491bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  zeros = (int16_t *)calloc(zeros_to_fill * 2, sizeof(*zeros));
10501bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  EXPECT_EQ(0, memcmp(audio_buffer, zeros, zeros_to_fill * 2 * 2));
10511bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  free(zeros);
10521bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang
10531bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  ResetStubData();
10541bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang
10551bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  // Device is running. hw_level is not less than target.
10561bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  // No need to fill zeros.
10571bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  dev_running_ret_value = 1;
10581bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  hw_level = min_cb_level * 2;
10591bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  fr_queued = hw_level;
10601bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  zeros_to_fill = 0;
10611bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang
1062016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  rc = cras_iodev_no_stream_playback(&iodev, 1);
10631bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  EXPECT_EQ(0, rc);
1064016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  EXPECT_EQ(1, no_stream_called);
1065016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  EXPECT_EQ(1, no_stream_enable);
1066016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  EXPECT_EQ(1, iodev.no_stream_state);
10671bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang  EXPECT_EQ(zeros_to_fill, put_buffer_nframes);
1068016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang
1069016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  ResetStubData();
1070016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang
1071016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  // Device is running. Resume normal playback.
1072016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  dev_running_ret_value = 1;
1073016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  rc = cras_iodev_no_stream_playback(&iodev, 0);
1074016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  EXPECT_EQ(0, rc);
1075016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  EXPECT_EQ(1, no_stream_called);
1076016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  EXPECT_EQ(0, no_stream_enable);
1077016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  EXPECT_EQ(0, iodev.no_stream_state);
10781bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang}
10791bb02937ca9072624d74ff1032b63dc2e17a2229Cheng-Yi Chiang
1080103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi ChiangTEST(IoDev, OutputDeviceShouldWake) {
1081103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  struct cras_iodev iodev;
1082103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  int rc;
1083103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang
1084103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  memset(&iodev, 0, sizeof(iodev));
1085103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  iodev.dev_running = dev_running;
1086103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang
1087103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  ResetStubData();
1088103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang
1089103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  // Device is not running. No need to wake for this device.
1090103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  dev_running_ret_value = 0;
1091103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  rc = cras_iodev_odev_should_wake(&iodev);
1092103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  EXPECT_EQ(0, rc);
1093103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang
1094103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  // Device is running. Need to wake for this device.
1095103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  dev_running_ret_value = 1;
1096103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  rc = cras_iodev_odev_should_wake(&iodev);
1097103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  EXPECT_EQ(1, rc);
1098103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang
1099016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  // Device is running. Device has output_should_wake ops.
1100016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  iodev.output_should_wake = output_should_wake;
1101016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  output_should_wake_ret = 0;
1102016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  rc = cras_iodev_odev_should_wake(&iodev);
1103016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  EXPECT_EQ(0, rc);
1104016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang
1105016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  // Device is running. Device has output_should_wake ops.
1106016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  output_should_wake_ret = 1;
1107016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  rc = cras_iodev_odev_should_wake(&iodev);
1108016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang  EXPECT_EQ(1, rc);
1109016277914b2ab40298e86145a25f8cb3cd22b790Cheng-Yi Chiang
1110103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  // Ignore input device.
1111103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  iodev.direction = CRAS_STREAM_INPUT;
1112103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  rc = cras_iodev_odev_should_wake(&iodev);
1113103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  EXPECT_EQ(0, rc);
1114103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang}
1115103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang
1116103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi ChiangTEST(IoDev, FramesToPlayInSleep) {
1117103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  struct cras_iodev iodev;
1118103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  unsigned int min_cb_level = 240, hw_level;
1119103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  unsigned int got_hw_level, got_frames;
1120103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang
1121103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  memset(&iodev, 0, sizeof(iodev));
1122103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  iodev.dev_running = dev_running;
1123103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  iodev.frames_queued = frames_queued;
1124103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  iodev.min_buffer_level = 0;
1125103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  iodev.direction = CRAS_STREAM_OUTPUT;
1126103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  iodev.buffer_size = BUFFER_SIZE;
1127103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  iodev.min_cb_level = min_cb_level;
1128103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang
1129103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  ResetStubData();
1130103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang
1131103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  // Device is running. There is at least one stream for this device.
1132103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  // hw_level is greater than min_cb_level.
1133103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  dev_running_ret_value = 1;
1134103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  hw_level = min_cb_level + 50;
1135103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  fr_queued = hw_level;
1136103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  iodev.streams = reinterpret_cast<struct dev_stream *>(0x1);
1137103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang
1138103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  got_frames = cras_iodev_frames_to_play_in_sleep(&iodev, &got_hw_level);
1139103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  EXPECT_EQ(hw_level, got_hw_level);
1140103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  EXPECT_EQ(hw_level, got_frames);
1141103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang
1142103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  // Device is running. There is no stream for this device.
1143103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  // hw_level is greater than min_cb_level.
1144103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  iodev.streams = NULL;
1145103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang
1146103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  got_frames = cras_iodev_frames_to_play_in_sleep(&iodev, &got_hw_level);
1147103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  EXPECT_EQ(hw_level, got_hw_level);
1148103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  EXPECT_EQ(hw_level - min_cb_level, got_frames);
1149103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang
1150103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  // Device is running. There is no stream for this device.
1151103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  // hw_level is less than min_cb_level.
1152103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  iodev.streams = NULL;
1153103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  hw_level = min_cb_level - 50;
1154103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  fr_queued = hw_level;
1155103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang
1156103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  got_frames = cras_iodev_frames_to_play_in_sleep(&iodev, &got_hw_level);
1157103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  EXPECT_EQ(hw_level, got_hw_level);
1158103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang  EXPECT_EQ(0, got_frames);
1159103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang}
1160103c80cc42d08844f1918e6e394531cb86d94254Cheng-Yi Chiang
1161838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reidextern "C" {
1162838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
1163838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid//  From libpthread.
1164838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reidint pthread_create(pthread_t *thread, const pthread_attr_t *attr,
1165838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid                   void *(*start_routine)(void*), void *arg) {
1166838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  return 0;
1167838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid}
1168838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
1169838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reidint pthread_join(pthread_t thread, void **value_ptr) {
1170838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  return 0;
1171838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid}
1172838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
1173f4d68a96948ce913348cc35ba34d9202014a9bdbHsin-Yu Chao// From audio_thread
1174f4d68a96948ce913348cc35ba34d9202014a9bdbHsin-Yu Chaostruct cras_fmt_conv *audio_thread_get_global_remix_converter()
1175f4d68a96948ce913348cc35ba34d9202014a9bdbHsin-Yu Chao{
1176f4d68a96948ce913348cc35ba34d9202014a9bdbHsin-Yu Chao  return NULL;
1177f4d68a96948ce913348cc35ba34d9202014a9bdbHsin-Yu Chao}
1178f4d68a96948ce913348cc35ba34d9202014a9bdbHsin-Yu Chao
1179f4d68a96948ce913348cc35ba34d9202014a9bdbHsin-Yu Chao// Fromt fmt_conv
1180f4d68a96948ce913348cc35ba34d9202014a9bdbHsin-Yu Chaovoid cras_channel_remix_convert(struct cras_fmt_conv *conv,
1181f4d68a96948ce913348cc35ba34d9202014a9bdbHsin-Yu Chao    uint8_t *in_buf,
1182f4d68a96948ce913348cc35ba34d9202014a9bdbHsin-Yu Chao    size_t frames)
1183f4d68a96948ce913348cc35ba34d9202014a9bdbHsin-Yu Chao{
1184f4d68a96948ce913348cc35ba34d9202014a9bdbHsin-Yu Chao}
1185f4d68a96948ce913348cc35ba34d9202014a9bdbHsin-Yu Chao
1186fd73a24e3fcb3de2efdf8fd0091b104c69fd62f4Dylan Reid// From buffer_share
1187fd73a24e3fcb3de2efdf8fd0091b104c69fd62f4Dylan Reidstruct buffer_share *buffer_share_create(unsigned int buf_sz) {
1188fd73a24e3fcb3de2efdf8fd0091b104c69fd62f4Dylan Reid  return NULL;
1189fd73a24e3fcb3de2efdf8fd0091b104c69fd62f4Dylan Reid}
1190fd73a24e3fcb3de2efdf8fd0091b104c69fd62f4Dylan Reid
1191fd73a24e3fcb3de2efdf8fd0091b104c69fd62f4Dylan Reidvoid buffer_share_destroy(struct buffer_share *mix)
1192fd73a24e3fcb3de2efdf8fd0091b104c69fd62f4Dylan Reid{
1193fd73a24e3fcb3de2efdf8fd0091b104c69fd62f4Dylan Reid}
1194fd73a24e3fcb3de2efdf8fd0091b104c69fd62f4Dylan Reid
1195fd73a24e3fcb3de2efdf8fd0091b104c69fd62f4Dylan Reidint buffer_share_offset_update(struct buffer_share *mix, unsigned int id,
1196fd73a24e3fcb3de2efdf8fd0091b104c69fd62f4Dylan Reid                               unsigned int frames) {
1197fd73a24e3fcb3de2efdf8fd0091b104c69fd62f4Dylan Reid  return 0;
1198fd73a24e3fcb3de2efdf8fd0091b104c69fd62f4Dylan Reid}
1199fd73a24e3fcb3de2efdf8fd0091b104c69fd62f4Dylan Reid
1200fd73a24e3fcb3de2efdf8fd0091b104c69fd62f4Dylan Reidunsigned int buffer_share_get_new_write_point(struct buffer_share *mix) {
1201fd73a24e3fcb3de2efdf8fd0091b104c69fd62f4Dylan Reid  return 0;
1202fd73a24e3fcb3de2efdf8fd0091b104c69fd62f4Dylan Reid}
1203fd73a24e3fcb3de2efdf8fd0091b104c69fd62f4Dylan Reid
1204fd73a24e3fcb3de2efdf8fd0091b104c69fd62f4Dylan Reidint buffer_share_add_id(struct buffer_share *mix, unsigned int id) {
1205fd73a24e3fcb3de2efdf8fd0091b104c69fd62f4Dylan Reid  return 0;
1206fd73a24e3fcb3de2efdf8fd0091b104c69fd62f4Dylan Reid}
1207fd73a24e3fcb3de2efdf8fd0091b104c69fd62f4Dylan Reid
1208fd73a24e3fcb3de2efdf8fd0091b104c69fd62f4Dylan Reidint buffer_share_rm_id(struct buffer_share *mix, unsigned int id) {
1209fd73a24e3fcb3de2efdf8fd0091b104c69fd62f4Dylan Reid  return 0;
1210fd73a24e3fcb3de2efdf8fd0091b104c69fd62f4Dylan Reid}
1211fd73a24e3fcb3de2efdf8fd0091b104c69fd62f4Dylan Reid
1212fd73a24e3fcb3de2efdf8fd0091b104c69fd62f4Dylan Reidunsigned int buffer_share_id_offset(const struct buffer_share *mix,
1213fd73a24e3fcb3de2efdf8fd0091b104c69fd62f4Dylan Reid                                    unsigned int id)
1214fd73a24e3fcb3de2efdf8fd0091b104c69fd62f4Dylan Reid{
1215fd73a24e3fcb3de2efdf8fd0091b104c69fd62f4Dylan Reid  return 0;
1216fd73a24e3fcb3de2efdf8fd0091b104c69fd62f4Dylan Reid}
1217fd73a24e3fcb3de2efdf8fd0091b104c69fd62f4Dylan Reid
1218386ab71e324831d632544f8bcecc8d0ba1890f01Dylan Reid// From cras_system_state.
121957852ea82d5f4c4491f4cfe9faafc5cbddfc4979Cheng-Yi Chiangvoid cras_system_state_stream_added(enum CRAS_STREAM_DIRECTION direction) {
1220386ab71e324831d632544f8bcecc8d0ba1890f01Dylan Reid}
1221386ab71e324831d632544f8bcecc8d0ba1890f01Dylan Reid
122257852ea82d5f4c4491f4cfe9faafc5cbddfc4979Cheng-Yi Chiangvoid cras_system_state_stream_removed(enum CRAS_STREAM_DIRECTION direction) {
1223386ab71e324831d632544f8bcecc8d0ba1890f01Dylan Reid}
1224386ab71e324831d632544f8bcecc8d0ba1890f01Dylan Reid
12255b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Chang// From cras_dsp
1226aa66420d69c297eec83e1b5a17b0b2cf06cddfd5Dylan Reidstruct cras_dsp_context *cras_dsp_context_new(int sample_rate,
12275b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Chang                                              const char *purpose)
12285b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Chang{
1229ccff36a4576d4810784f0b0ae5fe32a5fbcbe3c4Chih-Chung Chang  dsp_context_new_sample_rate = sample_rate;
1230ccff36a4576d4810784f0b0ae5fe32a5fbcbe3c4Chih-Chung Chang  dsp_context_new_purpose = purpose;
12312db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid  return cras_dsp_context_new_return;
12325b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Chang}
12335b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Chang
12345b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Changvoid cras_dsp_context_free(struct cras_dsp_context *ctx)
12355b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Chang{
12365fa790469656d3e093799329f814756600762a71Dylan Reid  dsp_context_free_called++;
12375b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Chang}
12385b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Chang
12395b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Changvoid cras_dsp_load_pipeline(struct cras_dsp_context *ctx)
12405b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Chang{
12415b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Chang}
12425b1717f92baa7ab7006e04431bd6b33a24d8a23fChih-Chung Chang
12437057df0d12f641d9bd9aad64d3aa09127a4e84a3Chih-Chung Changvoid cras_dsp_set_variable(struct cras_dsp_context *ctx, const char *key,
12447057df0d12f641d9bd9aad64d3aa09127a4e84a3Chih-Chung Chang                           const char *value)
12457057df0d12f641d9bd9aad64d3aa09127a4e84a3Chih-Chung Chang{
12467057df0d12f641d9bd9aad64d3aa09127a4e84a3Chih-Chung Chang}
12477057df0d12f641d9bd9aad64d3aa09127a4e84a3Chih-Chung Chang
1248d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reidstruct pipeline *cras_dsp_get_pipeline(struct cras_dsp_context *ctx)
1249d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid{
1250d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid  cras_dsp_get_pipeline_called++;
1251d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid  return reinterpret_cast<struct pipeline *>(cras_dsp_get_pipeline_ret);
1252d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid}
1253d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid
1254d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reidvoid cras_dsp_put_pipeline(struct cras_dsp_context *ctx)
1255d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid{
1256d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid  cras_dsp_put_pipeline_called++;
1257d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid}
1258d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid
1259d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reidfloat *cras_dsp_pipeline_get_source_buffer(struct pipeline *pipeline,
1260d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid					   int index)
1261d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid{
1262d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid  cras_dsp_pipeline_get_source_buffer_called++;
1263d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid  return cras_dsp_pipeline_source_buffer[index];
1264d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid}
1265d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid
1266d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reidfloat *cras_dsp_pipeline_get_sink_buffer(struct pipeline *pipeline, int index)
1267d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid{
1268d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid  cras_dsp_pipeline_get_sink_buffer_called++;
1269d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid  return cras_dsp_pipeline_sink_buffer[index];
1270d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid}
1271d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid
1272d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reidint cras_dsp_pipeline_get_delay(struct pipeline *pipeline)
1273d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid{
1274d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid  cras_dsp_pipeline_get_delay_called++;
1275d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid  return 0;
1276d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid}
1277d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid
1278aa66420d69c297eec83e1b5a17b0b2cf06cddfd5Dylan Reidvoid cras_dsp_pipeline_apply(struct pipeline *pipeline,
1279d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid			     uint8_t *buf, unsigned int frames)
1280d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid{
1281d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid  cras_dsp_pipeline_apply_called++;
1282d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid  cras_dsp_pipeline_apply_sample_count = frames;
1283d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid}
1284d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid
1285d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reidvoid cras_dsp_pipeline_add_statistic(struct pipeline *pipeline,
1286d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid                                     const struct timespec *time_delta,
1287d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid                                     int samples)
1288d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid{
1289d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid}
1290d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid
1291aa66420d69c297eec83e1b5a17b0b2cf06cddfd5Dylan Reidunsigned int cras_dsp_num_output_channels(const struct cras_dsp_context *ctx)
1292aa66420d69c297eec83e1b5a17b0b2cf06cddfd5Dylan Reid{
12932db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid	return cras_dsp_num_output_channels_return;
1294aa66420d69c297eec83e1b5a17b0b2cf06cddfd5Dylan Reid}
1295aa66420d69c297eec83e1b5a17b0b2cf06cddfd5Dylan Reid
1296aa66420d69c297eec83e1b5a17b0b2cf06cddfd5Dylan Reidunsigned int cras_dsp_num_input_channels(const struct cras_dsp_context *ctx)
1297aa66420d69c297eec83e1b5a17b0b2cf06cddfd5Dylan Reid{
12982db05743bb5c0c626b49ea19f3b759c0351e98d7Dylan Reid	return cras_dsp_num_input_channels_return;
1299aa66420d69c297eec83e1b5a17b0b2cf06cddfd5Dylan Reid}
1300aa66420d69c297eec83e1b5a17b0b2cf06cddfd5Dylan Reid
1301d6957a4d295e22b427af40ff4dd29c4d14514d7fDylan Reid// From audio thread
1302d6957a4d295e22b427af40ff4dd29c4d14514d7fDylan Reidint audio_thread_post_message(struct audio_thread *thread,
1303d6957a4d295e22b427af40ff4dd29c4d14514d7fDylan Reid                              struct audio_thread_msg *msg) {
1304d6957a4d295e22b427af40ff4dd29c4d14514d7fDylan Reid  return 0;
1305d6957a4d295e22b427af40ff4dd29c4d14514d7fDylan Reid}
1306d6957a4d295e22b427af40ff4dd29c4d14514d7fDylan Reid
1307ea1b78a018d72fd22f5ce5650121f5e4b8325a1dChih-Chung Changvoid cras_iodev_list_select_node(enum CRAS_STREAM_DIRECTION direction,
1308ea1b78a018d72fd22f5ce5650121f5e4b8325a1dChih-Chung Chang                                 cras_node_id_t node_id)
1309f1a7e0c094f29c16f6aa9f97d328a93769e69e5cChih-Chung Chang{
1310ea1b78a018d72fd22f5ce5650121f5e4b8325a1dChih-Chung Chang  select_node_called++;
1311ea1b78a018d72fd22f5ce5650121f5e4b8325a1dChih-Chung Chang  select_node_direction = direction;
1312ea1b78a018d72fd22f5ce5650121f5e4b8325a1dChih-Chung Chang  select_node_id = node_id;
1313f1a7e0c094f29c16f6aa9f97d328a93769e69e5cChih-Chung Chang}
1314f1a7e0c094f29c16f6aa9f97d328a93769e69e5cChih-Chung Chang
1315ea1b78a018d72fd22f5ce5650121f5e4b8325a1dChih-Chung Changint cras_iodev_list_node_selected(struct cras_ionode *node)
13166f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang{
1317ea1b78a018d72fd22f5ce5650121f5e4b8325a1dChih-Chung Chang  return node == node_selected;
13186f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang}
13196f0a5e6a967558105f37513801af573167890f67Chih-Chung Chang
1320e53b58efa0e284527ed48cd429b6c87c18cfd0bfHsin-Yu Chaovoid cras_iodev_list_disable_dev(struct cras_iodev *dev)
1321e53b58efa0e284527ed48cd429b6c87c18cfd0bfHsin-Yu Chao{
1322e53b58efa0e284527ed48cd429b6c87c18cfd0bfHsin-Yu Chao  cras_iodev_list_disable_dev_called++;
1323e53b58efa0e284527ed48cd429b6c87c18cfd0bfHsin-Yu Chao}
1324e53b58efa0e284527ed48cd429b6c87c18cfd0bfHsin-Yu Chao
1325b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Changvoid cras_iodev_list_notify_nodes_changed()
1326b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang{
1327b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang  notify_nodes_changed_called++;
1328b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang}
1329b2ad33424e21106930eb23db093746dc30926f27Chih-Chung Chang
1330dc115f02e335a6d197b6ef4bf0516e4866a7fc6eDylan Reidvoid cras_iodev_list_notify_active_node_changed(
1331dc115f02e335a6d197b6ef4bf0516e4866a7fc6eDylan Reid				enum CRAS_STREAM_DIRECTION direction)
1332c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Chang{
1333c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Chang  notify_active_node_changed_called++;
1334c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Chang}
1335c732e27a905ddce9ccb4507bec7431b6406fdda4Chih-Chung Chang
1336b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reidvoid cras_iodev_list_notify_node_volume(struct cras_ionode *node)
1337b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reid{
1338b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reid	notify_node_volume_called++;
1339b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reid}
1340b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reid
1341b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reidvoid cras_iodev_list_notify_node_capture_gain(struct cras_ionode *node)
1342b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reid{
1343b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reid	notify_node_capture_gain_called++;
1344b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reid}
1345b6670c0295704e171c518e7ae9fd9a2c6f88f535Dylan Reid
13463ac00e542de73e404423161a412b04b64fe7d847Cheng-Yi Chiangvoid cras_iodev_list_notify_node_left_right_swapped(struct cras_ionode *node)
13473ac00e542de73e404423161a412b04b64fe7d847Cheng-Yi Chiang{
13483ac00e542de73e404423161a412b04b64fe7d847Cheng-Yi Chiang  notify_node_left_right_swapped_called++;
13493ac00e542de73e404423161a412b04b64fe7d847Cheng-Yi Chiang}
13503ac00e542de73e404423161a412b04b64fe7d847Cheng-Yi Chiang
13519690a3281b7167e5a38368fd8db39375bea8a1f8Hsin-Yu Chaostruct cras_audio_area *cras_audio_area_create(int num_channels) {
13529690a3281b7167e5a38368fd8db39375bea8a1f8Hsin-Yu Chao	return NULL;
13539690a3281b7167e5a38368fd8db39375bea8a1f8Hsin-Yu Chao}
13549690a3281b7167e5a38368fd8db39375bea8a1f8Hsin-Yu Chao
13559690a3281b7167e5a38368fd8db39375bea8a1f8Hsin-Yu Chaovoid cras_audio_area_destroy(struct cras_audio_area *area) {
13569690a3281b7167e5a38368fd8db39375bea8a1f8Hsin-Yu Chao}
13579690a3281b7167e5a38368fd8db39375bea8a1f8Hsin-Yu Chao
13589690a3281b7167e5a38368fd8db39375bea8a1f8Hsin-Yu Chaovoid cras_audio_area_config_channels(struct cras_audio_area *area,
13599690a3281b7167e5a38368fd8db39375bea8a1f8Hsin-Yu Chao                                     const struct cras_audio_format *fmt) {
13609690a3281b7167e5a38368fd8db39375bea8a1f8Hsin-Yu Chao}
13619690a3281b7167e5a38368fd8db39375bea8a1f8Hsin-Yu Chao
13627b7d64a58cdc405c76b7df32c8042050b9c8bf4aHsin-Yu Chaoint cras_audio_format_set_channel_layout(struct cras_audio_format *format,
13637b7d64a58cdc405c76b7df32c8042050b9c8bf4aHsin-Yu Chao					 const int8_t layout[CRAS_CH_MAX])
13647b7d64a58cdc405c76b7df32c8042050b9c8bf4aHsin-Yu Chao{
1365a8a86fe67e3cc98173c9bf4e219262a619c0670aHsin-Yu Chao  int i;
1366a8a86fe67e3cc98173c9bf4e219262a619c0670aHsin-Yu Chao  cras_audio_format_set_channel_layout_called++;
1367a8a86fe67e3cc98173c9bf4e219262a619c0670aHsin-Yu Chao  for (i = 0; i < CRAS_CH_MAX; i++)
1368a8a86fe67e3cc98173c9bf4e219262a619c0670aHsin-Yu Chao    format->channel_layout[i] = layout[i];
13697b7d64a58cdc405c76b7df32c8042050b9c8bf4aHsin-Yu Chao  return 0;
13707b7d64a58cdc405c76b7df32c8042050b9c8bf4aHsin-Yu Chao}
13717b7d64a58cdc405c76b7df32c8042050b9c8bf4aHsin-Yu Chao
13725342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiangfloat softvol_get_scaler(unsigned int volume_index)
13735342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang{
13745342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang	return softvol_scalers[volume_index];
13755342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang}
13765342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang
13775342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiangsize_t cras_system_get_volume() {
13785342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang  return cras_system_get_volume_return;
13795342a08d8e1f5c3c6205e7c6d2d40ab47280f3a3Cheng-Yi Chiang}
13807b7d64a58cdc405c76b7df32c8042050b9c8bf4aHsin-Yu Chao
1381034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chianglong cras_system_get_capture_gain() {
1382034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang  return cras_system_get_capture_gain_ret_value;
1383034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang}
1384034f0437c330515bb73bbe6e13271f1e1572bbbaCheng-Yi Chiang
1385d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reidint cras_system_get_mute() {
13861c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  return cras_system_get_mute_return;
1387d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid}
1388d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid
1389d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reidint cras_system_get_capture_mute() {
1390d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid  return 0;
1391d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid}
1392d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid
1393249e72919eb928e107d251b262c305a8fe531641Dylan Reidvoid cras_scale_buffer(snd_pcm_format_t fmt, uint8_t *buffer,
13941efd30f3854ac69a6916bdeaa82dae3f01d18acaDylan Reid                       unsigned int count, float scaler) {
1395249e72919eb928e107d251b262c305a8fe531641Dylan Reid  cras_scale_buffer_fmt = fmt;
13961c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  cras_scale_buffer_scaler = scaler;
1397d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid}
1398d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid
1399d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reidsize_t cras_mix_mute_buffer(uint8_t *dst,
1400d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid                            size_t frame_bytes,
1401d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid                            size_t count) {
1402d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid  cras_mix_mute_count = count;
1403d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid  return count;
1404d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid}
1405d3f0c13098e8c6373a6912f6e963ea460cacb432Dylan Reid
140665ee52aacc676ac2ecabadd6072a4dfffec61312Dylan Reidstruct rate_estimator *rate_estimator_create(unsigned int rate,
140765ee52aacc676ac2ecabadd6072a4dfffec61312Dylan Reid                                             const struct timespec *window_size,
140865ee52aacc676ac2ecabadd6072a4dfffec61312Dylan Reid                                             double smooth_factor) {
140965ee52aacc676ac2ecabadd6072a4dfffec61312Dylan Reid  return NULL;
141065ee52aacc676ac2ecabadd6072a4dfffec61312Dylan Reid}
141165ee52aacc676ac2ecabadd6072a4dfffec61312Dylan Reid
141265ee52aacc676ac2ecabadd6072a4dfffec61312Dylan Reidvoid rate_estimator_destroy(struct rate_estimator *re) {
141365ee52aacc676ac2ecabadd6072a4dfffec61312Dylan Reid}
141465ee52aacc676ac2ecabadd6072a4dfffec61312Dylan Reid
141565ee52aacc676ac2ecabadd6072a4dfffec61312Dylan Reidvoid rate_estimator_add_frames(struct rate_estimator *re, int fr) {
14161c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  rate_estimator_add_frames_called++;
14171c3dbf26145ecd84b58c27f934f0bdde0458fa38Dylan Reid  rate_estimator_add_frames_num_frames = fr;
141865ee52aacc676ac2ecabadd6072a4dfffec61312Dylan Reid}
141965ee52aacc676ac2ecabadd6072a4dfffec61312Dylan Reid
142065ee52aacc676ac2ecabadd6072a4dfffec61312Dylan Reidint rate_estimator_check(struct rate_estimator *re, int level,
142165ee52aacc676ac2ecabadd6072a4dfffec61312Dylan Reid                         struct timespec *now) {
142265ee52aacc676ac2ecabadd6072a4dfffec61312Dylan Reid  return 0;
142365ee52aacc676ac2ecabadd6072a4dfffec61312Dylan Reid}
142465ee52aacc676ac2ecabadd6072a4dfffec61312Dylan Reid
142565ee52aacc676ac2ecabadd6072a4dfffec61312Dylan Reidvoid rate_estimator_reset_rate(struct rate_estimator *re, unsigned int rate) {
142665ee52aacc676ac2ecabadd6072a4dfffec61312Dylan Reid}
142765ee52aacc676ac2ecabadd6072a4dfffec61312Dylan Reid
142865ee52aacc676ac2ecabadd6072a4dfffec61312Dylan Reiddouble rate_estimator_get_rate(struct rate_estimator *re) {
142965ee52aacc676ac2ecabadd6072a4dfffec61312Dylan Reid  return 0.0;
143065ee52aacc676ac2ecabadd6072a4dfffec61312Dylan Reid}
143165ee52aacc676ac2ecabadd6072a4dfffec61312Dylan Reid
1432c2c6a6e97e5534a4717ecec3ccb811e4af887279Hsin-Yu Chaounsigned int dev_stream_cb_threshold(const struct dev_stream *dev_stream) {
143324cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao  if (dev_stream->stream)
143424cd7e982a045254b20e9a84830072ffa8f18180Hsin-Yu Chao    return dev_stream->stream->cb_threshold;
1435c2c6a6e97e5534a4717ecec3ccb811e4af887279Hsin-Yu Chao  return 0;
1436c2c6a6e97e5534a4717ecec3ccb811e4af887279Hsin-Yu Chao}
1437c2c6a6e97e5534a4717ecec3ccb811e4af887279Hsin-Yu Chao
1438838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid}  // extern "C"
1439838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid}  //  namespace
1440838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid
1441838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reidint main(int argc, char **argv) {
1442838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  ::testing::InitGoogleTest(&argc, argv);
1443838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid  return RUN_ALL_TESTS();
1444838597c9ca04f19584c6fbcc78ee5f417c1528bfDylan Reid}
1445