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

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