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> |
| 12 |
11 #include <memory> | 13 #include <memory> |
12 #include <utility> | 14 #include <utility> |
13 | 15 |
14 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "webrtc/modules/audio_mixer/audio_mixer_defines.h" | 17 #include "webrtc/modules/audio_mixer/audio_mixer_defines.h" |
16 #include "webrtc/modules/audio_mixer/audio_mixer.h" | 18 #include "webrtc/modules/audio_mixer/audio_mixer.h" |
17 | 19 |
18 using testing::_; | 20 using testing::_; |
19 using testing::Exactly; | 21 using testing::Exactly; |
20 using testing::Invoke; | 22 using testing::Invoke; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 for (int i = 0; i < num_audio_sources; i++) { | 98 for (int i = 0; i < num_audio_sources; i++) { |
97 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participants[i], true)); | 99 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participants[i], true)); |
98 EXPECT_CALL(participants[i], | 100 EXPECT_CALL(participants[i], |
99 GetAudioFrameWithMuted(_, kDefaultSampleRateHz)) | 101 GetAudioFrameWithMuted(_, kDefaultSampleRateHz)) |
100 .Times(Exactly(1)); | 102 .Times(Exactly(1)); |
101 } | 103 } |
102 | 104 |
103 mixer->Mix(kDefaultSampleRateHz, 1, &frame_for_mixing); | 105 mixer->Mix(kDefaultSampleRateHz, 1, &frame_for_mixing); |
104 | 106 |
105 for (int i = 0; i < num_audio_sources; i++) { | 107 for (int i = 0; i < num_audio_sources; i++) { |
106 EXPECT_EQ(participants[i].IsMixed(), expected_status[i]) | 108 EXPECT_EQ(expected_status[i], participants[i].IsMixed()) |
107 << "Mixed status of AudioSource #" << i << " wrong."; | 109 << "Mixed status of AudioSource #" << i << " wrong."; |
108 } | 110 } |
109 } | 111 } |
110 | 112 |
111 TEST(AudioMixer, AnonymousAndNamed) { | 113 TEST(AudioMixer, AnonymousAndNamed) { |
112 // Should not matter even if partipants are more than | 114 // Should not matter even if partipants are more than |
113 // kMaximumAmountOfMixedAudioSources. | 115 // kMaximumAmountOfMixedAudioSources. |
114 constexpr int kNamed = AudioMixer::kMaximumAmountOfMixedAudioSources + 1; | 116 constexpr int kNamed = AudioMixer::kMaximumAmountOfMixedAudioSources + 1; |
115 constexpr int kAnonymous = AudioMixer::kMaximumAmountOfMixedAudioSources + 1; | 117 constexpr int kAnonymous = AudioMixer::kMaximumAmountOfMixedAudioSources + 1; |
116 | 118 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 i < kAudioSources - 1 - AudioMixer::kMaximumAmountOfMixedAudioSources) { | 197 i < kAudioSources - 1 - AudioMixer::kMaximumAmountOfMixedAudioSources) { |
196 EXPECT_FALSE(is_mixed) << "Mixing status of AudioSource #" << i | 198 EXPECT_FALSE(is_mixed) << "Mixing status of AudioSource #" << i |
197 << " wrong."; | 199 << " wrong."; |
198 } else { | 200 } else { |
199 EXPECT_TRUE(is_mixed) << "Mixing status of AudioSource #" << i | 201 EXPECT_TRUE(is_mixed) << "Mixing status of AudioSource #" << i |
200 << " wrong."; | 202 << " wrong."; |
201 } | 203 } |
202 } | 204 } |
203 } | 205 } |
204 | 206 |
| 207 TEST(AudioMixer, FrameNotModifiedForSingleParticipant) { |
| 208 const std::unique_ptr<AudioMixer> mixer(AudioMixer::Create(kId)); |
| 209 |
| 210 MockMixerAudioSource participant; |
| 211 |
| 212 ResetFrame(participant.fake_frame()); |
| 213 const int n_samples = participant.fake_frame()->samples_per_channel_; |
| 214 |
| 215 // Modify the frame so that it's not zero. |
| 216 for (int j = 0; j < n_samples; j++) { |
| 217 participant.fake_frame()->data_[j] = j; |
| 218 } |
| 219 |
| 220 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participant, true)); |
| 221 EXPECT_CALL(participant, GetAudioFrameWithMuted(_, _)).Times(Exactly(2)); |
| 222 |
| 223 AudioFrame audio_frame; |
| 224 // Two mix iteration to compare after the ramp-up step. |
| 225 for (int i = 0; i < 2; i++) { |
| 226 mixer->Mix(kDefaultSampleRateHz, |
| 227 1, // number of channels |
| 228 &audio_frame); |
| 229 } |
| 230 |
| 231 EXPECT_EQ( |
| 232 0, memcmp(participant.fake_frame()->data_, audio_frame.data_, n_samples)); |
| 233 } |
| 234 |
| 235 TEST(AudioMixer, FrameNotModifiedForSingleAnonymousParticipant) { |
| 236 const std::unique_ptr<AudioMixer> mixer(AudioMixer::Create(kId)); |
| 237 |
| 238 MockMixerAudioSource participant; |
| 239 |
| 240 ResetFrame(participant.fake_frame()); |
| 241 const int n_samples = participant.fake_frame()->samples_per_channel_; |
| 242 |
| 243 // Modify the frame so that it's not zero. |
| 244 for (int j = 0; j < n_samples; j++) { |
| 245 participant.fake_frame()->data_[j] = j; |
| 246 } |
| 247 |
| 248 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participant, true)); |
| 249 EXPECT_EQ(0, mixer->SetAnonymousMixabilityStatus(&participant, true)); |
| 250 EXPECT_CALL(participant, GetAudioFrameWithMuted(_, _)).Times(Exactly(2)); |
| 251 |
| 252 AudioFrame audio_frame; |
| 253 // Two mix iteration to compare after the ramp-up step. |
| 254 for (int i = 0; i < 2; i++) { |
| 255 mixer->Mix(kDefaultSampleRateHz, |
| 256 1, // number of channels |
| 257 &audio_frame); |
| 258 } |
| 259 |
| 260 EXPECT_EQ( |
| 261 0, memcmp(participant.fake_frame()->data_, audio_frame.data_, n_samples)); |
| 262 } |
| 263 |
205 TEST(AudioMixer, ParticipantSampleRate) { | 264 TEST(AudioMixer, ParticipantSampleRate) { |
206 const std::unique_ptr<AudioMixer> mixer(AudioMixer::Create(kId)); | 265 const std::unique_ptr<AudioMixer> mixer(AudioMixer::Create(kId)); |
207 | 266 |
208 MockMixerAudioSource participant; | 267 MockMixerAudioSource participant; |
209 ResetFrame(participant.fake_frame()); | 268 ResetFrame(participant.fake_frame()); |
210 | 269 |
211 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participant, true)); | 270 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participant, true)); |
212 for (auto frequency : {8000, 16000, 32000, 48000}) { | 271 for (auto frequency : {8000, 16000, 32000, 48000}) { |
213 EXPECT_CALL(participant, GetAudioFrameWithMuted(_, frequency)) | 272 EXPECT_CALL(participant, GetAudioFrameWithMuted(_, frequency)) |
214 .Times(Exactly(1)); | 273 .Times(Exactly(1)); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 } | 384 } |
326 | 385 |
327 mixer->Mix(kDefaultSampleRateHz, 1, &frame_for_mixing); | 386 mixer->Mix(kDefaultSampleRateHz, 1, &frame_for_mixing); |
328 | 387 |
329 // The most quiet participant should not have been mixed. | 388 // The most quiet participant should not have been mixed. |
330 EXPECT_FALSE(participants[0].IsMixed()) | 389 EXPECT_FALSE(participants[0].IsMixed()) |
331 << "Mixed status of AudioSource #0 wrong."; | 390 << "Mixed status of AudioSource #0 wrong."; |
332 | 391 |
333 // The loudest participants should have been mixed. | 392 // The loudest participants should have been mixed. |
334 for (int i = 1; i < kAudioSources; i++) { | 393 for (int i = 1; i < kAudioSources; i++) { |
335 EXPECT_EQ(participants[i].IsMixed(), true) | 394 EXPECT_EQ(true, participants[i].IsMixed()) |
336 << "Mixed status of AudioSource #" << i << " wrong."; | 395 << "Mixed status of AudioSource #" << i << " wrong."; |
337 } | 396 } |
338 } | 397 } |
339 | 398 |
340 TEST(AudioMixer, MutedShouldMixAfterUnmuted) { | 399 TEST(AudioMixer, MutedShouldMixAfterUnmuted) { |
341 constexpr int kAudioSources = | 400 constexpr int kAudioSources = |
342 AudioMixer::kMaximumAmountOfMixedAudioSources + 1; | 401 AudioMixer::kMaximumAmountOfMixedAudioSources + 1; |
343 | 402 |
344 std::vector<AudioFrame> frames(kAudioSources); | 403 std::vector<AudioFrame> frames(kAudioSources); |
345 for (auto& frame : frames) { | 404 for (auto& frame : frames) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 kAudioSources, MixerAudioSource::AudioFrameInfo::kNormal); | 465 kAudioSources, MixerAudioSource::AudioFrameInfo::kNormal); |
407 frame_info[0] = MixerAudioSource::AudioFrameInfo::kMuted; | 466 frame_info[0] = MixerAudioSource::AudioFrameInfo::kMuted; |
408 std::fill(frames[0].data_, frames[0].data_ + kDefaultSampleRateHz / 100, | 467 std::fill(frames[0].data_, frames[0].data_ + kDefaultSampleRateHz / 100, |
409 std::numeric_limits<int16_t>::max()); | 468 std::numeric_limits<int16_t>::max()); |
410 std::vector<bool> expected_status(kAudioSources, true); | 469 std::vector<bool> expected_status(kAudioSources, true); |
411 expected_status[0] = false; | 470 expected_status[0] = false; |
412 | 471 |
413 MixAndCompare(frames, frame_info, expected_status); | 472 MixAndCompare(frames, frame_info, expected_status); |
414 } | 473 } |
415 } // namespace webrtc | 474 } // namespace webrtc |
OLD | NEW |