OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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 |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 } | 368 } |
369 } | 369 } |
370 | 370 |
371 // This test checks that the initialization and participant addition | 371 // This test checks that the initialization and participant addition |
372 // can be done on a different thread. | 372 // can be done on a different thread. |
373 TEST(AudioMixer, ConstructFromOtherThread) { | 373 TEST(AudioMixer, ConstructFromOtherThread) { |
374 std::unique_ptr<rtc::Thread> init_thread = rtc::Thread::Create(); | 374 std::unique_ptr<rtc::Thread> init_thread = rtc::Thread::Create(); |
375 std::unique_ptr<rtc::Thread> participant_thread = rtc::Thread::Create(); | 375 std::unique_ptr<rtc::Thread> participant_thread = rtc::Thread::Create(); |
376 init_thread->Start(); | 376 init_thread->Start(); |
377 const auto mixer = init_thread->Invoke<rtc::scoped_refptr<AudioMixer>>( | 377 const auto mixer = init_thread->Invoke<rtc::scoped_refptr<AudioMixer>>( |
378 RTC_FROM_HERE, &AudioMixerImpl::Create); | 378 RTC_FROM_HERE, |
| 379 // Since AudioMixerImpl::Create is overloaded, we have to |
| 380 // specify the type of which version we want. |
| 381 static_cast<rtc::scoped_refptr<AudioMixerImpl>(*)()>( |
| 382 &AudioMixerImpl::Create)); |
379 MockMixerAudioSource participant; | 383 MockMixerAudioSource participant; |
380 | 384 |
381 ResetFrame(participant.fake_frame()); | 385 ResetFrame(participant.fake_frame()); |
382 | 386 |
383 participant_thread->Start(); | 387 participant_thread->Start(); |
384 EXPECT_TRUE(participant_thread->Invoke<int>( | 388 EXPECT_TRUE(participant_thread->Invoke<int>( |
385 RTC_FROM_HERE, | 389 RTC_FROM_HERE, |
386 rtc::Bind(&AudioMixer::AddSource, mixer.get(), &participant))); | 390 rtc::Bind(&AudioMixer::AddSource, mixer.get(), &participant))); |
387 | 391 |
388 EXPECT_CALL(participant, GetAudioFrameWithInfo(kDefaultSampleRateHz, _)) | 392 EXPECT_CALL(participant, GetAudioFrameWithInfo(kDefaultSampleRateHz, _)) |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 std::fill(frames[0].data_, frames[0].data_ + kDefaultSampleRateHz / 100, | 467 std::fill(frames[0].data_, frames[0].data_ + kDefaultSampleRateHz / 100, |
464 std::numeric_limits<int16_t>::max()); | 468 std::numeric_limits<int16_t>::max()); |
465 std::vector<bool> expected_status(kAudioSources, true); | 469 std::vector<bool> expected_status(kAudioSources, true); |
466 expected_status[0] = false; | 470 expected_status[0] = false; |
467 | 471 |
468 MixAndCompare(frames, frame_info, expected_status); | 472 MixAndCompare(frames, frame_info, expected_status); |
469 } | 473 } |
470 | 474 |
471 TEST(AudioMixer, MixingRateShouldBeDecidedByRateCalculator) { | 475 TEST(AudioMixer, MixingRateShouldBeDecidedByRateCalculator) { |
472 constexpr int kOutputRate = 22000; | 476 constexpr int kOutputRate = 22000; |
473 const auto mixer = AudioMixerImpl::CreateWithOutputRateCalculatorAndLimiter( | 477 const auto mixer = |
474 std::unique_ptr<OutputRateCalculator>( | 478 AudioMixerImpl::Create(std::unique_ptr<OutputRateCalculator>( |
475 new CustomRateCalculator(kOutputRate)), | 479 new CustomRateCalculator(kOutputRate)), |
476 true); | 480 true); |
477 MockMixerAudioSource audio_source; | 481 MockMixerAudioSource audio_source; |
478 mixer->AddSource(&audio_source); | 482 mixer->AddSource(&audio_source); |
479 ResetFrame(audio_source.fake_frame()); | 483 ResetFrame(audio_source.fake_frame()); |
480 | 484 |
481 EXPECT_CALL(audio_source, GetAudioFrameWithInfo(kOutputRate, _)) | 485 EXPECT_CALL(audio_source, GetAudioFrameWithInfo(kOutputRate, _)) |
482 .Times(Exactly(1)); | 486 .Times(Exactly(1)); |
483 | 487 |
484 mixer->Mix(1, &frame_for_mixing); | 488 mixer->Mix(1, &frame_for_mixing); |
485 } | 489 } |
486 | 490 |
487 TEST(AudioMixer, ZeroSourceRateShouldBeDecidedByRateCalculator) { | 491 TEST(AudioMixer, ZeroSourceRateShouldBeDecidedByRateCalculator) { |
488 constexpr int kOutputRate = 8000; | 492 constexpr int kOutputRate = 8000; |
489 const auto mixer = AudioMixerImpl::CreateWithOutputRateCalculatorAndLimiter( | 493 const auto mixer = |
490 std::unique_ptr<OutputRateCalculator>( | 494 AudioMixerImpl::Create(std::unique_ptr<OutputRateCalculator>( |
491 new CustomRateCalculator(kOutputRate)), | 495 new CustomRateCalculator(kOutputRate)), |
492 true); | 496 true); |
493 | 497 |
494 mixer->Mix(1, &frame_for_mixing); | 498 mixer->Mix(1, &frame_for_mixing); |
495 | 499 |
496 EXPECT_EQ(kOutputRate, frame_for_mixing.sample_rate_hz_); | 500 EXPECT_EQ(kOutputRate, frame_for_mixing.sample_rate_hz_); |
497 } | 501 } |
498 | 502 |
499 TEST(AudioMixer, NoLimiterBasicApiCalls) { | 503 TEST(AudioMixer, NoLimiterBasicApiCalls) { |
500 const auto mixer = AudioMixerImpl::CreateWithOutputRateCalculatorAndLimiter( | 504 const auto mixer = AudioMixerImpl::Create( |
501 std::unique_ptr<OutputRateCalculator>(new DefaultOutputRateCalculator()), | 505 std::unique_ptr<OutputRateCalculator>(new DefaultOutputRateCalculator()), |
502 false); | 506 false); |
503 mixer->Mix(1, &frame_for_mixing); | 507 mixer->Mix(1, &frame_for_mixing); |
504 } | 508 } |
505 | 509 |
506 TEST(AudioMixer, AnyRateIsPossibleWithNoLimiter) { | 510 TEST(AudioMixer, AnyRateIsPossibleWithNoLimiter) { |
507 // No APM limiter means no AudioProcessing::NativeRate restriction | 511 // No APM limiter means no AudioProcessing::NativeRate restriction |
508 // on mixing rate. The rate has to be divisible by 100 since we use | 512 // on mixing rate. The rate has to be divisible by 100 since we use |
509 // 10 ms frames, though. | 513 // 10 ms frames, though. |
510 for (const auto rate : {8000, 20000, 24000, 32000, 44100}) { | 514 for (const auto rate : {8000, 20000, 24000, 32000, 44100}) { |
511 for (const size_t number_of_channels : {1, 2}) { | 515 for (const size_t number_of_channels : {1, 2}) { |
512 for (const auto number_of_sources : {0, 1, 2, 3, 4}) { | 516 for (const auto number_of_sources : {0, 1, 2, 3, 4}) { |
513 SCOPED_TRACE( | 517 SCOPED_TRACE( |
514 ProduceDebugText(rate, number_of_sources, number_of_sources)); | 518 ProduceDebugText(rate, number_of_sources, number_of_sources)); |
515 const auto mixer = | 519 const auto mixer = |
516 AudioMixerImpl::CreateWithOutputRateCalculatorAndLimiter( | 520 AudioMixerImpl::Create(std::unique_ptr<OutputRateCalculator>( |
517 std::unique_ptr<OutputRateCalculator>( | 521 new CustomRateCalculator(rate)), |
518 new CustomRateCalculator(rate)), | 522 false); |
519 false); | |
520 | 523 |
521 std::vector<MockMixerAudioSource> sources(number_of_sources); | 524 std::vector<MockMixerAudioSource> sources(number_of_sources); |
522 for (auto& source : sources) { | 525 for (auto& source : sources) { |
523 mixer->AddSource(&source); | 526 mixer->AddSource(&source); |
524 } | 527 } |
525 | 528 |
526 mixer->Mix(number_of_channels, &frame_for_mixing); | 529 mixer->Mix(number_of_channels, &frame_for_mixing); |
527 EXPECT_EQ(rate, frame_for_mixing.sample_rate_hz_); | 530 EXPECT_EQ(rate, frame_for_mixing.sample_rate_hz_); |
528 EXPECT_EQ(number_of_channels, frame_for_mixing.num_channels_); | 531 EXPECT_EQ(number_of_channels, frame_for_mixing.num_channels_); |
529 } | 532 } |
530 } | 533 } |
531 } | 534 } |
532 } | 535 } |
533 } // namespace webrtc | 536 } // namespace webrtc |
OLD | NEW |