diff --git a/webrtc/audio/BUILD.gn b/webrtc/audio/BUILD.gn index 5cba616c53..127900544c 100644 --- a/webrtc/audio/BUILD.gn +++ b/webrtc/audio/BUILD.gn @@ -27,6 +27,7 @@ rtc_static_library("audio") { deps = [ "..:webrtc_common", + "../api:audio_mixer_api", "../api:call_api", "../system_wrappers", "../voice_engine", diff --git a/webrtc/audio/audio_receive_stream.cc b/webrtc/audio/audio_receive_stream.cc index 11a1c5815e..d05934297c 100644 --- a/webrtc/audio/audio_receive_stream.cc +++ b/webrtc/audio/audio_receive_stream.cc @@ -272,6 +272,15 @@ bool AudioReceiveStream::DeliverRtp(const uint8_t* packet, return channel_proxy_->ReceivedRTPPacket(packet, length, packet_time); } +AudioMixer::Source::AudioFrameWithInfo +AudioReceiveStream::GetAudioFrameWithInfo(int sample_rate_hz) { + return channel_proxy_->GetAudioFrameWithInfo(sample_rate_hz); +} + +int AudioReceiveStream::Ssrc() { + return config_.rtp.local_ssrc; +} + VoiceEngine* AudioReceiveStream::voice_engine() const { internal::AudioState* audio_state = static_cast(audio_state_.get()); diff --git a/webrtc/audio/audio_receive_stream.h b/webrtc/audio/audio_receive_stream.h index 871d48d6b0..82c642a137 100644 --- a/webrtc/audio/audio_receive_stream.h +++ b/webrtc/audio/audio_receive_stream.h @@ -13,6 +13,7 @@ #include +#include "webrtc/api/audio/audio_mixer.h" #include "webrtc/api/call/audio_receive_stream.h" #include "webrtc/api/call/audio_state.h" #include "webrtc/base/constructormagic.h" @@ -30,7 +31,8 @@ class ChannelProxy; namespace internal { -class AudioReceiveStream final : public webrtc::AudioReceiveStream { +class AudioReceiveStream final : public webrtc::AudioReceiveStream, + public AudioMixer::Source { public: AudioReceiveStream(CongestionController* congestion_controller, const webrtc::AudioReceiveStream::Config& config, @@ -52,6 +54,10 @@ class AudioReceiveStream final : public webrtc::AudioReceiveStream { const PacketTime& packet_time); const webrtc::AudioReceiveStream::Config& config() const; + // AudioMixer::Source + AudioFrameWithInfo GetAudioFrameWithInfo(int sample_rate_hz) override; + int Ssrc() override; + private: VoiceEngine* voice_engine() const; diff --git a/webrtc/audio/webrtc_audio.gypi b/webrtc/audio/webrtc_audio.gypi index 4439d1fcbb..a79459d0e4 100644 --- a/webrtc/audio/webrtc_audio.gypi +++ b/webrtc/audio/webrtc_audio.gypi @@ -8,6 +8,7 @@ { 'variables': { 'webrtc_audio_dependencies': [ + '<(webrtc_root)/api/api.gyp:audio_mixer_api', '<(webrtc_root)/api/api.gyp:call_api', '<(webrtc_root)/common.gyp:webrtc_common', '<(webrtc_root)/system_wrappers/system_wrappers.gyp:system_wrappers', diff --git a/webrtc/voice_engine/BUILD.gn b/webrtc/voice_engine/BUILD.gn index 79ecca552c..2b5d029b2f 100644 --- a/webrtc/voice_engine/BUILD.gn +++ b/webrtc/voice_engine/BUILD.gn @@ -87,6 +87,7 @@ rtc_static_library("voice_engine") { deps = [ ":level_indicator", "..:webrtc_common", + "../api:audio_mixer_api", "../api:call_api", "../base:rtc_base_approved", "../common_audio", diff --git a/webrtc/voice_engine/channel.cc b/webrtc/voice_engine/channel.cc index e36e54d075..44a1c73b08 100644 --- a/webrtc/voice_engine/channel.cc +++ b/webrtc/voice_engine/channel.cc @@ -712,6 +712,28 @@ MixerParticipant::AudioFrameInfo Channel::GetAudioFrameWithMuted( : MixerParticipant::AudioFrameInfo::kNormal; } +AudioMixer::Source::AudioFrameWithInfo Channel::GetAudioFrameWithInfo( + int sample_rate_hz) { + mix_audio_frame_.sample_rate_hz_ = sample_rate_hz; + + const auto frame_info = GetAudioFrameWithMuted(-1, &mix_audio_frame_); + + using FrameInfo = AudioMixer::Source::AudioFrameInfo; + FrameInfo new_audio_frame_info = FrameInfo::kError; + switch (frame_info) { + case MixerParticipant::AudioFrameInfo::kNormal: + new_audio_frame_info = FrameInfo::kNormal; + break; + case MixerParticipant::AudioFrameInfo::kMuted: + new_audio_frame_info = FrameInfo::kMuted; + break; + case MixerParticipant::AudioFrameInfo::kError: + new_audio_frame_info = FrameInfo::kError; + break; + } + return {&mix_audio_frame_, new_audio_frame_info}; +} + int32_t Channel::NeededFrequency(int32_t id) const { WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, _channelId), "Channel::NeededFrequency(id=%d)", id); diff --git a/webrtc/voice_engine/channel.h b/webrtc/voice_engine/channel.h index b0725867aa..97340beb4a 100644 --- a/webrtc/voice_engine/channel.h +++ b/webrtc/voice_engine/channel.h @@ -13,6 +13,7 @@ #include +#include "webrtc/api/audio/audio_mixer.h" #include "webrtc/api/call/audio_sink.h" #include "webrtc/base/criticalsection.h" #include "webrtc/base/optional.h" @@ -377,6 +378,10 @@ class Channel AudioFrame* audioFrame) override; int32_t NeededFrequency(int32_t id) const override; + // From AudioMixer::Source. + AudioMixer::Source::AudioFrameWithInfo GetAudioFrameWithInfo( + int sample_rate_hz); + // From FileCallback void PlayNotification(int32_t id, uint32_t durationMs) override; void RecordNotification(int32_t id, uint32_t durationMs) override; @@ -470,6 +475,7 @@ class Channel AudioLevel _outputAudioLevel; bool _externalTransport; AudioFrame _audioFrame; + AudioFrame mix_audio_frame_; // Downsamples to the codec rate if necessary. PushResampler input_resampler_; std::unique_ptr input_file_player_; diff --git a/webrtc/voice_engine/channel_proxy.cc b/webrtc/voice_engine/channel_proxy.cc index fc22180566..dc01c9b627 100644 --- a/webrtc/voice_engine/channel_proxy.cc +++ b/webrtc/voice_engine/channel_proxy.cc @@ -214,6 +214,12 @@ void ChannelProxy::SetRtcEventLog(RtcEventLog* event_log) { channel()->SetRtcEventLog(event_log); } +AudioMixer::Source::AudioFrameWithInfo ChannelProxy::GetAudioFrameWithInfo( + int sample_rate_hz) { + RTC_DCHECK_RUNS_SERIALIZED(&race_checker_); + return channel()->GetAudioFrameWithInfo(sample_rate_hz); +} + 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 d84e73b60f..b09a56c302 100644 --- a/webrtc/voice_engine/channel_proxy.h +++ b/webrtc/voice_engine/channel_proxy.h @@ -11,7 +11,9 @@ #ifndef WEBRTC_VOICE_ENGINE_CHANNEL_PROXY_H_ #define WEBRTC_VOICE_ENGINE_CHANNEL_PROXY_H_ +#include "webrtc/api/audio/audio_mixer.h" #include "webrtc/base/constructormagic.h" +#include "webrtc/base/race_checker.h" #include "webrtc/base/thread_checker.h" #include "webrtc/voice_engine/channel_manager.h" #include "webrtc/voice_engine/include/voe_rtp_rtcp.h" @@ -91,10 +93,14 @@ class ChannelProxy { virtual void SetRtcEventLog(RtcEventLog* event_log); + virtual AudioMixer::Source::AudioFrameWithInfo GetAudioFrameWithInfo( + int sample_rate_hz); + private: Channel* channel() const; rtc::ThreadChecker thread_checker_; + rtc::RaceChecker race_checker_; ChannelOwner channel_owner_; RTC_DISALLOW_COPY_AND_ASSIGN(ChannelProxy); diff --git a/webrtc/voice_engine/voice_engine.gyp b/webrtc/voice_engine/voice_engine.gyp index 3521a8d662..5971dec14c 100644 --- a/webrtc/voice_engine/voice_engine.gyp +++ b/webrtc/voice_engine/voice_engine.gyp @@ -15,6 +15,7 @@ 'target_name': 'voice_engine', 'type': 'static_library', 'dependencies': [ + '<(webrtc_root)/api/api.gyp:audio_mixer_api', '<(webrtc_root)/api/api.gyp:call_api', '<(webrtc_root)/base/base.gyp:rtc_base_approved', '<(webrtc_root)/common.gyp:webrtc_common',