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 <memory> | 11 #include <memory> |
12 | 12 |
13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
14 | 14 |
15 #include "webrtc/modules/audio_conference_mixer/source/audio_frame_manipulator.h
" | 15 #include "webrtc/modules/audio_conference_mixer/source/audio_frame_manipulator.h
" |
16 #include "webrtc/modules/audio_mixer/audio_mixer.h" | 16 #include "webrtc/modules/audio_mixer/audio_mixer.h" |
17 #include "webrtc/modules/audio_mixer/include/audio_mixer_defines.h" | 17 #include "webrtc/modules/audio_mixer/include/audio_mixer_defines.h" |
18 #include "webrtc/modules/audio_mixer/include/new_audio_conference_mixer.h" | 18 #include "webrtc/modules/audio_mixer/include/new_audio_conference_mixer.h" |
19 #include "webrtc/modules/audio_mixer/source/new_audio_conference_mixer_impl.h" | 19 #include "webrtc/modules/audio_mixer/source/new_audio_conference_mixer_impl.h" |
20 | 20 |
21 using testing::_; | 21 using testing::_; |
22 using testing::AtLeast; | 22 using testing::Exactly; |
23 using testing::Invoke; | 23 using testing::Invoke; |
24 using testing::Return; | 24 using testing::Return; |
25 | 25 |
26 using webrtc::voe::AudioMixer; | 26 using webrtc::voe::AudioMixer; |
27 | 27 |
28 namespace webrtc { | 28 namespace webrtc { |
29 class MockMixerAudioSource : public MixerAudioSource { | 29 class MockMixerAudioSource : public MixerAudioSource { |
30 public: | 30 public: |
31 MockMixerAudioSource() { | 31 MockMixerAudioSource() { |
32 ON_CALL(*this, GetAudioFrame(_, _)) | 32 ON_CALL(*this, GetAudioFrameWithMuted(_, _)) |
33 .WillByDefault(Invoke(this, &MockMixerAudioSource::FakeAudioFrame)); | 33 .WillByDefault( |
| 34 Invoke(this, &MockMixerAudioSource::FakeAudioFrameWithMuted)); |
34 } | 35 } |
35 MOCK_METHOD2(GetAudioFrame, | 36 MOCK_METHOD2(GetAudioFrameWithMuted, |
36 int32_t(const int32_t id, AudioFrame* audio_frame)); | 37 AudioFrameWithInfo(const int32_t id, int sample_rate_hz)); |
37 MOCK_CONST_METHOD1(NeededFrequency, int32_t(const int32_t id)); | 38 MOCK_CONST_METHOD1(NeededFrequency, int32_t(const int32_t id)); |
| 39 |
38 AudioFrame* fake_frame() { return &fake_frame_; } | 40 AudioFrame* fake_frame() { return &fake_frame_; } |
39 | 41 |
40 private: | 42 private: |
41 AudioFrame fake_frame_; | 43 AudioFrame fake_frame_; |
42 int32_t FakeAudioFrame(const int32_t id, AudioFrame* audio_frame) { | 44 AudioFrameWithInfo FakeAudioFrameWithMuted(const int32_t id, |
43 audio_frame->CopyFrom(fake_frame_); | 45 int sample_rate_hz) { |
44 return 0; | 46 return { |
| 47 fake_frame(), // audio_frame_pointer |
| 48 AudioFrameInfo::kNormal, // audio_frame_info |
| 49 }; |
45 } | 50 } |
46 }; | 51 }; |
47 | 52 |
48 class BothMixersTest : public testing::Test { | 53 class BothMixersTest : public testing::Test { |
49 protected: | 54 protected: |
50 BothMixersTest() { | 55 BothMixersTest() { |
51 // Create an OutputMixer. | 56 // Create an OutputMixer. |
52 AudioMixer::Create(audio_mixer_, kId); | 57 AudioMixer::Create(audio_mixer_, kId); |
53 | 58 |
54 // Create one mixer participant and add it to the mixer. | 59 // Create one mixer participant and add it to the mixer. |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 participants[i].fake_frame()->num_channels_ = 1; | 166 participants[i].fake_frame()->num_channels_ = 1; |
162 | 167 |
163 // Frame duration 10ms. | 168 // Frame duration 10ms. |
164 participants[i].fake_frame()->samples_per_channel_ = kSampleRateHz / 100; | 169 participants[i].fake_frame()->samples_per_channel_ = kSampleRateHz / 100; |
165 | 170 |
166 // We set the 80-th sample value since the first 80 samples may be | 171 // We set the 80-th sample value since the first 80 samples may be |
167 // modified by a ramped-in window. | 172 // modified by a ramped-in window. |
168 participants[i].fake_frame()->data_[80] = i; | 173 participants[i].fake_frame()->data_[80] = i; |
169 | 174 |
170 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participants[i], true)); | 175 EXPECT_EQ(0, mixer->SetMixabilityStatus(&participants[i], true)); |
171 EXPECT_CALL(participants[i], GetAudioFrame(_, _)).Times(AtLeast(1)); | 176 EXPECT_CALL(participants[i], GetAudioFrameWithMuted(_, _)) |
| 177 .Times(Exactly(1)); |
172 EXPECT_CALL(participants[i], NeededFrequency(_)) | 178 EXPECT_CALL(participants[i], NeededFrequency(_)) |
173 .WillRepeatedly(Return(kSampleRateHz)); | 179 .WillRepeatedly(Return(kSampleRateHz)); |
174 } | 180 } |
175 | 181 |
176 // Last participant gives audio frame with passive VAD, although it has the | 182 // Last participant gives audio frame with passive VAD, although it has the |
177 // largest energy. | 183 // largest energy. |
178 participants[kAudioSources - 1].fake_frame()->vad_activity_ = | 184 participants[kAudioSources - 1].fake_frame()->vad_activity_ = |
179 AudioFrame::kVadPassive; | 185 AudioFrame::kVadPassive; |
180 | 186 |
181 AudioFrame audio_frame; | 187 AudioFrame audio_frame; |
182 mixer->Mix(&audio_frame); | 188 mixer->Mix(&audio_frame); |
183 | 189 |
184 for (int i = 0; i < kAudioSources; ++i) { | 190 for (int i = 0; i < kAudioSources; ++i) { |
185 bool is_mixed = participants[i].IsMixed(); | 191 bool is_mixed = participants[i].IsMixed(); |
186 if (i == kAudioSources - 1 || | 192 if (i == kAudioSources - 1 || |
187 i < kAudioSources - 1 - | 193 i < kAudioSources - 1 - |
188 NewAudioConferenceMixer::kMaximumAmountOfMixedAudioSources) { | 194 NewAudioConferenceMixer::kMaximumAmountOfMixedAudioSources) { |
189 EXPECT_FALSE(is_mixed) << "Mixing status of AudioSource #" << i | 195 EXPECT_FALSE(is_mixed) << "Mixing status of AudioSource #" << i |
190 << " wrong."; | 196 << " wrong."; |
191 } else { | 197 } else { |
192 EXPECT_TRUE(is_mixed) << "Mixing status of AudioSource #" << i | 198 EXPECT_TRUE(is_mixed) << "Mixing status of AudioSource #" << i |
193 << " wrong."; | 199 << " wrong."; |
194 } | 200 } |
195 } | 201 } |
196 } | 202 } |
197 | 203 |
198 TEST_F(BothMixersTest, CompareInitialFrameAudio) { | 204 TEST_F(BothMixersTest, CompareInitialFrameAudio) { |
199 EXPECT_CALL(participant_, GetAudioFrame(_, _)).Times(AtLeast(1)); | 205 EXPECT_CALL(participant_, GetAudioFrameWithMuted(_, _)).Times(Exactly(1)); |
200 | 206 |
201 // Make sure the participant is marked as 'non-mixed' so that it is | 207 // Make sure the participant is marked as 'non-mixed' so that it is |
202 // ramped in next round. | 208 // ramped in next round. |
203 ResetAudioSource(); | 209 ResetAudioSource(); |
204 | 210 |
205 // Construct the expected sound for the first mixing round. | 211 // Construct the expected sound for the first mixing round. |
206 mixing_round_frame.CopyFrom(*participant_.fake_frame()); | 212 mixing_round_frame.CopyFrom(*participant_.fake_frame()); |
207 RampIn(mixing_round_frame); | 213 RampIn(mixing_round_frame); |
208 | 214 |
209 // Mix frames and put the result into a frame. | 215 // Mix frames and put the result into a frame. |
210 audio_mixer_->MixActiveChannels(); | 216 audio_mixer_->MixActiveChannels(); |
211 audio_mixer_->GetMixedAudio(kSampleRateHz, 1, &mixed_results_frame_); | 217 audio_mixer_->GetMixedAudio(kSampleRateHz, 1, &mixed_results_frame_); |
212 | 218 |
213 // Compare the received frame with the expected. | 219 // Compare the received frame with the expected. |
214 EXPECT_EQ(mixing_round_frame.sample_rate_hz_, | 220 EXPECT_EQ(mixing_round_frame.sample_rate_hz_, |
215 mixed_results_frame_.sample_rate_hz_); | 221 mixed_results_frame_.sample_rate_hz_); |
216 EXPECT_EQ(mixing_round_frame.num_channels_, | 222 EXPECT_EQ(mixing_round_frame.num_channels_, |
217 mixed_results_frame_.num_channels_); | 223 mixed_results_frame_.num_channels_); |
218 EXPECT_EQ(mixing_round_frame.samples_per_channel_, | 224 EXPECT_EQ(mixing_round_frame.samples_per_channel_, |
219 mixed_results_frame_.samples_per_channel_); | 225 mixed_results_frame_.samples_per_channel_); |
220 EXPECT_EQ(0, memcmp(mixing_round_frame.data_, mixed_results_frame_.data_, | 226 EXPECT_EQ(0, memcmp(mixing_round_frame.data_, mixed_results_frame_.data_, |
221 sizeof(mixing_round_frame.data_))); | 227 sizeof(mixing_round_frame.data_))); |
222 } | 228 } |
223 | 229 |
224 TEST_F(BothMixersTest, CompareSecondFrameAudio) { | 230 TEST_F(BothMixersTest, CompareSecondFrameAudio) { |
225 EXPECT_CALL(participant_, GetAudioFrame(_, _)).Times(AtLeast(1)); | 231 EXPECT_CALL(participant_, GetAudioFrameWithMuted(_, _)).Times(Exactly(2)); |
226 | 232 |
227 // Make sure the participant is marked as 'non-mixed' so that it is | 233 // Make sure the participant is marked as 'non-mixed' so that it is |
228 // ramped in next round. | 234 // ramped in next round. |
229 ResetAudioSource(); | 235 ResetAudioSource(); |
230 | 236 |
231 // Do one mixing iteration. | 237 // Do one mixing iteration. |
232 audio_mixer_->MixActiveChannels(); | 238 audio_mixer_->MixActiveChannels(); |
233 | 239 |
234 // Mix frames a second time and compare with the expected frame | 240 // Mix frames a second time and compare with the expected frame |
235 // (which is the participant's frame). | 241 // (which is the participant's frame). |
236 audio_mixer_->MixActiveChannels(); | 242 audio_mixer_->MixActiveChannels(); |
237 audio_mixer_->GetMixedAudio(kSampleRateHz, 1, &mixed_results_frame_); | 243 audio_mixer_->GetMixedAudio(kSampleRateHz, 1, &mixed_results_frame_); |
238 EXPECT_EQ(0, | 244 EXPECT_EQ(0, |
239 memcmp(participant_.fake_frame()->data_, mixed_results_frame_.data_, | 245 memcmp(participant_.fake_frame()->data_, mixed_results_frame_.data_, |
240 sizeof(mixing_round_frame.data_))); | 246 sizeof(mixing_round_frame.data_))); |
241 } | 247 } |
242 | 248 |
243 } // namespace webrtc | 249 } // namespace webrtc |
OLD | NEW |