From 10111bc49539589113c76318b7ba53591946e78a Mon Sep 17 00:00:00 2001 From: aleloi Date: Thu, 17 Nov 2016 06:48:48 -0800 Subject: [PATCH] Passed AudioMixer to AudioState::Config. This is a refactoring change in preparation for enabling AudioMixer with the goal to have a small CL as possible for passing audio through the new audio mixer in WebRTC. The dependent CL https://codereview.webrtc.org/2436033002/ enables the mixer. An object of class AudioState is shared across different webrtc audio connections. It is created in tests and in WebRTCVoiceEngine. AudioState is constructed by passing a Config struct, where one argument is scoped_refptr. Populating this field has now been mandatory. Tests and WebRTCVoiceEngine create and pass either a AudioMixerImpl. WebRTCVoiceEngine passes a real AudioMixer, which is currently unused. An alternative would have tests pass a mocked audio mixer. We chose not to do that, because we believe that tests should use the real thing unless there are reasons against it. Construction time is not an issue, because the real mixer is relatively lightweight. We couldn't find a way to test any mixer-related changes in AudioState before the mixes is connected. The next dependent CL https://codereview.webrtc.org/2436033002/ contains unit tests for mixer usage. BUG=webrtc:6346 Review-Url: https://codereview.webrtc.org/2469743002 Cr-Commit-Position: refs/heads/master@{#15134} --- webrtc/audio/BUILD.gn | 2 ++ webrtc/audio/DEPS | 1 + webrtc/audio/audio_receive_stream_unittest.cc | 2 ++ webrtc/audio/audio_send_stream_unittest.cc | 2 ++ webrtc/audio/audio_state.cc | 3 +++ webrtc/audio/audio_state_unittest.cc | 2 ++ webrtc/call/BUILD.gn | 3 +++ webrtc/call/DEPS | 1 + webrtc/call/call_perf_tests.cc | 4 +++- webrtc/call/call_unittest.cc | 2 ++ webrtc/media/BUILD.gn | 1 + webrtc/media/DEPS | 1 + webrtc/media/engine/webrtcvoiceengine.cc | 2 ++ webrtc/modules/audio_mixer/BUILD.gn | 4 ---- webrtc/test/BUILD.gn | 1 + webrtc/test/DEPS | 1 + webrtc/test/call_test.cc | 4 ++++ webrtc/video/DEPS | 1 + webrtc/video/video_quality_test.cc | 2 ++ 19 files changed, 34 insertions(+), 5 deletions(-) diff --git a/webrtc/audio/BUILD.gn b/webrtc/audio/BUILD.gn index e1d583f8e5..e89350e89a 100644 --- a/webrtc/audio/BUILD.gn +++ b/webrtc/audio/BUILD.gn @@ -48,7 +48,9 @@ if (rtc_include_tests) { ] deps = [ ":audio", + "../base:rtc_base_approved", "../modules/audio_device:mock_audio_device", + "../test:test_common", "//testing/gmock", "//testing/gtest", ] diff --git a/webrtc/audio/DEPS b/webrtc/audio/DEPS index e53d28578e..6e6259b9e5 100644 --- a/webrtc/audio/DEPS +++ b/webrtc/audio/DEPS @@ -4,6 +4,7 @@ include_rules = [ "+webrtc/logging/rtc_event_log", "+webrtc/modules/audio_coding/codecs/mock", "+webrtc/modules/audio_device", + "+webrtc/modules/audio_mixer", "+webrtc/modules/audio_processing/include", "+webrtc/modules/bitrate_controller", "+webrtc/modules/congestion_controller", diff --git a/webrtc/audio/audio_receive_stream_unittest.cc b/webrtc/audio/audio_receive_stream_unittest.cc index 0fc93b8b34..f263948fc4 100644 --- a/webrtc/audio/audio_receive_stream_unittest.cc +++ b/webrtc/audio/audio_receive_stream_unittest.cc @@ -15,6 +15,7 @@ #include "webrtc/audio/conversion.h" #include "webrtc/logging/rtc_event_log/mock/mock_rtc_event_log.h" #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_decoder_factory.h" +#include "webrtc/modules/audio_mixer/audio_mixer_impl.h" #include "webrtc/modules/bitrate_controller/include/mock/mock_bitrate_controller.h" #include "webrtc/modules/congestion_controller/include/mock/mock_congestion_controller.h" #include "webrtc/modules/pacing/packet_router.h" @@ -84,6 +85,7 @@ struct ConfigHelper { AudioState::Config config; config.voice_engine = &voice_engine_; + config.audio_mixer = AudioMixerImpl::Create(); audio_state_ = AudioState::Create(config); EXPECT_CALL(voice_engine_, ChannelProxyFactory(kChannelId)) diff --git a/webrtc/audio/audio_send_stream_unittest.cc b/webrtc/audio/audio_send_stream_unittest.cc index 7e0ea45bb2..dbc49662e6 100644 --- a/webrtc/audio/audio_send_stream_unittest.cc +++ b/webrtc/audio/audio_send_stream_unittest.cc @@ -16,6 +16,7 @@ #include "webrtc/audio/conversion.h" #include "webrtc/base/task_queue.h" #include "webrtc/logging/rtc_event_log/mock/mock_rtc_event_log.h" +#include "webrtc/modules/audio_mixer/audio_mixer_impl.h" #include "webrtc/modules/audio_processing/include/mock_audio_processing.h" #include "webrtc/modules/congestion_controller/include/congestion_controller.h" #include "webrtc/modules/congestion_controller/include/mock/mock_congestion_controller.h" @@ -81,6 +82,7 @@ struct ConfigHelper { AudioState::Config config; config.voice_engine = &voice_engine_; + config.audio_mixer = AudioMixerImpl::Create(); audio_state_ = AudioState::Create(config); SetupDefaultChannelProxy(); diff --git a/webrtc/audio/audio_state.cc b/webrtc/audio/audio_state.cc index 95a90a5bf1..c15ddd7795 100644 --- a/webrtc/audio/audio_state.cc +++ b/webrtc/audio/audio_state.cc @@ -26,6 +26,8 @@ AudioState::AudioState(const AudioState::Config& config) voe_base_->audio_processing(), config_.audio_mixer) { process_thread_checker_.DetachFromThread(); + RTC_DCHECK(config_.audio_mixer); + // Only one AudioState should be created per VoiceEngine. RTC_CHECK(voe_base_->RegisterVoiceEngineObserver(*this) != -1); @@ -48,6 +50,7 @@ VoiceEngine* AudioState::voice_engine() { } rtc::scoped_refptr AudioState::mixer() { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); return config_.audio_mixer; } diff --git a/webrtc/audio/audio_state_unittest.cc b/webrtc/audio/audio_state_unittest.cc index bd39baac1b..38485a88bf 100644 --- a/webrtc/audio/audio_state_unittest.cc +++ b/webrtc/audio/audio_state_unittest.cc @@ -11,6 +11,7 @@ #include #include "webrtc/audio/audio_state.h" +#include "webrtc/modules/audio_mixer/audio_mixer_impl.h" #include "webrtc/test/gtest.h" #include "webrtc/test/mock_voice_engine.h" @@ -29,6 +30,7 @@ struct ConfigHelper { EXPECT_CALL(voice_engine_, audio_transport()); config_.voice_engine = &voice_engine_; + config_.audio_mixer = AudioMixerImpl::Create(); } AudioState::Config& config() { return config_; } MockVoiceEngine& voice_engine() { return voice_engine_; } diff --git a/webrtc/call/BUILD.gn b/webrtc/call/BUILD.gn index ad20f340fc..d77dfc6b60 100644 --- a/webrtc/call/BUILD.gn +++ b/webrtc/call/BUILD.gn @@ -49,7 +49,10 @@ if (rtc_include_tests) { ] deps = [ ":call", + "../base:rtc_base_approved", "../modules/audio_device:mock_audio_device", + "../modules/audio_mixer", + "../test:test_common", "//testing/gmock", "//testing/gtest", ] diff --git a/webrtc/call/DEPS b/webrtc/call/DEPS index 01ad1d69cb..2ef22fca8f 100644 --- a/webrtc/call/DEPS +++ b/webrtc/call/DEPS @@ -4,6 +4,7 @@ include_rules = [ "+webrtc/logging/rtc_event_log", "+webrtc/modules/audio_coding", "+webrtc/modules/audio_device", + "+webrtc/modules/audio_mixer", "+webrtc/modules/audio_processing", "+webrtc/modules/bitrate_controller", "+webrtc/modules/congestion_controller", diff --git a/webrtc/call/call_perf_tests.cc b/webrtc/call/call_perf_tests.cc index b09d73c424..354e092a4f 100644 --- a/webrtc/call/call_perf_tests.cc +++ b/webrtc/call/call_perf_tests.cc @@ -20,6 +20,7 @@ #include "webrtc/config.h" #include "webrtc/logging/rtc_event_log/rtc_event_log.h" #include "webrtc/modules/audio_coding/include/audio_coding_module.h" +#include "webrtc/modules/audio_mixer/audio_mixer_impl.h" #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" #include "webrtc/system_wrappers/include/metrics_default.h" @@ -159,6 +160,7 @@ void CallPerfTest::TestAudioVideoSync(FecMode fec, AudioState::Config send_audio_state_config; send_audio_state_config.voice_engine = voice_engine; + send_audio_state_config.audio_mixer = AudioMixerImpl::Create(); Call::Config sender_config(&event_log_); sender_config.audio_state = AudioState::Create(send_audio_state_config); Call::Config receiver_config(&event_log_); @@ -264,7 +266,7 @@ void CallPerfTest::TestAudioVideoSync(FecMode fec, Start(); fake_audio_device.Start(); - EXPECT_EQ(0, voe_base->StartPlayout(recv_channel_id)); + audio_receive_stream->Start(); EXPECT_EQ(0, voe_base->StartSend(send_channel_id)); EXPECT_TRUE(observer.Wait()) diff --git a/webrtc/call/call_unittest.cc b/webrtc/call/call_unittest.cc index d981b0b013..2d75be5eda 100644 --- a/webrtc/call/call_unittest.cc +++ b/webrtc/call/call_unittest.cc @@ -14,6 +14,7 @@ #include "webrtc/api/call/audio_state.h" #include "webrtc/call.h" #include "webrtc/logging/rtc_event_log/rtc_event_log.h" +#include "webrtc/modules/audio_mixer/audio_mixer_impl.h" #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_decoder_factory.h" #include "webrtc/test/gtest.h" #include "webrtc/test/mock_voice_engine.h" @@ -26,6 +27,7 @@ struct CallHelper { : voice_engine_(decoder_factory) { webrtc::AudioState::Config audio_state_config; audio_state_config.voice_engine = &voice_engine_; + audio_state_config.audio_mixer = webrtc::AudioMixerImpl::Create(); EXPECT_CALL(voice_engine_, audio_device_module()); EXPECT_CALL(voice_engine_, audio_processing()); EXPECT_CALL(voice_engine_, audio_transport()); diff --git a/webrtc/media/BUILD.gn b/webrtc/media/BUILD.gn index c3c456c297..c3d173aac8 100644 --- a/webrtc/media/BUILD.gn +++ b/webrtc/media/BUILD.gn @@ -168,6 +168,7 @@ rtc_static_library("rtc_media") { "../api:call_api", "../base:rtc_base_approved", "../call", + "../modules/audio_mixer:audio_mixer_impl", "../modules/video_coding", "../p2p", "../system_wrappers", diff --git a/webrtc/media/DEPS b/webrtc/media/DEPS index 580ac5c452..e6d642daa1 100644 --- a/webrtc/media/DEPS +++ b/webrtc/media/DEPS @@ -6,6 +6,7 @@ include_rules = [ "+webrtc/logging/rtc_event_log", "+webrtc/modules/audio_coding", "+webrtc/modules/audio_device", + "+webrtc/modules/audio_mixer", "+webrtc/modules/audio_processing", "+webrtc/modules/video_capture", "+webrtc/modules/video_coding", diff --git a/webrtc/media/engine/webrtcvoiceengine.cc b/webrtc/media/engine/webrtcvoiceengine.cc index 2c67c56406..937078c3e9 100644 --- a/webrtc/media/engine/webrtcvoiceengine.cc +++ b/webrtc/media/engine/webrtcvoiceengine.cc @@ -37,6 +37,7 @@ #include "webrtc/media/engine/webrtcmediaengine.h" #include "webrtc/media/engine/webrtcvoe.h" #include "webrtc/modules/audio_coding/acm2/rent_a_codec.h" +#include "webrtc/modules/audio_mixer/audio_mixer_impl.h" #include "webrtc/modules/audio_processing/include/audio_processing.h" #include "webrtc/system_wrappers/include/field_trial.h" #include "webrtc/system_wrappers/include/trace.h" @@ -279,6 +280,7 @@ void GetOpusConfig(const AudioCodec& codec, webrtc::AudioState::Config MakeAudioStateConfig(VoEWrapper* voe_wrapper) { webrtc::AudioState::Config config; config.voice_engine = voe_wrapper->engine(); + config.audio_mixer = webrtc::AudioMixerImpl::Create(); return config; } diff --git a/webrtc/modules/audio_mixer/BUILD.gn b/webrtc/modules/audio_mixer/BUILD.gn index 9b34d54300..addffdd9f4 100644 --- a/webrtc/modules/audio_mixer/BUILD.gn +++ b/webrtc/modules/audio_mixer/BUILD.gn @@ -16,10 +16,6 @@ group("audio_mixer") { } rtc_static_library("audio_mixer_impl") { - visibility = [ - "../../audio:audio", - "../../modules/*", - ] sources = [ "audio_mixer_impl.cc", "audio_mixer_impl.h", diff --git a/webrtc/test/BUILD.gn b/webrtc/test/BUILD.gn index 28251e6cfb..126857b50c 100644 --- a/webrtc/test/BUILD.gn +++ b/webrtc/test/BUILD.gn @@ -334,6 +334,7 @@ rtc_source_set("test_common") { "../base:rtc_base_approved", "../call", "../modules/audio_device:mock_audio_device", + "../modules/audio_mixer:audio_mixer_impl", "../modules/audio_processing", "../modules/media_file", "../modules/video_capture:video_capture_module", diff --git a/webrtc/test/DEPS b/webrtc/test/DEPS index 9c41bd4ce8..59167aaed1 100644 --- a/webrtc/test/DEPS +++ b/webrtc/test/DEPS @@ -6,6 +6,7 @@ include_rules = [ "+webrtc/media/base", "+webrtc/modules/audio_coding", "+webrtc/modules/audio_device", + "+webrtc/modules/audio_mixer", "+webrtc/modules/audio_processing", "+webrtc/modules/media_file", "+webrtc/modules/rtp_rtcp", diff --git a/webrtc/test/call_test.cc b/webrtc/test/call_test.cc index ddff552565..28971af986 100644 --- a/webrtc/test/call_test.cc +++ b/webrtc/test/call_test.cc @@ -15,6 +15,8 @@ #include "webrtc/base/checks.h" #include "webrtc/config.h" #include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h" +#include "webrtc/modules/audio_mixer/audio_mixer_impl.h" +#include "webrtc/test/call_test.h" #include "webrtc/test/testsupport/fileutils.h" #include "webrtc/voice_engine/include/voe_base.h" @@ -52,6 +54,7 @@ void CallTest::RunBaseTest(BaseTest* test) { CreateVoiceEngines(); AudioState::Config audio_state_config; audio_state_config.voice_engine = voe_send_.voice_engine; + audio_state_config.audio_mixer = AudioMixerImpl::Create(); send_config.audio_state = AudioState::Create(audio_state_config); } CreateSenderCall(send_config); @@ -60,6 +63,7 @@ void CallTest::RunBaseTest(BaseTest* test) { if (num_audio_streams_ > 0) { AudioState::Config audio_state_config; audio_state_config.voice_engine = voe_recv_.voice_engine; + audio_state_config.audio_mixer = AudioMixerImpl::Create(); recv_config.audio_state = AudioState::Create(audio_state_config); } CreateReceiverCall(recv_config); diff --git a/webrtc/video/DEPS b/webrtc/video/DEPS index fafad7b9ed..1cdad193e3 100644 --- a/webrtc/video/DEPS +++ b/webrtc/video/DEPS @@ -4,6 +4,7 @@ include_rules = [ "+webrtc/common_video", "+webrtc/logging/rtc_event_log", "+webrtc/media/base", + "+webrtc/modules/audio_mixer", "+webrtc/modules/bitrate_controller", "+webrtc/modules/congestion_controller", "+webrtc/modules/pacing", diff --git a/webrtc/video/video_quality_test.cc b/webrtc/video/video_quality_test.cc index b48c692376..d0624c0a52 100644 --- a/webrtc/video/video_quality_test.cc +++ b/webrtc/video/video_quality_test.cc @@ -26,6 +26,7 @@ #include "webrtc/call.h" #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/logging/rtc_event_log/rtc_event_log.h" +#include "webrtc/modules/audio_mixer/audio_mixer_impl.h" #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" #include "webrtc/system_wrappers/include/cpu_info.h" @@ -1341,6 +1342,7 @@ void VideoQualityTest::RunWithRenderers(const Params& params) { CreateVoiceEngine(&voe, decoder_factory_); AudioState::Config audio_state_config; audio_state_config.voice_engine = voe.voice_engine; + audio_state_config.audio_mixer = AudioMixerImpl::Create(); call_config.audio_state = AudioState::Create(audio_state_config); }