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