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_impl.h" |
19 #include "webrtc/modules/audio_mixer/audio_mixer_defines.h" | 19 #include "webrtc/modules/audio_mixer/audio_mixer.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 |
29 namespace { | 29 namespace { |
(...skipping 11 matching lines...) Expand all Loading... |
41 // Frame duration 10ms. | 41 // Frame duration 10ms. |
42 frame->samples_per_channel_ = kDefaultSampleRateHz / 100; | 42 frame->samples_per_channel_ = kDefaultSampleRateHz / 100; |
43 frame->vad_activity_ = AudioFrame::kVadActive; | 43 frame->vad_activity_ = AudioFrame::kVadActive; |
44 frame->speech_type_ = AudioFrame::kNormalSpeech; | 44 frame->speech_type_ = AudioFrame::kNormalSpeech; |
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 MixerAudioSource { | 51 class MockMixerAudioSource : public AudioMixer::Source { |
52 public: | 52 public: |
53 MockMixerAudioSource() | 53 MockMixerAudioSource() |
54 : fake_audio_frame_info_(MixerAudioSource::AudioFrameInfo::kNormal) { | 54 : fake_audio_frame_info_(AudioMixer::Source::AudioFrameInfo::kNormal) { |
55 ON_CALL(*this, GetAudioFrameWithMuted(_, _)) | 55 ON_CALL(*this, GetAudioFrameWithMuted(_, _)) |
56 .WillByDefault( | 56 .WillByDefault( |
57 Invoke(this, &MockMixerAudioSource::FakeAudioFrameWithMuted)); | 57 Invoke(this, &MockMixerAudioSource::FakeAudioFrameWithMuted)); |
58 } | 58 } |
59 | 59 |
60 MOCK_METHOD2(GetAudioFrameWithMuted, | 60 MOCK_METHOD2(GetAudioFrameWithMuted, |
61 AudioFrameWithMuted(const int32_t id, int sample_rate_hz)); | 61 AudioFrameWithMuted(const int32_t id, int sample_rate_hz)); |
62 | 62 |
63 AudioFrame* fake_frame() { return &fake_frame_; } | 63 AudioFrame* fake_frame() { return &fake_frame_; } |
64 AudioFrameInfo fake_info() { return fake_audio_frame_info_; } | 64 AudioFrameInfo fake_info() { return fake_audio_frame_info_; } |
(...skipping 11 matching lines...) Expand all Loading... |
76 &fake_output_frame_, // audio_frame_pointer | 76 &fake_output_frame_, // audio_frame_pointer |
77 fake_info(), // audio_frame_info | 77 fake_info(), // audio_frame_info |
78 }; | 78 }; |
79 } | 79 } |
80 }; | 80 }; |
81 | 81 |
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<AudioMixer::Source::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<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]); |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 | 435 |
436 TEST(AudioMixer, MutedShouldMixAfterUnmuted) { | 436 TEST(AudioMixer, MutedShouldMixAfterUnmuted) { |
437 constexpr int kAudioSources = | 437 constexpr int kAudioSources = |
438 AudioMixer::kMaximumAmountOfMixedAudioSources + 1; | 438 AudioMixer::kMaximumAmountOfMixedAudioSources + 1; |
439 | 439 |
440 std::vector<AudioFrame> frames(kAudioSources); | 440 std::vector<AudioFrame> frames(kAudioSources); |
441 for (auto& frame : frames) { | 441 for (auto& frame : frames) { |
442 ResetFrame(&frame); | 442 ResetFrame(&frame); |
443 } | 443 } |
444 | 444 |
445 std::vector<MixerAudioSource::AudioFrameInfo> frame_info( | 445 std::vector<AudioMixer::Source::AudioFrameInfo> frame_info( |
446 kAudioSources, MixerAudioSource::AudioFrameInfo::kNormal); | 446 kAudioSources, AudioMixer::Source::AudioFrameInfo::kNormal); |
447 frame_info[0] = MixerAudioSource::AudioFrameInfo::kMuted; | 447 frame_info[0] = AudioMixer::Source::AudioFrameInfo::kMuted; |
448 std::vector<bool> expected_status(kAudioSources, true); | 448 std::vector<bool> expected_status(kAudioSources, true); |
449 expected_status[0] = false; | 449 expected_status[0] = false; |
450 | 450 |
451 MixAndCompare(frames, frame_info, expected_status); | 451 MixAndCompare(frames, frame_info, expected_status); |
452 } | 452 } |
453 | 453 |
454 TEST(AudioMixer, PassiveShouldMixAfterNormal) { | 454 TEST(AudioMixer, PassiveShouldMixAfterNormal) { |
455 constexpr int kAudioSources = | 455 constexpr int kAudioSources = |
456 AudioMixer::kMaximumAmountOfMixedAudioSources + 1; | 456 AudioMixer::kMaximumAmountOfMixedAudioSources + 1; |
457 | 457 |
458 std::vector<AudioFrame> frames(kAudioSources); | 458 std::vector<AudioFrame> frames(kAudioSources); |
459 for (auto& frame : frames) { | 459 for (auto& frame : frames) { |
460 ResetFrame(&frame); | 460 ResetFrame(&frame); |
461 } | 461 } |
462 | 462 |
463 std::vector<MixerAudioSource::AudioFrameInfo> frame_info( | 463 std::vector<AudioMixer::Source::AudioFrameInfo> frame_info( |
464 kAudioSources, MixerAudioSource::AudioFrameInfo::kNormal); | 464 kAudioSources, AudioMixer::Source::AudioFrameInfo::kNormal); |
465 frames[0].vad_activity_ = AudioFrame::kVadPassive; | 465 frames[0].vad_activity_ = AudioFrame::kVadPassive; |
466 std::vector<bool> expected_status(kAudioSources, true); | 466 std::vector<bool> expected_status(kAudioSources, true); |
467 expected_status[0] = false; | 467 expected_status[0] = false; |
468 | 468 |
469 MixAndCompare(frames, frame_info, expected_status); | 469 MixAndCompare(frames, frame_info, expected_status); |
470 } | 470 } |
471 | 471 |
472 TEST(AudioMixer, ActiveShouldMixBeforeLoud) { | 472 TEST(AudioMixer, ActiveShouldMixBeforeLoud) { |
473 constexpr int kAudioSources = | 473 constexpr int kAudioSources = |
474 AudioMixer::kMaximumAmountOfMixedAudioSources + 1; | 474 AudioMixer::kMaximumAmountOfMixedAudioSources + 1; |
475 | 475 |
476 std::vector<AudioFrame> frames(kAudioSources); | 476 std::vector<AudioFrame> frames(kAudioSources); |
477 for (auto& frame : frames) { | 477 for (auto& frame : frames) { |
478 ResetFrame(&frame); | 478 ResetFrame(&frame); |
479 } | 479 } |
480 | 480 |
481 std::vector<MixerAudioSource::AudioFrameInfo> frame_info( | 481 std::vector<AudioMixer::Source::AudioFrameInfo> frame_info( |
482 kAudioSources, MixerAudioSource::AudioFrameInfo::kNormal); | 482 kAudioSources, AudioMixer::Source::AudioFrameInfo::kNormal); |
483 frames[0].vad_activity_ = AudioFrame::kVadPassive; | 483 frames[0].vad_activity_ = AudioFrame::kVadPassive; |
484 std::fill(frames[0].data_, frames[0].data_ + kDefaultSampleRateHz / 100, | 484 std::fill(frames[0].data_, frames[0].data_ + kDefaultSampleRateHz / 100, |
485 std::numeric_limits<int16_t>::max()); | 485 std::numeric_limits<int16_t>::max()); |
486 std::vector<bool> expected_status(kAudioSources, true); | 486 std::vector<bool> expected_status(kAudioSources, true); |
487 expected_status[0] = false; | 487 expected_status[0] = false; |
488 | 488 |
489 MixAndCompare(frames, frame_info, expected_status); | 489 MixAndCompare(frames, frame_info, expected_status); |
490 } | 490 } |
491 | 491 |
492 TEST(AudioMixer, UnmutedShouldMixBeforeLoud) { | 492 TEST(AudioMixer, UnmutedShouldMixBeforeLoud) { |
493 constexpr int kAudioSources = | 493 constexpr int kAudioSources = |
494 AudioMixer::kMaximumAmountOfMixedAudioSources + 1; | 494 AudioMixer::kMaximumAmountOfMixedAudioSources + 1; |
495 | 495 |
496 std::vector<AudioFrame> frames(kAudioSources); | 496 std::vector<AudioFrame> frames(kAudioSources); |
497 for (auto& frame : frames) { | 497 for (auto& frame : frames) { |
498 ResetFrame(&frame); | 498 ResetFrame(&frame); |
499 } | 499 } |
500 | 500 |
501 std::vector<MixerAudioSource::AudioFrameInfo> frame_info( | 501 std::vector<AudioMixer::Source::AudioFrameInfo> frame_info( |
502 kAudioSources, MixerAudioSource::AudioFrameInfo::kNormal); | 502 kAudioSources, AudioMixer::Source::AudioFrameInfo::kNormal); |
503 frame_info[0] = MixerAudioSource::AudioFrameInfo::kMuted; | 503 frame_info[0] = AudioMixer::Source::AudioFrameInfo::kMuted; |
504 std::fill(frames[0].data_, frames[0].data_ + kDefaultSampleRateHz / 100, | 504 std::fill(frames[0].data_, frames[0].data_ + kDefaultSampleRateHz / 100, |
505 std::numeric_limits<int16_t>::max()); | 505 std::numeric_limits<int16_t>::max()); |
506 std::vector<bool> expected_status(kAudioSources, true); | 506 std::vector<bool> expected_status(kAudioSources, true); |
507 expected_status[0] = false; | 507 expected_status[0] = false; |
508 | 508 |
509 MixAndCompare(frames, frame_info, expected_status); | 509 MixAndCompare(frames, frame_info, expected_status); |
510 } | 510 } |
511 } // namespace webrtc | 511 } // namespace webrtc |
OLD | NEW |