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

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

Issue 2408683002: Cleanup of the mixer interface. (Closed)
Patch Set: Added clarifying comments for adding/removing sources and threading aspects of the interface. Created 4 years, 2 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 <memory> 14 #include <memory>
14 #include <utility> 15 #include <utility>
15 16
16 #include "webrtc/base/bind.h" 17 #include "webrtc/base/bind.h"
17 #include "webrtc/base/thread.h" 18 #include "webrtc/base/thread.h"
18 #include "webrtc/modules/audio_mixer/audio_mixer_impl.h" 19 #include "webrtc/modules/audio_mixer/audio_mixer_impl.h"
19 #include "webrtc/modules/audio_mixer/audio_mixer.h" 20 #include "webrtc/modules/audio_mixer/audio_mixer.h"
20 #include "webrtc/test/gmock.h" 21 #include "webrtc/test/gmock.h"
21 22
22 using testing::_; 23 using testing::_;
(...skipping 29 matching lines...) Expand all
52 public: 53 public:
53 MockMixerAudioSource() 54 MockMixerAudioSource()
54 : fake_audio_frame_info_(AudioMixer::Source::AudioFrameInfo::kNormal) { 55 : fake_audio_frame_info_(AudioMixer::Source::AudioFrameInfo::kNormal) {
55 ON_CALL(*this, GetAudioFrameWithInfo(_)) 56 ON_CALL(*this, GetAudioFrameWithInfo(_))
56 .WillByDefault( 57 .WillByDefault(
57 Invoke(this, &MockMixerAudioSource::FakeAudioFrameWithInfo)); 58 Invoke(this, &MockMixerAudioSource::FakeAudioFrameWithInfo));
58 } 59 }
59 60
60 MOCK_METHOD1(GetAudioFrameWithInfo, AudioFrameWithInfo(int sample_rate_hz)); 61 MOCK_METHOD1(GetAudioFrameWithInfo, AudioFrameWithInfo(int sample_rate_hz));
61 62
63 MOCK_METHOD0(ssrc, int());
64
62 AudioFrame* fake_frame() { return &fake_frame_; } 65 AudioFrame* fake_frame() { return &fake_frame_; }
63 AudioFrameInfo fake_info() { return fake_audio_frame_info_; } 66 AudioFrameInfo fake_info() { return fake_audio_frame_info_; }
64 void set_fake_info(const AudioFrameInfo audio_frame_info) { 67 void set_fake_info(const AudioFrameInfo audio_frame_info) {
65 fake_audio_frame_info_ = audio_frame_info; 68 fake_audio_frame_info_ = audio_frame_info;
66 } 69 }
67 70
68 private: 71 private:
69 AudioFrame fake_frame_, fake_output_frame_; 72 AudioFrame fake_frame_, fake_output_frame_;
70 AudioFrameInfo fake_audio_frame_info_; 73 AudioFrameInfo fake_audio_frame_info_;
71 AudioFrameWithInfo FakeAudioFrameWithInfo(int sample_rate_hz) { 74 AudioFrameWithInfo FakeAudioFrameWithInfo(int sample_rate_hz) {
72 fake_output_frame_.CopyFrom(fake_frame_); 75 fake_output_frame_.CopyFrom(fake_frame_);
73 return { 76 return {
74 &fake_output_frame_, // audio_frame_pointer 77 &fake_output_frame_, // audio_frame_pointer
75 fake_info(), // audio_frame_info 78 fake_info(), // audio_frame_info
76 }; 79 };
77 } 80 }
78 }; 81 };
79 82
80 // Creates participants from |frames| and |frame_info| and adds them 83 // Creates participants from |frames| and |frame_info| and adds them
81 // to the mixer. Compares mixed status with |expected_status| 84 // to the mixer. Compares mixed status with |expected_status|
82 void MixAndCompare( 85 void MixAndCompare(
83 const std::vector<AudioFrame>& frames, 86 const std::vector<AudioFrame>& frames,
84 const std::vector<AudioMixer::Source::AudioFrameInfo>& frame_info, 87 const std::vector<AudioMixer::Source::AudioFrameInfo>& frame_info,
85 const std::vector<bool>& expected_status) { 88 const std::vector<bool>& expected_status) {
86 int num_audio_sources = frames.size(); 89 int num_audio_sources = frames.size();
87 RTC_DCHECK(frames.size() == frame_info.size()); 90 RTC_DCHECK(frames.size() == frame_info.size());
88 RTC_DCHECK(frame_info.size() == expected_status.size()); 91 RTC_DCHECK(frame_info.size() == expected_status.size());
89 92
90 const std::unique_ptr<AudioMixerImpl> mixer(AudioMixerImpl::Create()); 93 const auto mixer = AudioMixerImpl::Create();
91 std::vector<MockMixerAudioSource> participants(num_audio_sources); 94 std::vector<MockMixerAudioSource> participants(num_audio_sources);
92 95
93 for (int i = 0; i < num_audio_sources; i++) { 96 for (int i = 0; i < num_audio_sources; i++) {
94 participants[i].fake_frame()->CopyFrom(frames[i]); 97 participants[i].fake_frame()->CopyFrom(frames[i]);
95 participants[i].set_fake_info(frame_info[i]); 98 participants[i].set_fake_info(frame_info[i]);
96 } 99 }
97 100
98 for (int i = 0; i < num_audio_sources; i++) { 101 for (int i = 0; i < num_audio_sources; i++) {
99 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participants[i], true)); 102 EXPECT_TRUE(mixer->AddSource(&participants[i]));
100 EXPECT_CALL(participants[i], GetAudioFrameWithInfo(kDefaultSampleRateHz)) 103 EXPECT_CALL(participants[i], GetAudioFrameWithInfo(kDefaultSampleRateHz))
101 .Times(Exactly(1)); 104 .Times(Exactly(1));
102 } 105 }
103 106
104 mixer->Mix(kDefaultSampleRateHz, 1, &frame_for_mixing); 107 mixer->Mix(kDefaultSampleRateHz, 1, &frame_for_mixing);
105 108
106 for (int i = 0; i < num_audio_sources; i++) { 109 for (int i = 0; i < num_audio_sources; i++) {
107 EXPECT_EQ(expected_status[i], 110 EXPECT_EQ(expected_status[i],
108 mixer->GetAudioSourceMixabilityStatusForTest(&participants[i])) 111 mixer->GetAudioSourceMixabilityStatusForTest(&participants[i]))
109 << "Mixed status of AudioSource #" << i << " wrong."; 112 << "Mixed status of AudioSource #" << i << " wrong.";
110 } 113 }
111 } 114 }
112 115
113 TEST(AudioMixer, LargestEnergyVadActiveMixed) { 116 TEST(AudioMixer, LargestEnergyVadActiveMixed) {
114 constexpr int kAudioSources = 117 constexpr int kAudioSources =
115 AudioMixer::kMaximumAmountOfMixedAudioSources + 3; 118 AudioMixerImpl::kMaximumAmountOfMixedAudioSources + 3;
116 119
117 const std::unique_ptr<AudioMixerImpl> mixer(AudioMixerImpl::Create()); 120 const auto mixer = AudioMixerImpl::Create();
118 121
119 MockMixerAudioSource participants[kAudioSources]; 122 MockMixerAudioSource participants[kAudioSources];
120 123
121 for (int i = 0; i < kAudioSources; ++i) { 124 for (int i = 0; i < kAudioSources; ++i) {
122 ResetFrame(participants[i].fake_frame()); 125 ResetFrame(participants[i].fake_frame());
123 126
124 // We set the 80-th sample value since the first 80 samples may be 127 // We set the 80-th sample value since the first 80 samples may be
125 // modified by a ramped-in window. 128 // modified by a ramped-in window.
126 participants[i].fake_frame()->data_[80] = i; 129 participants[i].fake_frame()->data_[80] = i;
127 130
128 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participants[i], true)); 131 EXPECT_TRUE(mixer->AddSource(&participants[i]));
129 EXPECT_CALL(participants[i], GetAudioFrameWithInfo(_)).Times(Exactly(1)); 132 EXPECT_CALL(participants[i], GetAudioFrameWithInfo(_)).Times(Exactly(1));
130 } 133 }
131 134
132 // Last participant gives audio frame with passive VAD, although it has the 135 // Last participant gives audio frame with passive VAD, although it has the
133 // largest energy. 136 // largest energy.
134 participants[kAudioSources - 1].fake_frame()->vad_activity_ = 137 participants[kAudioSources - 1].fake_frame()->vad_activity_ =
135 AudioFrame::kVadPassive; 138 AudioFrame::kVadPassive;
136 139
137 AudioFrame audio_frame; 140 AudioFrame audio_frame;
138 mixer->Mix(kDefaultSampleRateHz, 141 mixer->Mix(kDefaultSampleRateHz,
139 1, // number of channels 142 1, // number of channels
140 &audio_frame); 143 &audio_frame);
141 144
142 for (int i = 0; i < kAudioSources; ++i) { 145 for (int i = 0; i < kAudioSources; ++i) {
143 bool is_mixed = 146 bool is_mixed =
144 mixer->GetAudioSourceMixabilityStatusForTest(&participants[i]); 147 mixer->GetAudioSourceMixabilityStatusForTest(&participants[i]);
145 if (i == kAudioSources - 1 || 148 if (i == kAudioSources - 1 ||
146 i < kAudioSources - 1 - AudioMixer::kMaximumAmountOfMixedAudioSources) { 149 i < kAudioSources - 1 -
150 AudioMixerImpl::kMaximumAmountOfMixedAudioSources) {
147 EXPECT_FALSE(is_mixed) << "Mixing status of AudioSource #" << i 151 EXPECT_FALSE(is_mixed) << "Mixing status of AudioSource #" << i
148 << " wrong."; 152 << " wrong.";
149 } else { 153 } else {
150 EXPECT_TRUE(is_mixed) << "Mixing status of AudioSource #" << i 154 EXPECT_TRUE(is_mixed) << "Mixing status of AudioSource #" << i
151 << " wrong."; 155 << " wrong.";
152 } 156 }
153 } 157 }
154 } 158 }
155 159
156 TEST(AudioMixer, FrameNotModifiedForSingleParticipant) { 160 TEST(AudioMixer, FrameNotModifiedForSingleParticipant) {
157 const std::unique_ptr<AudioMixer> mixer(AudioMixer::Create()); 161 const auto mixer = AudioMixerImpl::Create();
158 162
159 MockMixerAudioSource participant; 163 MockMixerAudioSource participant;
160 164
161 ResetFrame(participant.fake_frame()); 165 ResetFrame(participant.fake_frame());
162 const int n_samples = participant.fake_frame()->samples_per_channel_; 166 const int n_samples = participant.fake_frame()->samples_per_channel_;
163 167
164 // Modify the frame so that it's not zero. 168 // Modify the frame so that it's not zero.
165 for (int j = 0; j < n_samples; j++) { 169 for (int j = 0; j < n_samples; j++) {
166 participant.fake_frame()->data_[j] = j; 170 participant.fake_frame()->data_[j] = j;
167 } 171 }
168 172
169 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participant, true)); 173 EXPECT_TRUE(mixer->AddSource(&participant));
170 EXPECT_CALL(participant, GetAudioFrameWithInfo(_)).Times(Exactly(2)); 174 EXPECT_CALL(participant, GetAudioFrameWithInfo(_)).Times(Exactly(2));
171 175
172 AudioFrame audio_frame; 176 AudioFrame audio_frame;
173 // Two mix iteration to compare after the ramp-up step. 177 // Two mix iteration to compare after the ramp-up step.
174 for (int i = 0; i < 2; i++) { 178 for (int i = 0; i < 2; i++) {
175 mixer->Mix(kDefaultSampleRateHz, 179 mixer->Mix(kDefaultSampleRateHz,
176 1, // number of channels 180 1, // number of channels
177 &audio_frame); 181 &audio_frame);
178 } 182 }
179 183
180 EXPECT_EQ( 184 EXPECT_EQ(
181 0, memcmp(participant.fake_frame()->data_, audio_frame.data_, n_samples)); 185 0, memcmp(participant.fake_frame()->data_, audio_frame.data_, n_samples));
182 } 186 }
183 187
184 TEST(AudioMixer, ParticipantSampleRate) { 188 TEST(AudioMixer, ParticipantSampleRate) {
185 const std::unique_ptr<AudioMixer> mixer(AudioMixer::Create()); 189 const auto mixer = AudioMixerImpl::Create();
186 190
187 MockMixerAudioSource participant; 191 MockMixerAudioSource participant;
188 ResetFrame(participant.fake_frame()); 192 ResetFrame(participant.fake_frame());
189 193
190 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participant, true)); 194 EXPECT_TRUE(mixer->AddSource(&participant));
191 for (auto frequency : {8000, 16000, 32000, 48000}) { 195 for (auto frequency : {8000, 16000, 32000, 48000}) {
192 EXPECT_CALL(participant, GetAudioFrameWithInfo(frequency)) 196 EXPECT_CALL(participant, GetAudioFrameWithInfo(frequency))
193 .Times(Exactly(1)); 197 .Times(Exactly(1));
194 participant.fake_frame()->sample_rate_hz_ = frequency; 198 participant.fake_frame()->sample_rate_hz_ = frequency;
195 participant.fake_frame()->samples_per_channel_ = frequency / 100; 199 participant.fake_frame()->samples_per_channel_ = frequency / 100;
196 mixer->Mix(frequency, 1, &frame_for_mixing); 200 mixer->Mix(frequency, 1, &frame_for_mixing);
197 EXPECT_EQ(frequency, frame_for_mixing.sample_rate_hz_); 201 EXPECT_EQ(frequency, frame_for_mixing.sample_rate_hz_);
198 } 202 }
199 } 203 }
200 204
201 TEST(AudioMixer, ParticipantNumberOfChannels) { 205 TEST(AudioMixer, ParticipantNumberOfChannels) {
202 const std::unique_ptr<AudioMixer> mixer(AudioMixer::Create()); 206 const auto mixer = AudioMixerImpl::Create();
203 207
204 MockMixerAudioSource participant; 208 MockMixerAudioSource participant;
205 ResetFrame(participant.fake_frame()); 209 ResetFrame(participant.fake_frame());
206 210
207 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participant, true)); 211 EXPECT_TRUE(mixer->AddSource(&participant));
208 for (size_t number_of_channels : {1, 2}) { 212 for (size_t number_of_channels : {1, 2}) {
209 EXPECT_CALL(participant, GetAudioFrameWithInfo(kDefaultSampleRateHz)) 213 EXPECT_CALL(participant, GetAudioFrameWithInfo(kDefaultSampleRateHz))
210 .Times(Exactly(1)); 214 .Times(Exactly(1));
211 mixer->Mix(kDefaultSampleRateHz, number_of_channels, &frame_for_mixing); 215 mixer->Mix(kDefaultSampleRateHz, number_of_channels, &frame_for_mixing);
212 EXPECT_EQ(number_of_channels, frame_for_mixing.num_channels_); 216 EXPECT_EQ(number_of_channels, frame_for_mixing.num_channels_);
213 } 217 }
214 } 218 }
215 219
216 // Maximal amount of participants are mixed one iteration, then 220 // Maximal amount of participants are mixed one iteration, then
217 // another participant with higher energy is added. 221 // another participant with higher energy is added.
218 TEST(AudioMixer, RampedOutSourcesShouldNotBeMarkedMixed) { 222 TEST(AudioMixer, RampedOutSourcesShouldNotBeMarkedMixed) {
219 constexpr int kAudioSources = 223 constexpr int kAudioSources =
220 AudioMixer::kMaximumAmountOfMixedAudioSources + 1; 224 AudioMixerImpl::kMaximumAmountOfMixedAudioSources + 1;
221 225
222 const std::unique_ptr<AudioMixerImpl> mixer(AudioMixerImpl::Create()); 226 const auto mixer = AudioMixerImpl::Create();
223 MockMixerAudioSource participants[kAudioSources]; 227 MockMixerAudioSource participants[kAudioSources];
224 228
225 for (int i = 0; i < kAudioSources; i++) { 229 for (int i = 0; i < kAudioSources; i++) {
226 ResetFrame(participants[i].fake_frame()); 230 ResetFrame(participants[i].fake_frame());
227 // Set the participant audio energy to increase with the index 231 // Set the participant audio energy to increase with the index
228 // |i|. 232 // |i|.
229 participants[i].fake_frame()->data_[0] = 100 * i; 233 participants[i].fake_frame()->data_[0] = 100 * i;
230 } 234 }
231 235
232 // Add all participants but the loudest for mixing. 236 // Add all participants but the loudest for mixing.
233 for (int i = 0; i < kAudioSources - 1; i++) { 237 for (int i = 0; i < kAudioSources - 1; i++) {
234 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participants[i], true)); 238 EXPECT_TRUE(mixer->AddSource(&participants[i]));
235 EXPECT_CALL(participants[i], GetAudioFrameWithInfo(kDefaultSampleRateHz)) 239 EXPECT_CALL(participants[i], GetAudioFrameWithInfo(kDefaultSampleRateHz))
236 .Times(Exactly(1)); 240 .Times(Exactly(1));
237 } 241 }
238 242
239 // First mixer iteration 243 // First mixer iteration
240 mixer->Mix(kDefaultSampleRateHz, 1, &frame_for_mixing); 244 mixer->Mix(kDefaultSampleRateHz, 1, &frame_for_mixing);
241 245
242 // All participants but the loudest should have been mixed. 246 // All participants but the loudest should have been mixed.
243 for (int i = 0; i < kAudioSources - 1; i++) { 247 for (int i = 0; i < kAudioSources - 1; i++) {
244 EXPECT_TRUE(mixer->GetAudioSourceMixabilityStatusForTest(&participants[i])) 248 EXPECT_TRUE(mixer->GetAudioSourceMixabilityStatusForTest(&participants[i]))
245 << "Mixed status of AudioSource #" << i << " wrong."; 249 << "Mixed status of AudioSource #" << i << " wrong.";
246 } 250 }
247 251
248 // Add new participant with higher energy. 252 // Add new participant with higher energy.
249 EXPECT_EQ(0, 253 EXPECT_TRUE(mixer->AddSource(&participants[kAudioSources - 1]));
250 mixer->SetMixabilityStatus(&participants[kAudioSources - 1], true));
251 for (int i = 0; i < kAudioSources; i++) { 254 for (int i = 0; i < kAudioSources; i++) {
252 EXPECT_CALL(participants[i], GetAudioFrameWithInfo(kDefaultSampleRateHz)) 255 EXPECT_CALL(participants[i], GetAudioFrameWithInfo(kDefaultSampleRateHz))
253 .Times(Exactly(1)); 256 .Times(Exactly(1));
254 } 257 }
255 258
256 mixer->Mix(kDefaultSampleRateHz, 1, &frame_for_mixing); 259 mixer->Mix(kDefaultSampleRateHz, 1, &frame_for_mixing);
257 260
258 // The most quiet participant should not have been mixed. 261 // The most quiet participant should not have been mixed.
259 EXPECT_FALSE(mixer->GetAudioSourceMixabilityStatusForTest(&participants[0])) 262 EXPECT_FALSE(mixer->GetAudioSourceMixabilityStatusForTest(&participants[0]))
260 << "Mixed status of AudioSource #0 wrong."; 263 << "Mixed status of AudioSource #0 wrong.";
261 264
262 // The loudest participants should have been mixed. 265 // The loudest participants should have been mixed.
263 for (int i = 1; i < kAudioSources; i++) { 266 for (int i = 1; i < kAudioSources; i++) {
264 EXPECT_EQ(true, 267 EXPECT_EQ(true,
265 mixer->GetAudioSourceMixabilityStatusForTest(&participants[i])) 268 mixer->GetAudioSourceMixabilityStatusForTest(&participants[i]))
266 << "Mixed status of AudioSource #" << i << " wrong."; 269 << "Mixed status of AudioSource #" << i << " wrong.";
267 } 270 }
268 } 271 }
269 272
270 // This test checks that the initialization and participant addition 273 // This test checks that the initialization and participant addition
271 // can be done on a different thread. 274 // can be done on a different thread.
272 TEST(AudioMixer, ConstructFromOtherThread) { 275 TEST(AudioMixer, ConstructFromOtherThread) {
273 std::unique_ptr<rtc::Thread> init_thread = rtc::Thread::Create(); 276 std::unique_ptr<rtc::Thread> init_thread = rtc::Thread::Create();
274 std::unique_ptr<rtc::Thread> participant_thread = rtc::Thread::Create(); 277 std::unique_ptr<rtc::Thread> participant_thread = rtc::Thread::Create();
275 init_thread->Start(); 278 init_thread->Start();
276 std::unique_ptr<AudioMixer> mixer( 279 const auto mixer = init_thread->Invoke<rtc::scoped_refptr<AudioMixer>>(
277 init_thread->Invoke<std::unique_ptr<AudioMixer>>( 280 RTC_FROM_HERE, &AudioMixerImpl::Create);
278 RTC_FROM_HERE, &AudioMixer::Create));
279 MockMixerAudioSource participant; 281 MockMixerAudioSource participant;
280 282
281 ResetFrame(participant.fake_frame()); 283 ResetFrame(participant.fake_frame());
282 284
283 participant_thread->Start(); 285 participant_thread->Start();
284 EXPECT_EQ(0, participant_thread->Invoke<int>( 286 EXPECT_TRUE(participant_thread->Invoke<int>(
285 RTC_FROM_HERE, rtc::Bind(&AudioMixer::SetMixabilityStatus, 287 RTC_FROM_HERE,
286 mixer.get(), &participant, true))); 288 rtc::Bind(&AudioMixer::AddSource, mixer.get(), &participant)));
287 289
288 EXPECT_CALL(participant, GetAudioFrameWithInfo(kDefaultSampleRateHz)) 290 EXPECT_CALL(participant, GetAudioFrameWithInfo(kDefaultSampleRateHz))
289 .Times(Exactly(1)); 291 .Times(Exactly(1));
290 292
291 // Do one mixer iteration 293 // Do one mixer iteration
292 mixer->Mix(kDefaultSampleRateHz, 1, &frame_for_mixing); 294 mixer->Mix(kDefaultSampleRateHz, 1, &frame_for_mixing);
293 } 295 }
294 296
295 TEST(AudioMixer, MutedShouldMixAfterUnmuted) { 297 TEST(AudioMixer, MutedShouldMixAfterUnmuted) {
296 constexpr int kAudioSources = 298 constexpr int kAudioSources =
297 AudioMixer::kMaximumAmountOfMixedAudioSources + 1; 299 AudioMixerImpl::kMaximumAmountOfMixedAudioSources + 1;
298 300
299 std::vector<AudioFrame> frames(kAudioSources); 301 std::vector<AudioFrame> frames(kAudioSources);
300 for (auto& frame : frames) { 302 for (auto& frame : frames) {
301 ResetFrame(&frame); 303 ResetFrame(&frame);
302 } 304 }
303 305
304 std::vector<AudioMixer::Source::AudioFrameInfo> frame_info( 306 std::vector<AudioMixer::Source::AudioFrameInfo> frame_info(
305 kAudioSources, AudioMixer::Source::AudioFrameInfo::kNormal); 307 kAudioSources, AudioMixer::Source::AudioFrameInfo::kNormal);
306 frame_info[0] = AudioMixer::Source::AudioFrameInfo::kMuted; 308 frame_info[0] = AudioMixer::Source::AudioFrameInfo::kMuted;
307 std::vector<bool> expected_status(kAudioSources, true); 309 std::vector<bool> expected_status(kAudioSources, true);
308 expected_status[0] = false; 310 expected_status[0] = false;
309 311
310 MixAndCompare(frames, frame_info, expected_status); 312 MixAndCompare(frames, frame_info, expected_status);
311 } 313 }
312 314
313 TEST(AudioMixer, PassiveShouldMixAfterNormal) { 315 TEST(AudioMixer, PassiveShouldMixAfterNormal) {
314 constexpr int kAudioSources = 316 constexpr int kAudioSources =
315 AudioMixer::kMaximumAmountOfMixedAudioSources + 1; 317 AudioMixerImpl::kMaximumAmountOfMixedAudioSources + 1;
316 318
317 std::vector<AudioFrame> frames(kAudioSources); 319 std::vector<AudioFrame> frames(kAudioSources);
318 for (auto& frame : frames) { 320 for (auto& frame : frames) {
319 ResetFrame(&frame); 321 ResetFrame(&frame);
320 } 322 }
321 323
322 std::vector<AudioMixer::Source::AudioFrameInfo> frame_info( 324 std::vector<AudioMixer::Source::AudioFrameInfo> frame_info(
323 kAudioSources, AudioMixer::Source::AudioFrameInfo::kNormal); 325 kAudioSources, AudioMixer::Source::AudioFrameInfo::kNormal);
324 frames[0].vad_activity_ = AudioFrame::kVadPassive; 326 frames[0].vad_activity_ = AudioFrame::kVadPassive;
325 std::vector<bool> expected_status(kAudioSources, true); 327 std::vector<bool> expected_status(kAudioSources, true);
326 expected_status[0] = false; 328 expected_status[0] = false;
327 329
328 MixAndCompare(frames, frame_info, expected_status); 330 MixAndCompare(frames, frame_info, expected_status);
329 } 331 }
330 332
331 TEST(AudioMixer, ActiveShouldMixBeforeLoud) { 333 TEST(AudioMixer, ActiveShouldMixBeforeLoud) {
332 constexpr int kAudioSources = 334 constexpr int kAudioSources =
333 AudioMixer::kMaximumAmountOfMixedAudioSources + 1; 335 AudioMixerImpl::kMaximumAmountOfMixedAudioSources + 1;
334 336
335 std::vector<AudioFrame> frames(kAudioSources); 337 std::vector<AudioFrame> frames(kAudioSources);
336 for (auto& frame : frames) { 338 for (auto& frame : frames) {
337 ResetFrame(&frame); 339 ResetFrame(&frame);
338 } 340 }
339 341
340 std::vector<AudioMixer::Source::AudioFrameInfo> frame_info( 342 std::vector<AudioMixer::Source::AudioFrameInfo> frame_info(
341 kAudioSources, AudioMixer::Source::AudioFrameInfo::kNormal); 343 kAudioSources, AudioMixer::Source::AudioFrameInfo::kNormal);
342 frames[0].vad_activity_ = AudioFrame::kVadPassive; 344 frames[0].vad_activity_ = AudioFrame::kVadPassive;
343 std::fill(frames[0].data_, frames[0].data_ + kDefaultSampleRateHz / 100, 345 std::fill(frames[0].data_, frames[0].data_ + kDefaultSampleRateHz / 100,
344 std::numeric_limits<int16_t>::max()); 346 std::numeric_limits<int16_t>::max());
345 std::vector<bool> expected_status(kAudioSources, true); 347 std::vector<bool> expected_status(kAudioSources, true);
346 expected_status[0] = false; 348 expected_status[0] = false;
347 349
348 MixAndCompare(frames, frame_info, expected_status); 350 MixAndCompare(frames, frame_info, expected_status);
349 } 351 }
350 352
351 TEST(AudioMixer, UnmutedShouldMixBeforeLoud) { 353 TEST(AudioMixer, UnmutedShouldMixBeforeLoud) {
352 constexpr int kAudioSources = 354 constexpr int kAudioSources =
353 AudioMixer::kMaximumAmountOfMixedAudioSources + 1; 355 AudioMixerImpl::kMaximumAmountOfMixedAudioSources + 1;
354 356
355 std::vector<AudioFrame> frames(kAudioSources); 357 std::vector<AudioFrame> frames(kAudioSources);
356 for (auto& frame : frames) { 358 for (auto& frame : frames) {
357 ResetFrame(&frame); 359 ResetFrame(&frame);
358 } 360 }
359 361
360 std::vector<AudioMixer::Source::AudioFrameInfo> frame_info( 362 std::vector<AudioMixer::Source::AudioFrameInfo> frame_info(
361 kAudioSources, AudioMixer::Source::AudioFrameInfo::kNormal); 363 kAudioSources, AudioMixer::Source::AudioFrameInfo::kNormal);
362 frame_info[0] = AudioMixer::Source::AudioFrameInfo::kMuted; 364 frame_info[0] = AudioMixer::Source::AudioFrameInfo::kMuted;
363 std::fill(frames[0].data_, frames[0].data_ + kDefaultSampleRateHz / 100, 365 std::fill(frames[0].data_, frames[0].data_ + kDefaultSampleRateHz / 100,
364 std::numeric_limits<int16_t>::max()); 366 std::numeric_limits<int16_t>::max());
365 std::vector<bool> expected_status(kAudioSources, true); 367 std::vector<bool> expected_status(kAudioSources, true);
366 expected_status[0] = false; 368 expected_status[0] = false;
367 369
368 MixAndCompare(frames, frame_info, expected_status); 370 MixAndCompare(frames, frame_info, expected_status);
369 } 371 }
370 } // namespace webrtc 372 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_mixer/audio_mixer_impl.cc ('k') | webrtc/modules/audio_mixer/test/audio_mixer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698