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

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

Issue 2557713006: Injectable output rate calculater for AudioMixer. (Closed)
Patch Set: stl instead of loop, renamed SetOutputFrequency. 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
88 // Creates participants from |frames| and |frame_info| and adds them 100 // Creates participants from |frames| and |frame_info| and adds them
89 // to the mixer. Compares mixed status with |expected_status| 101 // to the mixer. Compares mixed status with |expected_status|
90 void MixAndCompare( 102 void MixAndCompare(
91 const std::vector<AudioFrame>& frames, 103 const std::vector<AudioFrame>& frames,
92 const std::vector<AudioMixer::Source::AudioFrameInfo>& frame_info, 104 const std::vector<AudioMixer::Source::AudioFrameInfo>& frame_info,
93 const std::vector<bool>& expected_status) { 105 const std::vector<bool>& expected_status) {
94 int num_audio_sources = frames.size(); 106 int num_audio_sources = frames.size();
95 RTC_DCHECK(frames.size() == frame_info.size()); 107 RTC_DCHECK(frames.size() == frame_info.size());
96 RTC_DCHECK(frame_info.size() == expected_status.size()); 108 RTC_DCHECK(frame_info.size() == expected_status.size());
97 109
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 std::vector<AudioMixer::Source::AudioFrameInfo> frame_info( 446 std::vector<AudioMixer::Source::AudioFrameInfo> frame_info(
435 kAudioSources, AudioMixer::Source::AudioFrameInfo::kNormal); 447 kAudioSources, AudioMixer::Source::AudioFrameInfo::kNormal);
436 frame_info[0] = AudioMixer::Source::AudioFrameInfo::kMuted; 448 frame_info[0] = AudioMixer::Source::AudioFrameInfo::kMuted;
437 std::fill(frames[0].data_, frames[0].data_ + kDefaultSampleRateHz / 100, 449 std::fill(frames[0].data_, frames[0].data_ + kDefaultSampleRateHz / 100,
438 std::numeric_limits<int16_t>::max()); 450 std::numeric_limits<int16_t>::max());
439 std::vector<bool> expected_status(kAudioSources, true); 451 std::vector<bool> expected_status(kAudioSources, true);
440 expected_status[0] = false; 452 expected_status[0] = false;
441 453
442 MixAndCompare(frames, frame_info, expected_status); 454 MixAndCompare(frames, frame_info, expected_status);
443 } 455 }
456
457 TEST(AudioMixer, MixingRateShouldBeDecidedByRateCalculator) {
458 constexpr int kOutputRate = 22000;
459 const auto mixer = AudioMixerImpl::CreateWithOutputRateCalculator(
460 std::unique_ptr<OutputRateCalculator>(
461 new CustomRateCalculator(kOutputRate)));
462 MockMixerAudioSource audio_source;
463 mixer->AddSource(&audio_source);
464 ResetFrame(audio_source.fake_frame());
465
466 EXPECT_CALL(audio_source, GetAudioFrameWithInfo(kOutputRate, _))
467 .Times(Exactly(1));
468
469 mixer->Mix(1, &frame_for_mixing);
470 }
471
472 TEST(AudioMixer, ZeroSourceRateShouldBeDecidedByRateCalculator) {
473 constexpr int kOutputRate = 8000;
474 const auto mixer = AudioMixerImpl::CreateWithOutputRateCalculator(
475 std::unique_ptr<OutputRateCalculator>(
476 new CustomRateCalculator(kOutputRate)));
477
478 mixer->Mix(1, &frame_for_mixing);
479
480 EXPECT_EQ(kOutputRate, frame_for_mixing.sample_rate_hz_);
481 }
444 } // namespace webrtc 482 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_mixer/audio_mixer_impl.cc ('k') | webrtc/modules/audio_mixer/default_output_rate_calculator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698