OLD | NEW |
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 <memory> | 13 #include <memory> |
14 #include <utility> | 14 #include <utility> |
15 | 15 |
16 #include "webrtc/base/bind.h" | 16 #include "webrtc/base/bind.h" |
17 #include "webrtc/base/thread.h" | 17 #include "webrtc/base/thread.h" |
18 #include "webrtc/modules/audio_mixer/audio_mixer_impl.h" | 18 #include "webrtc/modules/audio_mixer/audio_mixer.h" |
19 #include "webrtc/modules/audio_mixer/audio_mixer_defines.h" | 19 #include "webrtc/modules/audio_mixer/audio_mixer_defines.h" |
20 #include "webrtc/test/gmock.h" | 20 #include "webrtc/test/gmock.h" |
21 | 21 |
22 using testing::_; | 22 using testing::_; |
23 using testing::Exactly; | 23 using testing::Exactly; |
24 using testing::Invoke; | 24 using testing::Invoke; |
25 using testing::Return; | 25 using testing::Return; |
26 | 26 |
27 namespace webrtc { | 27 namespace webrtc { |
28 | 28 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 // Creates participants from |frames| and |frame_info| and adds them | 82 // Creates participants from |frames| and |frame_info| and adds them |
83 // to the mixer. Compares mixed status with |expected_status| | 83 // to the mixer. Compares mixed status with |expected_status| |
84 void MixAndCompare( | 84 void MixAndCompare( |
85 const std::vector<AudioFrame>& frames, | 85 const std::vector<AudioFrame>& frames, |
86 const std::vector<MixerAudioSource::AudioFrameInfo>& frame_info, | 86 const std::vector<MixerAudioSource::AudioFrameInfo>& frame_info, |
87 const std::vector<bool>& expected_status) { | 87 const std::vector<bool>& expected_status) { |
88 int num_audio_sources = frames.size(); | 88 int num_audio_sources = frames.size(); |
89 RTC_DCHECK(frames.size() == frame_info.size()); | 89 RTC_DCHECK(frames.size() == frame_info.size()); |
90 RTC_DCHECK(frame_info.size() == expected_status.size()); | 90 RTC_DCHECK(frame_info.size() == expected_status.size()); |
91 | 91 |
92 const std::unique_ptr<AudioMixerImpl> mixer(AudioMixerImpl::Create(kId)); | 92 const std::unique_ptr<AudioMixer> mixer(AudioMixer::Create(kId)); |
93 std::vector<MockMixerAudioSource> participants(num_audio_sources); | 93 std::vector<MockMixerAudioSource> participants(num_audio_sources); |
94 | 94 |
95 for (int i = 0; i < num_audio_sources; i++) { | 95 for (int i = 0; i < num_audio_sources; i++) { |
96 participants[i].fake_frame()->CopyFrom(frames[i]); | 96 participants[i].fake_frame()->CopyFrom(frames[i]); |
97 participants[i].set_fake_info(frame_info[i]); | 97 participants[i].set_fake_info(frame_info[i]); |
98 } | 98 } |
99 | 99 |
100 for (int i = 0; i < num_audio_sources; i++) { | 100 for (int i = 0; i < num_audio_sources; i++) { |
101 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participants[i], true)); | 101 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participants[i], true)); |
102 EXPECT_CALL(participants[i], | 102 EXPECT_CALL(participants[i], |
103 GetAudioFrameWithMuted(_, kDefaultSampleRateHz)) | 103 GetAudioFrameWithMuted(_, kDefaultSampleRateHz)) |
104 .Times(Exactly(1)); | 104 .Times(Exactly(1)); |
105 } | 105 } |
106 | 106 |
107 mixer->Mix(kDefaultSampleRateHz, 1, &frame_for_mixing); | 107 mixer->Mix(kDefaultSampleRateHz, 1, &frame_for_mixing); |
108 | 108 |
109 for (int i = 0; i < num_audio_sources; i++) { | 109 for (int i = 0; i < num_audio_sources; i++) { |
110 EXPECT_EQ(expected_status[i], | 110 EXPECT_EQ(expected_status[i], participants[i].IsMixed()) |
111 mixer->GetAudioSourceMixabilityStatusForTest(&participants[i])) | |
112 << "Mixed status of AudioSource #" << i << " wrong."; | 111 << "Mixed status of AudioSource #" << i << " wrong."; |
113 } | 112 } |
114 } | 113 } |
115 | 114 |
116 TEST(AudioMixer, AnonymousAndNamed) { | 115 TEST(AudioMixer, AnonymousAndNamed) { |
117 // Should not matter even if partipants are more than | 116 // Should not matter even if partipants are more than |
118 // kMaximumAmountOfMixedAudioSources. | 117 // kMaximumAmountOfMixedAudioSources. |
119 constexpr int kNamed = AudioMixer::kMaximumAmountOfMixedAudioSources + 1; | 118 constexpr int kNamed = AudioMixer::kMaximumAmountOfMixedAudioSources + 1; |
120 constexpr int kAnonymous = AudioMixer::kMaximumAmountOfMixedAudioSources + 1; | 119 constexpr int kAnonymous = AudioMixer::kMaximumAmountOfMixedAudioSources + 1; |
121 | 120 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 // anonymous and named groups. | 160 // anonymous and named groups. |
162 EXPECT_EQ(0, mixer->SetMixabilityStatus(&anonymous[kAnonymous - 1], false)); | 161 EXPECT_EQ(0, mixer->SetMixabilityStatus(&anonymous[kAnonymous - 1], false)); |
163 EXPECT_FALSE(mixer->AnonymousMixabilityStatus(anonymous[kAnonymous - 1])); | 162 EXPECT_FALSE(mixer->AnonymousMixabilityStatus(anonymous[kAnonymous - 1])); |
164 EXPECT_FALSE(mixer->MixabilityStatus(anonymous[kAnonymous - 1])); | 163 EXPECT_FALSE(mixer->MixabilityStatus(anonymous[kAnonymous - 1])); |
165 } | 164 } |
166 | 165 |
167 TEST(AudioMixer, LargestEnergyVadActiveMixed) { | 166 TEST(AudioMixer, LargestEnergyVadActiveMixed) { |
168 constexpr int kAudioSources = | 167 constexpr int kAudioSources = |
169 AudioMixer::kMaximumAmountOfMixedAudioSources + 3; | 168 AudioMixer::kMaximumAmountOfMixedAudioSources + 3; |
170 | 169 |
171 const std::unique_ptr<AudioMixerImpl> mixer(AudioMixerImpl::Create(kId)); | 170 const std::unique_ptr<AudioMixer> mixer(AudioMixer::Create(kId)); |
172 | 171 |
173 MockMixerAudioSource participants[kAudioSources]; | 172 MockMixerAudioSource participants[kAudioSources]; |
174 | 173 |
175 for (int i = 0; i < kAudioSources; ++i) { | 174 for (int i = 0; i < kAudioSources; ++i) { |
176 ResetFrame(participants[i].fake_frame()); | 175 ResetFrame(participants[i].fake_frame()); |
177 | 176 |
178 // We set the 80-th sample value since the first 80 samples may be | 177 // We set the 80-th sample value since the first 80 samples may be |
179 // modified by a ramped-in window. | 178 // modified by a ramped-in window. |
180 participants[i].fake_frame()->data_[80] = i; | 179 participants[i].fake_frame()->data_[80] = i; |
181 | 180 |
182 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participants[i], true)); | 181 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participants[i], true)); |
183 EXPECT_CALL(participants[i], GetAudioFrameWithMuted(_, _)) | 182 EXPECT_CALL(participants[i], GetAudioFrameWithMuted(_, _)) |
184 .Times(Exactly(1)); | 183 .Times(Exactly(1)); |
185 } | 184 } |
186 | 185 |
187 // Last participant gives audio frame with passive VAD, although it has the | 186 // Last participant gives audio frame with passive VAD, although it has the |
188 // largest energy. | 187 // largest energy. |
189 participants[kAudioSources - 1].fake_frame()->vad_activity_ = | 188 participants[kAudioSources - 1].fake_frame()->vad_activity_ = |
190 AudioFrame::kVadPassive; | 189 AudioFrame::kVadPassive; |
191 | 190 |
192 AudioFrame audio_frame; | 191 AudioFrame audio_frame; |
193 mixer->Mix(kDefaultSampleRateHz, | 192 mixer->Mix(kDefaultSampleRateHz, |
194 1, // number of channels | 193 1, // number of channels |
195 &audio_frame); | 194 &audio_frame); |
196 | 195 |
197 for (int i = 0; i < kAudioSources; ++i) { | 196 for (int i = 0; i < kAudioSources; ++i) { |
198 bool is_mixed = | 197 bool is_mixed = participants[i].IsMixed(); |
199 mixer->GetAudioSourceMixabilityStatusForTest(&participants[i]); | |
200 if (i == kAudioSources - 1 || | 198 if (i == kAudioSources - 1 || |
201 i < kAudioSources - 1 - AudioMixer::kMaximumAmountOfMixedAudioSources) { | 199 i < kAudioSources - 1 - AudioMixer::kMaximumAmountOfMixedAudioSources) { |
202 EXPECT_FALSE(is_mixed) << "Mixing status of AudioSource #" << i | 200 EXPECT_FALSE(is_mixed) << "Mixing status of AudioSource #" << i |
203 << " wrong."; | 201 << " wrong."; |
204 } else { | 202 } else { |
205 EXPECT_TRUE(is_mixed) << "Mixing status of AudioSource #" << i | 203 EXPECT_TRUE(is_mixed) << "Mixing status of AudioSource #" << i |
206 << " wrong."; | 204 << " wrong."; |
207 } | 205 } |
208 } | 206 } |
209 } | 207 } |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 EXPECT_EQ(std::numeric_limits<int16_t>::max(), | 344 EXPECT_EQ(std::numeric_limits<int16_t>::max(), |
347 mixer->GetOutputAudioLevelFullRange()); | 345 mixer->GetOutputAudioLevelFullRange()); |
348 } | 346 } |
349 | 347 |
350 // Maximal amount of participants are mixed one iteration, then | 348 // Maximal amount of participants are mixed one iteration, then |
351 // another participant with higher energy is added. | 349 // another participant with higher energy is added. |
352 TEST(AudioMixer, RampedOutSourcesShouldNotBeMarkedMixed) { | 350 TEST(AudioMixer, RampedOutSourcesShouldNotBeMarkedMixed) { |
353 constexpr int kAudioSources = | 351 constexpr int kAudioSources = |
354 AudioMixer::kMaximumAmountOfMixedAudioSources + 1; | 352 AudioMixer::kMaximumAmountOfMixedAudioSources + 1; |
355 | 353 |
356 const std::unique_ptr<AudioMixerImpl> mixer(AudioMixerImpl::Create(kId)); | 354 const std::unique_ptr<AudioMixer> mixer(AudioMixer::Create(kId)); |
357 MockMixerAudioSource participants[kAudioSources]; | 355 MockMixerAudioSource participants[kAudioSources]; |
358 | 356 |
359 for (int i = 0; i < kAudioSources; i++) { | 357 for (int i = 0; i < kAudioSources; i++) { |
360 ResetFrame(participants[i].fake_frame()); | 358 ResetFrame(participants[i].fake_frame()); |
361 // Set the participant audio energy to increase with the index | 359 // Set the participant audio energy to increase with the index |
362 // |i|. | 360 // |i|. |
363 participants[i].fake_frame()->data_[0] = 100 * i; | 361 participants[i].fake_frame()->data_[0] = 100 * i; |
364 } | 362 } |
365 | 363 |
366 // Add all participants but the loudest for mixing. | 364 // Add all participants but the loudest for mixing. |
367 for (int i = 0; i < kAudioSources - 1; i++) { | 365 for (int i = 0; i < kAudioSources - 1; i++) { |
368 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participants[i], true)); | 366 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participants[i], true)); |
369 EXPECT_CALL(participants[i], | 367 EXPECT_CALL(participants[i], |
370 GetAudioFrameWithMuted(_, kDefaultSampleRateHz)) | 368 GetAudioFrameWithMuted(_, kDefaultSampleRateHz)) |
371 .Times(Exactly(1)); | 369 .Times(Exactly(1)); |
372 } | 370 } |
373 | 371 |
374 // First mixer iteration | 372 // First mixer iteration |
375 mixer->Mix(kDefaultSampleRateHz, 1, &frame_for_mixing); | 373 mixer->Mix(kDefaultSampleRateHz, 1, &frame_for_mixing); |
376 | 374 |
377 // All participants but the loudest should have been mixed. | 375 // All participants but the loudest should have been mixed. |
378 for (int i = 0; i < kAudioSources - 1; i++) { | 376 for (int i = 0; i < kAudioSources - 1; i++) { |
379 EXPECT_TRUE(mixer->GetAudioSourceMixabilityStatusForTest(&participants[i])) | 377 EXPECT_TRUE(participants[i].IsMixed()) << "Mixed status of AudioSource #" |
380 << "Mixed status of AudioSource #" << i << " wrong."; | 378 << i << " wrong."; |
381 } | 379 } |
382 | 380 |
383 // Add new participant with higher energy. | 381 // Add new participant with higher energy. |
384 EXPECT_EQ(0, | 382 EXPECT_EQ(0, |
385 mixer->SetMixabilityStatus(&participants[kAudioSources - 1], true)); | 383 mixer->SetMixabilityStatus(&participants[kAudioSources - 1], true)); |
386 for (int i = 0; i < kAudioSources; i++) { | 384 for (int i = 0; i < kAudioSources; i++) { |
387 EXPECT_CALL(participants[i], | 385 EXPECT_CALL(participants[i], |
388 GetAudioFrameWithMuted(_, kDefaultSampleRateHz)) | 386 GetAudioFrameWithMuted(_, kDefaultSampleRateHz)) |
389 .Times(Exactly(1)); | 387 .Times(Exactly(1)); |
390 } | 388 } |
391 | 389 |
392 mixer->Mix(kDefaultSampleRateHz, 1, &frame_for_mixing); | 390 mixer->Mix(kDefaultSampleRateHz, 1, &frame_for_mixing); |
393 | 391 |
394 // The most quiet participant should not have been mixed. | 392 // The most quiet participant should not have been mixed. |
395 EXPECT_FALSE(mixer->GetAudioSourceMixabilityStatusForTest(&participants[0])) | 393 EXPECT_FALSE(participants[0].IsMixed()) |
396 << "Mixed status of AudioSource #0 wrong."; | 394 << "Mixed status of AudioSource #0 wrong."; |
397 | 395 |
398 // The loudest participants should have been mixed. | 396 // The loudest participants should have been mixed. |
399 for (int i = 1; i < kAudioSources; i++) { | 397 for (int i = 1; i < kAudioSources; i++) { |
400 EXPECT_EQ(true, | 398 EXPECT_EQ(true, participants[i].IsMixed()) |
401 mixer->GetAudioSourceMixabilityStatusForTest(&participants[i])) | |
402 << "Mixed status of AudioSource #" << i << " wrong."; | 399 << "Mixed status of AudioSource #" << i << " wrong."; |
403 } | 400 } |
404 } | 401 } |
405 | 402 |
406 // This test checks that the initialization and participant addition | 403 // This test checks that the initialization and participant addition |
407 // can be done on a different thread. | 404 // can be done on a different thread. |
408 TEST(AudioMixer, ConstructFromOtherThread) { | 405 TEST(AudioMixer, ConstructFromOtherThread) { |
409 std::unique_ptr<rtc::Thread> init_thread = rtc::Thread::Create(); | 406 std::unique_ptr<rtc::Thread> init_thread = rtc::Thread::Create(); |
410 std::unique_ptr<rtc::Thread> participant_thread = rtc::Thread::Create(); | 407 std::unique_ptr<rtc::Thread> participant_thread = rtc::Thread::Create(); |
411 init_thread->Start(); | 408 init_thread->Start(); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 kAudioSources, MixerAudioSource::AudioFrameInfo::kNormal); | 499 kAudioSources, MixerAudioSource::AudioFrameInfo::kNormal); |
503 frame_info[0] = MixerAudioSource::AudioFrameInfo::kMuted; | 500 frame_info[0] = MixerAudioSource::AudioFrameInfo::kMuted; |
504 std::fill(frames[0].data_, frames[0].data_ + kDefaultSampleRateHz / 100, | 501 std::fill(frames[0].data_, frames[0].data_ + kDefaultSampleRateHz / 100, |
505 std::numeric_limits<int16_t>::max()); | 502 std::numeric_limits<int16_t>::max()); |
506 std::vector<bool> expected_status(kAudioSources, true); | 503 std::vector<bool> expected_status(kAudioSources, true); |
507 expected_status[0] = false; | 504 expected_status[0] = false; |
508 | 505 |
509 MixAndCompare(frames, frame_info, expected_status); | 506 MixAndCompare(frames, frame_info, expected_status); |
510 } | 507 } |
511 } // namespace webrtc | 508 } // namespace webrtc |
OLD | NEW |