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/event.h" | |
19 #include "webrtc/base/platform_thread.h" | 20 #include "webrtc/base/platform_thread.h" |
20 #include "webrtc/config.h" | 21 #include "webrtc/config.h" |
21 #include "webrtc/modules/audio_processing/test/test_utils.h" | 22 #include "webrtc/modules/audio_processing/test/test_utils.h" |
22 #include "webrtc/modules/include/module_common_types.h" | 23 #include "webrtc/modules/include/module_common_types.h" |
23 #include "webrtc/system_wrappers/include/event_wrapper.h" | |
24 #include "webrtc/system_wrappers/include/sleep.h" | 24 #include "webrtc/system_wrappers/include/sleep.h" |
25 #include "webrtc/test/random.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 // Type of the render thread APM API call to use in the test. | 33 // Type of the render thread APM API call to use in the test. |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
266 void IncreaseRenderCounter() { | 266 void IncreaseRenderCounter() { |
267 rtc::CritScope cs(&crit_); | 267 rtc::CritScope cs(&crit_); |
268 render_count++; | 268 render_count++; |
269 } | 269 } |
270 | 270 |
271 void IncreaseCaptureCounter() { | 271 void IncreaseCaptureCounter() { |
272 rtc::CritScope cs(&crit_); | 272 rtc::CritScope cs(&crit_); |
273 capture_count++; | 273 capture_count++; |
274 } | 274 } |
275 | 275 |
276 int GetCaptureCounter() { | 276 int GetCaptureCounter() const { |
277 rtc::CritScope cs(&crit_); | 277 rtc::CritScope cs(&crit_); |
278 return capture_count; | 278 return capture_count; |
279 } | 279 } |
280 | 280 |
281 int GetRenderCounter() { | 281 int GetRenderCounter() const { |
282 rtc::CritScope cs(&crit_); | 282 rtc::CritScope cs(&crit_); |
283 return render_count; | 283 return render_count; |
284 } | 284 } |
285 | 285 |
286 int CaptureMinusRenderCounters() { | 286 int CaptureMinusRenderCounters() const { |
287 rtc::CritScope cs(&crit_); | 287 rtc::CritScope cs(&crit_); |
288 return capture_count - render_count; | 288 return capture_count - render_count; |
289 } | 289 } |
290 | 290 |
291 int RenderMinusCaptureCounters() const { | |
292 return -CaptureMinusRenderCounters(); | |
293 } | |
294 | |
295 | |
291 bool BothCountersExceedeThreshold(int threshold) { | 296 bool BothCountersExceedeThreshold(int threshold) { |
292 rtc::CritScope cs(&crit_); | 297 rtc::CritScope cs(&crit_); |
293 return (render_count > threshold && capture_count > threshold); | 298 return (render_count > threshold && capture_count > threshold); |
294 } | 299 } |
295 | 300 |
296 private: | 301 private: |
297 rtc::CriticalSection crit_; | 302 mutable rtc::CriticalSection crit_; |
298 int render_count GUARDED_BY(crit_) = 0; | 303 int render_count GUARDED_BY(crit_) = 0; |
299 int capture_count GUARDED_BY(crit_) = 0; | 304 int capture_count GUARDED_BY(crit_) = 0; |
300 }; | 305 }; |
301 | 306 |
302 // Checker for whether the capture side has been called. | |
303 class CaptureSideCalledChecker { | |
304 public: | |
305 bool CaptureSideCalled() { | |
306 rtc::CritScope cs(&crit_); | |
307 return capture_side_called_; | |
308 } | |
309 | |
310 void FlagCaptureSideCalled() { | |
311 rtc::CritScope cs(&crit_); | |
312 capture_side_called_ = true; | |
313 } | |
314 | |
315 private: | |
316 rtc::CriticalSection crit_; | |
317 bool capture_side_called_ GUARDED_BY(crit_) = false; | |
318 }; | |
319 | |
320 // Class for handling the capture side processing. | 307 // Class for handling the capture side processing. |
321 class CaptureProcessor { | 308 class CaptureProcessor { |
322 public: | 309 public: |
323 CaptureProcessor(int max_frame_size, | 310 CaptureProcessor(int max_frame_size, |
324 RandomGenerator* rand_gen, | 311 RandomGenerator* rand_gen, |
312 rtc::Event* render_call_event, | |
313 rtc::Event* capture_call_event, | |
325 FrameCounters* shared_counters_state, | 314 FrameCounters* shared_counters_state, |
326 CaptureSideCalledChecker* capture_call_checker, | |
327 AudioProcessingImplLockTest* test_framework, | 315 AudioProcessingImplLockTest* test_framework, |
328 TestConfig* test_config, | 316 TestConfig* test_config, |
329 AudioProcessing* apm); | 317 AudioProcessing* apm); |
330 bool Process(); | 318 bool Process(); |
331 | 319 |
332 private: | 320 private: |
333 static const int kMaxCallDifference = 10; | 321 static const int kMaxCallDifference = 10; |
334 static const float kCaptureInputFloatLevel; | 322 static const float kCaptureInputFloatLevel; |
335 static const int kCaptureInputFixLevel = 1024; | 323 static const int kCaptureInputFixLevel = 1024; |
336 | 324 |
337 void PrepareFrame(); | 325 void PrepareFrame(); |
338 void CallApmCaptureSide(); | 326 void CallApmCaptureSide(); |
339 void ApplyRuntimeSettingScheme(); | 327 void ApplyRuntimeSettingScheme(); |
340 | 328 |
341 RandomGenerator* rand_gen_ = nullptr; | 329 RandomGenerator* rand_gen_ = nullptr; |
330 rtc::Event* render_call_event_; | |
pbos-webrtc
2015/12/02 15:33:13
* const
peah-webrtc
2015/12/02 22:44:41
Added some more const specifiers as well.
Done.
| |
331 rtc::Event* capture_call_event_; | |
pbos-webrtc
2015/12/02 15:33:13
* const
peah-webrtc
2015/12/02 22:44:41
Added some more const specifiers as well.
Done.
| |
342 FrameCounters* frame_counters_ = nullptr; | 332 FrameCounters* frame_counters_ = nullptr; |
343 CaptureSideCalledChecker* capture_call_checker_ = nullptr; | |
344 AudioProcessingImplLockTest* test_ = nullptr; | 333 AudioProcessingImplLockTest* test_ = nullptr; |
345 TestConfig* test_config_ = nullptr; | 334 TestConfig* test_config_ = nullptr; |
346 AudioProcessing* apm_ = nullptr; | 335 AudioProcessing* apm_ = nullptr; |
347 AudioFrameData frame_data_; | 336 AudioFrameData frame_data_; |
348 }; | 337 }; |
349 | 338 |
350 // Class for handling the stats processing. | 339 // Class for handling the stats processing. |
351 class StatsProcessor { | 340 class StatsProcessor { |
352 public: | 341 public: |
353 StatsProcessor(RandomGenerator* rand_gen, | 342 StatsProcessor(RandomGenerator* rand_gen, |
354 TestConfig* test_config, | 343 TestConfig* test_config, |
355 AudioProcessing* apm); | 344 AudioProcessing* apm); |
356 bool Process(); | 345 bool Process(); |
357 | 346 |
358 private: | 347 private: |
359 RandomGenerator* rand_gen_ = nullptr; | 348 RandomGenerator* rand_gen_ = nullptr; |
360 TestConfig* test_config_ = nullptr; | 349 TestConfig* test_config_ = nullptr; |
361 AudioProcessing* apm_ = nullptr; | 350 AudioProcessing* apm_ = nullptr; |
362 }; | 351 }; |
363 | 352 |
364 // Class for handling the render side processing. | 353 // Class for handling the render side processing. |
365 class RenderProcessor { | 354 class RenderProcessor { |
366 public: | 355 public: |
367 RenderProcessor(int max_frame_size, | 356 RenderProcessor(int max_frame_size, |
368 RandomGenerator* rand_gen, | 357 RandomGenerator* rand_gen, |
358 rtc::Event* render_call_event, | |
359 rtc::Event* capture_call_event, | |
369 FrameCounters* shared_counters_state, | 360 FrameCounters* shared_counters_state, |
370 CaptureSideCalledChecker* capture_call_checker, | |
371 AudioProcessingImplLockTest* test_framework, | 361 AudioProcessingImplLockTest* test_framework, |
372 TestConfig* test_config, | 362 TestConfig* test_config, |
373 AudioProcessing* apm); | 363 AudioProcessing* apm); |
374 bool Process(); | 364 bool Process(); |
375 | 365 |
376 private: | 366 private: |
377 static const int kMaxCallDifference = 10; | 367 static const int kMaxCallDifference = 10; |
378 static const int kRenderInputFixLevel = 16384; | 368 static const int kRenderInputFixLevel = 16384; |
379 static const float kRenderInputFloatLevel; | 369 static const float kRenderInputFloatLevel; |
380 | 370 |
381 void PrepareFrame(); | 371 void PrepareFrame(); |
382 void CallApmRenderSide(); | 372 void CallApmRenderSide(); |
383 void ApplyRuntimeSettingScheme(); | 373 void ApplyRuntimeSettingScheme(); |
384 | 374 |
385 RandomGenerator* rand_gen_ = nullptr; | 375 RandomGenerator* rand_gen_ = nullptr; |
376 rtc::Event* render_call_event_; | |
pbos-webrtc
2015/12/02 15:33:13
* const
peah-webrtc
2015/12/02 22:44:41
Added some more const specifiers as well.
Done.
| |
377 rtc::Event* capture_call_event_; | |
pbos-webrtc
2015/12/02 15:33:13
* const
peah-webrtc
2015/12/02 22:44:41
Added some more const specifiers as well.
Done.
| |
386 FrameCounters* frame_counters_ = nullptr; | 378 FrameCounters* frame_counters_ = nullptr; |
387 CaptureSideCalledChecker* capture_call_checker_ = nullptr; | |
388 AudioProcessingImplLockTest* test_ = nullptr; | 379 AudioProcessingImplLockTest* test_ = nullptr; |
389 TestConfig* test_config_ = nullptr; | 380 TestConfig* test_config_ = nullptr; |
390 AudioProcessing* apm_ = nullptr; | 381 AudioProcessing* apm_ = nullptr; |
391 bool first_render_side_call_ = true; | |
392 AudioFrameData frame_data_; | 382 AudioFrameData frame_data_; |
383 bool first_render_call_ = true; | |
393 }; | 384 }; |
394 | 385 |
395 class AudioProcessingImplLockTest | 386 class AudioProcessingImplLockTest |
396 : public ::testing::TestWithParam<TestConfig> { | 387 : public ::testing::TestWithParam<TestConfig> { |
397 public: | 388 public: |
398 AudioProcessingImplLockTest(); | 389 AudioProcessingImplLockTest(); |
399 EventTypeWrapper RunTest(); | 390 bool RunTest(); |
400 void CheckTestCompleteness(); | 391 bool MaybeEndTest(); |
401 | 392 |
402 private: | 393 private: |
403 static const int kTestTimeOutLimit = 10 * 60 * 1000; | 394 static const int kTestTimeOutLimit = 10 * 60 * 1000; |
404 static const int kMaxFrameSize = 480; | 395 static const int kMaxFrameSize = 480; |
405 | 396 |
406 // ::testing::TestWithParam<> implementation | 397 // ::testing::TestWithParam<> implementation |
407 void SetUp() override; | 398 void SetUp() override; |
408 void TearDown() override; | 399 void TearDown() override; |
409 | 400 |
410 // Thread callback for the render thread | 401 // Thread callback for the render thread |
(...skipping 24 matching lines...) Expand all Loading... | |
435 // Start the threads used in the test. | 426 // Start the threads used in the test. |
436 void StartThreads() { | 427 void StartThreads() { |
437 render_thread_.Start(); | 428 render_thread_.Start(); |
438 render_thread_.SetPriority(rtc::kRealtimePriority); | 429 render_thread_.SetPriority(rtc::kRealtimePriority); |
439 capture_thread_.Start(); | 430 capture_thread_.Start(); |
440 capture_thread_.SetPriority(rtc::kRealtimePriority); | 431 capture_thread_.SetPriority(rtc::kRealtimePriority); |
441 stats_thread_.Start(); | 432 stats_thread_.Start(); |
442 stats_thread_.SetPriority(rtc::kNormalPriority); | 433 stats_thread_.SetPriority(rtc::kNormalPriority); |
443 } | 434 } |
444 | 435 |
445 // Event handler for the test. | 436 // Event handlers for the test. |
446 const rtc::scoped_ptr<EventWrapper> test_complete_; | 437 rtc::Event test_complete_; |
438 rtc::Event render_call_event_; | |
439 rtc::Event capture_call_event_; | |
447 | 440 |
448 // Thread related variables. | 441 // Thread related variables. |
449 rtc::PlatformThread render_thread_; | 442 rtc::PlatformThread render_thread_; |
450 rtc::PlatformThread capture_thread_; | 443 rtc::PlatformThread capture_thread_; |
451 rtc::PlatformThread stats_thread_; | 444 rtc::PlatformThread stats_thread_; |
452 mutable RandomGenerator rand_gen_; | 445 mutable RandomGenerator rand_gen_; |
453 | 446 |
454 rtc::scoped_ptr<AudioProcessing> apm_; | 447 rtc::scoped_ptr<AudioProcessing> apm_; |
455 TestConfig test_config_; | 448 TestConfig test_config_; |
456 FrameCounters frame_counters_; | 449 FrameCounters frame_counters_; |
457 CaptureSideCalledChecker capture_call_checker_; | |
458 RenderProcessor render_thread_state_; | 450 RenderProcessor render_thread_state_; |
459 CaptureProcessor capture_thread_state_; | 451 CaptureProcessor capture_thread_state_; |
460 StatsProcessor stats_thread_state_; | 452 StatsProcessor stats_thread_state_; |
461 }; | 453 }; |
462 | 454 |
463 // Sleeps a random time between 0 and max_sleep milliseconds. | 455 // Sleeps a random time between 0 and max_sleep milliseconds. |
464 void SleepRandomMs(int max_sleep, RandomGenerator* rand_gen) { | 456 void SleepRandomMs(int max_sleep, RandomGenerator* rand_gen) { |
465 int sleeptime = rand_gen->RandInt(0, max_sleep); | 457 int sleeptime = rand_gen->RandInt(0, max_sleep); |
466 SleepMs(sleeptime); | 458 SleepMs(sleeptime); |
467 } | 459 } |
(...skipping 22 matching lines...) Expand all Loading... | |
490 for (int k = 0; k < static_cast<int>(frame->samples_per_channel_); k++) { | 482 for (int k = 0; k < static_cast<int>(frame->samples_per_channel_); k++) { |
491 // Store random 16 bit number between -(amplitude+1) and | 483 // Store random 16 bit number between -(amplitude+1) and |
492 // amplitude. | 484 // amplitude. |
493 frame->data_[k * ch] = | 485 frame->data_[k * ch] = |
494 rand_gen->RandInt(2 * amplitude + 1) - amplitude - 1; | 486 rand_gen->RandInt(2 * amplitude + 1) - amplitude - 1; |
495 } | 487 } |
496 } | 488 } |
497 } | 489 } |
498 | 490 |
499 AudioProcessingImplLockTest::AudioProcessingImplLockTest() | 491 AudioProcessingImplLockTest::AudioProcessingImplLockTest() |
500 : test_complete_(EventWrapper::Create()), | 492 : test_complete_(false, false), |
493 render_call_event_(false, false), | |
494 capture_call_event_(false, false), | |
501 render_thread_(RenderProcessorThreadFunc, this, "render"), | 495 render_thread_(RenderProcessorThreadFunc, this, "render"), |
502 capture_thread_(CaptureProcessorThreadFunc, this, "capture"), | 496 capture_thread_(CaptureProcessorThreadFunc, this, "capture"), |
503 stats_thread_(StatsProcessorThreadFunc, this, "stats"), | 497 stats_thread_(StatsProcessorThreadFunc, this, "stats"), |
504 apm_(AudioProcessingImpl::Create()), | 498 apm_(AudioProcessingImpl::Create()), |
505 render_thread_state_(kMaxFrameSize, | 499 render_thread_state_(kMaxFrameSize, |
506 &rand_gen_, | 500 &rand_gen_, |
501 &render_call_event_, | |
502 &capture_call_event_, | |
507 &frame_counters_, | 503 &frame_counters_, |
508 &capture_call_checker_, | |
509 this, | 504 this, |
510 &test_config_, | 505 &test_config_, |
511 apm_.get()), | 506 apm_.get()), |
512 capture_thread_state_(kMaxFrameSize, | 507 capture_thread_state_(kMaxFrameSize, |
513 &rand_gen_, | 508 &rand_gen_, |
509 &render_call_event_, | |
510 &capture_call_event_, | |
514 &frame_counters_, | 511 &frame_counters_, |
515 &capture_call_checker_, | |
516 this, | 512 this, |
517 &test_config_, | 513 &test_config_, |
518 apm_.get()), | 514 apm_.get()), |
519 stats_thread_state_(&rand_gen_, &test_config_, apm_.get()) {} | 515 stats_thread_state_(&rand_gen_, &test_config_, apm_.get()) {} |
520 | 516 |
521 // Run the test with a timeout. | 517 // Run the test with a timeout. |
522 EventTypeWrapper AudioProcessingImplLockTest::RunTest() { | 518 bool AudioProcessingImplLockTest::RunTest() { |
523 StartThreads(); | 519 StartThreads(); |
524 return test_complete_->Wait(kTestTimeOutLimit); | 520 return test_complete_.Wait(kTestTimeOutLimit); |
525 } | 521 } |
526 | 522 |
527 void AudioProcessingImplLockTest::CheckTestCompleteness() { | 523 bool AudioProcessingImplLockTest::MaybeEndTest() { |
528 if (HasFatalFailure() || TestDone()) { | 524 if (HasFatalFailure() || TestDone()) { |
529 test_complete_->Set(); | 525 test_complete_.Set(); |
526 return true; | |
530 } | 527 } |
528 return false; | |
531 } | 529 } |
532 | 530 |
533 // Setup of test and APM. | 531 // Setup of test and APM. |
534 void AudioProcessingImplLockTest::SetUp() { | 532 void AudioProcessingImplLockTest::SetUp() { |
535 test_config_ = static_cast<TestConfig>(GetParam()); | 533 test_config_ = static_cast<TestConfig>(GetParam()); |
536 | 534 |
537 ASSERT_EQ(apm_->kNoError, apm_->level_estimator()->Enable(true)); | 535 ASSERT_EQ(apm_->kNoError, apm_->level_estimator()->Enable(true)); |
538 ASSERT_EQ(apm_->kNoError, apm_->gain_control()->Enable(true)); | 536 ASSERT_EQ(apm_->kNoError, apm_->gain_control()->Enable(true)); |
539 | 537 |
540 ASSERT_EQ(apm_->kNoError, | 538 ASSERT_EQ(apm_->kNoError, |
(...skipping 24 matching lines...) Expand all Loading... | |
565 | 563 |
566 config.Set<DelayAgnostic>( | 564 config.Set<DelayAgnostic>( |
567 new DelayAgnostic(test_config_.aec_type == | 565 new DelayAgnostic(test_config_.aec_type == |
568 AecType::BasicWebRtcAecSettingsWithDelayAgnosticAec)); | 566 AecType::BasicWebRtcAecSettingsWithDelayAgnosticAec)); |
569 | 567 |
570 apm_->SetExtraOptions(config); | 568 apm_->SetExtraOptions(config); |
571 } | 569 } |
572 } | 570 } |
573 | 571 |
574 void AudioProcessingImplLockTest::TearDown() { | 572 void AudioProcessingImplLockTest::TearDown() { |
573 render_call_event_.Set(); | |
574 capture_call_event_.Set(); | |
575 render_thread_.Stop(); | 575 render_thread_.Stop(); |
576 capture_thread_.Stop(); | 576 capture_thread_.Stop(); |
577 stats_thread_.Stop(); | 577 stats_thread_.Stop(); |
578 } | 578 } |
579 | 579 |
580 StatsProcessor::StatsProcessor(RandomGenerator* rand_gen, | 580 StatsProcessor::StatsProcessor(RandomGenerator* rand_gen, |
581 TestConfig* test_config, | 581 TestConfig* test_config, |
582 AudioProcessing* apm) | 582 AudioProcessing* apm) |
583 : rand_gen_(rand_gen), test_config_(test_config), apm_(apm) {} | 583 : rand_gen_(rand_gen), test_config_(test_config), apm_(apm) {} |
584 | 584 |
(...skipping 20 matching lines...) Expand all Loading... | |
605 apm_->voice_detection()->is_enabled(); | 605 apm_->voice_detection()->is_enabled(); |
606 | 606 |
607 return true; | 607 return true; |
608 } | 608 } |
609 | 609 |
610 const float CaptureProcessor::kCaptureInputFloatLevel = 0.03125f; | 610 const float CaptureProcessor::kCaptureInputFloatLevel = 0.03125f; |
611 | 611 |
612 CaptureProcessor::CaptureProcessor( | 612 CaptureProcessor::CaptureProcessor( |
613 int max_frame_size, | 613 int max_frame_size, |
614 RandomGenerator* rand_gen, | 614 RandomGenerator* rand_gen, |
615 rtc::Event* render_call_event, | |
616 rtc::Event* capture_call_event, | |
615 FrameCounters* shared_counters_state, | 617 FrameCounters* shared_counters_state, |
616 CaptureSideCalledChecker* capture_call_checker, | |
617 AudioProcessingImplLockTest* test_framework, | 618 AudioProcessingImplLockTest* test_framework, |
618 TestConfig* test_config, | 619 TestConfig* test_config, |
619 AudioProcessing* apm) | 620 AudioProcessing* apm) |
620 : rand_gen_(rand_gen), | 621 : rand_gen_(rand_gen), |
622 render_call_event_(render_call_event), | |
623 capture_call_event_(capture_call_event), | |
621 frame_counters_(shared_counters_state), | 624 frame_counters_(shared_counters_state), |
622 capture_call_checker_(capture_call_checker), | |
623 test_(test_framework), | 625 test_(test_framework), |
624 test_config_(test_config), | 626 test_config_(test_config), |
625 apm_(apm), | 627 apm_(apm), |
626 frame_data_(max_frame_size) {} | 628 frame_data_(max_frame_size) {} |
627 | 629 |
628 // Implements the callback functionality for the capture thread. | 630 // Implements the callback functionality for the capture thread. |
629 bool CaptureProcessor::Process() { | 631 bool CaptureProcessor::Process() { |
630 // Sleep a random time to simulate thread jitter. | 632 // Sleep a random time to simulate thread jitter. |
631 SleepRandomMs(3, rand_gen_); | 633 SleepRandomMs(3, rand_gen_); |
632 | 634 |
633 // End the test if complete. | |
634 test_->CheckTestCompleteness(); | |
635 | |
636 // Ensure that there are not more capture side calls than render side | 635 // Ensure that there are not more capture side calls than render side |
637 // calls. | 636 // calls. |
638 if (capture_call_checker_->CaptureSideCalled()) { | 637 while (!test_->MaybeEndTest() && |
639 while (kMaxCallDifference < frame_counters_->CaptureMinusRenderCounters()) { | 638 frame_counters_->CaptureMinusRenderCounters() > kMaxCallDifference) { |
640 SleepMs(1); | 639 render_call_event_->Wait(1); |
pbos-webrtc
2015/12/02 15:33:13
This should wait indefinitely right? Any shutdown
peah-webrtc
2015/12/02 22:44:41
Awesome! Great! Made the change.
Done.
| |
641 } | |
642 } | 640 } |
643 | 641 |
644 // Apply any specified capture side APM non-processing runtime calls. | 642 // Apply any specified capture side APM non-processing runtime calls. |
645 ApplyRuntimeSettingScheme(); | 643 ApplyRuntimeSettingScheme(); |
646 | 644 |
647 // Apply the capture side processing call. | 645 // Apply the capture side processing call. |
648 CallApmCaptureSide(); | 646 CallApmCaptureSide(); |
649 | 647 |
650 // Increase the number of capture-side calls. | 648 // Increase the number of capture-side calls. |
651 frame_counters_->IncreaseCaptureCounter(); | 649 frame_counters_->IncreaseCaptureCounter(); |
652 | 650 |
653 // Flag that the capture side has been called at least once | 651 // Flag to the render thread that another capture api call has occurred |
654 // (needed to ensure that a capture call has been done | 652 // by triggering this threads call event. |
655 // before the first render call is performed (implicitly | 653 capture_call_event_->Set(); |
656 // required by the APM API). | |
657 capture_call_checker_->FlagCaptureSideCalled(); | |
658 | 654 |
659 return true; | 655 return true; |
660 } | 656 } |
661 | 657 |
662 // Prepares a frame with relevant audio data and metadata. | 658 // Prepares a frame with relevant audio data and metadata. |
663 void CaptureProcessor::PrepareFrame() { | 659 void CaptureProcessor::PrepareFrame() { |
664 // Restrict to a common fixed sample rate if the AudioFrame | 660 // Restrict to a common fixed sample rate if the AudioFrame |
665 // interface is used. | 661 // interface is used. |
666 if (test_config_->capture_api_function == | 662 if (test_config_->capture_api_function == |
667 CaptureApiImpl::ProcessStreamImpl1) { | 663 CaptureApiImpl::ProcessStreamImpl1) { |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
866 // the number of input channels. | 862 // the number of input channels. |
867 frame_data_.output_number_of_channels = | 863 frame_data_.output_number_of_channels = |
868 std::min(frame_data_.output_number_of_channels, | 864 std::min(frame_data_.output_number_of_channels, |
869 frame_data_.input_number_of_channels); | 865 frame_data_.input_number_of_channels); |
870 } | 866 } |
871 | 867 |
872 const float RenderProcessor::kRenderInputFloatLevel = 0.5f; | 868 const float RenderProcessor::kRenderInputFloatLevel = 0.5f; |
873 | 869 |
874 RenderProcessor::RenderProcessor(int max_frame_size, | 870 RenderProcessor::RenderProcessor(int max_frame_size, |
875 RandomGenerator* rand_gen, | 871 RandomGenerator* rand_gen, |
872 rtc::Event* render_call_event, | |
873 rtc::Event* capture_call_event, | |
876 FrameCounters* shared_counters_state, | 874 FrameCounters* shared_counters_state, |
877 CaptureSideCalledChecker* capture_call_checker, | |
878 AudioProcessingImplLockTest* test_framework, | 875 AudioProcessingImplLockTest* test_framework, |
879 TestConfig* test_config, | 876 TestConfig* test_config, |
880 AudioProcessing* apm) | 877 AudioProcessing* apm) |
881 : rand_gen_(rand_gen), | 878 : rand_gen_(rand_gen), |
879 render_call_event_(render_call_event), | |
880 capture_call_event_(capture_call_event), | |
882 frame_counters_(shared_counters_state), | 881 frame_counters_(shared_counters_state), |
883 capture_call_checker_(capture_call_checker), | |
884 test_(test_framework), | 882 test_(test_framework), |
885 test_config_(test_config), | 883 test_config_(test_config), |
886 apm_(apm), | 884 apm_(apm), |
887 frame_data_(max_frame_size) {} | 885 frame_data_(max_frame_size) {} |
888 | 886 |
889 // Implements the callback functionality for the render thread. | 887 // Implements the callback functionality for the render thread. |
890 bool RenderProcessor::Process() { | 888 bool RenderProcessor::Process() { |
891 // Conditional wait to ensure that a capture call has been done | 889 // Conditional wait to ensure that a capture call has been done |
892 // before the first render call is performed (implicitly | 890 // before the first render call is performed (implicitly |
893 // required by the APM API). | 891 // required by the APM API). |
894 if (first_render_side_call_) { | 892 if (first_render_call_) { |
895 while (!capture_call_checker_->CaptureSideCalled()) { | 893 capture_call_event_->Wait(rtc::Event::kForever); |
896 SleepRandomMs(3, rand_gen_); | 894 first_render_call_ = false; |
897 } | |
898 | |
899 first_render_side_call_ = false; | |
900 } | 895 } |
901 | 896 |
902 // Sleep a random time to simulate thread jitter. | 897 // Sleep a random time to simulate thread jitter. |
903 SleepRandomMs(3, rand_gen_); | 898 SleepRandomMs(3, rand_gen_); |
904 | 899 |
905 // End the test early if a fatal failure (ASSERT_*) has occurred. | |
906 test_->CheckTestCompleteness(); | |
907 | |
908 // Ensure that the number of render and capture calls do not | 900 // Ensure that the number of render and capture calls do not |
909 // differ too much. | 901 // differ too much. |
910 while (kMaxCallDifference < -frame_counters_->CaptureMinusRenderCounters()) { | 902 while (!test_->MaybeEndTest() && |
pbos-webrtc
2015/12/02 15:33:13
shouldn't this be:
while (true) {
if (test_->En
peah-webrtc
2015/12/02 22:44:41
I think you are right. That is the correct way to
| |
911 SleepMs(1); | 903 frame_counters_->RenderMinusCaptureCounters() > kMaxCallDifference) { |
904 capture_call_event_->Wait(1); | |
pbos-webrtc
2015/12/02 15:33:13
Same here, wait indefinitely?
peah-webrtc
2015/12/02 22:44:41
Done.
| |
912 } | 905 } |
913 | 906 |
914 // Apply any specified render side APM non-processing runtime calls. | 907 // Apply any specified render side APM non-processing runtime calls. |
915 ApplyRuntimeSettingScheme(); | 908 ApplyRuntimeSettingScheme(); |
916 | 909 |
917 // Apply the render side processing call. | 910 // Apply the render side processing call. |
918 CallApmRenderSide(); | 911 CallApmRenderSide(); |
919 | 912 |
920 // Increase the number of render-side calls. | 913 // Increase the number of render-side calls. |
921 frame_counters_->IncreaseRenderCounter(); | 914 frame_counters_->IncreaseRenderCounter(); |
922 | 915 |
916 // Flag to the capture thread that another render api call as occurred | |
pbos-webrtc
2015/12/02 15:33:13
has occurred, render API
peah-webrtc
2015/12/02 22:44:41
Done.
| |
917 // by triggering this threads call event. | |
918 render_call_event_->Set(); | |
923 return true; | 919 return true; |
924 } | 920 } |
925 | 921 |
926 // Prepares the render side frame and the accompanying metadata | 922 // Prepares the render side frame and the accompanying metadata |
927 // with the appropriate information. | 923 // with the appropriate information. |
928 void RenderProcessor::PrepareFrame() { | 924 void RenderProcessor::PrepareFrame() { |
929 // Restrict to a common fixed sample rate if the AudioFrame interface is | 925 // Restrict to a common fixed sample rate if the AudioFrame interface is |
930 // used. | 926 // used. |
931 if ((test_config_->render_api_function == | 927 if ((test_config_->render_api_function == |
932 RenderApiImpl::AnalyzeReverseStreamImpl1) || | 928 RenderApiImpl::AnalyzeReverseStreamImpl1) || |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1107 // the number of input channels. | 1103 // the number of input channels. |
1108 frame_data_.output_number_of_channels = | 1104 frame_data_.output_number_of_channels = |
1109 std::min(frame_data_.output_number_of_channels, | 1105 std::min(frame_data_.output_number_of_channels, |
1110 frame_data_.input_number_of_channels); | 1106 frame_data_.input_number_of_channels); |
1111 } | 1107 } |
1112 | 1108 |
1113 } // anonymous namespace | 1109 } // anonymous namespace |
1114 | 1110 |
1115 TEST_P(AudioProcessingImplLockTest, LockTest) { | 1111 TEST_P(AudioProcessingImplLockTest, LockTest) { |
1116 // Run test and verify that it did not time out. | 1112 // Run test and verify that it did not time out. |
1117 ASSERT_EQ(kEventSignaled, RunTest()); | 1113 ASSERT_TRUE(RunTest()); |
1118 } | 1114 } |
1119 | 1115 |
1120 // Instantiate tests from the extreme test configuration set. | 1116 // Instantiate tests from the extreme test configuration set. |
1121 INSTANTIATE_TEST_CASE_P( | 1117 INSTANTIATE_TEST_CASE_P( |
1122 DISABLED_AudioProcessingImplLockExtensive, | 1118 DISABLED_AudioProcessingImplLockExtensive, |
1123 AudioProcessingImplLockTest, | 1119 AudioProcessingImplLockTest, |
1124 ::testing::ValuesIn(TestConfig::GenerateExtensiveTestConfigs())); | 1120 ::testing::ValuesIn(TestConfig::GenerateExtensiveTestConfigs())); |
1125 | 1121 |
1126 INSTANTIATE_TEST_CASE_P( | 1122 INSTANTIATE_TEST_CASE_P( |
1127 AudioProcessingImplLockBrief, | 1123 AudioProcessingImplLockBrief, |
1128 AudioProcessingImplLockTest, | 1124 AudioProcessingImplLockTest, |
1129 ::testing::ValuesIn(TestConfig::GenerateBriefTestConfigs())); | 1125 ::testing::ValuesIn(TestConfig::GenerateBriefTestConfigs())); |
1130 | 1126 |
1131 } // namespace webrtc | 1127 } // namespace webrtc |
OLD | NEW |