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

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

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