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

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

Issue 2557713006: Injectable output rate calculater for AudioMixer. (Closed)
Patch Set: Include order, win compilation, comments. Created 4 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
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/thread.h" 19 #include "webrtc/base/thread.h"
20 #include "webrtc/modules/audio_mixer/audio_mixer_impl.h" 20 #include "webrtc/modules/audio_mixer/audio_mixer_impl.h"
21 #include "webrtc/modules/audio_mixer/default_output_rate_calculator.h"
21 #include "webrtc/test/gmock.h" 22 #include "webrtc/test/gmock.h"
22 23
23 using testing::_; 24 using testing::_;
24 using testing::Exactly; 25 using testing::Exactly;
25 using testing::Invoke; 26 using testing::Invoke;
26 using testing::Return; 27 using testing::Return;
27 28
28 namespace webrtc { 29 namespace webrtc {
29 30
30 namespace { 31 namespace {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 audio_frame->CopyFrom(fake_frame_); 79 audio_frame->CopyFrom(fake_frame_);
79 audio_frame->sample_rate_hz_ = sample_rate_hz; 80 audio_frame->sample_rate_hz_ = sample_rate_hz;
80 audio_frame->samples_per_channel_ = sample_rate_hz / 100; 81 audio_frame->samples_per_channel_ = sample_rate_hz / 100;
81 return fake_info(); 82 return fake_info();
82 } 83 }
83 84
84 AudioFrame fake_frame_; 85 AudioFrame fake_frame_;
85 AudioFrameInfo fake_audio_frame_info_; 86 AudioFrameInfo fake_audio_frame_info_;
86 }; 87 };
87 88
89 class CustomRateCalculator : public OutputRateCalculator {
90 public:
91 explicit CustomRateCalculator(int rate) : rate_(rate) {}
92 int CalculateOutputRate(const std::vector<int>& preferred_rates) {
93 return rate_;
94 }
95
96 private:
97 const int rate_;
98 };
99
100
88 // Creates participants from |frames| and |frame_info| and adds them 101 // Creates participants from |frames| and |frame_info| and adds them
89 // to the mixer. Compares mixed status with |expected_status| 102 // to the mixer. Compares mixed status with |expected_status|
90 void MixAndCompare( 103 void MixAndCompare(
91 const std::vector<AudioFrame>& frames, 104 const std::vector<AudioFrame>& frames,
92 const std::vector<AudioMixer::Source::AudioFrameInfo>& frame_info, 105 const std::vector<AudioMixer::Source::AudioFrameInfo>& frame_info,
93 const std::vector<bool>& expected_status) { 106 const std::vector<bool>& expected_status) {
94 int num_audio_sources = frames.size(); 107 int num_audio_sources = frames.size();
95 RTC_DCHECK(frames.size() == frame_info.size()); 108 RTC_DCHECK(frames.size() == frame_info.size());
96 RTC_DCHECK(frame_info.size() == expected_status.size()); 109 RTC_DCHECK(frame_info.size() == expected_status.size());
97 110
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 std::vector<AudioMixer::Source::AudioFrameInfo> frame_info( 447 std::vector<AudioMixer::Source::AudioFrameInfo> frame_info(
435 kAudioSources, AudioMixer::Source::AudioFrameInfo::kNormal); 448 kAudioSources, AudioMixer::Source::AudioFrameInfo::kNormal);
436 frame_info[0] = AudioMixer::Source::AudioFrameInfo::kMuted; 449 frame_info[0] = AudioMixer::Source::AudioFrameInfo::kMuted;
437 std::fill(frames[0].data_, frames[0].data_ + kDefaultSampleRateHz / 100, 450 std::fill(frames[0].data_, frames[0].data_ + kDefaultSampleRateHz / 100,
438 std::numeric_limits<int16_t>::max()); 451 std::numeric_limits<int16_t>::max());
439 std::vector<bool> expected_status(kAudioSources, true); 452 std::vector<bool> expected_status(kAudioSources, true);
440 expected_status[0] = false; 453 expected_status[0] = false;
441 454
442 MixAndCompare(frames, frame_info, expected_status); 455 MixAndCompare(frames, frame_info, expected_status);
443 } 456 }
457
458 TEST(AudioMixer, MixingRateShouldBeDecidedByRateCalculator) {
459 constexpr int kOutputRate = 22000;
460 const auto mixer = AudioMixerImpl::CreateWithOutputRateCalculator(
461 std::unique_ptr<OutputRateCalculator>(
462 new CustomRateCalculator(kOutputRate)));
463 MockMixerAudioSource audio_source;
464 mixer->AddSource(&audio_source);
465 ResetFrame(audio_source.fake_frame());
466
467 EXPECT_CALL(audio_source, GetAudioFrameWithInfo(kOutputRate, _))
468 .Times(Exactly(1));
469
470 mixer->Mix(1, &frame_for_mixing);
471 }
472
473 TEST(AudioMixer, ZeroSourceRateShouldBeDecidedByRateCalculator) {
474 constexpr int kOutputRate = 8000;
475 const auto mixer = AudioMixerImpl::CreateWithOutputRateCalculator(
476 std::unique_ptr<OutputRateCalculator>(
477 new CustomRateCalculator(kOutputRate)));
478
479 mixer->Mix(1, &frame_for_mixing);
480
481 EXPECT_EQ(kOutputRate, frame_for_mixing.sample_rate_hz_);
482 }
444 } // namespace webrtc 483 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698