Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: webrtc/modules/audio_processing/audio_processing_impl_locking_unittest.cc

Issue 1490113004: Replaced the custom thread synchronization with rtc::Event (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Added proper test termination Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 rtc::CritScope cs(&crit_); 292 rtc::CritScope cs(&crit_);
293 return (render_count > threshold && capture_count > threshold); 293 return (render_count > threshold && capture_count > threshold);
294 } 294 }
295 295
296 private: 296 private:
297 rtc::CriticalSection crit_; 297 rtc::CriticalSection crit_;
298 int render_count GUARDED_BY(crit_) = 0; 298 int render_count GUARDED_BY(crit_) = 0;
299 int capture_count GUARDED_BY(crit_) = 0; 299 int capture_count GUARDED_BY(crit_) = 0;
300 }; 300 };
301 301
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. 302 // Class for handling the capture side processing.
321 class CaptureProcessor { 303 class CaptureProcessor {
322 public: 304 public:
323 CaptureProcessor(int max_frame_size, 305 CaptureProcessor(int max_frame_size,
324 RandomGenerator* rand_gen, 306 RandomGenerator* rand_gen,
325 FrameCounters* shared_counters_state, 307 FrameCounters* shared_counters_state,
326 CaptureSideCalledChecker* capture_call_checker,
327 AudioProcessingImplLockTest* test_framework, 308 AudioProcessingImplLockTest* test_framework,
328 TestConfig* test_config, 309 TestConfig* test_config,
329 AudioProcessing* apm); 310 AudioProcessing* apm);
330 bool Process(); 311 bool Process();
331 312
332 private: 313 private:
333 static const int kMaxCallDifference = 10; 314 static const int kMaxCallDifference = 10;
334 static const float kCaptureInputFloatLevel; 315 static const float kCaptureInputFloatLevel;
335 static const int kCaptureInputFixLevel = 1024; 316 static const int kCaptureInputFixLevel = 1024;
336 317
337 void PrepareFrame(); 318 void PrepareFrame();
338 void CallApmCaptureSide(); 319 void CallApmCaptureSide();
339 void ApplyRuntimeSettingScheme(); 320 void ApplyRuntimeSettingScheme();
340 321
341 RandomGenerator* rand_gen_ = nullptr; 322 RandomGenerator* rand_gen_ = nullptr;
342 FrameCounters* frame_counters_ = nullptr; 323 FrameCounters* frame_counters_ = nullptr;
343 CaptureSideCalledChecker* capture_call_checker_ = nullptr;
344 AudioProcessingImplLockTest* test_ = nullptr; 324 AudioProcessingImplLockTest* test_ = nullptr;
345 TestConfig* test_config_ = nullptr; 325 TestConfig* test_config_ = nullptr;
346 AudioProcessing* apm_ = nullptr; 326 AudioProcessing* apm_ = nullptr;
347 AudioFrameData frame_data_; 327 AudioFrameData frame_data_;
348 }; 328 };
349 329
350 // Class for handling the stats processing. 330 // Class for handling the stats processing.
351 class StatsProcessor { 331 class StatsProcessor {
352 public: 332 public:
353 StatsProcessor(RandomGenerator* rand_gen, 333 StatsProcessor(RandomGenerator* rand_gen,
354 TestConfig* test_config, 334 TestConfig* test_config,
355 AudioProcessing* apm); 335 AudioProcessing* apm);
356 bool Process(); 336 bool Process();
357 337
358 private: 338 private:
359 RandomGenerator* rand_gen_ = nullptr; 339 RandomGenerator* rand_gen_ = nullptr;
360 TestConfig* test_config_ = nullptr; 340 TestConfig* test_config_ = nullptr;
361 AudioProcessing* apm_ = nullptr; 341 AudioProcessing* apm_ = nullptr;
362 }; 342 };
363 343
364 // Class for handling the render side processing. 344 // Class for handling the render side processing.
365 class RenderProcessor { 345 class RenderProcessor {
366 public: 346 public:
367 RenderProcessor(int max_frame_size, 347 RenderProcessor(int max_frame_size,
368 RandomGenerator* rand_gen, 348 RandomGenerator* rand_gen,
369 FrameCounters* shared_counters_state, 349 FrameCounters* shared_counters_state,
370 CaptureSideCalledChecker* capture_call_checker,
371 AudioProcessingImplLockTest* test_framework, 350 AudioProcessingImplLockTest* test_framework,
372 TestConfig* test_config, 351 TestConfig* test_config,
373 AudioProcessing* apm); 352 AudioProcessing* apm);
374 bool Process(); 353 bool Process();
375 354
376 private: 355 private:
377 static const int kMaxCallDifference = 10; 356 static const int kMaxCallDifference = 10;
378 static const int kRenderInputFixLevel = 16384; 357 static const int kRenderInputFixLevel = 16384;
379 static const float kRenderInputFloatLevel; 358 static const float kRenderInputFloatLevel;
380 359
381 void PrepareFrame(); 360 void PrepareFrame();
382 void CallApmRenderSide(); 361 void CallApmRenderSide();
383 void ApplyRuntimeSettingScheme(); 362 void ApplyRuntimeSettingScheme();
384 363
385 RandomGenerator* rand_gen_ = nullptr; 364 RandomGenerator* rand_gen_ = nullptr;
386 FrameCounters* frame_counters_ = nullptr; 365 FrameCounters* frame_counters_ = nullptr;
387 CaptureSideCalledChecker* capture_call_checker_ = nullptr;
388 AudioProcessingImplLockTest* test_ = nullptr; 366 AudioProcessingImplLockTest* test_ = nullptr;
389 TestConfig* test_config_ = nullptr; 367 TestConfig* test_config_ = nullptr;
390 AudioProcessing* apm_ = nullptr; 368 AudioProcessing* apm_ = nullptr;
391 bool first_render_side_call_ = true;
392 AudioFrameData frame_data_; 369 AudioFrameData frame_data_;
370 bool first_render_call_ = true;
393 }; 371 };
394 372
395 class AudioProcessingImplLockTest 373 class AudioProcessingImplLockTest
396 : public ::testing::TestWithParam<TestConfig> { 374 : public ::testing::TestWithParam<TestConfig> {
397 public: 375 public:
398 AudioProcessingImplLockTest(); 376 AudioProcessingImplLockTest();
399 EventTypeWrapper RunTest(); 377 bool RunTest();
400 void CheckTestCompleteness(); 378 bool MaybeEndTest();
379
380 rtc::Event& get_render_call_event() { return render_call_event_; }
pbos-webrtc 2015/12/02 13:01:12 no non-const references allowed (googlestyle), use
pbos-webrtc 2015/12/02 13:01:12 remove get_ prefix
peah-webrtc 2015/12/02 15:02:27 Thanks! I revised this according to your feedback
peah-webrtc 2015/12/02 15:02:27 Acknowledged.
381 rtc::Event& get_capture_call_event() { return capture_call_event_; }
401 382
402 private: 383 private:
403 static const int kTestTimeOutLimit = 10 * 60 * 1000; 384 static const int kTestTimeOutLimit = 10 * 60 * 1000;
404 static const int kMaxFrameSize = 480; 385 static const int kMaxFrameSize = 480;
405 386
406 // ::testing::TestWithParam<> implementation 387 // ::testing::TestWithParam<> implementation
407 void SetUp() override; 388 void SetUp() override;
408 void TearDown() override; 389 void TearDown() override;
409 390
410 // Thread callback for the render thread 391 // Thread callback for the render thread
(...skipping 24 matching lines...) Expand all
435 // Start the threads used in the test. 416 // Start the threads used in the test.
436 void StartThreads() { 417 void StartThreads() {
437 render_thread_.Start(); 418 render_thread_.Start();
438 render_thread_.SetPriority(rtc::kRealtimePriority); 419 render_thread_.SetPriority(rtc::kRealtimePriority);
439 capture_thread_.Start(); 420 capture_thread_.Start();
440 capture_thread_.SetPriority(rtc::kRealtimePriority); 421 capture_thread_.SetPriority(rtc::kRealtimePriority);
441 stats_thread_.Start(); 422 stats_thread_.Start();
442 stats_thread_.SetPriority(rtc::kNormalPriority); 423 stats_thread_.SetPriority(rtc::kNormalPriority);
443 } 424 }
444 425
445 // Event handler for the test. 426 // Event handlers for the test.
446 const rtc::scoped_ptr<EventWrapper> test_complete_; 427 rtc::Event test_complete_;
428 rtc::Event render_call_event_;
429 rtc::Event capture_call_event_;
447 430
448 // Thread related variables. 431 // Thread related variables.
449 rtc::PlatformThread render_thread_; 432 rtc::PlatformThread render_thread_;
450 rtc::PlatformThread capture_thread_; 433 rtc::PlatformThread capture_thread_;
451 rtc::PlatformThread stats_thread_; 434 rtc::PlatformThread stats_thread_;
452 mutable RandomGenerator rand_gen_; 435 mutable RandomGenerator rand_gen_;
453 436
454 rtc::scoped_ptr<AudioProcessing> apm_; 437 rtc::scoped_ptr<AudioProcessing> apm_;
455 TestConfig test_config_; 438 TestConfig test_config_;
456 FrameCounters frame_counters_; 439 FrameCounters frame_counters_;
457 CaptureSideCalledChecker capture_call_checker_;
458 RenderProcessor render_thread_state_; 440 RenderProcessor render_thread_state_;
459 CaptureProcessor capture_thread_state_; 441 CaptureProcessor capture_thread_state_;
460 StatsProcessor stats_thread_state_; 442 StatsProcessor stats_thread_state_;
461 }; 443 };
462 444
463 // Sleeps a random time between 0 and max_sleep milliseconds. 445 // Sleeps a random time between 0 and max_sleep milliseconds.
464 void SleepRandomMs(int max_sleep, RandomGenerator* rand_gen) { 446 void SleepRandomMs(int max_sleep, RandomGenerator* rand_gen) {
465 int sleeptime = rand_gen->RandInt(0, max_sleep); 447 int sleeptime = rand_gen->RandInt(0, max_sleep);
466 SleepMs(sleeptime); 448 SleepMs(sleeptime);
467 } 449 }
(...skipping 22 matching lines...) Expand all
490 for (int k = 0; k < static_cast<int>(frame->samples_per_channel_); k++) { 472 for (int k = 0; k < static_cast<int>(frame->samples_per_channel_); k++) {
491 // Store random 16 bit number between -(amplitude+1) and 473 // Store random 16 bit number between -(amplitude+1) and
492 // amplitude. 474 // amplitude.
493 frame->data_[k * ch] = 475 frame->data_[k * ch] =
494 rand_gen->RandInt(2 * amplitude + 1) - amplitude - 1; 476 rand_gen->RandInt(2 * amplitude + 1) - amplitude - 1;
495 } 477 }
496 } 478 }
497 } 479 }
498 480
499 AudioProcessingImplLockTest::AudioProcessingImplLockTest() 481 AudioProcessingImplLockTest::AudioProcessingImplLockTest()
500 : test_complete_(EventWrapper::Create()), 482 : test_complete_(rtc::Event(false, false)),
pbos-webrtc 2015/12/02 13:01:12 remove rtc::Event here and below (no copy-construc
peah-webrtc 2015/12/02 15:02:27 Done.
483 render_call_event_(rtc::Event(false, false)),
484 capture_call_event_(rtc::Event(false, false)),
501 render_thread_(RenderProcessorThreadFunc, this, "render"), 485 render_thread_(RenderProcessorThreadFunc, this, "render"),
502 capture_thread_(CaptureProcessorThreadFunc, this, "capture"), 486 capture_thread_(CaptureProcessorThreadFunc, this, "capture"),
503 stats_thread_(StatsProcessorThreadFunc, this, "stats"), 487 stats_thread_(StatsProcessorThreadFunc, this, "stats"),
504 apm_(AudioProcessingImpl::Create()), 488 apm_(AudioProcessingImpl::Create()),
505 render_thread_state_(kMaxFrameSize, 489 render_thread_state_(kMaxFrameSize,
506 &rand_gen_, 490 &rand_gen_,
507 &frame_counters_, 491 &frame_counters_,
508 &capture_call_checker_,
509 this, 492 this,
510 &test_config_, 493 &test_config_,
511 apm_.get()), 494 apm_.get()),
512 capture_thread_state_(kMaxFrameSize, 495 capture_thread_state_(kMaxFrameSize,
513 &rand_gen_, 496 &rand_gen_,
514 &frame_counters_, 497 &frame_counters_,
515 &capture_call_checker_,
516 this, 498 this,
517 &test_config_, 499 &test_config_,
518 apm_.get()), 500 apm_.get()),
519 stats_thread_state_(&rand_gen_, &test_config_, apm_.get()) {} 501 stats_thread_state_(&rand_gen_, &test_config_, apm_.get()) {}
520 502
521 // Run the test with a timeout. 503 // Run the test with a timeout.
522 EventTypeWrapper AudioProcessingImplLockTest::RunTest() { 504 bool AudioProcessingImplLockTest::RunTest() {
523 StartThreads(); 505 StartThreads();
524 return test_complete_->Wait(kTestTimeOutLimit); 506 return test_complete_.Wait(kTestTimeOutLimit);
525 } 507 }
526 508
527 void AudioProcessingImplLockTest::CheckTestCompleteness() { 509 bool AudioProcessingImplLockTest::MaybeEndTest() {
528 if (HasFatalFailure() || TestDone()) { 510 if (HasFatalFailure() || TestDone()) {
529 test_complete_->Set(); 511 test_complete_.Set();
512 return true;
530 } 513 }
514 return false;
531 } 515 }
532 516
533 // Setup of test and APM. 517 // Setup of test and APM.
534 void AudioProcessingImplLockTest::SetUp() { 518 void AudioProcessingImplLockTest::SetUp() {
535 test_config_ = static_cast<TestConfig>(GetParam()); 519 test_config_ = static_cast<TestConfig>(GetParam());
536 520
537 ASSERT_EQ(apm_->kNoError, apm_->level_estimator()->Enable(true)); 521 ASSERT_EQ(apm_->kNoError, apm_->level_estimator()->Enable(true));
538 ASSERT_EQ(apm_->kNoError, apm_->gain_control()->Enable(true)); 522 ASSERT_EQ(apm_->kNoError, apm_->gain_control()->Enable(true));
539 523
540 ASSERT_EQ(apm_->kNoError, 524 ASSERT_EQ(apm_->kNoError,
(...skipping 24 matching lines...) Expand all
565 549
566 config.Set<DelayAgnostic>( 550 config.Set<DelayAgnostic>(
567 new DelayAgnostic(test_config_.aec_type == 551 new DelayAgnostic(test_config_.aec_type ==
568 AecType::BasicWebRtcAecSettingsWithDelayAgnosticAec)); 552 AecType::BasicWebRtcAecSettingsWithDelayAgnosticAec));
569 553
570 apm_->SetExtraOptions(config); 554 apm_->SetExtraOptions(config);
571 } 555 }
572 } 556 }
573 557
574 void AudioProcessingImplLockTest::TearDown() { 558 void AudioProcessingImplLockTest::TearDown() {
559 render_call_event_.Set();
560 capture_call_event_.Set();
575 render_thread_.Stop(); 561 render_thread_.Stop();
576 capture_thread_.Stop(); 562 capture_thread_.Stop();
577 stats_thread_.Stop(); 563 stats_thread_.Stop();
578 } 564 }
579 565
580 StatsProcessor::StatsProcessor(RandomGenerator* rand_gen, 566 StatsProcessor::StatsProcessor(RandomGenerator* rand_gen,
581 TestConfig* test_config, 567 TestConfig* test_config,
582 AudioProcessing* apm) 568 AudioProcessing* apm)
583 : rand_gen_(rand_gen), test_config_(test_config), apm_(apm) {} 569 : rand_gen_(rand_gen), test_config_(test_config), apm_(apm) {}
584 570
(...skipping 21 matching lines...) Expand all
606 592
607 return true; 593 return true;
608 } 594 }
609 595
610 const float CaptureProcessor::kCaptureInputFloatLevel = 0.03125f; 596 const float CaptureProcessor::kCaptureInputFloatLevel = 0.03125f;
611 597
612 CaptureProcessor::CaptureProcessor( 598 CaptureProcessor::CaptureProcessor(
613 int max_frame_size, 599 int max_frame_size,
614 RandomGenerator* rand_gen, 600 RandomGenerator* rand_gen,
615 FrameCounters* shared_counters_state, 601 FrameCounters* shared_counters_state,
616 CaptureSideCalledChecker* capture_call_checker,
617 AudioProcessingImplLockTest* test_framework, 602 AudioProcessingImplLockTest* test_framework,
618 TestConfig* test_config, 603 TestConfig* test_config,
pbos-webrtc 2015/12/02 13:01:12 supply events on construction instead of having th
peah-webrtc 2015/12/02 15:02:27 Done.
619 AudioProcessing* apm) 604 AudioProcessing* apm)
620 : rand_gen_(rand_gen), 605 : rand_gen_(rand_gen),
621 frame_counters_(shared_counters_state), 606 frame_counters_(shared_counters_state),
622 capture_call_checker_(capture_call_checker),
623 test_(test_framework), 607 test_(test_framework),
624 test_config_(test_config), 608 test_config_(test_config),
625 apm_(apm), 609 apm_(apm),
626 frame_data_(max_frame_size) {} 610 frame_data_(max_frame_size) {}
627 611
628 // Implements the callback functionality for the capture thread. 612 // Implements the callback functionality for the capture thread.
629 bool CaptureProcessor::Process() { 613 bool CaptureProcessor::Process() {
630 // Sleep a random time to simulate thread jitter. 614 // Sleep a random time to simulate thread jitter.
631 SleepRandomMs(3, rand_gen_); 615 SleepRandomMs(3, rand_gen_);
632 616
633 // End the test if complete.
634 test_->CheckTestCompleteness();
635
636 // Ensure that there are not more capture side calls than render side 617 // Ensure that there are not more capture side calls than render side
637 // calls. 618 // calls.
638 if (capture_call_checker_->CaptureSideCalled()) { 619 while (!test_->MaybeEndTest() &&
639 while (kMaxCallDifference < frame_counters_->CaptureMinusRenderCounters()) { 620 frame_counters_->CaptureMinusRenderCounters() > kMaxCallDifference) {
640 SleepMs(1); 621 test_->get_render_call_event().Wait(1);
641 }
642 } 622 }
643 623
644 // Apply any specified capture side APM non-processing runtime calls. 624 // Apply any specified capture side APM non-processing runtime calls.
645 ApplyRuntimeSettingScheme(); 625 ApplyRuntimeSettingScheme();
646 626
647 // Apply the capture side processing call. 627 // Apply the capture side processing call.
648 CallApmCaptureSide(); 628 CallApmCaptureSide();
649 629
650 // Increase the number of capture-side calls. 630 // Increase the number of capture-side calls.
651 frame_counters_->IncreaseCaptureCounter(); 631 frame_counters_->IncreaseCaptureCounter();
652 632
653 // Flag that the capture side has been called at least once 633 // Set api call flag.
654 // (needed to ensure that a capture call has been done 634 test_->get_capture_call_event().Set();
655 // before the first render call is performed (implicitly
656 // required by the APM API).
657 capture_call_checker_->FlagCaptureSideCalled();
658 635
659 return true; 636 return true;
660 } 637 }
661 638
662 // Prepares a frame with relevant audio data and metadata. 639 // Prepares a frame with relevant audio data and metadata.
663 void CaptureProcessor::PrepareFrame() { 640 void CaptureProcessor::PrepareFrame() {
664 // Restrict to a common fixed sample rate if the AudioFrame 641 // Restrict to a common fixed sample rate if the AudioFrame
665 // interface is used. 642 // interface is used.
666 if (test_config_->capture_api_function == 643 if (test_config_->capture_api_function ==
667 CaptureApiImpl::ProcessStreamImpl1) { 644 CaptureApiImpl::ProcessStreamImpl1) {
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 frame_data_.output_number_of_channels = 844 frame_data_.output_number_of_channels =
868 std::min(frame_data_.output_number_of_channels, 845 std::min(frame_data_.output_number_of_channels,
869 frame_data_.input_number_of_channels); 846 frame_data_.input_number_of_channels);
870 } 847 }
871 848
872 const float RenderProcessor::kRenderInputFloatLevel = 0.5f; 849 const float RenderProcessor::kRenderInputFloatLevel = 0.5f;
873 850
874 RenderProcessor::RenderProcessor(int max_frame_size, 851 RenderProcessor::RenderProcessor(int max_frame_size,
875 RandomGenerator* rand_gen, 852 RandomGenerator* rand_gen,
876 FrameCounters* shared_counters_state, 853 FrameCounters* shared_counters_state,
877 CaptureSideCalledChecker* capture_call_checker,
878 AudioProcessingImplLockTest* test_framework, 854 AudioProcessingImplLockTest* test_framework,
879 TestConfig* test_config, 855 TestConfig* test_config,
880 AudioProcessing* apm) 856 AudioProcessing* apm)
881 : rand_gen_(rand_gen), 857 : rand_gen_(rand_gen),
882 frame_counters_(shared_counters_state), 858 frame_counters_(shared_counters_state),
883 capture_call_checker_(capture_call_checker),
884 test_(test_framework), 859 test_(test_framework),
885 test_config_(test_config), 860 test_config_(test_config),
886 apm_(apm), 861 apm_(apm),
887 frame_data_(max_frame_size) {} 862 frame_data_(max_frame_size) {}
888 863
889 // Implements the callback functionality for the render thread. 864 // Implements the callback functionality for the render thread.
890 bool RenderProcessor::Process() { 865 bool RenderProcessor::Process() {
891 // Conditional wait to ensure that a capture call has been done 866 // Conditional wait to ensure that a capture call has been done
892 // before the first render call is performed (implicitly 867 // before the first render call is performed (implicitly
893 // required by the APM API). 868 // required by the APM API).
894 if (first_render_side_call_) { 869 if (first_render_call_) {
895 while (!capture_call_checker_->CaptureSideCalled()) { 870 test_->get_capture_call_event().Wait(rtc::Event::kForever);
896 SleepRandomMs(3, rand_gen_); 871 first_render_call_ = false;
897 }
898
899 first_render_side_call_ = false;
900 } 872 }
901 873
902 // Sleep a random time to simulate thread jitter. 874 // Sleep a random time to simulate thread jitter.
903 SleepRandomMs(3, rand_gen_); 875 SleepRandomMs(3, rand_gen_);
904 876
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 877 // Ensure that the number of render and capture calls do not
909 // differ too much. 878 // differ too much.
910 while (kMaxCallDifference < -frame_counters_->CaptureMinusRenderCounters()) { 879 while (!test_->MaybeEndTest() &&
911 SleepMs(1); 880 -frame_counters_->CaptureMinusRenderCounters() > kMaxCallDifference) {
pbos-webrtc 2015/12/02 13:01:12 document the unary minus, or a function that's ren
peah-webrtc 2015/12/02 15:02:27 Good point! I instead created a function for that.
881 test_->get_capture_call_event().Wait(1);
912 } 882 }
913 883
914 // Apply any specified render side APM non-processing runtime calls. 884 // Apply any specified render side APM non-processing runtime calls.
915 ApplyRuntimeSettingScheme(); 885 ApplyRuntimeSettingScheme();
916 886
917 // Apply the render side processing call. 887 // Apply the render side processing call.
918 CallApmRenderSide(); 888 CallApmRenderSide();
919 889
920 // Increase the number of render-side calls. 890 // Increase the number of render-side calls.
921 frame_counters_->IncreaseRenderCounter(); 891 frame_counters_->IncreaseRenderCounter();
922 892
893 // Set api call flag.
pbos-webrtc 2015/12/02 13:01:12 put in comment what this should do/trigger
peah-webrtc 2015/12/02 15:02:27 Done.
894 test_->get_render_call_event().Set();
923 return true; 895 return true;
924 } 896 }
925 897
926 // Prepares the render side frame and the accompanying metadata 898 // Prepares the render side frame and the accompanying metadata
927 // with the appropriate information. 899 // with the appropriate information.
928 void RenderProcessor::PrepareFrame() { 900 void RenderProcessor::PrepareFrame() {
929 // Restrict to a common fixed sample rate if the AudioFrame interface is 901 // Restrict to a common fixed sample rate if the AudioFrame interface is
930 // used. 902 // used.
931 if ((test_config_->render_api_function == 903 if ((test_config_->render_api_function ==
932 RenderApiImpl::AnalyzeReverseStreamImpl1) || 904 RenderApiImpl::AnalyzeReverseStreamImpl1) ||
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 // the number of input channels. 1079 // the number of input channels.
1108 frame_data_.output_number_of_channels = 1080 frame_data_.output_number_of_channels =
1109 std::min(frame_data_.output_number_of_channels, 1081 std::min(frame_data_.output_number_of_channels,
1110 frame_data_.input_number_of_channels); 1082 frame_data_.input_number_of_channels);
1111 } 1083 }
1112 1084
1113 } // anonymous namespace 1085 } // anonymous namespace
1114 1086
1115 TEST_P(AudioProcessingImplLockTest, LockTest) { 1087 TEST_P(AudioProcessingImplLockTest, LockTest) {
1116 // Run test and verify that it did not time out. 1088 // Run test and verify that it did not time out.
1117 ASSERT_EQ(kEventSignaled, RunTest()); 1089 ASSERT_EQ(true, RunTest());
pbos-webrtc 2015/12/02 13:01:12 ASSERT_TRUE(RunTest())
peah-webrtc 2015/12/02 15:02:27 Done.
1118 } 1090 }
1119 1091
1120 // Instantiate tests from the extreme test configuration set. 1092 // Instantiate tests from the extreme test configuration set.
1121 INSTANTIATE_TEST_CASE_P( 1093 INSTANTIATE_TEST_CASE_P(
1122 DISABLED_AudioProcessingImplLockExtensive, 1094 DISABLED_AudioProcessingImplLockExtensive,
1123 AudioProcessingImplLockTest, 1095 AudioProcessingImplLockTest,
1124 ::testing::ValuesIn(TestConfig::GenerateExtensiveTestConfigs())); 1096 ::testing::ValuesIn(TestConfig::GenerateExtensiveTestConfigs()));
1125 1097
1126 INSTANTIATE_TEST_CASE_P( 1098 INSTANTIATE_TEST_CASE_P(
1127 AudioProcessingImplLockBrief, 1099 AudioProcessingImplLockBrief,
1128 AudioProcessingImplLockTest, 1100 AudioProcessingImplLockTest,
1129 ::testing::ValuesIn(TestConfig::GenerateBriefTestConfigs())); 1101 ::testing::ValuesIn(TestConfig::GenerateBriefTestConfigs()));
1130 1102
1131 } // namespace webrtc 1103 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698