From 051f678808d03fb2e68fe2a084b1deeb326c71bf Mon Sep 17 00:00:00 2001 From: aleloi Date: Mon, 31 Oct 2016 03:26:40 -0700 Subject: [PATCH] Add a NeededFrequency() method to the AudioMixer::Source interface. This change will allow for a audio source to report its sampling rate to the audio mixer. It is needed in order to mix at a lower sampling rate. Mixing at a lower sampling rate can in many cases lead to big efficiency improvements, as reported by experiments. The code affected is all implementations of the Source interface: AudioReceiveStream and a mock class. The AudioReceiveStream now queries its underlying voe::Channel object for the needed frequency. Note that the changes to the mixing algorithm are done in a later CL. BUG=webrtc:6346 NOTRY=True TBR=solenberg@webrtc.org Review-Url: https://codereview.webrtc.org/2448113009 Cr-Commit-Position: refs/heads/master@{#14839} --- webrtc/api/audio/audio_mixer.h | 6 +++++- webrtc/audio/audio_receive_stream.cc | 6 +++++- webrtc/audio/audio_receive_stream.h | 3 ++- webrtc/modules/audio_mixer/audio_mixer_impl_unittest.cc | 3 ++- webrtc/voice_engine/channel_proxy.cc | 4 ++++ webrtc/voice_engine/channel_proxy.h | 2 ++ 6 files changed, 20 insertions(+), 4 deletions(-) diff --git a/webrtc/api/audio/audio_mixer.h b/webrtc/api/audio/audio_mixer.h index ee39daaf10..f786d6c99b 100644 --- a/webrtc/api/audio/audio_mixer.h +++ b/webrtc/api/audio/audio_mixer.h @@ -42,7 +42,11 @@ class AudioMixer : public rtc::RefCountInterface { AudioFrame* audio_frame) = 0; // A way for a mixer implementation to distinguish participants. - virtual int Ssrc() = 0; + virtual int Ssrc() const = 0; + + // A way for this source to say that GetAudioFrameWithInfo called + // with this sample rate or higher will not cause quality loss. + virtual int PreferredSampleRate() const = 0; virtual ~Source() {} }; diff --git a/webrtc/audio/audio_receive_stream.cc b/webrtc/audio/audio_receive_stream.cc index 12b8b3f7ad..657a7608ec 100644 --- a/webrtc/audio/audio_receive_stream.cc +++ b/webrtc/audio/audio_receive_stream.cc @@ -278,7 +278,11 @@ AudioMixer::Source::AudioFrameInfo AudioReceiveStream::GetAudioFrameWithInfo( return channel_proxy_->GetAudioFrameWithInfo(sample_rate_hz, audio_frame); } -int AudioReceiveStream::Ssrc() { +int AudioReceiveStream::PreferredSampleRate() const { + return channel_proxy_->NeededFrequency(); +} + +int AudioReceiveStream::Ssrc() const { return config_.rtp.local_ssrc; } diff --git a/webrtc/audio/audio_receive_stream.h b/webrtc/audio/audio_receive_stream.h index e6416cd9a3..906ddb626d 100644 --- a/webrtc/audio/audio_receive_stream.h +++ b/webrtc/audio/audio_receive_stream.h @@ -57,7 +57,8 @@ class AudioReceiveStream final : public webrtc::AudioReceiveStream, // AudioMixer::Source AudioFrameInfo GetAudioFrameWithInfo(int sample_rate_hz, AudioFrame* audio_frame) override; - int Ssrc() override; + int PreferredSampleRate() const override; + int Ssrc() const override; private: VoiceEngine* voice_engine() const; diff --git a/webrtc/modules/audio_mixer/audio_mixer_impl_unittest.cc b/webrtc/modules/audio_mixer/audio_mixer_impl_unittest.cc index 28976fae88..e743192d02 100644 --- a/webrtc/modules/audio_mixer/audio_mixer_impl_unittest.cc +++ b/webrtc/modules/audio_mixer/audio_mixer_impl_unittest.cc @@ -61,7 +61,8 @@ class MockMixerAudioSource : public AudioMixer::Source { MOCK_METHOD2(GetAudioFrameWithInfo, AudioFrameInfo(int sample_rate_hz, AudioFrame* audio_frame)); - MOCK_METHOD0(Ssrc, int()); + MOCK_CONST_METHOD0(PreferredSampleRate, int()); + MOCK_CONST_METHOD0(Ssrc, int()); AudioFrame* fake_frame() { return &fake_frame_; } AudioFrameInfo fake_info() { return fake_audio_frame_info_; } diff --git a/webrtc/voice_engine/channel_proxy.cc b/webrtc/voice_engine/channel_proxy.cc index ba58502e95..982cf1db7f 100644 --- a/webrtc/voice_engine/channel_proxy.cc +++ b/webrtc/voice_engine/channel_proxy.cc @@ -221,6 +221,10 @@ AudioMixer::Source::AudioFrameInfo ChannelProxy::GetAudioFrameWithInfo( return channel()->GetAudioFrameWithInfo(sample_rate_hz, audio_frame); } +int ChannelProxy::NeededFrequency() const { + return static_cast(channel()->NeededFrequency(-1)); +} + Channel* ChannelProxy::channel() const { RTC_DCHECK(channel_owner_.channel()); return channel_owner_.channel(); diff --git a/webrtc/voice_engine/channel_proxy.h b/webrtc/voice_engine/channel_proxy.h index d19c0092a7..a9ec8604ab 100644 --- a/webrtc/voice_engine/channel_proxy.h +++ b/webrtc/voice_engine/channel_proxy.h @@ -97,6 +97,8 @@ class ChannelProxy { int sample_rate_hz, AudioFrame* audio_frame); + virtual int NeededFrequency() const; + private: Channel* channel() const;