diff --git a/audio/audio_receive_stream_unittest.cc b/audio/audio_receive_stream_unittest.cc index 4fdb68c1db..d6c2dbe69b 100644 --- a/audio/audio_receive_stream_unittest.cc +++ b/audio/audio_receive_stream_unittest.cc @@ -75,7 +75,6 @@ struct ConfigHelper { audio_mixer_(new rtc::RefCountedObject()) { using testing::Invoke; - EXPECT_CALL(voice_engine_, audio_device_module()); EXPECT_CALL(voice_engine_, audio_transport()); AudioState::Config config; diff --git a/audio/audio_send_stream_unittest.cc b/audio/audio_send_stream_unittest.cc index 8e42029cbf..c67eb9ba00 100644 --- a/audio/audio_send_stream_unittest.cc +++ b/audio/audio_send_stream_unittest.cc @@ -148,7 +148,6 @@ struct ConfigHelper { audio_encoder_(nullptr) { using testing::Invoke; - EXPECT_CALL(voice_engine_, audio_device_module()); EXPECT_CALL(voice_engine_, audio_transport()); AudioState::Config config; diff --git a/audio/audio_state.cc b/audio/audio_state.cc index a1dd956a24..5a30c53b3d 100644 --- a/audio/audio_state.cc +++ b/audio/audio_state.cc @@ -29,13 +29,6 @@ AudioState::AudioState(const AudioState::Config& config) config_.audio_mixer) { process_thread_checker_.DetachFromThread(); RTC_DCHECK(config_.audio_mixer); - - auto* const device = voe_base_->audio_device_module(); - RTC_DCHECK(device); - - // This is needed for the Chrome implementation of RegisterAudioCallback. - device->RegisterAudioCallback(nullptr); - device->RegisterAudioCallback(&audio_transport_proxy_); } AudioState::~AudioState() { diff --git a/audio/audio_state_unittest.cc b/audio/audio_state_unittest.cc index 86be2458e5..28b0a715f6 100644 --- a/audio/audio_state_unittest.cc +++ b/audio/audio_state_unittest.cc @@ -26,22 +26,9 @@ const int kBytesPerSample = 2; struct ConfigHelper { ConfigHelper() : audio_mixer(AudioMixerImpl::Create()) { - EXPECT_CALL(mock_voice_engine, audio_device_module()) - .Times(testing::AtLeast(1)); EXPECT_CALL(mock_voice_engine, audio_transport()) .WillRepeatedly(testing::Return(&audio_transport)); - auto device = static_cast( - voice_engine().audio_device_module()); - - // Populate the audio transport proxy pointer to the most recent - // transport connected to the Audio Device. - ON_CALL(*device, RegisterAudioCallback(testing::_)) - .WillByDefault(testing::Invoke([this](AudioTransport* transport) { - registered_audio_transport = transport; - return 0; - })); - audio_state_config.voice_engine = &mock_voice_engine; audio_state_config.audio_mixer = audio_mixer; audio_state_config.audio_processing = @@ -51,14 +38,12 @@ struct ConfigHelper { MockVoiceEngine& voice_engine() { return mock_voice_engine; } rtc::scoped_refptr mixer() { return audio_mixer; } MockAudioTransport& original_audio_transport() { return audio_transport; } - AudioTransport* audio_transport_proxy() { return registered_audio_transport; } private: testing::StrictMock mock_voice_engine; AudioState::Config audio_state_config; rtc::scoped_refptr audio_mixer; MockAudioTransport audio_transport; - AudioTransport* registered_audio_transport = nullptr; }; class FakeAudioSource : public AudioMixer::Source { @@ -112,7 +97,7 @@ TEST(AudioStateAudioPathTest, RecordedAudioArrivesAtOriginalTransport) { kNumberOfChannels, kSampleRate, 0, 0, 0, false, testing::Ref(new_mic_level))); - helper.audio_transport_proxy()->RecordedDataIsAvailable( + audio_state->audio_transport()->RecordedDataIsAvailable( nullptr, kSampleRate / 100, kBytesPerSample, kNumberOfChannels, kSampleRate, 0, 0, 0, false, new_mic_level); } @@ -141,7 +126,7 @@ TEST(AudioStateAudioPathTest, size_t n_samples_out; int64_t elapsed_time_ms; int64_t ntp_time_ms; - helper.audio_transport_proxy()->NeedMorePlayData( + audio_state->audio_transport()->NeedMorePlayData( kSampleRate / 100, kBytesPerSample, kNumberOfChannels, kSampleRate, audio_buffer, n_samples_out, &elapsed_time_ms, &ntp_time_ms); } diff --git a/call/call_perf_tests.cc b/call/call_perf_tests.cc index 98ebe8b657..a6fe0b27ad 100644 --- a/call/call_perf_tests.cc +++ b/call/call_perf_tests.cc @@ -176,6 +176,7 @@ void CallPerfTest::TestAudioVideoSync(FecMode fec, fake_audio_device = rtc::MakeUnique( FakeAudioDevice::CreatePulsedNoiseCapturer(256, 48000), FakeAudioDevice::CreateDiscardRenderer(48000), audio_rtp_speed); + EXPECT_EQ(0, fake_audio_device->Init()); EXPECT_EQ(0, voe_base->Init(fake_audio_device.get(), audio_processing.get(), decoder_factory_)); VoEBase::ChannelConfig config; @@ -189,9 +190,11 @@ void CallPerfTest::TestAudioVideoSync(FecMode fec, send_audio_state_config.audio_processing = audio_processing; Call::Config sender_config(event_log_.get()); - sender_config.audio_state = AudioState::Create(send_audio_state_config); + auto audio_state = AudioState::Create(send_audio_state_config); + fake_audio_device->RegisterAudioCallback(audio_state->audio_transport()); + sender_config.audio_state = audio_state; Call::Config receiver_config(event_log_.get()); - receiver_config.audio_state = sender_config.audio_state; + receiver_config.audio_state = audio_state; CreateCalls(sender_config, receiver_config); std::copy_if(std::begin(payload_type_map_), std::end(payload_type_map_), diff --git a/call/call_unittest.cc b/call/call_unittest.cc index aeba5a8168..7b16271584 100644 --- a/call/call_unittest.cc +++ b/call/call_unittest.cc @@ -41,7 +41,6 @@ struct CallHelper { audio_state_config.voice_engine = &voice_engine_; audio_state_config.audio_mixer = webrtc::AudioMixerImpl::Create(); audio_state_config.audio_processing = webrtc::AudioProcessing::Create(); - EXPECT_CALL(voice_engine_, audio_device_module()); EXPECT_CALL(voice_engine_, audio_transport()); webrtc::Call::Config config(&event_log_); config.audio_state = webrtc::AudioState::Create(audio_state_config); diff --git a/media/engine/adm_helpers.cc b/media/engine/adm_helpers.cc index b973ce6ebd..119cc64451 100644 --- a/media/engine/adm_helpers.cc +++ b/media/engine/adm_helpers.cc @@ -32,94 +32,50 @@ namespace adm_helpers { #define AUDIO_DEVICE_ID (0u) #endif // defined(WEBRTC_WIN) -void SetRecordingDevice(AudioDeviceModule* adm) { +void Init(AudioDeviceModule* adm) { RTC_DCHECK(adm); - // Save recording status and stop recording. - const bool was_recording = adm->Recording(); - if (was_recording && adm->StopRecording() != 0) { - RTC_LOG(LS_ERROR) << "Unable to stop recording."; - return; - } + RTC_CHECK_EQ(0, adm->Init()) << "Failed to initialize the ADM."; - // Set device to default. - if (adm->SetRecordingDevice(AUDIO_DEVICE_ID) != 0) { - RTC_LOG(LS_ERROR) << "Unable to set recording device."; - return; - } - - // Init microphone, so user can do volume settings etc. - if (adm->InitMicrophone() != 0) { - RTC_LOG(LS_ERROR) << "Unable to access microphone."; - } - - // Set number of channels - bool available = false; - if (adm->StereoRecordingIsAvailable(&available) != 0) { - RTC_LOG(LS_ERROR) << "Failed to query stereo recording."; - } - if (adm->SetStereoRecording(available) != 0) { - RTC_LOG(LS_ERROR) << "Failed to set stereo recording mode."; - } - - // Restore recording if it was enabled already when calling this function. - if (was_recording) { - if (adm->InitRecording() != 0) { - RTC_LOG(LS_ERROR) << "Failed to initialize recording."; + // Playout device. + { + if (adm->SetPlayoutDevice(AUDIO_DEVICE_ID) != 0) { + RTC_LOG(LS_ERROR) << "Unable to set playout device."; return; } - if (adm->StartRecording() != 0) { - RTC_LOG(LS_ERROR) << "Failed to start recording."; - return; + if (adm->InitSpeaker() != 0) { + RTC_LOG(LS_ERROR) << "Unable to access speaker."; + } + + // Set number of channels + bool available = false; + if (adm->StereoPlayoutIsAvailable(&available) != 0) { + RTC_LOG(LS_ERROR) << "Failed to query stereo playout."; + } + if (adm->SetStereoPlayout(available) != 0) { + RTC_LOG(LS_ERROR) << "Failed to set stereo playout mode."; } } - RTC_LOG(LS_INFO) << "Set recording device."; + // Recording device. + { + if (adm->SetRecordingDevice(AUDIO_DEVICE_ID) != 0) { + RTC_LOG(LS_ERROR) << "Unable to set recording device."; + return; + } + if (adm->InitMicrophone() != 0) { + RTC_LOG(LS_ERROR) << "Unable to access microphone."; + } + + // Set number of channels + bool available = false; + if (adm->StereoRecordingIsAvailable(&available) != 0) { + RTC_LOG(LS_ERROR) << "Failed to query stereo recording."; + } + if (adm->SetStereoRecording(available) != 0) { + RTC_LOG(LS_ERROR) << "Failed to set stereo recording mode."; + } + } } - -void SetPlayoutDevice(AudioDeviceModule* adm) { - RTC_DCHECK(adm); - - // Save playing status and stop playout. - const bool was_playing = adm->Playing(); - if (was_playing && adm->StopPlayout() != 0) { - RTC_LOG(LS_ERROR) << "Unable to stop playout."; - } - - // Set device. - if (adm->SetPlayoutDevice(AUDIO_DEVICE_ID) != 0) { - RTC_LOG(LS_ERROR) << "Unable to set playout device."; - return; - } - - // Init speaker, so user can do volume settings etc. - if (adm->InitSpeaker() != 0) { - RTC_LOG(LS_ERROR) << "Unable to access speaker."; - } - - // Set number of channels - bool available = false; - if (adm->StereoPlayoutIsAvailable(&available) != 0) { - RTC_LOG(LS_ERROR) << "Failed to query stereo playout."; - } - if (adm->SetStereoPlayout(available) != 0) { - RTC_LOG(LS_ERROR) << "Failed to set stereo playout mode."; - } - - // Restore recording if it was enabled already when calling this function. - if (was_playing) { - if (adm->InitPlayout() != 0) { - RTC_LOG(LS_ERROR) << "Failed to initialize playout."; - return; - } - if (adm->StartPlayout() != 0) { - RTC_LOG(LS_ERROR) << "Failed to start playout."; - return; - } - } - - RTC_LOG(LS_INFO) << "Set playout device."; -} - } // namespace adm_helpers } // namespace webrtc diff --git a/media/engine/adm_helpers.h b/media/engine/adm_helpers.h index d04db17331..c6ea3a209f 100644 --- a/media/engine/adm_helpers.h +++ b/media/engine/adm_helpers.h @@ -19,8 +19,7 @@ class AudioDeviceModule; namespace adm_helpers { -void SetRecordingDevice(AudioDeviceModule* adm); -void SetPlayoutDevice(AudioDeviceModule* adm); +void Init(AudioDeviceModule* adm); } // namespace adm_helpers } // namespace webrtc diff --git a/media/engine/fakewebrtcvoiceengine.h b/media/engine/fakewebrtcvoiceengine.h index 55d31004ca..9c9a4285ec 100644 --- a/media/engine/fakewebrtcvoiceengine.h +++ b/media/engine/fakewebrtcvoiceengine.h @@ -69,9 +69,6 @@ class FakeWebRtcVoiceEngine : public webrtc::VoEBase { inited_ = false; return 0; } - webrtc::AudioDeviceModule* audio_device_module() override { - return nullptr; - } webrtc::voe::TransmitMixer* transmit_mixer() override { return transmit_mixer_; } diff --git a/media/engine/webrtcvoiceengine.cc b/media/engine/webrtcvoiceengine.cc index 19619a3a0f..9630bc4caa 100644 --- a/media/engine/webrtcvoiceengine.cc +++ b/media/engine/webrtcvoiceengine.cc @@ -28,6 +28,7 @@ #include "media/engine/payload_type_mapper.h" #include "media/engine/webrtcmediaengine.h" #include "media/engine/webrtcvoe.h" +#include "modules/audio_device/audio_device_impl.h" #include "modules/audio_mixer/audio_mixer_impl.h" #include "modules/audio_processing/aec_dump/aec_dump_factory.h" #include "modules/audio_processing/include/audio_processing.h" @@ -251,6 +252,12 @@ WebRtcVoiceEngine::~WebRtcVoiceEngine() { if (initialized_) { StopAecDump(); voe_wrapper_->base()->Terminate(); + + // Stop AudioDevice. + adm()->StopPlayout(); + adm()->StopRecording(); + adm()->RegisterAudioCallback(nullptr); + adm()->Terminate(); } } @@ -283,15 +290,17 @@ void WebRtcVoiceEngine::Init() { channel_config_.enable_voice_pacing = true; - RTC_CHECK_EQ(0, - voe_wrapper_->base()->Init(adm_.get(), apm(), decoder_factory_)); - - // No ADM supplied? Get the default one from VoE. +#if defined(WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE) + // No ADM supplied? Create a default one. if (!adm_) { - adm_ = voe_wrapper_->base()->audio_device_module(); + adm_ = webrtc::AudioDeviceModule::Create( + webrtc::AudioDeviceModule::kPlatformDefaultAudio); } - RTC_DCHECK(adm_); +#endif // WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE + RTC_CHECK(adm()); + webrtc::adm_helpers::Init(adm()); + RTC_CHECK_EQ(0, voe_wrapper_->base()->Init(adm(), apm(), decoder_factory_)); transmit_mixer_ = voe_wrapper_->base()->transmit_mixer(); RTC_DCHECK(transmit_mixer_); @@ -324,15 +333,16 @@ void WebRtcVoiceEngine::Init() { // Set default audio devices. #if !defined(WEBRTC_IOS) - webrtc::adm_helpers::SetRecordingDevice(adm_); apm()->Initialize(); - webrtc::adm_helpers::SetPlayoutDevice(adm_); #endif // !WEBRTC_IOS // May be null for VoE injected for testing. if (voe()->engine()) { audio_state_ = webrtc::AudioState::Create( MakeAudioStateConfig(voe(), audio_mixer_, apm_)); + + // Connect the ADM to our audio path. + adm()->RegisterAudioCallback(audio_state_->audio_transport()); } initialized_ = true; @@ -708,7 +718,7 @@ int WebRtcVoiceEngine::CreateVoEChannel() { webrtc::AudioDeviceModule* WebRtcVoiceEngine::adm() { RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); RTC_DCHECK(adm_); - return adm_; + return adm_.get(); } webrtc::AudioProcessing* WebRtcVoiceEngine::apm() const { diff --git a/media/engine/webrtcvoiceengine_unittest.cc b/media/engine/webrtcvoiceengine_unittest.cc index ef56473376..f1782626d0 100644 --- a/media/engine/webrtcvoiceengine_unittest.cc +++ b/media/engine/webrtcvoiceengine_unittest.cc @@ -85,23 +85,10 @@ class MockTransmitMixer : public webrtc::voe::TransmitMixer { void AdmSetupExpectations(webrtc::test::MockAudioDeviceModule* adm) { RTC_DCHECK(adm); + + // Setup. EXPECT_CALL(*adm, AddRef()).Times(1); - EXPECT_CALL(*adm, Release()) - .WillOnce(Return(rtc::RefCountReleaseStatus::kDroppedLastRef)); -#if !defined(WEBRTC_IOS) - EXPECT_CALL(*adm, Recording()).WillOnce(Return(false)); -#if defined(WEBRTC_WIN) - EXPECT_CALL(*adm, SetRecordingDevice( - testing::Matcher( - webrtc::AudioDeviceModule::kDefaultCommunicationDevice))) - .WillOnce(Return(0)); -#else - EXPECT_CALL(*adm, SetRecordingDevice(0)).WillOnce(Return(0)); -#endif // #if defined(WEBRTC_WIN) - EXPECT_CALL(*adm, InitMicrophone()).WillOnce(Return(0)); - EXPECT_CALL(*adm, StereoRecordingIsAvailable(testing::_)).WillOnce(Return(0)); - EXPECT_CALL(*adm, SetStereoRecording(false)).WillOnce(Return(0)); - EXPECT_CALL(*adm, Playing()).WillOnce(Return(false)); + EXPECT_CALL(*adm, Init()).WillOnce(Return(0)); #if defined(WEBRTC_WIN) EXPECT_CALL(*adm, SetPlayoutDevice( testing::Matcher( @@ -113,11 +100,29 @@ void AdmSetupExpectations(webrtc::test::MockAudioDeviceModule* adm) { EXPECT_CALL(*adm, InitSpeaker()).WillOnce(Return(0)); EXPECT_CALL(*adm, StereoPlayoutIsAvailable(testing::_)).WillOnce(Return(0)); EXPECT_CALL(*adm, SetStereoPlayout(false)).WillOnce(Return(0)); -#endif // #if !defined(WEBRTC_IOS) +#if defined(WEBRTC_WIN) + EXPECT_CALL(*adm, SetRecordingDevice( + testing::Matcher( + webrtc::AudioDeviceModule::kDefaultCommunicationDevice))) + .WillOnce(Return(0)); +#else + EXPECT_CALL(*adm, SetRecordingDevice(0)).WillOnce(Return(0)); +#endif // #if defined(WEBRTC_WIN) + EXPECT_CALL(*adm, InitMicrophone()).WillOnce(Return(0)); + EXPECT_CALL(*adm, StereoRecordingIsAvailable(testing::_)).WillOnce(Return(0)); + EXPECT_CALL(*adm, SetStereoRecording(false)).WillOnce(Return(0)); EXPECT_CALL(*adm, BuiltInAECIsAvailable()).WillOnce(Return(false)); EXPECT_CALL(*adm, BuiltInAGCIsAvailable()).WillOnce(Return(false)); EXPECT_CALL(*adm, BuiltInNSIsAvailable()).WillOnce(Return(false)); EXPECT_CALL(*adm, SetAGC(true)).WillOnce(Return(0)); + + // Teardown. + EXPECT_CALL(*adm, StopPlayout()).WillOnce(Return(0)); + EXPECT_CALL(*adm, StopRecording()).WillOnce(Return(0)); + EXPECT_CALL(*adm, RegisterAudioCallback(nullptr)).WillOnce(Return(0)); + EXPECT_CALL(*adm, Terminate()).WillOnce(Return(0)); + EXPECT_CALL(*adm, Release()) + .WillOnce(Return(rtc::RefCountReleaseStatus::kDroppedLastRef)); } } // namespace diff --git a/test/call_test.cc b/test/call_test.cc index f4b387774a..3210e6460d 100644 --- a/test/call_test.cc +++ b/test/call_test.cc @@ -75,6 +75,8 @@ void CallTest::RunBaseTest(BaseTest* test) { audio_state_config.audio_mixer = AudioMixerImpl::Create(); audio_state_config.audio_processing = apm_send_; send_config.audio_state = AudioState::Create(audio_state_config); + fake_send_audio_device_->RegisterAudioCallback( + send_config.audio_state->audio_transport()); } CreateSenderCall(send_config); if (sender_call_transport_controller_ != nullptr) { @@ -89,7 +91,8 @@ void CallTest::RunBaseTest(BaseTest* test) { audio_state_config.audio_mixer = AudioMixerImpl::Create(); audio_state_config.audio_processing = apm_recv_; recv_config.audio_state = AudioState::Create(audio_state_config); - } + fake_recv_audio_device_->RegisterAudioCallback( + recv_config.audio_state->audio_transport()); } CreateReceiverCall(recv_config); } test->OnCallsCreated(sender_call_.get(), receiver_call_.get()); @@ -427,6 +430,7 @@ void CallTest::SetFakeVideoCaptureRotation(VideoRotation rotation) { void CallTest::CreateVoiceEngines() { voe_send_.voice_engine = VoiceEngine::Create(); voe_send_.base = VoEBase::GetInterface(voe_send_.voice_engine); + EXPECT_EQ(0, fake_send_audio_device_->Init()); EXPECT_EQ(0, voe_send_.base->Init(fake_send_audio_device_.get(), apm_send_.get(), decoder_factory_)); VoEBase::ChannelConfig config; @@ -436,6 +440,7 @@ void CallTest::CreateVoiceEngines() { voe_recv_.voice_engine = VoiceEngine::Create(); voe_recv_.base = VoEBase::GetInterface(voe_recv_.voice_engine); + EXPECT_EQ(0, fake_recv_audio_device_->Init()); EXPECT_EQ(0, voe_recv_.base->Init(fake_recv_audio_device_.get(), apm_recv_.get(), decoder_factory_)); voe_recv_.channel_id = voe_recv_.base->CreateChannel(); diff --git a/test/fake_audio_device.cc b/test/fake_audio_device.cc index fa3f1f4494..eef8bfd015 100644 --- a/test/fake_audio_device.cc +++ b/test/fake_audio_device.cc @@ -303,13 +303,9 @@ int32_t FakeAudioDevice::StopRecording() { } int32_t FakeAudioDevice::Init() { - // TODO(solenberg): Temporarily allow multiple init calls. - if (!inited_) { - RTC_CHECK(tick_->StartTimer(true, kFrameLengthMs / speed_)); - thread_.Start(); - thread_.SetPriority(rtc::kHighPriority); - inited_ = true; - } + RTC_CHECK(tick_->StartTimer(true, kFrameLengthMs / speed_)); + thread_.Start(); + thread_.SetPriority(rtc::kHighPriority); return 0; } diff --git a/test/fake_audio_device.h b/test/fake_audio_device.h index 4d906194ba..f71fd016d9 100644 --- a/test/fake_audio_device.h +++ b/test/fake_audio_device.h @@ -137,7 +137,6 @@ class FakeAudioDevice : public FakeAudioDeviceModule { std::unique_ptr tick_; rtc::PlatformThread thread_; - bool inited_ = false; }; } // namespace test } // namespace webrtc diff --git a/test/mock_voice_engine.h b/test/mock_voice_engine.h index 67bc993c9b..7fec1200ae 100644 --- a/test/mock_voice_engine.h +++ b/test/mock_voice_engine.h @@ -13,7 +13,6 @@ #include -#include "modules/audio_device/include/mock_audio_device.h" #include "modules/audio_device/include/mock_audio_transport.h" #include "modules/rtp_rtcp/mocks/mock_rtp_rtcp.h" #include "test/gmock.h" @@ -63,8 +62,6 @@ class MockVoiceEngine : public VoiceEngineImpl { return proxy; })); - ON_CALL(*this, audio_device_module()) - .WillByDefault(testing::Return(&mock_audio_device_)); ON_CALL(*this, audio_transport()) .WillByDefault(testing::Return(&mock_audio_transport_)); } @@ -97,7 +94,6 @@ class MockVoiceEngine : public VoiceEngineImpl { int(AudioDeviceModule* external_adm, AudioProcessing* external_apm, const rtc::scoped_refptr& decoder_factory)); - MOCK_METHOD0(audio_device_module, AudioDeviceModule*()); MOCK_METHOD0(transmit_mixer, voe::TransmitMixer*()); MOCK_METHOD0(Terminate, int()); MOCK_METHOD0(CreateChannel, int()); @@ -120,7 +116,6 @@ class MockVoiceEngine : public VoiceEngineImpl { std::map> mock_rtp_rtcps_; - MockAudioDeviceModule mock_audio_device_; MockAudioTransport mock_audio_transport_; }; } // namespace test diff --git a/video/video_quality_test.cc b/video/video_quality_test.cc index 512a9bbfe3..e40d2955f0 100644 --- a/video/video_quality_test.cc +++ b/video/video_quality_test.cc @@ -92,11 +92,13 @@ struct VoiceEngineState { void CreateVoiceEngine( VoiceEngineState* voe, + webrtc::AudioDeviceModule* adm, webrtc::AudioProcessing* apm, rtc::scoped_refptr decoder_factory) { voe->voice_engine = webrtc::VoiceEngine::Create(); voe->base = webrtc::VoEBase::GetInterface(voe->voice_engine); - EXPECT_EQ(0, voe->base->Init(nullptr, apm, decoder_factory)); + EXPECT_EQ(0, adm->Init()); + EXPECT_EQ(0, voe->base->Init(adm, apm, decoder_factory)); webrtc::VoEBase::ChannelConfig config; config.enable_voice_pacing = true; voe->send_channel_id = voe->base->CreateChannel(config); @@ -1968,6 +1970,7 @@ void VideoQualityTest::SetupAudio(int send_channel_id, void VideoQualityTest::RunWithRenderers(const Params& params) { std::unique_ptr send_transport; std::unique_ptr recv_transport; + std::unique_ptr fake_audio_device; ::VoiceEngineState voe; std::unique_ptr local_preview; std::vector> loopback_renderers; @@ -1982,16 +1985,24 @@ void VideoQualityTest::RunWithRenderers(const Params& params) { Call::Config call_config(event_log_.get()); call_config.bitrate_config = params_.call.call_bitrate_config; + fake_audio_device.reset(new test::FakeAudioDevice( + test::FakeAudioDevice::CreatePulsedNoiseCapturer(32000, 48000), + test::FakeAudioDevice::CreateDiscardRenderer(48000), + 1.f)); + rtc::scoped_refptr audio_processing( webrtc::AudioProcessing::Create()); if (params_.audio.enabled) { - CreateVoiceEngine(&voe, audio_processing.get(), decoder_factory_); + CreateVoiceEngine(&voe, fake_audio_device.get(), audio_processing.get(), + decoder_factory_); AudioState::Config audio_state_config; audio_state_config.voice_engine = voe.voice_engine; audio_state_config.audio_mixer = AudioMixerImpl::Create(); audio_state_config.audio_processing = audio_processing; call_config.audio_state = AudioState::Create(audio_state_config); + fake_audio_device->RegisterAudioCallback( + call_config.audio_state->audio_transport()); } CreateCalls(call_config, call_config); diff --git a/voice_engine/include/voe_base.h b/voice_engine/include/voe_base.h index 06a8cf330d..2f74fcc7c5 100644 --- a/voice_engine/include/voe_base.h +++ b/voice_engine/include/voe_base.h @@ -92,15 +92,10 @@ class WEBRTC_DLLEXPORT VoEBase { // functionality in a separate (reference counted) module. // - The AudioProcessing module handles capture-side processing. // - An AudioDecoderFactory - used to create audio decoders. - // If NULL is passed for ADM, VoiceEngine - // will create its own. Returns -1 in case of an error, 0 otherwise. virtual int Init( - AudioDeviceModule* external_adm, - AudioProcessing* external_apm, + AudioDeviceModule* audio_device, + AudioProcessing* audio_processing, const rtc::scoped_refptr& decoder_factory) = 0; - // This method is WIP - DO NOT USE! - // Returns NULL before Init() is called. - virtual AudioDeviceModule* audio_device_module() = 0; // This method is WIP - DO NOT USE! // Returns NULL before Init() is called. diff --git a/voice_engine/voe_base_impl.cc b/voice_engine/voe_base_impl.cc index 9848557cbc..695b06dd6c 100644 --- a/voice_engine/voe_base_impl.cc +++ b/voice_engine/voe_base_impl.cc @@ -142,91 +142,17 @@ void VoEBaseImpl::PullRenderData(int bits_per_sample, } int VoEBaseImpl::Init( - AudioDeviceModule* external_adm, + AudioDeviceModule* audio_device, AudioProcessing* audio_processing, const rtc::scoped_refptr& decoder_factory) { + RTC_DCHECK(audio_device); RTC_DCHECK(audio_processing); rtc::CritScope cs(shared_->crit_sec()); - WebRtcSpl_Init(); if (shared_->process_thread()) { shared_->process_thread()->Start(); } - // Create an internal ADM if the user has not added an external - // ADM implementation as input to Init(). - if (external_adm == nullptr) { -#if !defined(WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE) - return -1; -#else - // Create the internal ADM implementation. - shared_->set_audio_device(AudioDeviceModule::Create( - AudioDeviceModule::kPlatformDefaultAudio)); - if (shared_->audio_device() == nullptr) { - RTC_LOG(LS_ERROR) << "Init() failed to create the ADM"; - return -1; - } -#endif // WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE - } else { - // Use the already existing external ADM implementation. - shared_->set_audio_device(external_adm); - RTC_LOG_F(LS_INFO) - << "An external ADM implementation will be used in VoiceEngine"; - } - - bool available = false; - - // -------------------- - // Reinitialize the ADM - - // Register the AudioTransport implementation - if (shared_->audio_device()->RegisterAudioCallback(this) != 0) { - RTC_LOG(LS_ERROR) << "Init() failed to register audio callback for the ADM"; - } - - // ADM initialization - if (shared_->audio_device()->Init() != 0) { - RTC_LOG(LS_ERROR) << "Init() failed to initialize the ADM"; - return -1; - } - - // Initialize the default speaker - if (shared_->audio_device()->SetPlayoutDevice( - WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE) != 0) { - RTC_LOG(LS_ERROR) << "Init() failed to set the default output device"; - } - if (shared_->audio_device()->InitSpeaker() != 0) { - RTC_LOG(LS_ERROR) << "Init() failed to initialize the speaker"; - } - - // Initialize the default microphone - if (shared_->audio_device()->SetRecordingDevice( - WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE) != 0) { - RTC_LOG(LS_ERROR) << "Init() failed to set the default input device"; - } - if (shared_->audio_device()->InitMicrophone() != 0) { - RTC_LOG(LS_ERROR) << "Init() failed to initialize the microphone"; - } - - // Set number of channels - if (shared_->audio_device()->StereoPlayoutIsAvailable(&available) != 0) { - RTC_LOG(LS_ERROR) << "Init() failed to query stereo playout mode"; - } - if (shared_->audio_device()->SetStereoPlayout(available) != 0) { - RTC_LOG(LS_ERROR) << "Init() failed to set mono/stereo playout mode"; - } - - // TODO(andrew): These functions don't tell us whether stereo recording - // is truly available. We simply set the AudioProcessing input to stereo - // here, because we have to wait until receiving the first frame to - // determine the actual number of channels anyway. - // - // These functions may be changed; tracked here: - // http://code.google.com/p/webrtc/issues/detail?id=204 - shared_->audio_device()->StereoRecordingIsAvailable(&available); - if (shared_->audio_device()->SetStereoRecording(available) != 0) { - RTC_LOG(LS_ERROR) << "Init() failed to set mono/stereo recording mode"; - } - + shared_->set_audio_device(audio_device); shared_->set_audio_processing(audio_processing); // Configure AudioProcessing components. @@ -518,23 +444,7 @@ int32_t VoEBaseImpl::TerminateInternal() { shared_->process_thread()->Stop(); } - if (shared_->audio_device()) { - if (shared_->audio_device()->StopPlayout() != 0) { - RTC_LOG(LS_ERROR) << "TerminateInternal() failed to stop playout"; - } - if (shared_->audio_device()->StopRecording() != 0) { - RTC_LOG(LS_ERROR) << "TerminateInternal() failed to stop recording"; - } - if (shared_->audio_device()->RegisterAudioCallback(nullptr) != 0) { - RTC_LOG(LS_ERROR) << "TerminateInternal() failed to de-register audio " - "callback for the ADM"; - } - if (shared_->audio_device()->Terminate() != 0) { - RTC_LOG(LS_ERROR) << "TerminateInternal() failed to terminate the ADM"; - } - shared_->set_audio_device(nullptr); - } - + shared_->set_audio_device(nullptr); shared_->set_audio_processing(nullptr); return 0; diff --git a/voice_engine/voe_base_impl.h b/voice_engine/voe_base_impl.h index e6471243a1..4cd6c86ec1 100644 --- a/voice_engine/voe_base_impl.h +++ b/voice_engine/voe_base_impl.h @@ -25,12 +25,9 @@ class VoEBaseImpl : public VoEBase, public AudioTransport { public: int Init( - AudioDeviceModule* external_adm, + AudioDeviceModule* audio_device, AudioProcessing* audio_processing, const rtc::scoped_refptr& decoder_factory) override; - AudioDeviceModule* audio_device_module() override { - return shared_->audio_device(); - } voe::TransmitMixer* transmit_mixer() override { return shared_->transmit_mixer(); } diff --git a/voice_engine/voice_engine_defines.h b/voice_engine/voice_engine_defines.h index 4397662057..35f9492527 100644 --- a/voice_engine/voice_engine_defines.h +++ b/voice_engine/voice_engine_defines.h @@ -47,23 +47,4 @@ enum { kVoiceEngineMaxMinPlayoutDelayMs = 10000 }; } // namespace webrtc -namespace webrtc { - -inline int VoEId(int veId, int chId) { - if (chId == -1) { - const int dummyChannel(99); - return (int)((veId << 16) + dummyChannel); - } - return (int)((veId << 16) + chId); -} - -} // namespace webrtc - -#if defined(_WIN32) -#define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE \ - AudioDeviceModule::kDefaultCommunicationDevice -#else -#define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0 -#endif // #if (defined(_WIN32) - #endif // VOICE_ENGINE_VOICE_ENGINE_DEFINES_H_