| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/modules/audio_processing/audio_processing_impl.h" | 11 #include "webrtc/modules/audio_processing/audio_processing_impl.h" |
| 12 | 12 |
| 13 #include <algorithm> | 13 #include <algorithm> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "webrtc/base/array_view.h" | 17 #include "webrtc/base/array_view.h" |
| 18 #include "webrtc/base/criticalsection.h" | 18 #include "webrtc/base/criticalsection.h" |
| 19 #include "webrtc/base/random.h" |
| 19 #include "webrtc/config.h" | 20 #include "webrtc/config.h" |
| 20 #include "webrtc/modules/audio_processing/test/test_utils.h" | 21 #include "webrtc/modules/audio_processing/test/test_utils.h" |
| 21 #include "webrtc/modules/include/module_common_types.h" | 22 #include "webrtc/modules/include/module_common_types.h" |
| 22 #include "webrtc/system_wrappers/include/event_wrapper.h" | 23 #include "webrtc/system_wrappers/include/event_wrapper.h" |
| 23 #include "webrtc/system_wrappers/include/sleep.h" | 24 #include "webrtc/system_wrappers/include/sleep.h" |
| 24 #include "webrtc/system_wrappers/include/thread_wrapper.h" | 25 #include "webrtc/system_wrappers/include/thread_wrapper.h" |
| 25 #include "webrtc/test/random.h" | |
| 26 | 26 |
| 27 namespace webrtc { | 27 namespace webrtc { |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 class AudioProcessingImplLockTest; | 31 class AudioProcessingImplLockTest; |
| 32 | 32 |
| 33 // Sleeps a random time between 0 and max_sleep milliseconds. | 33 // Sleeps a random time between 0 and max_sleep milliseconds. |
| 34 void SleepRandomMs(int max_sleep, test::Random* rand_gen) { | 34 void SleepRandomMs(int max_sleep, Random* rand_gen) { |
| 35 int sleeptime = rand_gen->Rand(0, max_sleep); | 35 int sleeptime = rand_gen->Rand(0, max_sleep); |
| 36 SleepMs(sleeptime); | 36 SleepMs(sleeptime); |
| 37 } | 37 } |
| 38 | 38 |
| 39 // Populates a float audio frame with random data. | 39 // Populates a float audio frame with random data. |
| 40 void PopulateAudioFrame(float** frame, | 40 void PopulateAudioFrame(float** frame, |
| 41 float amplitude, | 41 float amplitude, |
| 42 size_t num_channels, | 42 size_t num_channels, |
| 43 size_t samples_per_channel, | 43 size_t samples_per_channel, |
| 44 test::Random* rand_gen) { | 44 Random* rand_gen) { |
| 45 for (size_t ch = 0; ch < num_channels; ch++) { | 45 for (size_t ch = 0; ch < num_channels; ch++) { |
| 46 for (size_t k = 0; k < samples_per_channel; k++) { | 46 for (size_t k = 0; k < samples_per_channel; k++) { |
| 47 // Store random 16 bit quantized float number between +-amplitude. | 47 // Store random 16 bit quantized float number between +-amplitude. |
| 48 frame[ch][k] = amplitude * (2 * rand_gen->Rand<float>() - 1); | 48 frame[ch][k] = amplitude * (2 * rand_gen->Rand<float>() - 1); |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 | 52 |
| 53 // Populates an audioframe frame of AudioFrame type with random data. | 53 // Populates an audioframe frame of AudioFrame type with random data. |
| 54 void PopulateAudioFrame(AudioFrame* frame, | 54 void PopulateAudioFrame(AudioFrame* frame, |
| 55 int16_t amplitude, | 55 int16_t amplitude, |
| 56 test::Random* rand_gen) { | 56 Random* rand_gen) { |
| 57 ASSERT_GT(amplitude, 0); | 57 ASSERT_GT(amplitude, 0); |
| 58 ASSERT_LE(amplitude, 32767); | 58 ASSERT_LE(amplitude, 32767); |
| 59 for (int ch = 0; ch < frame->num_channels_; ch++) { | 59 for (int ch = 0; ch < frame->num_channels_; ch++) { |
| 60 for (int k = 0; k < static_cast<int>(frame->samples_per_channel_); k++) { | 60 for (int k = 0; k < static_cast<int>(frame->samples_per_channel_); k++) { |
| 61 // Store random 16 bit number between -(amplitude+1) and | 61 // Store random 16 bit number between -(amplitude+1) and |
| 62 // amplitude. | 62 // amplitude. |
| 63 frame->data_[k * ch] = rand_gen->Rand(2 * amplitude + 1) - amplitude - 1; | 63 frame->data_[k * ch] = rand_gen->Rand(2 * amplitude + 1) - amplitude - 1; |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 } | 66 } |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 | 324 |
| 325 private: | 325 private: |
| 326 rtc::CriticalSection crit_; | 326 rtc::CriticalSection crit_; |
| 327 bool capture_side_called_ GUARDED_BY(crit_) = false; | 327 bool capture_side_called_ GUARDED_BY(crit_) = false; |
| 328 }; | 328 }; |
| 329 | 329 |
| 330 // Class for handling the capture side processing. | 330 // Class for handling the capture side processing. |
| 331 class CaptureProcessor { | 331 class CaptureProcessor { |
| 332 public: | 332 public: |
| 333 CaptureProcessor(int max_frame_size, | 333 CaptureProcessor(int max_frame_size, |
| 334 test::Random* rand_gen, | 334 Random* rand_gen, |
| 335 FrameCounters* shared_counters_state, | 335 FrameCounters* shared_counters_state, |
| 336 CaptureSideCalledChecker* capture_call_checker, | 336 CaptureSideCalledChecker* capture_call_checker, |
| 337 AudioProcessingImplLockTest* test_framework, | 337 AudioProcessingImplLockTest* test_framework, |
| 338 TestConfig* test_config, | 338 TestConfig* test_config, |
| 339 AudioProcessing* apm); | 339 AudioProcessing* apm); |
| 340 bool Process(); | 340 bool Process(); |
| 341 | 341 |
| 342 private: | 342 private: |
| 343 static const int kMaxCallDifference = 10; | 343 static const int kMaxCallDifference = 10; |
| 344 static const float kCaptureInputFloatLevel; | 344 static const float kCaptureInputFloatLevel; |
| 345 static const int kCaptureInputFixLevel = 1024; | 345 static const int kCaptureInputFixLevel = 1024; |
| 346 | 346 |
| 347 void PrepareFrame(); | 347 void PrepareFrame(); |
| 348 void CallApmCaptureSide(); | 348 void CallApmCaptureSide(); |
| 349 void ApplyRuntimeSettingScheme(); | 349 void ApplyRuntimeSettingScheme(); |
| 350 | 350 |
| 351 test::Random* rand_gen_ = nullptr; | 351 Random* rand_gen_ = nullptr; |
| 352 FrameCounters* frame_counters_ = nullptr; | 352 FrameCounters* frame_counters_ = nullptr; |
| 353 CaptureSideCalledChecker* capture_call_checker_ = nullptr; | 353 CaptureSideCalledChecker* capture_call_checker_ = nullptr; |
| 354 AudioProcessingImplLockTest* test_ = nullptr; | 354 AudioProcessingImplLockTest* test_ = nullptr; |
| 355 TestConfig* test_config_ = nullptr; | 355 TestConfig* test_config_ = nullptr; |
| 356 AudioProcessing* apm_ = nullptr; | 356 AudioProcessing* apm_ = nullptr; |
| 357 AudioFrameData frame_data_; | 357 AudioFrameData frame_data_; |
| 358 }; | 358 }; |
| 359 | 359 |
| 360 // Class for handling the stats processing. | 360 // Class for handling the stats processing. |
| 361 class StatsProcessor { | 361 class StatsProcessor { |
| 362 public: | 362 public: |
| 363 StatsProcessor(test::Random* rand_gen, | 363 StatsProcessor(Random* rand_gen, |
| 364 TestConfig* test_config, | 364 TestConfig* test_config, |
| 365 AudioProcessing* apm); | 365 AudioProcessing* apm); |
| 366 bool Process(); | 366 bool Process(); |
| 367 | 367 |
| 368 private: | 368 private: |
| 369 test::Random* rand_gen_ = nullptr; | 369 Random* rand_gen_ = nullptr; |
| 370 TestConfig* test_config_ = nullptr; | 370 TestConfig* test_config_ = nullptr; |
| 371 AudioProcessing* apm_ = nullptr; | 371 AudioProcessing* apm_ = nullptr; |
| 372 }; | 372 }; |
| 373 | 373 |
| 374 // Class for handling the render side processing. | 374 // Class for handling the render side processing. |
| 375 class RenderProcessor { | 375 class RenderProcessor { |
| 376 public: | 376 public: |
| 377 RenderProcessor(int max_frame_size, | 377 RenderProcessor(int max_frame_size, |
| 378 test::Random* rand_gen, | 378 Random* rand_gen, |
| 379 FrameCounters* shared_counters_state, | 379 FrameCounters* shared_counters_state, |
| 380 CaptureSideCalledChecker* capture_call_checker, | 380 CaptureSideCalledChecker* capture_call_checker, |
| 381 AudioProcessingImplLockTest* test_framework, | 381 AudioProcessingImplLockTest* test_framework, |
| 382 TestConfig* test_config, | 382 TestConfig* test_config, |
| 383 AudioProcessing* apm); | 383 AudioProcessing* apm); |
| 384 bool Process(); | 384 bool Process(); |
| 385 | 385 |
| 386 private: | 386 private: |
| 387 static const int kMaxCallDifference = 10; | 387 static const int kMaxCallDifference = 10; |
| 388 static const int kRenderInputFixLevel = 16384; | 388 static const int kRenderInputFixLevel = 16384; |
| 389 static const float kRenderInputFloatLevel; | 389 static const float kRenderInputFloatLevel; |
| 390 | 390 |
| 391 void PrepareFrame(); | 391 void PrepareFrame(); |
| 392 void CallApmRenderSide(); | 392 void CallApmRenderSide(); |
| 393 void ApplyRuntimeSettingScheme(); | 393 void ApplyRuntimeSettingScheme(); |
| 394 | 394 |
| 395 test::Random* rand_gen_ = nullptr; | 395 Random* rand_gen_ = nullptr; |
| 396 FrameCounters* frame_counters_ = nullptr; | 396 FrameCounters* frame_counters_ = nullptr; |
| 397 CaptureSideCalledChecker* capture_call_checker_ = nullptr; | 397 CaptureSideCalledChecker* capture_call_checker_ = nullptr; |
| 398 AudioProcessingImplLockTest* test_ = nullptr; | 398 AudioProcessingImplLockTest* test_ = nullptr; |
| 399 TestConfig* test_config_ = nullptr; | 399 TestConfig* test_config_ = nullptr; |
| 400 AudioProcessing* apm_ = nullptr; | 400 AudioProcessing* apm_ = nullptr; |
| 401 bool first_render_side_call_ = true; | 401 bool first_render_side_call_ = true; |
| 402 AudioFrameData frame_data_; | 402 AudioFrameData frame_data_; |
| 403 }; | 403 }; |
| 404 | 404 |
| 405 class AudioProcessingImplLockTest | 405 class AudioProcessingImplLockTest |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 stats_thread_->SetPriority(kNormalPriority); | 452 stats_thread_->SetPriority(kNormalPriority); |
| 453 } | 453 } |
| 454 | 454 |
| 455 // Event handler for the test. | 455 // Event handler for the test. |
| 456 const rtc::scoped_ptr<EventWrapper> test_complete_; | 456 const rtc::scoped_ptr<EventWrapper> test_complete_; |
| 457 | 457 |
| 458 // Thread related variables. | 458 // Thread related variables. |
| 459 rtc::scoped_ptr<ThreadWrapper> render_thread_; | 459 rtc::scoped_ptr<ThreadWrapper> render_thread_; |
| 460 rtc::scoped_ptr<ThreadWrapper> capture_thread_; | 460 rtc::scoped_ptr<ThreadWrapper> capture_thread_; |
| 461 rtc::scoped_ptr<ThreadWrapper> stats_thread_; | 461 rtc::scoped_ptr<ThreadWrapper> stats_thread_; |
| 462 mutable test::Random rand_gen_; | 462 mutable Random rand_gen_; |
| 463 | 463 |
| 464 rtc::scoped_ptr<AudioProcessing> apm_; | 464 rtc::scoped_ptr<AudioProcessing> apm_; |
| 465 TestConfig test_config_; | 465 TestConfig test_config_; |
| 466 FrameCounters frame_counters_; | 466 FrameCounters frame_counters_; |
| 467 CaptureSideCalledChecker capture_call_checker_; | 467 CaptureSideCalledChecker capture_call_checker_; |
| 468 RenderProcessor render_thread_state_; | 468 RenderProcessor render_thread_state_; |
| 469 CaptureProcessor capture_thread_state_; | 469 CaptureProcessor capture_thread_state_; |
| 470 StatsProcessor stats_thread_state_; | 470 StatsProcessor stats_thread_state_; |
| 471 }; | 471 }; |
| 472 | 472 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 apm_->SetExtraOptions(config); | 550 apm_->SetExtraOptions(config); |
| 551 } | 551 } |
| 552 } | 552 } |
| 553 | 553 |
| 554 void AudioProcessingImplLockTest::TearDown() { | 554 void AudioProcessingImplLockTest::TearDown() { |
| 555 render_thread_->Stop(); | 555 render_thread_->Stop(); |
| 556 capture_thread_->Stop(); | 556 capture_thread_->Stop(); |
| 557 stats_thread_->Stop(); | 557 stats_thread_->Stop(); |
| 558 } | 558 } |
| 559 | 559 |
| 560 StatsProcessor::StatsProcessor(test::Random* rand_gen, | 560 StatsProcessor::StatsProcessor(Random* rand_gen, |
| 561 TestConfig* test_config, | 561 TestConfig* test_config, |
| 562 AudioProcessing* apm) | 562 AudioProcessing* apm) |
| 563 : rand_gen_(rand_gen), test_config_(test_config), apm_(apm) {} | 563 : rand_gen_(rand_gen), test_config_(test_config), apm_(apm) {} |
| 564 | 564 |
| 565 // Implements the callback functionality for the statistics | 565 // Implements the callback functionality for the statistics |
| 566 // collection thread. | 566 // collection thread. |
| 567 bool StatsProcessor::Process() { | 567 bool StatsProcessor::Process() { |
| 568 SleepRandomMs(100, rand_gen_); | 568 SleepRandomMs(100, rand_gen_); |
| 569 | 569 |
| 570 EXPECT_EQ(apm_->echo_cancellation()->is_enabled(), | 570 EXPECT_EQ(apm_->echo_cancellation()->is_enabled(), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 584 apm_->noise_suppression()->speech_probability(); | 584 apm_->noise_suppression()->speech_probability(); |
| 585 apm_->voice_detection()->is_enabled(); | 585 apm_->voice_detection()->is_enabled(); |
| 586 | 586 |
| 587 return true; | 587 return true; |
| 588 } | 588 } |
| 589 | 589 |
| 590 const float CaptureProcessor::kCaptureInputFloatLevel = 0.03125f; | 590 const float CaptureProcessor::kCaptureInputFloatLevel = 0.03125f; |
| 591 | 591 |
| 592 CaptureProcessor::CaptureProcessor( | 592 CaptureProcessor::CaptureProcessor( |
| 593 int max_frame_size, | 593 int max_frame_size, |
| 594 test::Random* rand_gen, | 594 Random* rand_gen, |
| 595 FrameCounters* shared_counters_state, | 595 FrameCounters* shared_counters_state, |
| 596 CaptureSideCalledChecker* capture_call_checker, | 596 CaptureSideCalledChecker* capture_call_checker, |
| 597 AudioProcessingImplLockTest* test_framework, | 597 AudioProcessingImplLockTest* test_framework, |
| 598 TestConfig* test_config, | 598 TestConfig* test_config, |
| 599 AudioProcessing* apm) | 599 AudioProcessing* apm) |
| 600 : rand_gen_(rand_gen), | 600 : rand_gen_(rand_gen), |
| 601 frame_counters_(shared_counters_state), | 601 frame_counters_(shared_counters_state), |
| 602 capture_call_checker_(capture_call_checker), | 602 capture_call_checker_(capture_call_checker), |
| 603 test_(test_framework), | 603 test_(test_framework), |
| 604 test_config_(test_config), | 604 test_config_(test_config), |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 // Restric the number of output channels not to exceed | 852 // Restric the number of output channels not to exceed |
| 853 // the number of input channels. | 853 // the number of input channels. |
| 854 frame_data_.output_number_of_channels = | 854 frame_data_.output_number_of_channels = |
| 855 std::min(frame_data_.output_number_of_channels, | 855 std::min(frame_data_.output_number_of_channels, |
| 856 frame_data_.input_number_of_channels); | 856 frame_data_.input_number_of_channels); |
| 857 } | 857 } |
| 858 | 858 |
| 859 const float RenderProcessor::kRenderInputFloatLevel = 0.5f; | 859 const float RenderProcessor::kRenderInputFloatLevel = 0.5f; |
| 860 | 860 |
| 861 RenderProcessor::RenderProcessor(int max_frame_size, | 861 RenderProcessor::RenderProcessor(int max_frame_size, |
| 862 test::Random* rand_gen, | 862 Random* rand_gen, |
| 863 FrameCounters* shared_counters_state, | 863 FrameCounters* shared_counters_state, |
| 864 CaptureSideCalledChecker* capture_call_checker, | 864 CaptureSideCalledChecker* capture_call_checker, |
| 865 AudioProcessingImplLockTest* test_framework, | 865 AudioProcessingImplLockTest* test_framework, |
| 866 TestConfig* test_config, | 866 TestConfig* test_config, |
| 867 AudioProcessing* apm) | 867 AudioProcessing* apm) |
| 868 : rand_gen_(rand_gen), | 868 : rand_gen_(rand_gen), |
| 869 frame_counters_(shared_counters_state), | 869 frame_counters_(shared_counters_state), |
| 870 capture_call_checker_(capture_call_checker), | 870 capture_call_checker_(capture_call_checker), |
| 871 test_(test_framework), | 871 test_(test_framework), |
| 872 test_config_(test_config), | 872 test_config_(test_config), |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1109 DISABLED_AudioProcessingImplLockExtensive, | 1109 DISABLED_AudioProcessingImplLockExtensive, |
| 1110 AudioProcessingImplLockTest, | 1110 AudioProcessingImplLockTest, |
| 1111 ::testing::ValuesIn(TestConfig::GenerateExtensiveTestConfigs())); | 1111 ::testing::ValuesIn(TestConfig::GenerateExtensiveTestConfigs())); |
| 1112 | 1112 |
| 1113 INSTANTIATE_TEST_CASE_P( | 1113 INSTANTIATE_TEST_CASE_P( |
| 1114 DISABLED_AudioProcessingImplLockBrief, | 1114 DISABLED_AudioProcessingImplLockBrief, |
| 1115 AudioProcessingImplLockTest, | 1115 AudioProcessingImplLockTest, |
| 1116 ::testing::ValuesIn(TestConfig::GenerateBriefTestConfigs())); | 1116 ::testing::ValuesIn(TestConfig::GenerateBriefTestConfigs())); |
| 1117 | 1117 |
| 1118 } // namespace webrtc | 1118 } // namespace webrtc |
| OLD | NEW |