From 201dfe90a7b77eb97d940331ba367e2927e910c2 Mon Sep 17 00:00:00 2001 From: aleloi Date: Thu, 20 Oct 2016 05:06:39 -0700 Subject: [PATCH] Split audio mixer into interface and implementation. The AudioMixer is now split in a mixer and audio source interface part, which has moved to webrtc/api, and a default implementation part, which lies in webrtc/modules. This change makes it possible to create other mixer implementations and is a first step to facilitate passing down a mixer from outside of WebRTC. It will also create less build dependencies when the new mixer has replaced the old one. NOTRY=True TBR=henrik.lundin@webrtc.org BUG=webrtc:6346 Review-Url: https://codereview.webrtc.org/2411313003 Cr-Commit-Position: refs/heads/master@{#14705} --- .gn | 1 + webrtc/api/BUILD.gn | 11 ++++++ webrtc/api/api.gyp | 11 ++++++ .../audio_mixer => api/audio}/audio_mixer.h | 22 ++++++----- webrtc/modules/BUILD.gn | 6 ++- webrtc/modules/audio_mixer/BUILD.gn | 38 +++++++++++++------ .../audio_mixer/audio_frame_manipulator.cc | 1 - .../audio_mixer/audio_frame_manipulator.h | 1 - webrtc/modules/audio_mixer/audio_mixer.gypi | 22 ++++++++--- webrtc/modules/audio_mixer/audio_mixer_impl.h | 3 +- .../audio_mixer/audio_mixer_impl_unittest.cc | 4 +- .../audio_source_with_mix_status.h | 2 +- 12 files changed, 87 insertions(+), 35 deletions(-) rename webrtc/{modules/audio_mixer => api/audio}/audio_mixer.h (81%) diff --git a/.gn b/.gn index 7a98fadc36..4aa7a76345 100644 --- a/.gn +++ b/.gn @@ -20,6 +20,7 @@ secondary_source = "//build/secondary/" # "gn check" or "gn gen --check". # TODO(kjellander): Keep adding paths to this list as work in webrtc:5589 is done. check_targets = [ + "//webrtc/api:audio_mixer_api", "//webrtc/api:rtc_stats_api", "//webrtc/modules/audio_coding:g711_test", "//webrtc/modules/audio_coding:g722_test", diff --git a/webrtc/api/BUILD.gn b/webrtc/api/BUILD.gn index 6de99f7da0..6424de96a6 100644 --- a/webrtc/api/BUILD.gn +++ b/webrtc/api/BUILD.gn @@ -321,6 +321,17 @@ rtc_source_set("rtc_stats_api") { ] } +# GYP version: webrtc/api/api.gyp:audio_mixer_api +rtc_source_set("audio_mixer_api") { + sources = [ + "audio/audio_mixer.h", + ] + + deps = [ + "../base:rtc_base_approved", + ] +} + if (rtc_include_tests) { config("peerconnection_unittests_config") { # The warnings below are enabled by default. Since GN orders compiler flags diff --git a/webrtc/api/api.gyp b/webrtc/api/api.gyp index c431e9e669..8a7fe5aae7 100644 --- a/webrtc/api/api.gyp +++ b/webrtc/api/api.gyp @@ -232,5 +232,16 @@ 'stats/rtcstatsreport.h', ], }, # target rtc_stats_api + { + # GN version: webrtc/api:audio_mixer_api + 'target_name': 'audio_mixer_api', + 'type': 'static_library', + 'dependencies': [ + '<(webrtc_root)/base/base.gyp:rtc_base_approved', + ], + 'sources': [ + 'audio/audio_mixer.h', + ], + }, # target rtc_stats_api ], # targets } diff --git a/webrtc/modules/audio_mixer/audio_mixer.h b/webrtc/api/audio/audio_mixer.h similarity index 81% rename from webrtc/modules/audio_mixer/audio_mixer.h rename to webrtc/api/audio/audio_mixer.h index 7e58a8d6a0..960adbbd43 100644 --- a/webrtc/modules/audio_mixer/audio_mixer.h +++ b/webrtc/api/audio/audio_mixer.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_H_ -#define WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_H_ +#ifndef WEBRTC_API_AUDIO_AUDIO_MIXER_H_ +#define WEBRTC_API_AUDIO_AUDIO_MIXER_H_ #include @@ -18,6 +18,9 @@ namespace webrtc { +// WORK IN PROGRESS +// This class is under development and is not yet intended for for use outside +// of WebRtc/Libjingle. class AudioMixer : public rtc::RefCountInterface { public: // A callback class that all mixer participants must inherit from/implement. @@ -25,10 +28,11 @@ class AudioMixer : public rtc::RefCountInterface { public: enum class AudioFrameInfo { kNormal, // The samples in audio_frame are valid and should be used. - kMuted, // The samples in audio_frame should not be used, but should be - // implicitly interpreted as zero. Other fields in audio_frame - // may be read and should contain meaningful values. - kError // audio_frame will not be used. + kMuted, // The samples in audio_frame should not be used, but + // should be implicitly interpreted as zero. Other + // fields in audio_frame may be read and should + // contain meaningful values. + kError, // The audio_frame will not be used. }; struct AudioFrameWithInfo { @@ -47,8 +51,8 @@ class AudioMixer : public rtc::RefCountInterface { // mixer. virtual AudioFrameWithInfo GetAudioFrameWithInfo(int sample_rate_hz) = 0; - // A way for a mixer implementation do distinguish participants. - virtual int ssrc() = 0; + // A way for a mixer implementation to distinguish participants. + virtual int Ssrc() = 0; protected: virtual ~Source() {} @@ -75,4 +79,4 @@ class AudioMixer : public rtc::RefCountInterface { }; } // namespace webrtc -#endif // WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_H_ +#endif // WEBRTC_API_AUDIO_AUDIO_MIXER_H_ diff --git a/webrtc/modules/BUILD.gn b/webrtc/modules/BUILD.gn index d983360d9b..6c472a399f 100644 --- a/webrtc/modules/BUILD.gn +++ b/webrtc/modules/BUILD.gn @@ -19,7 +19,7 @@ group("modules") { "audio_coding", "audio_conference_mixer", "audio_device", - "audio_mixer", + "audio_mixer:audio_mixer_impl", "audio_processing", "bitrate_controller", "desktop_capture", @@ -629,6 +629,7 @@ if (rtc_include_tests) { "../system_wrappers:system_wrappers", "../test:rtp_test_utils", "../test:test_common", + "../test:test_support", "../test:test_support_main", "../test:video_test_common", "audio_coding", @@ -645,7 +646,8 @@ if (rtc_include_tests) { "audio_coding:webrtc_opus", "audio_conference_mixer", "audio_device", - "audio_mixer", + "audio_mixer:audio_frame_manipulator", + "audio_mixer:audio_mixer_impl", "audio_processing", "audio_processing:audioproc_test_utils", "bitrate_controller", diff --git a/webrtc/modules/audio_mixer/BUILD.gn b/webrtc/modules/audio_mixer/BUILD.gn index 412b4d08f7..26adcf83d0 100644 --- a/webrtc/modules/audio_mixer/BUILD.gn +++ b/webrtc/modules/audio_mixer/BUILD.gn @@ -8,15 +8,12 @@ import("../../build/webrtc.gni") -config("audio_conference_mixer_config") { - include_dirs = [ "../../modules/include" ] -} - -rtc_static_library("audio_mixer") { +rtc_static_library("audio_mixer_impl") { + visibility = [ + "../../audio:audio", + "../../modules/*", + ] sources = [ - "audio_frame_manipulator.cc", - "audio_frame_manipulator.h", - "audio_mixer.h", "audio_mixer_impl.cc", "audio_mixer_impl.h", "audio_source_with_mix_status.cc", @@ -24,17 +21,36 @@ rtc_static_library("audio_mixer") { ] public = [ - "audio_mixer.h", + "audio_mixer_impl.h", ] - public_configs = [ ":audio_conference_mixer_config" ] + public_deps = [ + "../../api:audio_mixer_api", + ] deps = [ + ":audio_frame_manipulator", "../..:webrtc_common", "../../base:rtc_base_approved", "../../modules/audio_processing", "../../modules/utility", "../../system_wrappers", - "../../voice_engine:level_indicator", + ] +} + +rtc_static_library("audio_frame_manipulator") { + visibility = [ + ":*", + "../../modules:*", + ] + + sources = [ + "audio_frame_manipulator.cc", + "audio_frame_manipulator.h", + ] + + deps = [ + "../../base:rtc_base_approved", + "../../modules/utility", ] } diff --git a/webrtc/modules/audio_mixer/audio_frame_manipulator.cc b/webrtc/modules/audio_mixer/audio_frame_manipulator.cc index 426c21b2b8..fca9a78b50 100644 --- a/webrtc/modules/audio_mixer/audio_frame_manipulator.cc +++ b/webrtc/modules/audio_mixer/audio_frame_manipulator.cc @@ -12,7 +12,6 @@ #include "webrtc/modules/audio_mixer/audio_frame_manipulator.h" #include "webrtc/modules/include/module_common_types.h" #include "webrtc/modules/utility/include/audio_frame_operations.h" -#include "webrtc/typedefs.h" namespace webrtc { diff --git a/webrtc/modules/audio_mixer/audio_frame_manipulator.h b/webrtc/modules/audio_mixer/audio_frame_manipulator.h index b149bf9430..20b66ca10d 100644 --- a/webrtc/modules/audio_mixer/audio_frame_manipulator.h +++ b/webrtc/modules/audio_mixer/audio_frame_manipulator.h @@ -12,7 +12,6 @@ #define WEBRTC_MODULES_AUDIO_MIXER_AUDIO_FRAME_MANIPULATOR_H_ #include "webrtc/modules/include/module_common_types.h" -#include "webrtc/typedefs.h" namespace webrtc { diff --git a/webrtc/modules/audio_mixer/audio_mixer.gypi b/webrtc/modules/audio_mixer/audio_mixer.gypi index 1ec0a4d26d..ee40a9caf8 100644 --- a/webrtc/modules/audio_mixer/audio_mixer.gypi +++ b/webrtc/modules/audio_mixer/audio_mixer.gypi @@ -9,24 +9,34 @@ { 'targets': [ { - 'target_name': 'audio_mixer', + 'target_name': 'audio_mixer_impl', 'type': 'static_library', 'dependencies': [ + 'audio_frame_manipulator', 'audio_processing', 'webrtc_utility', - '<(webrtc_root)/system_wrappers/system_wrappers.gyp:system_wrappers', + '<(webrtc_root)/api/api.gyp:audio_mixer_api', '<(webrtc_root)/base/base.gyp:rtc_base_approved', - '<(webrtc_root)/voice_engine/voice_engine.gyp:level_indicator', + '<(webrtc_root)/system_wrappers/system_wrappers.gyp:system_wrappers', ], 'sources': [ - 'audio_frame_manipulator.cc', - 'audio_frame_manipulator.h', - 'audio_mixer.h', 'audio_mixer_impl.cc', 'audio_mixer_impl.h', 'audio_source_with_mix_status.cc', 'audio_source_with_mix_status.h', ], }, + { + 'target_name': 'audio_frame_manipulator', + 'type': 'static_library', + 'dependencies': [ + 'webrtc_utility', + '<(webrtc_root)/base/base.gyp:rtc_base_approved', + ], + 'sources': [ + 'audio_frame_manipulator.cc', + 'audio_frame_manipulator.h', + ], + }, ], # targets } diff --git a/webrtc/modules/audio_mixer/audio_mixer_impl.h b/webrtc/modules/audio_mixer/audio_mixer_impl.h index 87541ee642..500bb7862e 100644 --- a/webrtc/modules/audio_mixer/audio_mixer_impl.h +++ b/webrtc/modules/audio_mixer/audio_mixer_impl.h @@ -14,14 +14,13 @@ #include #include +#include "webrtc/api/audio/audio_mixer.h" #include "webrtc/base/scoped_ref_ptr.h" #include "webrtc/base/thread_annotations.h" #include "webrtc/base/thread_checker.h" -#include "webrtc/modules/audio_mixer/audio_mixer.h" #include "webrtc/modules/audio_processing/include/audio_processing.h" #include "webrtc/modules/include/module_common_types.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" -#include "webrtc/voice_engine/level_indicator.h" #include "webrtc/voice_engine_configurations.h" namespace webrtc { diff --git a/webrtc/modules/audio_mixer/audio_mixer_impl_unittest.cc b/webrtc/modules/audio_mixer/audio_mixer_impl_unittest.cc index 1e5f1fee95..9147a15000 100644 --- a/webrtc/modules/audio_mixer/audio_mixer_impl_unittest.cc +++ b/webrtc/modules/audio_mixer/audio_mixer_impl_unittest.cc @@ -14,10 +14,10 @@ #include #include +#include "webrtc/api/audio/audio_mixer.h" #include "webrtc/base/bind.h" #include "webrtc/base/thread.h" #include "webrtc/modules/audio_mixer/audio_mixer_impl.h" -#include "webrtc/modules/audio_mixer/audio_mixer.h" #include "webrtc/test/gmock.h" using testing::_; @@ -60,7 +60,7 @@ class MockMixerAudioSource : public AudioMixer::Source { MOCK_METHOD1(GetAudioFrameWithInfo, AudioFrameWithInfo(int sample_rate_hz)); - MOCK_METHOD0(ssrc, int()); + MOCK_METHOD0(Ssrc, int()); AudioFrame* fake_frame() { return &fake_frame_; } AudioFrameInfo fake_info() { return fake_audio_frame_info_; } diff --git a/webrtc/modules/audio_mixer/audio_source_with_mix_status.h b/webrtc/modules/audio_mixer/audio_source_with_mix_status.h index 167118f9c5..4849d617fe 100644 --- a/webrtc/modules/audio_mixer/audio_source_with_mix_status.h +++ b/webrtc/modules/audio_mixer/audio_source_with_mix_status.h @@ -11,7 +11,7 @@ #ifndef WEBRTC_MODULES_AUDIO_MIXER_AUDIO_SOURCE_WITH_MIX_STATUS_H_ #define WEBRTC_MODULES_AUDIO_MIXER_AUDIO_SOURCE_WITH_MIX_STATUS_H_ -#include "webrtc/modules/audio_mixer/audio_mixer.h" +#include "webrtc/api/audio/audio_mixer.h" namespace webrtc {