blob: 9685ef95e9cf571ad60c2c8001f73e81f4359157 [file] [log] [blame]
peah1f1912d2015-11-09 11:13:191/*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 04:47:3111#include "modules/audio_processing/audio_processing_impl.h"
peah1f1912d2015-11-09 11:13:1912
13#include <algorithm>
kwiberg88788ad2016-02-19 15:04:4914#include <memory>
peah1f1912d2015-11-09 11:13:1915#include <vector>
16
Mirko Bonadei92ea95e2017-09-15 04:47:3117#include "api/array_view.h"
18#include "modules/audio_processing/test/test_utils.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3119#include "rtc_base/criticalsection.h"
20#include "rtc_base/event.h"
21#include "rtc_base/platform_thread.h"
22#include "rtc_base/random.h"
23#include "system_wrappers/include/sleep.h"
24#include "test/gtest.h"
peah1f1912d2015-11-09 11:13:1925
26namespace webrtc {
27
28namespace {
29
30class AudioProcessingImplLockTest;
31
peah1f1912d2015-11-09 11:13:1932// Type of the render thread APM API call to use in the test.
33enum class RenderApiImpl {
34 ProcessReverseStreamImpl1,
35 ProcessReverseStreamImpl2,
aluebsb0319552016-03-18 03:39:5336 AnalyzeReverseStreamImpl
peah1f1912d2015-11-09 11:13:1937};
38
39// Type of the capture thread APM API call to use in the test.
40enum class CaptureApiImpl {
41 ProcessStreamImpl1,
42 ProcessStreamImpl2,
43 ProcessStreamImpl3
44};
45
46// The runtime parameter setting scheme to use in the test.
47enum class RuntimeParameterSettingScheme {
48 SparseStreamMetadataChangeScheme,
49 ExtremeStreamMetadataChangeScheme,
50 FixedMonoStreamMetadataScheme,
51 FixedStereoStreamMetadataScheme
52};
53
54// Variant of echo canceller settings to use in the test.
55enum class AecType {
56 BasicWebRtcAecSettings,
57 AecTurnedOff,
58 BasicWebRtcAecSettingsWithExtentedFilter,
59 BasicWebRtcAecSettingsWithDelayAgnosticAec,
60 BasicWebRtcAecSettingsWithAecMobile
61};
62
peahdf3efa82015-11-28 20:35:1563// Thread-safe random number generator wrapper.
64class RandomGenerator {
65 public:
66 RandomGenerator() : rand_gen_(42U) {}
67
68 int RandInt(int min, int max) {
69 rtc::CritScope cs(&crit_);
70 return rand_gen_.Rand(min, max);
71 }
72
73 int RandInt(int max) {
74 rtc::CritScope cs(&crit_);
75 return rand_gen_.Rand(max);
76 }
77
78 float RandFloat() {
79 rtc::CritScope cs(&crit_);
80 return rand_gen_.Rand<float>();
81 }
82
83 private:
84 rtc::CriticalSection crit_;
danilchap56359be2017-09-07 14:53:4585 Random rand_gen_ RTC_GUARDED_BY(crit_);
peahdf3efa82015-11-28 20:35:1586};
87
peah1f1912d2015-11-09 11:13:1988// Variables related to the audio data and formats.
89struct AudioFrameData {
90 explicit AudioFrameData(int max_frame_size) {
91 // Set up the two-dimensional arrays needed for the APM API calls.
92 input_framechannels.resize(2 * max_frame_size);
93 input_frame.resize(2);
94 input_frame[0] = &input_framechannels[0];
95 input_frame[1] = &input_framechannels[max_frame_size];
96
97 output_frame_channels.resize(2 * max_frame_size);
98 output_frame.resize(2);
99 output_frame[0] = &output_frame_channels[0];
100 output_frame[1] = &output_frame_channels[max_frame_size];
101 }
102
103 AudioFrame frame;
104 std::vector<float*> output_frame;
105 std::vector<float> output_frame_channels;
106 AudioProcessing::ChannelLayout output_channel_layout =
107 AudioProcessing::ChannelLayout::kMono;
108 int input_sample_rate_hz = 16000;
109 int input_number_of_channels = -1;
110 std::vector<float*> input_frame;
111 std::vector<float> input_framechannels;
112 AudioProcessing::ChannelLayout input_channel_layout =
113 AudioProcessing::ChannelLayout::kMono;
114 int output_sample_rate_hz = 16000;
115 int output_number_of_channels = -1;
116 StreamConfig input_stream_config;
117 StreamConfig output_stream_config;
118 int input_samples_per_channel = -1;
119 int output_samples_per_channel = -1;
120};
121
122// The configuration for the test.
123struct TestConfig {
124 // Test case generator for the test configurations to use in the brief tests.
125 static std::vector<TestConfig> GenerateBriefTestConfigs() {
126 std::vector<TestConfig> test_configs;
127 AecType aec_types[] = {AecType::BasicWebRtcAecSettingsWithDelayAgnosticAec,
128 AecType::BasicWebRtcAecSettingsWithAecMobile};
129 for (auto aec_type : aec_types) {
130 TestConfig test_config;
131 test_config.aec_type = aec_type;
132
133 test_config.min_number_of_calls = 300;
134
135 // Perform tests only with the extreme runtime parameter setting scheme.
136 test_config.runtime_parameter_setting_scheme =
137 RuntimeParameterSettingScheme::ExtremeStreamMetadataChangeScheme;
138
139 // Only test 16 kHz for this test suite.
140 test_config.initial_sample_rate_hz = 16000;
141
142 // Create test config for the second processing API function set.
143 test_config.render_api_function =
144 RenderApiImpl::ProcessReverseStreamImpl2;
145 test_config.capture_api_function = CaptureApiImpl::ProcessStreamImpl2;
146
147 // Create test config for the first processing API function set.
148 test_configs.push_back(test_config);
Yves Gerey665174f2018-06-19 13:03:05149 test_config.render_api_function = RenderApiImpl::AnalyzeReverseStreamImpl;
peah1f1912d2015-11-09 11:13:19150 test_config.capture_api_function = CaptureApiImpl::ProcessStreamImpl3;
151 test_configs.push_back(test_config);
152 }
153
154 // Return the created test configurations.
155 return test_configs;
156 }
157
158 // Test case generator for the test configurations to use in the extensive
159 // tests.
160 static std::vector<TestConfig> GenerateExtensiveTestConfigs() {
161 // Lambda functions for the test config generation.
162 auto add_processing_apis = [](TestConfig test_config) {
163 struct AllowedApiCallCombinations {
164 RenderApiImpl render_api;
165 CaptureApiImpl capture_api;
166 };
167
168 const AllowedApiCallCombinations api_calls[] = {
169 {RenderApiImpl::ProcessReverseStreamImpl1,
170 CaptureApiImpl::ProcessStreamImpl1},
peah1f1912d2015-11-09 11:13:19171 {RenderApiImpl::ProcessReverseStreamImpl2,
172 CaptureApiImpl::ProcessStreamImpl2},
173 {RenderApiImpl::ProcessReverseStreamImpl2,
174 CaptureApiImpl::ProcessStreamImpl3},
aluebsb0319552016-03-18 03:39:53175 {RenderApiImpl::AnalyzeReverseStreamImpl,
peah1f1912d2015-11-09 11:13:19176 CaptureApiImpl::ProcessStreamImpl2},
aluebsb0319552016-03-18 03:39:53177 {RenderApiImpl::AnalyzeReverseStreamImpl,
peah1f1912d2015-11-09 11:13:19178 CaptureApiImpl::ProcessStreamImpl3}};
179 std::vector<TestConfig> out;
180 for (auto api_call : api_calls) {
181 test_config.render_api_function = api_call.render_api;
182 test_config.capture_api_function = api_call.capture_api;
183 out.push_back(test_config);
184 }
185 return out;
186 };
187
188 auto add_aec_settings = [](const std::vector<TestConfig>& in) {
189 std::vector<TestConfig> out;
190 AecType aec_types[] = {
191 AecType::BasicWebRtcAecSettings, AecType::AecTurnedOff,
192 AecType::BasicWebRtcAecSettingsWithExtentedFilter,
193 AecType::BasicWebRtcAecSettingsWithDelayAgnosticAec,
194 AecType::BasicWebRtcAecSettingsWithAecMobile};
195 for (auto test_config : in) {
conceptgenesis3f705622016-01-30 22:40:44196 // Due to a VisualStudio 2015 compiler issue, the internal loop
197 // variable here cannot override a previously defined name.
198 // In other words "type" cannot be named "aec_type" here.
199 // https://connect.microsoft.com/VisualStudio/feedback/details/2291755
200 for (auto type : aec_types) {
201 test_config.aec_type = type;
peah1f1912d2015-11-09 11:13:19202 out.push_back(test_config);
203 }
204 }
205 return out;
206 };
207
208 auto add_settings_scheme = [](const std::vector<TestConfig>& in) {
209 std::vector<TestConfig> out;
210 RuntimeParameterSettingScheme schemes[] = {
211 RuntimeParameterSettingScheme::SparseStreamMetadataChangeScheme,
212 RuntimeParameterSettingScheme::ExtremeStreamMetadataChangeScheme,
213 RuntimeParameterSettingScheme::FixedMonoStreamMetadataScheme,
214 RuntimeParameterSettingScheme::FixedStereoStreamMetadataScheme};
215
216 for (auto test_config : in) {
217 for (auto scheme : schemes) {
218 test_config.runtime_parameter_setting_scheme = scheme;
219 out.push_back(test_config);
220 }
221 }
222 return out;
223 };
224
225 auto add_sample_rates = [](const std::vector<TestConfig>& in) {
226 const int sample_rates[] = {8000, 16000, 32000, 48000};
227
228 std::vector<TestConfig> out;
229 for (auto test_config : in) {
230 auto available_rates =
231 (test_config.aec_type ==
232 AecType::BasicWebRtcAecSettingsWithAecMobile
233 ? rtc::ArrayView<const int>(sample_rates, 2)
234 : rtc::ArrayView<const int>(sample_rates));
235
236 for (auto rate : available_rates) {
237 test_config.initial_sample_rate_hz = rate;
238 out.push_back(test_config);
239 }
240 }
241 return out;
242 };
243
244 // Generate test configurations of the relevant combinations of the
245 // parameters to
246 // test.
247 TestConfig test_config;
248 test_config.min_number_of_calls = 10000;
249 return add_sample_rates(add_settings_scheme(
250 add_aec_settings(add_processing_apis(test_config))));
251 }
252
253 RenderApiImpl render_api_function = RenderApiImpl::ProcessReverseStreamImpl2;
254 CaptureApiImpl capture_api_function = CaptureApiImpl::ProcessStreamImpl2;
255 RuntimeParameterSettingScheme runtime_parameter_setting_scheme =
256 RuntimeParameterSettingScheme::ExtremeStreamMetadataChangeScheme;
257 int initial_sample_rate_hz = 16000;
258 AecType aec_type = AecType::BasicWebRtcAecSettingsWithDelayAgnosticAec;
259 int min_number_of_calls = 300;
260};
261
262// Handler for the frame counters.
263class FrameCounters {
264 public:
265 void IncreaseRenderCounter() {
266 rtc::CritScope cs(&crit_);
267 render_count++;
268 }
269
270 void IncreaseCaptureCounter() {
271 rtc::CritScope cs(&crit_);
272 capture_count++;
273 }
274
peah631e1342015-12-03 09:15:27275 int GetCaptureCounter() const {
peah1f1912d2015-11-09 11:13:19276 rtc::CritScope cs(&crit_);
277 return capture_count;
278 }
279
peah631e1342015-12-03 09:15:27280 int GetRenderCounter() const {
peah1f1912d2015-11-09 11:13:19281 rtc::CritScope cs(&crit_);
282 return render_count;
283 }
284
peah631e1342015-12-03 09:15:27285 int CaptureMinusRenderCounters() const {
peah1f1912d2015-11-09 11:13:19286 rtc::CritScope cs(&crit_);
287 return capture_count - render_count;
288 }
289
peah631e1342015-12-03 09:15:27290 int RenderMinusCaptureCounters() const {
291 return -CaptureMinusRenderCounters();
292 }
293
peah1f1912d2015-11-09 11:13:19294 bool BothCountersExceedeThreshold(int threshold) {
295 rtc::CritScope cs(&crit_);
296 return (render_count > threshold && capture_count > threshold);
297 }
298
299 private:
pbos5ad935c2016-01-25 11:52:44300 rtc::CriticalSection crit_;
danilchap56359be2017-09-07 14:53:45301 int render_count RTC_GUARDED_BY(crit_) = 0;
302 int capture_count RTC_GUARDED_BY(crit_) = 0;
peah1f1912d2015-11-09 11:13:19303};
304
peah1f1912d2015-11-09 11:13:19305// Class for handling the capture side processing.
306class CaptureProcessor {
307 public:
308 CaptureProcessor(int max_frame_size,
peahdf3efa82015-11-28 20:35:15309 RandomGenerator* rand_gen,
peah631e1342015-12-03 09:15:27310 rtc::Event* render_call_event,
311 rtc::Event* capture_call_event,
peah1f1912d2015-11-09 11:13:19312 FrameCounters* shared_counters_state,
peah1f1912d2015-11-09 11:13:19313 AudioProcessingImplLockTest* test_framework,
314 TestConfig* test_config,
315 AudioProcessing* apm);
316 bool Process();
317
318 private:
319 static const int kMaxCallDifference = 10;
320 static const float kCaptureInputFloatLevel;
321 static const int kCaptureInputFixLevel = 1024;
322
323 void PrepareFrame();
324 void CallApmCaptureSide();
325 void ApplyRuntimeSettingScheme();
326
peah631e1342015-12-03 09:15:27327 RandomGenerator* const rand_gen_ = nullptr;
328 rtc::Event* const render_call_event_ = nullptr;
329 rtc::Event* const capture_call_event_ = nullptr;
330 FrameCounters* const frame_counters_ = nullptr;
331 AudioProcessingImplLockTest* const test_ = nullptr;
332 const TestConfig* const test_config_ = nullptr;
333 AudioProcessing* const apm_ = nullptr;
peah1f1912d2015-11-09 11:13:19334 AudioFrameData frame_data_;
335};
336
337// Class for handling the stats processing.
338class StatsProcessor {
339 public:
peahdf3efa82015-11-28 20:35:15340 StatsProcessor(RandomGenerator* rand_gen,
peah1f1912d2015-11-09 11:13:19341 TestConfig* test_config,
342 AudioProcessing* apm);
343 bool Process();
344
345 private:
peahdf3efa82015-11-28 20:35:15346 RandomGenerator* rand_gen_ = nullptr;
peah1f1912d2015-11-09 11:13:19347 TestConfig* test_config_ = nullptr;
348 AudioProcessing* apm_ = nullptr;
349};
350
351// Class for handling the render side processing.
352class RenderProcessor {
353 public:
354 RenderProcessor(int max_frame_size,
peahdf3efa82015-11-28 20:35:15355 RandomGenerator* rand_gen,
peah631e1342015-12-03 09:15:27356 rtc::Event* render_call_event,
357 rtc::Event* capture_call_event,
peah1f1912d2015-11-09 11:13:19358 FrameCounters* shared_counters_state,
peah1f1912d2015-11-09 11:13:19359 AudioProcessingImplLockTest* test_framework,
360 TestConfig* test_config,
361 AudioProcessing* apm);
362 bool Process();
363
364 private:
365 static const int kMaxCallDifference = 10;
366 static const int kRenderInputFixLevel = 16384;
367 static const float kRenderInputFloatLevel;
368
369 void PrepareFrame();
370 void CallApmRenderSide();
371 void ApplyRuntimeSettingScheme();
372
peah631e1342015-12-03 09:15:27373 RandomGenerator* const rand_gen_ = nullptr;
374 rtc::Event* const render_call_event_ = nullptr;
375 rtc::Event* const capture_call_event_ = nullptr;
376 FrameCounters* const frame_counters_ = nullptr;
377 AudioProcessingImplLockTest* const test_ = nullptr;
378 const TestConfig* const test_config_ = nullptr;
379 AudioProcessing* const apm_ = nullptr;
peah1f1912d2015-11-09 11:13:19380 AudioFrameData frame_data_;
peah631e1342015-12-03 09:15:27381 bool first_render_call_ = true;
peah1f1912d2015-11-09 11:13:19382};
383
384class AudioProcessingImplLockTest
385 : public ::testing::TestWithParam<TestConfig> {
386 public:
387 AudioProcessingImplLockTest();
peah631e1342015-12-03 09:15:27388 bool RunTest();
389 bool MaybeEndTest();
peah1f1912d2015-11-09 11:13:19390
391 private:
392 static const int kTestTimeOutLimit = 10 * 60 * 1000;
393 static const int kMaxFrameSize = 480;
394
395 // ::testing::TestWithParam<> implementation
396 void SetUp() override;
397 void TearDown() override;
398
399 // Thread callback for the render thread
400 static bool RenderProcessorThreadFunc(void* context) {
401 return reinterpret_cast<AudioProcessingImplLockTest*>(context)
402 ->render_thread_state_.Process();
403 }
404
405 // Thread callback for the capture thread
406 static bool CaptureProcessorThreadFunc(void* context) {
407 return reinterpret_cast<AudioProcessingImplLockTest*>(context)
408 ->capture_thread_state_.Process();
409 }
410
411 // Thread callback for the stats thread
412 static bool StatsProcessorThreadFunc(void* context) {
413 return reinterpret_cast<AudioProcessingImplLockTest*>(context)
414 ->stats_thread_state_.Process();
415 }
416
417 // Tests whether all the required render and capture side calls have been
418 // done.
419 bool TestDone() {
420 return frame_counters_.BothCountersExceedeThreshold(
421 test_config_.min_number_of_calls);
422 }
423
424 // Start the threads used in the test.
425 void StartThreads() {
Peter Boström8c38e8b2015-11-26 16:45:47426 render_thread_.Start();
427 render_thread_.SetPriority(rtc::kRealtimePriority);
428 capture_thread_.Start();
429 capture_thread_.SetPriority(rtc::kRealtimePriority);
430 stats_thread_.Start();
431 stats_thread_.SetPriority(rtc::kNormalPriority);
peah1f1912d2015-11-09 11:13:19432 }
433
peah631e1342015-12-03 09:15:27434 // Event handlers for the test.
435 rtc::Event test_complete_;
436 rtc::Event render_call_event_;
437 rtc::Event capture_call_event_;
peah1f1912d2015-11-09 11:13:19438
439 // Thread related variables.
Peter Boström8c38e8b2015-11-26 16:45:47440 rtc::PlatformThread render_thread_;
441 rtc::PlatformThread capture_thread_;
442 rtc::PlatformThread stats_thread_;
peahdf3efa82015-11-28 20:35:15443 mutable RandomGenerator rand_gen_;
peah1f1912d2015-11-09 11:13:19444
kwiberg88788ad2016-02-19 15:04:49445 std::unique_ptr<AudioProcessing> apm_;
peah1f1912d2015-11-09 11:13:19446 TestConfig test_config_;
447 FrameCounters frame_counters_;
peah1f1912d2015-11-09 11:13:19448 RenderProcessor render_thread_state_;
449 CaptureProcessor capture_thread_state_;
450 StatsProcessor stats_thread_state_;
451};
452
peahdf3efa82015-11-28 20:35:15453// Sleeps a random time between 0 and max_sleep milliseconds.
454void SleepRandomMs(int max_sleep, RandomGenerator* rand_gen) {
455 int sleeptime = rand_gen->RandInt(0, max_sleep);
456 SleepMs(sleeptime);
457}
458
459// Populates a float audio frame with random data.
460void PopulateAudioFrame(float** frame,
461 float amplitude,
462 size_t num_channels,
463 size_t samples_per_channel,
464 RandomGenerator* rand_gen) {
465 for (size_t ch = 0; ch < num_channels; ch++) {
466 for (size_t k = 0; k < samples_per_channel; k++) {
467 // Store random 16 bit quantized float number between +-amplitude.
468 frame[ch][k] = amplitude * (2 * rand_gen->RandFloat() - 1);
469 }
470 }
471}
472
473// Populates an audioframe frame of AudioFrame type with random data.
474void PopulateAudioFrame(AudioFrame* frame,
475 int16_t amplitude,
476 RandomGenerator* rand_gen) {
477 ASSERT_GT(amplitude, 0);
478 ASSERT_LE(amplitude, 32767);
yujo36b1a5f2017-06-12 19:45:32479 int16_t* frame_data = frame->mutable_data();
Peter Kasting69558702016-01-13 00:26:35480 for (size_t ch = 0; ch < frame->num_channels_; ch++) {
pkasting25702cb2016-01-08 21:50:27481 for (size_t k = 0; k < frame->samples_per_channel_; k++) {
peahdf3efa82015-11-28 20:35:15482 // Store random 16 bit number between -(amplitude+1) and
483 // amplitude.
Yves Gerey665174f2018-06-19 13:03:05484 frame_data[k * ch] = rand_gen->RandInt(2 * amplitude + 1) - amplitude - 1;
peahdf3efa82015-11-28 20:35:15485 }
486 }
487}
488
peah1f1912d2015-11-09 11:13:19489AudioProcessingImplLockTest::AudioProcessingImplLockTest()
Niels Möllerc572ff32018-11-07 07:43:50490 : render_thread_(RenderProcessorThreadFunc, this, "render"),
Peter Boström8c38e8b2015-11-26 16:45:47491 capture_thread_(CaptureProcessorThreadFunc, this, "capture"),
492 stats_thread_(StatsProcessorThreadFunc, this, "stats"),
Ivo Creusen62337e52018-01-09 13:17:33493 apm_(AudioProcessingBuilder().Create()),
peah1f1912d2015-11-09 11:13:19494 render_thread_state_(kMaxFrameSize,
495 &rand_gen_,
peah631e1342015-12-03 09:15:27496 &render_call_event_,
497 &capture_call_event_,
peah1f1912d2015-11-09 11:13:19498 &frame_counters_,
peah1f1912d2015-11-09 11:13:19499 this,
500 &test_config_,
501 apm_.get()),
502 capture_thread_state_(kMaxFrameSize,
503 &rand_gen_,
peah631e1342015-12-03 09:15:27504 &render_call_event_,
505 &capture_call_event_,
peah1f1912d2015-11-09 11:13:19506 &frame_counters_,
peah1f1912d2015-11-09 11:13:19507 this,
508 &test_config_,
509 apm_.get()),
510 stats_thread_state_(&rand_gen_, &test_config_, apm_.get()) {}
511
512// Run the test with a timeout.
peah631e1342015-12-03 09:15:27513bool AudioProcessingImplLockTest::RunTest() {
peah1f1912d2015-11-09 11:13:19514 StartThreads();
peah631e1342015-12-03 09:15:27515 return test_complete_.Wait(kTestTimeOutLimit);
peah1f1912d2015-11-09 11:13:19516}
517
peah631e1342015-12-03 09:15:27518bool AudioProcessingImplLockTest::MaybeEndTest() {
peah1f1912d2015-11-09 11:13:19519 if (HasFatalFailure() || TestDone()) {
peah631e1342015-12-03 09:15:27520 test_complete_.Set();
521 return true;
peah1f1912d2015-11-09 11:13:19522 }
peah631e1342015-12-03 09:15:27523 return false;
peah1f1912d2015-11-09 11:13:19524}
525
526// Setup of test and APM.
527void AudioProcessingImplLockTest::SetUp() {
528 test_config_ = static_cast<TestConfig>(GetParam());
529
530 ASSERT_EQ(apm_->kNoError, apm_->level_estimator()->Enable(true));
531 ASSERT_EQ(apm_->kNoError, apm_->gain_control()->Enable(true));
532
533 ASSERT_EQ(apm_->kNoError,
peahdf3efa82015-11-28 20:35:15534 apm_->gain_control()->set_mode(GainControl::kAdaptiveDigital));
peah1f1912d2015-11-09 11:13:19535 ASSERT_EQ(apm_->kNoError, apm_->gain_control()->Enable(true));
536
537 ASSERT_EQ(apm_->kNoError, apm_->noise_suppression()->Enable(true));
538 ASSERT_EQ(apm_->kNoError, apm_->voice_detection()->Enable(true));
539
Sam Zackrissoncdf0e6d2018-09-17 09:05:17540 AudioProcessing::Config apm_config;
541 apm_config.echo_canceller.enabled =
542 (test_config_.aec_type != AecType::AecTurnedOff);
543 apm_config.echo_canceller.mobile_mode =
544 (test_config_.aec_type == AecType::BasicWebRtcAecSettingsWithAecMobile);
545 apm_->ApplyConfig(apm_config);
546
peah1f1912d2015-11-09 11:13:19547 Config config;
Sam Zackrissoncdf0e6d2018-09-17 09:05:17548 config.Set<ExtendedFilter>(
549 new ExtendedFilter(test_config_.aec_type ==
550 AecType::BasicWebRtcAecSettingsWithExtentedFilter));
peah1f1912d2015-11-09 11:13:19551
Sam Zackrissoncdf0e6d2018-09-17 09:05:17552 config.Set<DelayAgnostic>(
553 new DelayAgnostic(test_config_.aec_type ==
554 AecType::BasicWebRtcAecSettingsWithDelayAgnosticAec));
peah1f1912d2015-11-09 11:13:19555
Sam Zackrissoncdf0e6d2018-09-17 09:05:17556 apm_->SetExtraOptions(config);
peah1f1912d2015-11-09 11:13:19557}
558
559void AudioProcessingImplLockTest::TearDown() {
peah631e1342015-12-03 09:15:27560 render_call_event_.Set();
561 capture_call_event_.Set();
Peter Boström8c38e8b2015-11-26 16:45:47562 render_thread_.Stop();
563 capture_thread_.Stop();
564 stats_thread_.Stop();
peah1f1912d2015-11-09 11:13:19565}
566
peahdf3efa82015-11-28 20:35:15567StatsProcessor::StatsProcessor(RandomGenerator* rand_gen,
peah1f1912d2015-11-09 11:13:19568 TestConfig* test_config,
569 AudioProcessing* apm)
570 : rand_gen_(rand_gen), test_config_(test_config), apm_(apm) {}
571
572// Implements the callback functionality for the statistics
573// collection thread.
574bool StatsProcessor::Process() {
575 SleepRandomMs(100, rand_gen_);
576
Sam Zackrissoncdf0e6d2018-09-17 09:05:17577 AudioProcessing::Config apm_config = apm_->GetConfig();
578 if (test_config_->aec_type != AecType::AecTurnedOff) {
579 EXPECT_TRUE(apm_config.echo_canceller.enabled);
580 EXPECT_EQ(apm_config.echo_canceller.mobile_mode,
581 (test_config_->aec_type ==
582 AecType::BasicWebRtcAecSettingsWithAecMobile));
583 } else {
584 EXPECT_FALSE(apm_config.echo_canceller.enabled);
585 }
peah1f1912d2015-11-09 11:13:19586 EXPECT_TRUE(apm_->gain_control()->is_enabled());
peah1f1912d2015-11-09 11:13:19587 EXPECT_TRUE(apm_->noise_suppression()->is_enabled());
588
589 // The below return values are not testable.
590 apm_->noise_suppression()->speech_probability();
591 apm_->voice_detection()->is_enabled();
592
593 return true;
594}
595
596const float CaptureProcessor::kCaptureInputFloatLevel = 0.03125f;
597
peah631e1342015-12-03 09:15:27598CaptureProcessor::CaptureProcessor(int max_frame_size,
599 RandomGenerator* rand_gen,
600 rtc::Event* render_call_event,
601 rtc::Event* capture_call_event,
602 FrameCounters* shared_counters_state,
603 AudioProcessingImplLockTest* test_framework,
604 TestConfig* test_config,
605 AudioProcessing* apm)
peah1f1912d2015-11-09 11:13:19606 : rand_gen_(rand_gen),
peah631e1342015-12-03 09:15:27607 render_call_event_(render_call_event),
608 capture_call_event_(capture_call_event),
peah1f1912d2015-11-09 11:13:19609 frame_counters_(shared_counters_state),
peah1f1912d2015-11-09 11:13:19610 test_(test_framework),
611 test_config_(test_config),
612 apm_(apm),
613 frame_data_(max_frame_size) {}
614
615// Implements the callback functionality for the capture thread.
616bool CaptureProcessor::Process() {
617 // Sleep a random time to simulate thread jitter.
618 SleepRandomMs(3, rand_gen_);
619
peah631e1342015-12-03 09:15:27620 // Check whether the test is done.
621 if (test_->MaybeEndTest()) {
622 return false;
623 }
peah1f1912d2015-11-09 11:13:19624
peah631e1342015-12-03 09:15:27625 // Ensure that the number of render and capture calls do not
626 // differ too much.
627 if (frame_counters_->CaptureMinusRenderCounters() > kMaxCallDifference) {
628 render_call_event_->Wait(rtc::Event::kForever);
peah1f1912d2015-11-09 11:13:19629 }
630
631 // Apply any specified capture side APM non-processing runtime calls.
632 ApplyRuntimeSettingScheme();
633
634 // Apply the capture side processing call.
635 CallApmCaptureSide();
636
637 // Increase the number of capture-side calls.
638 frame_counters_->IncreaseCaptureCounter();
639
peah631e1342015-12-03 09:15:27640 // Flag to the render thread that another capture API call has occurred
641 // by triggering this threads call event.
642 capture_call_event_->Set();
peah1f1912d2015-11-09 11:13:19643
644 return true;
645}
646
647// Prepares a frame with relevant audio data and metadata.
648void CaptureProcessor::PrepareFrame() {
649 // Restrict to a common fixed sample rate if the AudioFrame
650 // interface is used.
651 if (test_config_->capture_api_function ==
652 CaptureApiImpl::ProcessStreamImpl1) {
653 frame_data_.input_sample_rate_hz = test_config_->initial_sample_rate_hz;
654 frame_data_.output_sample_rate_hz = test_config_->initial_sample_rate_hz;
655 }
656
657 // Prepare the audioframe data and metadata.
658 frame_data_.input_samples_per_channel =
659 frame_data_.input_sample_rate_hz * AudioProcessing::kChunkSizeMs / 1000;
660 frame_data_.frame.sample_rate_hz_ = frame_data_.input_sample_rate_hz;
661 frame_data_.frame.num_channels_ = frame_data_.input_number_of_channels;
662 frame_data_.frame.samples_per_channel_ =
663 frame_data_.input_samples_per_channel;
664 PopulateAudioFrame(&frame_data_.frame, kCaptureInputFixLevel, rand_gen_);
665
666 // Prepare the float audio input data and metadata.
667 frame_data_.input_stream_config.set_sample_rate_hz(
668 frame_data_.input_sample_rate_hz);
669 frame_data_.input_stream_config.set_num_channels(
670 frame_data_.input_number_of_channels);
671 frame_data_.input_stream_config.set_has_keyboard(false);
672 PopulateAudioFrame(&frame_data_.input_frame[0], kCaptureInputFloatLevel,
673 frame_data_.input_number_of_channels,
674 frame_data_.input_samples_per_channel, rand_gen_);
675 frame_data_.input_channel_layout =
676 (frame_data_.input_number_of_channels == 1
677 ? AudioProcessing::ChannelLayout::kMono
678 : AudioProcessing::ChannelLayout::kStereo);
679
680 // Prepare the float audio output data and metadata.
681 frame_data_.output_samples_per_channel =
682 frame_data_.output_sample_rate_hz * AudioProcessing::kChunkSizeMs / 1000;
683 frame_data_.output_stream_config.set_sample_rate_hz(
684 frame_data_.output_sample_rate_hz);
685 frame_data_.output_stream_config.set_num_channels(
686 frame_data_.output_number_of_channels);
687 frame_data_.output_stream_config.set_has_keyboard(false);
688 frame_data_.output_channel_layout =
689 (frame_data_.output_number_of_channels == 1
690 ? AudioProcessing::ChannelLayout::kMono
691 : AudioProcessing::ChannelLayout::kStereo);
692}
693
694// Applies the capture side processing API call.
695void CaptureProcessor::CallApmCaptureSide() {
696 // Prepare a proper capture side processing API call input.
697 PrepareFrame();
698
peahbe615622016-02-14 00:40:47699 // Set the stream delay.
peah1f1912d2015-11-09 11:13:19700 apm_->set_stream_delay_ms(30);
701
peahbe615622016-02-14 00:40:47702 // Set the analog level.
703 apm_->gain_control()->set_stream_analog_level(80);
704
peah1f1912d2015-11-09 11:13:19705 // Call the specified capture side API processing method.
706 int result = AudioProcessing::kNoError;
707 switch (test_config_->capture_api_function) {
708 case CaptureApiImpl::ProcessStreamImpl1:
709 result = apm_->ProcessStream(&frame_data_.frame);
710 break;
711 case CaptureApiImpl::ProcessStreamImpl2:
712 result = apm_->ProcessStream(
713 &frame_data_.input_frame[0], frame_data_.input_samples_per_channel,
714 frame_data_.input_sample_rate_hz, frame_data_.input_channel_layout,
715 frame_data_.output_sample_rate_hz, frame_data_.output_channel_layout,
716 &frame_data_.output_frame[0]);
717 break;
718 case CaptureApiImpl::ProcessStreamImpl3:
719 result = apm_->ProcessStream(
720 &frame_data_.input_frame[0], frame_data_.input_stream_config,
721 frame_data_.output_stream_config, &frame_data_.output_frame[0]);
722 break;
723 default:
724 FAIL();
725 }
726
peahbe615622016-02-14 00:40:47727 // Retrieve the new analog level.
728 apm_->gain_control()->stream_analog_level();
729
peah1f1912d2015-11-09 11:13:19730 // Check the return code for error.
731 ASSERT_EQ(AudioProcessing::kNoError, result);
732}
733
734// Applies any runtime capture APM API calls and audio stream characteristics
735// specified by the scheme for the test.
736void CaptureProcessor::ApplyRuntimeSettingScheme() {
737 const int capture_count_local = frame_counters_->GetCaptureCounter();
738
739 // Update the number of channels and sample rates for the input and output.
740 // Note that the counts frequencies for when to set parameters
741 // are set using prime numbers in order to ensure that the
742 // permutation scheme in the parameter setting changes.
743 switch (test_config_->runtime_parameter_setting_scheme) {
744 case RuntimeParameterSettingScheme::SparseStreamMetadataChangeScheme:
745 if (capture_count_local == 0)
746 frame_data_.input_sample_rate_hz = 16000;
747 else if (capture_count_local % 11 == 0)
748 frame_data_.input_sample_rate_hz = 32000;
749 else if (capture_count_local % 73 == 0)
750 frame_data_.input_sample_rate_hz = 48000;
751 else if (capture_count_local % 89 == 0)
752 frame_data_.input_sample_rate_hz = 16000;
753 else if (capture_count_local % 97 == 0)
754 frame_data_.input_sample_rate_hz = 8000;
755
756 if (capture_count_local == 0)
757 frame_data_.input_number_of_channels = 1;
758 else if (capture_count_local % 4 == 0)
759 frame_data_.input_number_of_channels =
760 (frame_data_.input_number_of_channels == 1 ? 2 : 1);
761
762 if (capture_count_local == 0)
763 frame_data_.output_sample_rate_hz = 16000;
764 else if (capture_count_local % 5 == 0)
765 frame_data_.output_sample_rate_hz = 32000;
766 else if (capture_count_local % 47 == 0)
767 frame_data_.output_sample_rate_hz = 48000;
768 else if (capture_count_local % 53 == 0)
769 frame_data_.output_sample_rate_hz = 16000;
770 else if (capture_count_local % 71 == 0)
771 frame_data_.output_sample_rate_hz = 8000;
772
773 if (capture_count_local == 0)
774 frame_data_.output_number_of_channels = 1;
775 else if (capture_count_local % 8 == 0)
776 frame_data_.output_number_of_channels =
777 (frame_data_.output_number_of_channels == 1 ? 2 : 1);
778 break;
779 case RuntimeParameterSettingScheme::ExtremeStreamMetadataChangeScheme:
780 if (capture_count_local % 2 == 0) {
781 frame_data_.input_number_of_channels = 1;
782 frame_data_.input_sample_rate_hz = 16000;
783 frame_data_.output_number_of_channels = 1;
784 frame_data_.output_sample_rate_hz = 16000;
785 } else {
786 frame_data_.input_number_of_channels =
787 (frame_data_.input_number_of_channels == 1 ? 2 : 1);
788 if (frame_data_.input_sample_rate_hz == 8000)
789 frame_data_.input_sample_rate_hz = 16000;
790 else if (frame_data_.input_sample_rate_hz == 16000)
791 frame_data_.input_sample_rate_hz = 32000;
792 else if (frame_data_.input_sample_rate_hz == 32000)
793 frame_data_.input_sample_rate_hz = 48000;
794 else if (frame_data_.input_sample_rate_hz == 48000)
795 frame_data_.input_sample_rate_hz = 8000;
796
797 frame_data_.output_number_of_channels =
798 (frame_data_.output_number_of_channels == 1 ? 2 : 1);
799 if (frame_data_.output_sample_rate_hz == 8000)
800 frame_data_.output_sample_rate_hz = 16000;
801 else if (frame_data_.output_sample_rate_hz == 16000)
802 frame_data_.output_sample_rate_hz = 32000;
803 else if (frame_data_.output_sample_rate_hz == 32000)
804 frame_data_.output_sample_rate_hz = 48000;
805 else if (frame_data_.output_sample_rate_hz == 48000)
806 frame_data_.output_sample_rate_hz = 8000;
807 }
808 break;
809 case RuntimeParameterSettingScheme::FixedMonoStreamMetadataScheme:
810 if (capture_count_local == 0) {
811 frame_data_.input_sample_rate_hz = 16000;
812 frame_data_.input_number_of_channels = 1;
813 frame_data_.output_sample_rate_hz = 16000;
814 frame_data_.output_number_of_channels = 1;
815 }
816 break;
817 case RuntimeParameterSettingScheme::FixedStereoStreamMetadataScheme:
818 if (capture_count_local == 0) {
819 frame_data_.input_sample_rate_hz = 16000;
820 frame_data_.input_number_of_channels = 2;
821 frame_data_.output_sample_rate_hz = 16000;
822 frame_data_.output_number_of_channels = 2;
823 }
824 break;
825 default:
826 FAIL();
827 }
828
829 // Call any specified runtime APM setter and
830 // getter calls.
831 switch (test_config_->runtime_parameter_setting_scheme) {
832 case RuntimeParameterSettingScheme::SparseStreamMetadataChangeScheme:
833 case RuntimeParameterSettingScheme::FixedMonoStreamMetadataScheme:
834 break;
835 case RuntimeParameterSettingScheme::ExtremeStreamMetadataChangeScheme:
836 case RuntimeParameterSettingScheme::FixedStereoStreamMetadataScheme:
837 if (capture_count_local % 2 == 0) {
838 ASSERT_EQ(AudioProcessing::Error::kNoError,
839 apm_->set_stream_delay_ms(30));
840 apm_->set_stream_key_pressed(true);
peah1f1912d2015-11-09 11:13:19841 apm_->set_delay_offset_ms(15);
842 EXPECT_EQ(apm_->delay_offset_ms(), 15);
peah1f1912d2015-11-09 11:13:19843 } else {
844 ASSERT_EQ(AudioProcessing::Error::kNoError,
845 apm_->set_stream_delay_ms(50));
846 apm_->set_stream_key_pressed(false);
peah1f1912d2015-11-09 11:13:19847 apm_->set_delay_offset_ms(20);
848 EXPECT_EQ(apm_->delay_offset_ms(), 20);
849 apm_->delay_offset_ms();
peah1f1912d2015-11-09 11:13:19850 }
851 break;
852 default:
853 FAIL();
854 }
855
856 // Restric the number of output channels not to exceed
857 // the number of input channels.
858 frame_data_.output_number_of_channels =
859 std::min(frame_data_.output_number_of_channels,
860 frame_data_.input_number_of_channels);
861}
862
863const float RenderProcessor::kRenderInputFloatLevel = 0.5f;
864
865RenderProcessor::RenderProcessor(int max_frame_size,
peahdf3efa82015-11-28 20:35:15866 RandomGenerator* rand_gen,
peah631e1342015-12-03 09:15:27867 rtc::Event* render_call_event,
868 rtc::Event* capture_call_event,
peah1f1912d2015-11-09 11:13:19869 FrameCounters* shared_counters_state,
peah1f1912d2015-11-09 11:13:19870 AudioProcessingImplLockTest* test_framework,
871 TestConfig* test_config,
872 AudioProcessing* apm)
873 : rand_gen_(rand_gen),
peah631e1342015-12-03 09:15:27874 render_call_event_(render_call_event),
875 capture_call_event_(capture_call_event),
peah1f1912d2015-11-09 11:13:19876 frame_counters_(shared_counters_state),
peah1f1912d2015-11-09 11:13:19877 test_(test_framework),
878 test_config_(test_config),
879 apm_(apm),
880 frame_data_(max_frame_size) {}
881
882// Implements the callback functionality for the render thread.
883bool RenderProcessor::Process() {
884 // Conditional wait to ensure that a capture call has been done
885 // before the first render call is performed (implicitly
886 // required by the APM API).
peah631e1342015-12-03 09:15:27887 if (first_render_call_) {
888 capture_call_event_->Wait(rtc::Event::kForever);
889 first_render_call_ = false;
peah1f1912d2015-11-09 11:13:19890 }
891
892 // Sleep a random time to simulate thread jitter.
893 SleepRandomMs(3, rand_gen_);
894
peah631e1342015-12-03 09:15:27895 // Check whether the test is done.
896 if (test_->MaybeEndTest()) {
897 return false;
898 }
peah1f1912d2015-11-09 11:13:19899
900 // Ensure that the number of render and capture calls do not
901 // differ too much.
peah631e1342015-12-03 09:15:27902 if (frame_counters_->RenderMinusCaptureCounters() > kMaxCallDifference) {
903 capture_call_event_->Wait(rtc::Event::kForever);
peah1f1912d2015-11-09 11:13:19904 }
905
906 // Apply any specified render side APM non-processing runtime calls.
907 ApplyRuntimeSettingScheme();
908
909 // Apply the render side processing call.
910 CallApmRenderSide();
911
912 // Increase the number of render-side calls.
913 frame_counters_->IncreaseRenderCounter();
914
peah631e1342015-12-03 09:15:27915 // Flag to the capture thread that another render API call has occurred
916 // by triggering this threads call event.
917 render_call_event_->Set();
peah1f1912d2015-11-09 11:13:19918 return true;
919}
920
921// Prepares the render side frame and the accompanying metadata
922// with the appropriate information.
923void RenderProcessor::PrepareFrame() {
924 // Restrict to a common fixed sample rate if the AudioFrame interface is
925 // used.
926 if ((test_config_->render_api_function ==
peah1f1912d2015-11-09 11:13:19927 RenderApiImpl::ProcessReverseStreamImpl1) ||
928 (test_config_->aec_type !=
929 AecType::BasicWebRtcAecSettingsWithAecMobile)) {
930 frame_data_.input_sample_rate_hz = test_config_->initial_sample_rate_hz;
931 frame_data_.output_sample_rate_hz = test_config_->initial_sample_rate_hz;
932 }
933
934 // Prepare the audioframe data and metadata
935 frame_data_.input_samples_per_channel =
936 frame_data_.input_sample_rate_hz * AudioProcessing::kChunkSizeMs / 1000;
937 frame_data_.frame.sample_rate_hz_ = frame_data_.input_sample_rate_hz;
938 frame_data_.frame.num_channels_ = frame_data_.input_number_of_channels;
939 frame_data_.frame.samples_per_channel_ =
940 frame_data_.input_samples_per_channel;
941 PopulateAudioFrame(&frame_data_.frame, kRenderInputFixLevel, rand_gen_);
942
943 // Prepare the float audio input data and metadata.
944 frame_data_.input_stream_config.set_sample_rate_hz(
945 frame_data_.input_sample_rate_hz);
946 frame_data_.input_stream_config.set_num_channels(
947 frame_data_.input_number_of_channels);
948 frame_data_.input_stream_config.set_has_keyboard(false);
949 PopulateAudioFrame(&frame_data_.input_frame[0], kRenderInputFloatLevel,
950 frame_data_.input_number_of_channels,
951 frame_data_.input_samples_per_channel, rand_gen_);
952 frame_data_.input_channel_layout =
953 (frame_data_.input_number_of_channels == 1
954 ? AudioProcessing::ChannelLayout::kMono
955 : AudioProcessing::ChannelLayout::kStereo);
956
957 // Prepare the float audio output data and metadata.
958 frame_data_.output_samples_per_channel =
959 frame_data_.output_sample_rate_hz * AudioProcessing::kChunkSizeMs / 1000;
960 frame_data_.output_stream_config.set_sample_rate_hz(
961 frame_data_.output_sample_rate_hz);
962 frame_data_.output_stream_config.set_num_channels(
963 frame_data_.output_number_of_channels);
964 frame_data_.output_stream_config.set_has_keyboard(false);
965 frame_data_.output_channel_layout =
966 (frame_data_.output_number_of_channels == 1
967 ? AudioProcessing::ChannelLayout::kMono
968 : AudioProcessing::ChannelLayout::kStereo);
969}
970
971// Makes the render side processing API call.
972void RenderProcessor::CallApmRenderSide() {
973 // Prepare a proper render side processing API call input.
974 PrepareFrame();
975
976 // Call the specified render side API processing method.
977 int result = AudioProcessing::kNoError;
978 switch (test_config_->render_api_function) {
979 case RenderApiImpl::ProcessReverseStreamImpl1:
980 result = apm_->ProcessReverseStream(&frame_data_.frame);
981 break;
982 case RenderApiImpl::ProcessReverseStreamImpl2:
983 result = apm_->ProcessReverseStream(
984 &frame_data_.input_frame[0], frame_data_.input_stream_config,
985 frame_data_.output_stream_config, &frame_data_.output_frame[0]);
986 break;
aluebsb0319552016-03-18 03:39:53987 case RenderApiImpl::AnalyzeReverseStreamImpl:
peah1f1912d2015-11-09 11:13:19988 result = apm_->AnalyzeReverseStream(
989 &frame_data_.input_frame[0], frame_data_.input_samples_per_channel,
990 frame_data_.input_sample_rate_hz, frame_data_.input_channel_layout);
991 break;
992 default:
993 FAIL();
994 }
995
996 // Check the return code for error.
997 ASSERT_EQ(AudioProcessing::kNoError, result);
998}
999
1000// Applies any render capture side APM API calls and audio stream
1001// characteristics
1002// specified by the scheme for the test.
1003void RenderProcessor::ApplyRuntimeSettingScheme() {
1004 const int render_count_local = frame_counters_->GetRenderCounter();
1005
1006 // Update the number of channels and sample rates for the input and output.
1007 // Note that the counts frequencies for when to set parameters
1008 // are set using prime numbers in order to ensure that the
1009 // permutation scheme in the parameter setting changes.
1010 switch (test_config_->runtime_parameter_setting_scheme) {
1011 case RuntimeParameterSettingScheme::SparseStreamMetadataChangeScheme:
1012 if (render_count_local == 0)
1013 frame_data_.input_sample_rate_hz = 16000;
1014 else if (render_count_local % 47 == 0)
1015 frame_data_.input_sample_rate_hz = 32000;
1016 else if (render_count_local % 71 == 0)
1017 frame_data_.input_sample_rate_hz = 48000;
1018 else if (render_count_local % 79 == 0)
1019 frame_data_.input_sample_rate_hz = 16000;
1020 else if (render_count_local % 83 == 0)
1021 frame_data_.input_sample_rate_hz = 8000;
1022
1023 if (render_count_local == 0)
1024 frame_data_.input_number_of_channels = 1;
1025 else if (render_count_local % 4 == 0)
1026 frame_data_.input_number_of_channels =
1027 (frame_data_.input_number_of_channels == 1 ? 2 : 1);
1028
1029 if (render_count_local == 0)
1030 frame_data_.output_sample_rate_hz = 16000;
1031 else if (render_count_local % 17 == 0)
1032 frame_data_.output_sample_rate_hz = 32000;
1033 else if (render_count_local % 19 == 0)
1034 frame_data_.output_sample_rate_hz = 48000;
1035 else if (render_count_local % 29 == 0)
1036 frame_data_.output_sample_rate_hz = 16000;
1037 else if (render_count_local % 61 == 0)
1038 frame_data_.output_sample_rate_hz = 8000;
1039
1040 if (render_count_local == 0)
1041 frame_data_.output_number_of_channels = 1;
1042 else if (render_count_local % 8 == 0)
1043 frame_data_.output_number_of_channels =
1044 (frame_data_.output_number_of_channels == 1 ? 2 : 1);
1045 break;
1046 case RuntimeParameterSettingScheme::ExtremeStreamMetadataChangeScheme:
1047 if (render_count_local == 0) {
1048 frame_data_.input_number_of_channels = 1;
1049 frame_data_.input_sample_rate_hz = 16000;
1050 frame_data_.output_number_of_channels = 1;
1051 frame_data_.output_sample_rate_hz = 16000;
1052 } else {
1053 frame_data_.input_number_of_channels =
1054 (frame_data_.input_number_of_channels == 1 ? 2 : 1);
1055 if (frame_data_.input_sample_rate_hz == 8000)
1056 frame_data_.input_sample_rate_hz = 16000;
1057 else if (frame_data_.input_sample_rate_hz == 16000)
1058 frame_data_.input_sample_rate_hz = 32000;
1059 else if (frame_data_.input_sample_rate_hz == 32000)
1060 frame_data_.input_sample_rate_hz = 48000;
1061 else if (frame_data_.input_sample_rate_hz == 48000)
1062 frame_data_.input_sample_rate_hz = 8000;
1063
1064 frame_data_.output_number_of_channels =
1065 (frame_data_.output_number_of_channels == 1 ? 2 : 1);
1066 if (frame_data_.output_sample_rate_hz == 8000)
1067 frame_data_.output_sample_rate_hz = 16000;
1068 else if (frame_data_.output_sample_rate_hz == 16000)
1069 frame_data_.output_sample_rate_hz = 32000;
1070 else if (frame_data_.output_sample_rate_hz == 32000)
1071 frame_data_.output_sample_rate_hz = 48000;
1072 else if (frame_data_.output_sample_rate_hz == 48000)
1073 frame_data_.output_sample_rate_hz = 8000;
1074 }
1075 break;
1076 case RuntimeParameterSettingScheme::FixedMonoStreamMetadataScheme:
1077 if (render_count_local == 0) {
1078 frame_data_.input_sample_rate_hz = 16000;
1079 frame_data_.input_number_of_channels = 1;
1080 frame_data_.output_sample_rate_hz = 16000;
1081 frame_data_.output_number_of_channels = 1;
1082 }
1083 break;
1084 case RuntimeParameterSettingScheme::FixedStereoStreamMetadataScheme:
1085 if (render_count_local == 0) {
1086 frame_data_.input_sample_rate_hz = 16000;
1087 frame_data_.input_number_of_channels = 2;
1088 frame_data_.output_sample_rate_hz = 16000;
1089 frame_data_.output_number_of_channels = 2;
1090 }
1091 break;
1092 default:
1093 FAIL();
1094 }
1095
1096 // Restric the number of output channels not to exceed
1097 // the number of input channels.
1098 frame_data_.output_number_of_channels =
1099 std::min(frame_data_.output_number_of_channels,
1100 frame_data_.input_number_of_channels);
1101}
1102
1103} // anonymous namespace
1104
1105TEST_P(AudioProcessingImplLockTest, LockTest) {
1106 // Run test and verify that it did not time out.
peah631e1342015-12-03 09:15:271107 ASSERT_TRUE(RunTest());
peah1f1912d2015-11-09 11:13:191108}
1109
1110// Instantiate tests from the extreme test configuration set.
1111INSTANTIATE_TEST_CASE_P(
1112 DISABLED_AudioProcessingImplLockExtensive,
1113 AudioProcessingImplLockTest,
1114 ::testing::ValuesIn(TestConfig::GenerateExtensiveTestConfigs()));
1115
1116INSTANTIATE_TEST_CASE_P(
peahdf3efa82015-11-28 20:35:151117 AudioProcessingImplLockBrief,
peah1f1912d2015-11-09 11:13:191118 AudioProcessingImplLockTest,
1119 ::testing::ValuesIn(TestConfig::GenerateBriefTestConfigs()));
1120
1121} // namespace webrtc