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

Side by Side Diff: webrtc/modules/audio_mixer/test/audio_mixer_unittest.cc

Issue 2402283003: Cleanup of the mixer interface. (Closed)
Patch Set: Formulation & upper case. 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
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 } 45 }
46 46
47 AudioFrame frame_for_mixing; 47 AudioFrame frame_for_mixing;
48 48
49 } // namespace 49 } // namespace
50 50
51 class MockMixerAudioSource : public AudioMixer::Source { 51 class MockMixerAudioSource : public AudioMixer::Source {
52 public: 52 public:
53 MockMixerAudioSource() 53 MockMixerAudioSource()
54 : fake_audio_frame_info_(AudioMixer::Source::AudioFrameInfo::kNormal) { 54 : fake_audio_frame_info_(AudioMixer::Source::AudioFrameInfo::kNormal) {
55 ON_CALL(*this, GetAudioFrameWithMuted(_, _)) 55 ON_CALL(*this, GetAudioFrameWithMuted(_))
56 .WillByDefault( 56 .WillByDefault(
57 Invoke(this, &MockMixerAudioSource::FakeAudioFrameWithMuted)); 57 Invoke(this, &MockMixerAudioSource::FakeAudioFrameWithMuted));
58 } 58 }
59 59
60 MOCK_METHOD2(GetAudioFrameWithMuted, 60 MOCK_METHOD1(GetAudioFrameWithMuted, AudioFrameWithMuted(int sample_rate_hz));
61 AudioFrameWithMuted(const int32_t id, int sample_rate_hz));
62 61
63 AudioFrame* fake_frame() { return &fake_frame_; } 62 AudioFrame* fake_frame() { return &fake_frame_; }
64 AudioFrameInfo fake_info() { return fake_audio_frame_info_; } 63 AudioFrameInfo fake_info() { return fake_audio_frame_info_; }
65 void set_fake_info(const AudioFrameInfo audio_frame_info) { 64 void set_fake_info(const AudioFrameInfo audio_frame_info) {
66 fake_audio_frame_info_ = audio_frame_info; 65 fake_audio_frame_info_ = audio_frame_info;
67 } 66 }
68 67
69 private: 68 private:
70 AudioFrame fake_frame_, fake_output_frame_; 69 AudioFrame fake_frame_, fake_output_frame_;
71 AudioFrameInfo fake_audio_frame_info_; 70 AudioFrameInfo fake_audio_frame_info_;
72 AudioFrameWithMuted FakeAudioFrameWithMuted(const int32_t id, 71 AudioFrameWithMuted FakeAudioFrameWithMuted(int sample_rate_hz) {
73 int sample_rate_hz) {
74 fake_output_frame_.CopyFrom(fake_frame_); 72 fake_output_frame_.CopyFrom(fake_frame_);
75 return { 73 return {
76 &fake_output_frame_, // audio_frame_pointer 74 &fake_output_frame_, // audio_frame_pointer
77 fake_info(), // audio_frame_info 75 fake_info(), // audio_frame_info
78 }; 76 };
79 } 77 }
80 }; 78 };
81 79
82 // Creates participants from |frames| and |frame_info| and adds them 80 // Creates participants from |frames| and |frame_info| and adds them
83 // to the mixer. Compares mixed status with |expected_status| 81 // to the mixer. Compares mixed status with |expected_status|
84 void MixAndCompare( 82 void MixAndCompare(
85 const std::vector<AudioFrame>& frames, 83 const std::vector<AudioFrame>& frames,
86 const std::vector<AudioMixer::Source::AudioFrameInfo>& frame_info, 84 const std::vector<AudioMixer::Source::AudioFrameInfo>& frame_info,
87 const std::vector<bool>& expected_status) { 85 const std::vector<bool>& expected_status) {
88 int num_audio_sources = frames.size(); 86 int num_audio_sources = frames.size();
89 RTC_DCHECK(frames.size() == frame_info.size()); 87 RTC_DCHECK(frames.size() == frame_info.size());
90 RTC_DCHECK(frame_info.size() == expected_status.size()); 88 RTC_DCHECK(frame_info.size() == expected_status.size());
91 89
92 const std::unique_ptr<AudioMixerImpl> mixer(AudioMixerImpl::Create(kId)); 90 const std::unique_ptr<AudioMixerImpl> mixer(AudioMixerImpl::Create());
93 std::vector<MockMixerAudioSource> participants(num_audio_sources); 91 std::vector<MockMixerAudioSource> participants(num_audio_sources);
94 92
95 for (int i = 0; i < num_audio_sources; i++) { 93 for (int i = 0; i < num_audio_sources; i++) {
96 participants[i].fake_frame()->CopyFrom(frames[i]); 94 participants[i].fake_frame()->CopyFrom(frames[i]);
97 participants[i].set_fake_info(frame_info[i]); 95 participants[i].set_fake_info(frame_info[i]);
98 } 96 }
99 97
100 for (int i = 0; i < num_audio_sources; i++) { 98 for (int i = 0; i < num_audio_sources; i++) {
101 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participants[i], true)); 99 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participants[i], true));
102 EXPECT_CALL(participants[i], 100 EXPECT_CALL(participants[i], GetAudioFrameWithMuted(kDefaultSampleRateHz))
103 GetAudioFrameWithMuted(_, kDefaultSampleRateHz))
104 .Times(Exactly(1)); 101 .Times(Exactly(1));
105 } 102 }
106 103
107 mixer->Mix(kDefaultSampleRateHz, 1, &frame_for_mixing); 104 mixer->Mix(kDefaultSampleRateHz, 1, &frame_for_mixing);
108 105
109 for (int i = 0; i < num_audio_sources; i++) { 106 for (int i = 0; i < num_audio_sources; i++) {
110 EXPECT_EQ(expected_status[i], 107 EXPECT_EQ(expected_status[i],
111 mixer->GetAudioSourceMixabilityStatusForTest(&participants[i])) 108 mixer->GetAudioSourceMixabilityStatusForTest(&participants[i]))
112 << "Mixed status of AudioSource #" << i << " wrong."; 109 << "Mixed status of AudioSource #" << i << " wrong.";
113 } 110 }
114 } 111 }
115 112
116 TEST(AudioMixer, AnonymousAndNamed) {
117 // Should not matter even if partipants are more than
118 // kMaximumAmountOfMixedAudioSources.
119 constexpr int kNamed = AudioMixer::kMaximumAmountOfMixedAudioSources + 1;
120 constexpr int kAnonymous = AudioMixer::kMaximumAmountOfMixedAudioSources + 1;
121
122 const std::unique_ptr<AudioMixer> mixer(AudioMixer::Create(kId));
123
124 MockMixerAudioSource named[kNamed];
125 MockMixerAudioSource anonymous[kAnonymous];
126
127 for (int i = 0; i < kNamed; ++i) {
128 EXPECT_EQ(0, mixer->SetMixabilityStatus(&named[i], true));
129 EXPECT_TRUE(mixer->MixabilityStatus(named[i]));
130 }
131
132 for (int i = 0; i < kAnonymous; ++i) {
133 // AudioSource must be registered before turning it into anonymous.
134 EXPECT_EQ(-1, mixer->SetAnonymousMixabilityStatus(&anonymous[i], true));
135 EXPECT_EQ(0, mixer->SetMixabilityStatus(&anonymous[i], true));
136 EXPECT_TRUE(mixer->MixabilityStatus(anonymous[i]));
137 EXPECT_FALSE(mixer->AnonymousMixabilityStatus(anonymous[i]));
138
139 EXPECT_EQ(0, mixer->SetAnonymousMixabilityStatus(&anonymous[i], true));
140 EXPECT_TRUE(mixer->AnonymousMixabilityStatus(anonymous[i]));
141
142 // Anonymous participants do not show status by MixabilityStatus.
143 EXPECT_FALSE(mixer->MixabilityStatus(anonymous[i]));
144 }
145
146 for (int i = 0; i < kNamed; ++i) {
147 EXPECT_EQ(0, mixer->SetMixabilityStatus(&named[i], false));
148 EXPECT_FALSE(mixer->MixabilityStatus(named[i]));
149 }
150
151 for (int i = 0; i < kAnonymous - 1; i++) {
152 EXPECT_EQ(0, mixer->SetAnonymousMixabilityStatus(&anonymous[i], false));
153 EXPECT_FALSE(mixer->AnonymousMixabilityStatus(anonymous[i]));
154
155 // SetAnonymousMixabilityStatus(anonymous, false) moves anonymous to the
156 // named group.
157 EXPECT_TRUE(mixer->MixabilityStatus(anonymous[i]));
158 }
159
160 // SetMixabilityStatus(anonymous, false) will remove anonymous from both
161 // anonymous and named groups.
162 EXPECT_EQ(0, mixer->SetMixabilityStatus(&anonymous[kAnonymous - 1], false));
163 EXPECT_FALSE(mixer->AnonymousMixabilityStatus(anonymous[kAnonymous - 1]));
164 EXPECT_FALSE(mixer->MixabilityStatus(anonymous[kAnonymous - 1]));
165 }
166
167 TEST(AudioMixer, LargestEnergyVadActiveMixed) { 113 TEST(AudioMixer, LargestEnergyVadActiveMixed) {
168 constexpr int kAudioSources = 114 constexpr int kAudioSources =
169 AudioMixer::kMaximumAmountOfMixedAudioSources + 3; 115 AudioMixer::kMaximumAmountOfMixedAudioSources + 3;
170 116
171 const std::unique_ptr<AudioMixerImpl> mixer(AudioMixerImpl::Create(kId)); 117 const std::unique_ptr<AudioMixerImpl> mixer(AudioMixerImpl::Create());
172 118
173 MockMixerAudioSource participants[kAudioSources]; 119 MockMixerAudioSource participants[kAudioSources];
174 120
175 for (int i = 0; i < kAudioSources; ++i) { 121 for (int i = 0; i < kAudioSources; ++i) {
176 ResetFrame(participants[i].fake_frame()); 122 ResetFrame(participants[i].fake_frame());
177 123
178 // We set the 80-th sample value since the first 80 samples may be 124 // We set the 80-th sample value since the first 80 samples may be
179 // modified by a ramped-in window. 125 // modified by a ramped-in window.
180 participants[i].fake_frame()->data_[80] = i; 126 participants[i].fake_frame()->data_[80] = i;
181 127
182 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participants[i], true)); 128 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participants[i], true));
183 EXPECT_CALL(participants[i], GetAudioFrameWithMuted(_, _)) 129 EXPECT_CALL(participants[i], GetAudioFrameWithMuted(_)).Times(Exactly(1));
184 .Times(Exactly(1));
185 } 130 }
186 131
187 // Last participant gives audio frame with passive VAD, although it has the 132 // Last participant gives audio frame with passive VAD, although it has the
188 // largest energy. 133 // largest energy.
189 participants[kAudioSources - 1].fake_frame()->vad_activity_ = 134 participants[kAudioSources - 1].fake_frame()->vad_activity_ =
190 AudioFrame::kVadPassive; 135 AudioFrame::kVadPassive;
191 136
192 AudioFrame audio_frame; 137 AudioFrame audio_frame;
193 mixer->Mix(kDefaultSampleRateHz, 138 mixer->Mix(kDefaultSampleRateHz,
194 1, // number of channels 139 1, // number of channels
195 &audio_frame); 140 &audio_frame);
196 141
197 for (int i = 0; i < kAudioSources; ++i) { 142 for (int i = 0; i < kAudioSources; ++i) {
198 bool is_mixed = 143 bool is_mixed =
199 mixer->GetAudioSourceMixabilityStatusForTest(&participants[i]); 144 mixer->GetAudioSourceMixabilityStatusForTest(&participants[i]);
200 if (i == kAudioSources - 1 || 145 if (i == kAudioSources - 1 ||
201 i < kAudioSources - 1 - AudioMixer::kMaximumAmountOfMixedAudioSources) { 146 i < kAudioSources - 1 - AudioMixer::kMaximumAmountOfMixedAudioSources) {
202 EXPECT_FALSE(is_mixed) << "Mixing status of AudioSource #" << i 147 EXPECT_FALSE(is_mixed) << "Mixing status of AudioSource #" << i
203 << " wrong."; 148 << " wrong.";
204 } else { 149 } else {
205 EXPECT_TRUE(is_mixed) << "Mixing status of AudioSource #" << i 150 EXPECT_TRUE(is_mixed) << "Mixing status of AudioSource #" << i
206 << " wrong."; 151 << " wrong.";
207 } 152 }
208 } 153 }
209 } 154 }
210 155
211 TEST(AudioMixer, FrameNotModifiedForSingleParticipant) { 156 TEST(AudioMixer, FrameNotModifiedForSingleParticipant) {
212 const std::unique_ptr<AudioMixer> mixer(AudioMixer::Create(kId)); 157 const std::unique_ptr<AudioMixer> mixer(AudioMixer::Create());
213 158
214 MockMixerAudioSource participant; 159 MockMixerAudioSource participant;
215 160
216 ResetFrame(participant.fake_frame());
217 const int n_samples = participant.fake_frame()->samples_per_channel_;
218
219 // Modify the frame so that it's not zero.
220 for (int j = 0; j < n_samples; j++) {
221 participant.fake_frame()->data_[j] = j;
222 }
223
224 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participant, true));
225 EXPECT_CALL(participant, GetAudioFrameWithMuted(_, _)).Times(Exactly(2));
226
227 AudioFrame audio_frame;
228 // Two mix iteration to compare after the ramp-up step.
229 for (int i = 0; i < 2; i++) {
230 mixer->Mix(kDefaultSampleRateHz,
231 1, // number of channels
232 &audio_frame);
233 }
234
235 EXPECT_EQ(
236 0, memcmp(participant.fake_frame()->data_, audio_frame.data_, n_samples));
237 }
238
239 TEST(AudioMixer, FrameNotModifiedForSingleAnonymousParticipant) {
240 const std::unique_ptr<AudioMixer> mixer(AudioMixer::Create(kId));
241
242 MockMixerAudioSource participant;
243
244 ResetFrame(participant.fake_frame()); 161 ResetFrame(participant.fake_frame());
245 const int n_samples = participant.fake_frame()->samples_per_channel_; 162 const int n_samples = participant.fake_frame()->samples_per_channel_;
246 163
247 // Modify the frame so that it's not zero. 164 // Modify the frame so that it's not zero.
248 for (int j = 0; j < n_samples; j++) { 165 for (int j = 0; j < n_samples; j++) {
249 participant.fake_frame()->data_[j] = j; 166 participant.fake_frame()->data_[j] = j;
250 } 167 }
251 168
252 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participant, true)); 169 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participant, true));
253 EXPECT_EQ(0, mixer->SetAnonymousMixabilityStatus(&participant, true)); 170 EXPECT_CALL(participant, GetAudioFrameWithMuted(_)).Times(Exactly(2));
254 EXPECT_CALL(participant, GetAudioFrameWithMuted(_, _)).Times(Exactly(2));
255 171
256 AudioFrame audio_frame; 172 AudioFrame audio_frame;
257 // Two mix iteration to compare after the ramp-up step. 173 // Two mix iteration to compare after the ramp-up step.
258 for (int i = 0; i < 2; i++) { 174 for (int i = 0; i < 2; i++) {
259 mixer->Mix(kDefaultSampleRateHz, 175 mixer->Mix(kDefaultSampleRateHz,
260 1, // number of channels 176 1, // number of channels
261 &audio_frame); 177 &audio_frame);
262 } 178 }
263 179
264 EXPECT_EQ( 180 EXPECT_EQ(
265 0, memcmp(participant.fake_frame()->data_, audio_frame.data_, n_samples)); 181 0, memcmp(participant.fake_frame()->data_, audio_frame.data_, n_samples));
266 } 182 }
267 183
268 TEST(AudioMixer, ParticipantSampleRate) { 184 TEST(AudioMixer, ParticipantSampleRate) {
269 const std::unique_ptr<AudioMixer> mixer(AudioMixer::Create(kId)); 185 const std::unique_ptr<AudioMixer> mixer(AudioMixer::Create());
270 186
271 MockMixerAudioSource participant; 187 MockMixerAudioSource participant;
272 ResetFrame(participant.fake_frame()); 188 ResetFrame(participant.fake_frame());
273 189
274 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participant, true)); 190 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participant, true));
275 for (auto frequency : {8000, 16000, 32000, 48000}) { 191 for (auto frequency : {8000, 16000, 32000, 48000}) {
276 EXPECT_CALL(participant, GetAudioFrameWithMuted(_, frequency)) 192 EXPECT_CALL(participant, GetAudioFrameWithMuted(frequency))
277 .Times(Exactly(1)); 193 .Times(Exactly(1));
278 participant.fake_frame()->sample_rate_hz_ = frequency; 194 participant.fake_frame()->sample_rate_hz_ = frequency;
279 participant.fake_frame()->samples_per_channel_ = frequency / 100; 195 participant.fake_frame()->samples_per_channel_ = frequency / 100;
280 mixer->Mix(frequency, 1, &frame_for_mixing); 196 mixer->Mix(frequency, 1, &frame_for_mixing);
281 EXPECT_EQ(frequency, frame_for_mixing.sample_rate_hz_); 197 EXPECT_EQ(frequency, frame_for_mixing.sample_rate_hz_);
282 } 198 }
283 } 199 }
284 200
285 TEST(AudioMixer, ParticipantNumberOfChannels) { 201 TEST(AudioMixer, ParticipantNumberOfChannels) {
286 const std::unique_ptr<AudioMixer> mixer(AudioMixer::Create(kId)); 202 const std::unique_ptr<AudioMixer> mixer(AudioMixer::Create());
287 203
288 MockMixerAudioSource participant; 204 MockMixerAudioSource participant;
289 ResetFrame(participant.fake_frame()); 205 ResetFrame(participant.fake_frame());
290 206
291 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participant, true)); 207 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participant, true));
292 for (size_t number_of_channels : {1, 2}) { 208 for (size_t number_of_channels : {1, 2}) {
293 EXPECT_CALL(participant, GetAudioFrameWithMuted(_, kDefaultSampleRateHz)) 209 EXPECT_CALL(participant, GetAudioFrameWithMuted(kDefaultSampleRateHz))
294 .Times(Exactly(1)); 210 .Times(Exactly(1));
295 mixer->Mix(kDefaultSampleRateHz, number_of_channels, &frame_for_mixing); 211 mixer->Mix(kDefaultSampleRateHz, number_of_channels, &frame_for_mixing);
296 EXPECT_EQ(number_of_channels, frame_for_mixing.num_channels_); 212 EXPECT_EQ(number_of_channels, frame_for_mixing.num_channels_);
297 } 213 }
298 } 214 }
299 215
300 // Test that the volume is reported as zero when the mixer input
301 // comprises only zero values.
302 TEST(AudioMixer, LevelIsZeroWhenMixingZeroes) {
303 const std::unique_ptr<AudioMixer> mixer(AudioMixer::Create(kId));
304
305 MockMixerAudioSource participant;
306 ResetFrame(participant.fake_frame());
307
308 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participant, true));
309 for (int i = 0; i < 11; i++) {
310 EXPECT_CALL(participant, GetAudioFrameWithMuted(_, kDefaultSampleRateHz))
311 .Times(Exactly(1));
312 mixer->Mix(kDefaultSampleRateHz, 1, &frame_for_mixing);
313 }
314
315 EXPECT_EQ(0, mixer->GetOutputAudioLevel());
316 EXPECT_EQ(0, mixer->GetOutputAudioLevelFullRange());
317 }
318
319 // Test that the reported volume is maximal when the mixer
320 // input comprises frames with maximal values.
321 TEST(AudioMixer, LevelIsMaximalWhenMixingMaximalValues) {
322 const std::unique_ptr<AudioMixer> mixer(AudioMixer::Create(kId));
323
324 MockMixerAudioSource participant;
325 ResetFrame(participant.fake_frame());
326
327 // Fill participant frame data with maximal sound.
328 std::fill(participant.fake_frame()->data_,
329 participant.fake_frame()->data_ + kDefaultSampleRateHz / 100,
330 std::numeric_limits<int16_t>::max());
331
332 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participant, true));
333
334 // We do >10 iterations, because the audio level indicator only
335 // updates once every 10 calls.
336 for (int i = 0; i < 11; i++) {
337 EXPECT_CALL(participant, GetAudioFrameWithMuted(_, kDefaultSampleRateHz))
338 .Times(Exactly(1));
339 mixer->Mix(kDefaultSampleRateHz, 1, &frame_for_mixing);
340 }
341
342 // 9 is the highest possible audio level
343 EXPECT_EQ(9, mixer->GetOutputAudioLevel());
344
345 // 0x7fff = 32767 is the highest full range audio level.
346 EXPECT_EQ(std::numeric_limits<int16_t>::max(),
347 mixer->GetOutputAudioLevelFullRange());
348 }
349
350 // Maximal amount of participants are mixed one iteration, then 216 // Maximal amount of participants are mixed one iteration, then
351 // another participant with higher energy is added. 217 // another participant with higher energy is added.
352 TEST(AudioMixer, RampedOutSourcesShouldNotBeMarkedMixed) { 218 TEST(AudioMixer, RampedOutSourcesShouldNotBeMarkedMixed) {
353 constexpr int kAudioSources = 219 constexpr int kAudioSources =
354 AudioMixer::kMaximumAmountOfMixedAudioSources + 1; 220 AudioMixer::kMaximumAmountOfMixedAudioSources + 1;
355 221
356 const std::unique_ptr<AudioMixerImpl> mixer(AudioMixerImpl::Create(kId)); 222 const std::unique_ptr<AudioMixerImpl> mixer(AudioMixerImpl::Create());
357 MockMixerAudioSource participants[kAudioSources]; 223 MockMixerAudioSource participants[kAudioSources];
358 224
359 for (int i = 0; i < kAudioSources; i++) { 225 for (int i = 0; i < kAudioSources; i++) {
360 ResetFrame(participants[i].fake_frame()); 226 ResetFrame(participants[i].fake_frame());
361 // Set the participant audio energy to increase with the index 227 // Set the participant audio energy to increase with the index
362 // |i|. 228 // |i|.
363 participants[i].fake_frame()->data_[0] = 100 * i; 229 participants[i].fake_frame()->data_[0] = 100 * i;
364 } 230 }
365 231
366 // Add all participants but the loudest for mixing. 232 // Add all participants but the loudest for mixing.
367 for (int i = 0; i < kAudioSources - 1; i++) { 233 for (int i = 0; i < kAudioSources - 1; i++) {
368 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participants[i], true)); 234 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participants[i], true));
369 EXPECT_CALL(participants[i], 235 EXPECT_CALL(participants[i], GetAudioFrameWithMuted(kDefaultSampleRateHz))
370 GetAudioFrameWithMuted(_, kDefaultSampleRateHz))
371 .Times(Exactly(1)); 236 .Times(Exactly(1));
372 } 237 }
373 238
374 // First mixer iteration 239 // First mixer iteration
375 mixer->Mix(kDefaultSampleRateHz, 1, &frame_for_mixing); 240 mixer->Mix(kDefaultSampleRateHz, 1, &frame_for_mixing);
376 241
377 // All participants but the loudest should have been mixed. 242 // All participants but the loudest should have been mixed.
378 for (int i = 0; i < kAudioSources - 1; i++) { 243 for (int i = 0; i < kAudioSources - 1; i++) {
379 EXPECT_TRUE(mixer->GetAudioSourceMixabilityStatusForTest(&participants[i])) 244 EXPECT_TRUE(mixer->GetAudioSourceMixabilityStatusForTest(&participants[i]))
380 << "Mixed status of AudioSource #" << i << " wrong."; 245 << "Mixed status of AudioSource #" << i << " wrong.";
381 } 246 }
382 247
383 // Add new participant with higher energy. 248 // Add new participant with higher energy.
384 EXPECT_EQ(0, 249 EXPECT_EQ(0,
385 mixer->SetMixabilityStatus(&participants[kAudioSources - 1], true)); 250 mixer->SetMixabilityStatus(&participants[kAudioSources - 1], true));
386 for (int i = 0; i < kAudioSources; i++) { 251 for (int i = 0; i < kAudioSources; i++) {
387 EXPECT_CALL(participants[i], 252 EXPECT_CALL(participants[i], GetAudioFrameWithMuted(kDefaultSampleRateHz))
388 GetAudioFrameWithMuted(_, kDefaultSampleRateHz))
389 .Times(Exactly(1)); 253 .Times(Exactly(1));
390 } 254 }
391 255
392 mixer->Mix(kDefaultSampleRateHz, 1, &frame_for_mixing); 256 mixer->Mix(kDefaultSampleRateHz, 1, &frame_for_mixing);
393 257
394 // The most quiet participant should not have been mixed. 258 // The most quiet participant should not have been mixed.
395 EXPECT_FALSE(mixer->GetAudioSourceMixabilityStatusForTest(&participants[0])) 259 EXPECT_FALSE(mixer->GetAudioSourceMixabilityStatusForTest(&participants[0]))
396 << "Mixed status of AudioSource #0 wrong."; 260 << "Mixed status of AudioSource #0 wrong.";
397 261
398 // The loudest participants should have been mixed. 262 // The loudest participants should have been mixed.
399 for (int i = 1; i < kAudioSources; i++) { 263 for (int i = 1; i < kAudioSources; i++) {
400 EXPECT_EQ(true, 264 EXPECT_EQ(true,
401 mixer->GetAudioSourceMixabilityStatusForTest(&participants[i])) 265 mixer->GetAudioSourceMixabilityStatusForTest(&participants[i]))
402 << "Mixed status of AudioSource #" << i << " wrong."; 266 << "Mixed status of AudioSource #" << i << " wrong.";
403 } 267 }
404 } 268 }
405 269
406 // This test checks that the initialization and participant addition 270 // This test checks that the initialization and participant addition
407 // can be done on a different thread. 271 // can be done on a different thread.
408 TEST(AudioMixer, ConstructFromOtherThread) { 272 TEST(AudioMixer, ConstructFromOtherThread) {
409 std::unique_ptr<rtc::Thread> init_thread = rtc::Thread::Create(); 273 std::unique_ptr<rtc::Thread> init_thread = rtc::Thread::Create();
410 std::unique_ptr<rtc::Thread> participant_thread = rtc::Thread::Create(); 274 std::unique_ptr<rtc::Thread> participant_thread = rtc::Thread::Create();
411 init_thread->Start(); 275 init_thread->Start();
412 std::unique_ptr<AudioMixer> mixer( 276 std::unique_ptr<AudioMixer> mixer(
413 init_thread->Invoke<std::unique_ptr<AudioMixer>>( 277 init_thread->Invoke<std::unique_ptr<AudioMixer>>(
414 RTC_FROM_HERE, std::bind(&AudioMixer::Create, kId))); 278 RTC_FROM_HERE, &AudioMixer::Create));
415 MockMixerAudioSource participant; 279 MockMixerAudioSource participant;
416 280
417 ResetFrame(participant.fake_frame()); 281 ResetFrame(participant.fake_frame());
418 282
419 participant_thread->Start(); 283 participant_thread->Start();
420 EXPECT_EQ(0, participant_thread->Invoke<int>( 284 EXPECT_EQ(0, participant_thread->Invoke<int>(
421 RTC_FROM_HERE, rtc::Bind(&AudioMixer::SetMixabilityStatus, 285 RTC_FROM_HERE, rtc::Bind(&AudioMixer::SetMixabilityStatus,
422 mixer.get(), &participant, true))); 286 mixer.get(), &participant, true)));
423 287
424 EXPECT_EQ( 288 EXPECT_CALL(participant, GetAudioFrameWithMuted(kDefaultSampleRateHz))
425 0, participant_thread->Invoke<int>(
426 RTC_FROM_HERE, rtc::Bind(&AudioMixer::SetAnonymousMixabilityStatus,
427 mixer.get(), &participant, true)));
428
429 EXPECT_CALL(participant, GetAudioFrameWithMuted(_, kDefaultSampleRateHz))
430 .Times(Exactly(1)); 289 .Times(Exactly(1));
431 290
432 // Do one mixer iteration 291 // Do one mixer iteration
433 mixer->Mix(kDefaultSampleRateHz, 1, &frame_for_mixing); 292 mixer->Mix(kDefaultSampleRateHz, 1, &frame_for_mixing);
434 } 293 }
435 294
436 TEST(AudioMixer, MutedShouldMixAfterUnmuted) { 295 TEST(AudioMixer, MutedShouldMixAfterUnmuted) {
437 constexpr int kAudioSources = 296 constexpr int kAudioSources =
438 AudioMixer::kMaximumAmountOfMixedAudioSources + 1; 297 AudioMixer::kMaximumAmountOfMixedAudioSources + 1;
439 298
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 kAudioSources, AudioMixer::Source::AudioFrameInfo::kNormal); 361 kAudioSources, AudioMixer::Source::AudioFrameInfo::kNormal);
503 frame_info[0] = AudioMixer::Source::AudioFrameInfo::kMuted; 362 frame_info[0] = AudioMixer::Source::AudioFrameInfo::kMuted;
504 std::fill(frames[0].data_, frames[0].data_ + kDefaultSampleRateHz / 100, 363 std::fill(frames[0].data_, frames[0].data_ + kDefaultSampleRateHz / 100,
505 std::numeric_limits<int16_t>::max()); 364 std::numeric_limits<int16_t>::max());
506 std::vector<bool> expected_status(kAudioSources, true); 365 std::vector<bool> expected_status(kAudioSources, true);
507 expected_status[0] = false; 366 expected_status[0] = false;
508 367
509 MixAndCompare(frames, frame_info, expected_status); 368 MixAndCompare(frames, frame_info, expected_status);
510 } 369 }
511 } // namespace webrtc 370 } // namespace webrtc
OLDNEW
« webrtc/modules/audio_mixer/audio_mixer.h ('K') | « webrtc/modules/audio_mixer/audio_mixer_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698