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

Side by Side Diff: webrtc/modules/audio_mixer/audio_mixer_impl_unittest.cc

Issue 2692333002: Optionally disable APM limiter in AudioMixer. (Closed)
Patch Set: Mini-change: participant -> source and for each loop. Created 3 years, 10 months 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
OLDNEW
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
11 #include <string.h> 11 #include <string.h>
12 12
13 #include <limits> 13 #include <limits>
14 #include <memory> 14 #include <memory>
15 #include <utility> 15 #include <utility>
16 16
17 #include "webrtc/api/audio/audio_mixer.h" 17 #include "webrtc/api/audio/audio_mixer.h"
18 #include "webrtc/base/bind.h" 18 #include "webrtc/base/bind.h"
19 #include "webrtc/base/checks.h"
19 #include "webrtc/base/thread.h" 20 #include "webrtc/base/thread.h"
20 #include "webrtc/modules/audio_mixer/audio_mixer_impl.h" 21 #include "webrtc/modules/audio_mixer/audio_mixer_impl.h"
21 #include "webrtc/modules/audio_mixer/default_output_rate_calculator.h" 22 #include "webrtc/modules/audio_mixer/default_output_rate_calculator.h"
22 #include "webrtc/test/gmock.h" 23 #include "webrtc/test/gmock.h"
23 24
24 using testing::_; 25 using testing::_;
25 using testing::Exactly; 26 using testing::Exactly;
26 using testing::Invoke; 27 using testing::Invoke;
27 using testing::Return; 28 using testing::Return;
28 29
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 AudioFrameInfo fake_info() { return fake_audio_frame_info_; } 72 AudioFrameInfo fake_info() { return fake_audio_frame_info_; }
72 void set_fake_info(const AudioFrameInfo audio_frame_info) { 73 void set_fake_info(const AudioFrameInfo audio_frame_info) {
73 fake_audio_frame_info_ = audio_frame_info; 74 fake_audio_frame_info_ = audio_frame_info;
74 } 75 }
75 76
76 private: 77 private:
77 AudioFrameInfo FakeAudioFrameWithInfo(int sample_rate_hz, 78 AudioFrameInfo FakeAudioFrameWithInfo(int sample_rate_hz,
78 AudioFrame* audio_frame) { 79 AudioFrame* audio_frame) {
79 audio_frame->CopyFrom(fake_frame_); 80 audio_frame->CopyFrom(fake_frame_);
80 audio_frame->sample_rate_hz_ = sample_rate_hz; 81 audio_frame->sample_rate_hz_ = sample_rate_hz;
81 audio_frame->samples_per_channel_ = sample_rate_hz / 100; 82 audio_frame->samples_per_channel_ =
83 rtc::CheckedDivExact(sample_rate_hz, 100);
82 return fake_info(); 84 return fake_info();
83 } 85 }
84 86
85 AudioFrame fake_frame_; 87 AudioFrame fake_frame_;
86 AudioFrameInfo fake_audio_frame_info_; 88 AudioFrameInfo fake_audio_frame_info_;
87 }; 89 };
88 90
89 class CustomRateCalculator : public OutputRateCalculator { 91 class CustomRateCalculator : public OutputRateCalculator {
90 public: 92 public:
91 explicit CustomRateCalculator(int rate) : rate_(rate) {} 93 explicit CustomRateCalculator(int rate) : rate_(rate) {}
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 std::fill(frames[0].data_, frames[0].data_ + kDefaultSampleRateHz / 100, 451 std::fill(frames[0].data_, frames[0].data_ + kDefaultSampleRateHz / 100,
450 std::numeric_limits<int16_t>::max()); 452 std::numeric_limits<int16_t>::max());
451 std::vector<bool> expected_status(kAudioSources, true); 453 std::vector<bool> expected_status(kAudioSources, true);
452 expected_status[0] = false; 454 expected_status[0] = false;
453 455
454 MixAndCompare(frames, frame_info, expected_status); 456 MixAndCompare(frames, frame_info, expected_status);
455 } 457 }
456 458
457 TEST(AudioMixer, MixingRateShouldBeDecidedByRateCalculator) { 459 TEST(AudioMixer, MixingRateShouldBeDecidedByRateCalculator) {
458 constexpr int kOutputRate = 22000; 460 constexpr int kOutputRate = 22000;
459 const auto mixer = AudioMixerImpl::CreateWithOutputRateCalculator( 461 const auto mixer = AudioMixerImpl::CreateWithOutputRateCalculatorAndLimiter(
460 std::unique_ptr<OutputRateCalculator>( 462 std::unique_ptr<OutputRateCalculator>(
461 new CustomRateCalculator(kOutputRate))); 463 new CustomRateCalculator(kOutputRate)),
464 true);
462 MockMixerAudioSource audio_source; 465 MockMixerAudioSource audio_source;
463 mixer->AddSource(&audio_source); 466 mixer->AddSource(&audio_source);
464 ResetFrame(audio_source.fake_frame()); 467 ResetFrame(audio_source.fake_frame());
465 468
466 EXPECT_CALL(audio_source, GetAudioFrameWithInfo(kOutputRate, _)) 469 EXPECT_CALL(audio_source, GetAudioFrameWithInfo(kOutputRate, _))
467 .Times(Exactly(1)); 470 .Times(Exactly(1));
468 471
469 mixer->Mix(1, &frame_for_mixing); 472 mixer->Mix(1, &frame_for_mixing);
470 } 473 }
471 474
472 TEST(AudioMixer, ZeroSourceRateShouldBeDecidedByRateCalculator) { 475 TEST(AudioMixer, ZeroSourceRateShouldBeDecidedByRateCalculator) {
473 constexpr int kOutputRate = 8000; 476 constexpr int kOutputRate = 8000;
474 const auto mixer = AudioMixerImpl::CreateWithOutputRateCalculator( 477 const auto mixer = AudioMixerImpl::CreateWithOutputRateCalculatorAndLimiter(
475 std::unique_ptr<OutputRateCalculator>( 478 std::unique_ptr<OutputRateCalculator>(
476 new CustomRateCalculator(kOutputRate))); 479 new CustomRateCalculator(kOutputRate)),
480 true);
477 481
478 mixer->Mix(1, &frame_for_mixing); 482 mixer->Mix(1, &frame_for_mixing);
479 483
480 EXPECT_EQ(kOutputRate, frame_for_mixing.sample_rate_hz_); 484 EXPECT_EQ(kOutputRate, frame_for_mixing.sample_rate_hz_);
481 } 485 }
486
487 TEST(AudioMixer, NoLimiterBasicApiCalls) {
488 const auto mixer = AudioMixerImpl::CreateWithOutputRateCalculatorAndLimiter(
489 std::unique_ptr<OutputRateCalculator>(new DefaultOutputRateCalculator()),
490 false);
491 mixer->Mix(1, &frame_for_mixing);
492 }
493
494 TEST(AudioMixer, AnyRateIsPossibleWithNoLimiter) {
495 // No APM limiter means no AudioProcessing::NativeRate restriction
496 // on mixing rate. The rate has to be divisible by 100 since we use
497 // 10 ms frames, though.
498 for (const auto rate : {8000, 20000, 24000, 32000, 44100}) {
499 for (const size_t number_of_channels : {1, 2}) {
500 for (const auto number_of_sources : {0, 1, 2, 3, 4}) {
501 const auto mixer =
hlundin-webrtc 2017/02/17 11:04:12 Please, use a SCOPED_TRACE to annotate which lap i
aleloi 2017/02/20 10:41:33 Done.
502 AudioMixerImpl::CreateWithOutputRateCalculatorAndLimiter(
503 std::unique_ptr<OutputRateCalculator>(
504 new CustomRateCalculator(rate)),
505 false);
506
507 std::vector<MockMixerAudioSource> sources(number_of_sources);
508 for (auto& source : sources) {
509 mixer->AddSource(&source);
510 }
511
512 mixer->Mix(number_of_channels, &frame_for_mixing);
513 EXPECT_EQ(rate, frame_for_mixing.sample_rate_hz_);
514 EXPECT_EQ(number_of_channels, frame_for_mixing.num_channels_);
515 }
516 }
517 }
518 }
482 } // namespace webrtc 519 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698