OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * |
| 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 |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 #include <memory> |
| 12 |
| 13 #include "webrtc/audio/audio_state.h" |
| 14 #include "webrtc/modules/audio_mixer/audio_mixer_impl.h" |
| 15 #include "webrtc/test/gtest.h" |
| 16 #include "webrtc/test/mock_voice_engine.h" |
| 17 |
| 18 namespace webrtc { |
| 19 namespace test { |
| 20 namespace { |
| 21 struct ConfigHelper { |
| 22 ConfigHelper() : audio_mixer_(AudioMixerImpl::Create()) { |
| 23 using testing::_; |
| 24 |
| 25 EXPECT_CALL(voice_engine_, RegisterVoiceEngineObserver(testing::_)) |
| 26 .WillOnce(testing::Return(0)); |
| 27 EXPECT_CALL(voice_engine_, DeRegisterVoiceEngineObserver()) |
| 28 .WillOnce(testing::Return(0)); |
| 29 EXPECT_CALL(voice_engine_, audio_processing()); |
| 30 EXPECT_CALL(voice_engine_, audio_transport()); |
| 31 |
| 32 ON_CALL(voice_engine_, audio_transport()) |
| 33 .WillByDefault(testing::Return(&audio_transport_)); |
| 34 |
| 35 config_.voice_engine = &voice_engine_; |
| 36 config_.audio_mixer = audio_mixer_; |
| 37 } |
| 38 |
| 39 rtc::scoped_refptr<AudioMixer> mixer() { return audio_mixer_; } |
| 40 |
| 41 MockAudioTransport& original_audio_transport() { return audio_transport_; } |
| 42 |
| 43 AudioState::Config& config() { return config_; } |
| 44 MockVoiceEngine& voice_engine() { return voice_engine_; } |
| 45 |
| 46 testing::StrictMock<MockVoiceEngine> voice_engine_; |
| 47 MockAudioTransport audio_transport_; |
| 48 rtc::scoped_refptr<AudioMixer> audio_mixer_; |
| 49 AudioState::Config config_; |
| 50 }; |
| 51 |
| 52 class FakeAudioSource : public AudioMixer::Source { |
| 53 public: |
| 54 int Ssrc() const /*override*/ { return 0; } |
| 55 |
| 56 int PreferredSampleRate() const /*override*/ { return 8000; } |
| 57 |
| 58 MOCK_METHOD2(GetAudioFrameWithInfo, |
| 59 AudioFrameInfo(int sample_rate_hz, AudioFrame* audio_frame)); |
| 60 }; |
| 61 } // namespace |
| 62 |
| 63 // Test that RecordedDataIsAvailable calls get to the original transport. |
| 64 TEST(AudioStateAudioPathTest, RecordedAudioArrivesAtOriginalTransport) { |
| 65 ConfigHelper helper; |
| 66 |
| 67 EXPECT_CALL(helper.voice_engine(), audio_device_module()).Times(2); |
| 68 auto device = static_cast<MockAudioDeviceModule*>( |
| 69 helper.voice_engine().audio_device_module()); |
| 70 |
| 71 // Get a local pointer to the most recent transport connected to the |
| 72 // Audio Device. |
| 73 AudioTransport* audio_transport_proxy = nullptr; |
| 74 ON_CALL(*device, RegisterAudioCallback(testing::_)) |
| 75 .WillByDefault( |
| 76 testing::Invoke([&audio_transport_proxy](AudioTransport* transport) { |
| 77 audio_transport_proxy = transport; |
| 78 return 0; |
| 79 })); |
| 80 |
| 81 rtc::scoped_refptr<AudioState> audio_state = |
| 82 AudioState::Create(helper.config()); |
| 83 |
| 84 // Setup completed. Ensure call of original transport is forwarded to new. |
| 85 uint32_t new_mic_level; |
| 86 EXPECT_CALL(helper.original_audio_transport(), |
| 87 RecordedDataIsAvailable(nullptr, 80, 2, 1, 8000, 0, 0, 0, false, |
| 88 testing::Ref(new_mic_level))); |
| 89 |
| 90 audio_transport_proxy->RecordedDataIsAvailable(nullptr, 80, 2, 1, 8000, 0, 0, |
| 91 0, false, new_mic_level); |
| 92 } |
| 93 |
| 94 TEST(AudioStateAudioPathTest, |
| 95 QueryingProxyForAudioShouldResultInGetAudioCallOnMixerSource) { |
| 96 ConfigHelper helper; |
| 97 |
| 98 EXPECT_CALL(helper.voice_engine(), audio_device_module()).Times(2); |
| 99 auto device = static_cast<MockAudioDeviceModule*>( |
| 100 helper.voice_engine().audio_device_module()); |
| 101 |
| 102 AudioTransport* audio_transport_proxy = nullptr; |
| 103 ON_CALL(*device, RegisterAudioCallback(testing::_)) |
| 104 .WillByDefault( |
| 105 testing::Invoke([&audio_transport_proxy](AudioTransport* transport) { |
| 106 audio_transport_proxy = transport; |
| 107 return 0; |
| 108 })); |
| 109 |
| 110 rtc::scoped_refptr<AudioState> audio_state = |
| 111 AudioState::Create(helper.config()); |
| 112 |
| 113 FakeAudioSource fake_source; |
| 114 |
| 115 helper.mixer()->AddSource(&fake_source); |
| 116 |
| 117 EXPECT_CALL(fake_source, GetAudioFrameWithInfo(testing::_, testing::_)) |
| 118 .WillOnce( |
| 119 testing::Invoke([](int sample_rate_hz, AudioFrame* audio_frame) { |
| 120 audio_frame->sample_rate_hz_ = sample_rate_hz; |
| 121 audio_frame->samples_per_channel_ = sample_rate_hz / 100; |
| 122 audio_frame->num_channels_ = 1; |
| 123 return AudioMixer::Source::AudioFrameInfo::kNormal; |
| 124 })); |
| 125 |
| 126 int16_t audio_buffer[80]; |
| 127 size_t n_samples_out; |
| 128 int64_t elapsed_time_ms; |
| 129 int64_t ntp_time_ms; |
| 130 audio_transport_proxy->NeedMorePlayData(80, 2, 1, 8000, audio_buffer, |
| 131 n_samples_out, &elapsed_time_ms, |
| 132 &ntp_time_ms); |
| 133 } |
| 134 } // namespace test |
| 135 } // namespace webrtc |
OLD | NEW |