From 42dda50860ed348f26d8d4f74ba50190a067ee65 Mon Sep 17 00:00:00 2001 From: "henrik.lundin" Date: Wed, 18 May 2016 05:36:01 -0700 Subject: [PATCH] Propagate muted info from VoE Channel to AudioConferenceMixer Required updating of a few related classes and tests. BUG=webrtc:5609 NOTRY=True Review-Url: https://codereview.webrtc.org/1986093002 Cr-Commit-Position: refs/heads/master@{#12794} --- .../include/audio_conference_mixer_defines.h | 29 ++++++++++++++++++- .../source/audio_conference_mixer_impl.cc | 24 ++++++++------- webrtc/voice_engine/channel.cc | 9 ++++-- webrtc/voice_engine/channel.h | 4 ++- .../voice_engine/voe_external_media_impl.cc | 6 +++- 5 files changed, 55 insertions(+), 17 deletions(-) diff --git a/webrtc/modules/audio_conference_mixer/include/audio_conference_mixer_defines.h b/webrtc/modules/audio_conference_mixer/include/audio_conference_mixer_defines.h index 5d58f42435..e1c5aedc88 100644 --- a/webrtc/modules/audio_conference_mixer/include/audio_conference_mixer_defines.h +++ b/webrtc/modules/audio_conference_mixer/include/audio_conference_mixer_defines.h @@ -11,6 +11,7 @@ #ifndef WEBRTC_MODULES_AUDIO_CONFERENCE_MIXER_INCLUDE_AUDIO_CONFERENCE_MIXER_DEFINES_H_ #define WEBRTC_MODULES_AUDIO_CONFERENCE_MIXER_INCLUDE_AUDIO_CONFERENCE_MIXER_DEFINES_H_ +#include "webrtc/base/checks.h" #include "webrtc/modules/include/module_common_types.h" #include "webrtc/typedefs.h" @@ -25,8 +26,34 @@ public: // audio every time it's called. // // If it returns -1, the frame will not be added to the mix. + // + // NOTE: This function should not be called. It will remain for a short + // time so that subclasses can override it without getting warnings. + // TODO(henrik.lundin) Remove this function. virtual int32_t GetAudioFrame(int32_t id, - AudioFrame* audioFrame) = 0; + AudioFrame* audioFrame) { + RTC_CHECK(false); + return -1; + } + + + // The implementation of GetAudioFrameWithMuted should update audio_frame + // with new audio every time it's called. The return value will be + // interpreted as follows. + 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. + }; + + virtual AudioFrameInfo GetAudioFrameWithMuted(int32_t id, + AudioFrame* audio_frame) { + return GetAudioFrame(id, audio_frame) == -1 ? + AudioFrameInfo::kError : + AudioFrameInfo::kNormal; + } // Returns true if the participant was mixed this mix iteration. bool IsMixed() const; diff --git a/webrtc/modules/audio_conference_mixer/source/audio_conference_mixer_impl.cc b/webrtc/modules/audio_conference_mixer/source/audio_conference_mixer_impl.cc index b7bf1bae13..dce3d0b545 100644 --- a/webrtc/modules/audio_conference_mixer/source/audio_conference_mixer_impl.cc +++ b/webrtc/modules/audio_conference_mixer/source/audio_conference_mixer_impl.cc @@ -555,13 +555,14 @@ void AudioConferenceMixerImpl::UpdateToMix( } audioFrame->sample_rate_hz_ = _outputFrequency; - bool muted = false; - if((*participant)->GetAudioFrame(_id, audioFrame) != 0) { + auto ret = (*participant)->GetAudioFrameWithMuted(_id, audioFrame); + if (ret == MixerParticipant::AudioFrameInfo::kError) { WEBRTC_TRACE(kTraceWarning, kTraceAudioMixerServer, _id, - "failed to GetAudioFrame() from participant"); + "failed to GetAudioFrameWithMuted() from participant"); _audioFramePool->PushMemory(audioFrame); continue; } + const bool muted = (ret == MixerParticipant::AudioFrameInfo::kMuted); if (_participantList.size() != 1) { // TODO(wu): Issue 3390, add support for multiple participants case. audioFrame->ntp_time_ms_ = -1; @@ -720,10 +721,10 @@ void AudioConferenceMixerImpl::GetAdditionalAudio( AudioFrameList* additionalFramesList) const { WEBRTC_TRACE(kTraceStream, kTraceAudioMixerServer, _id, "GetAdditionalAudio(additionalFramesList)"); - // The GetAudioFrame() callback may result in the participant being removed - // from additionalParticipantList_. If that happens it will invalidate any - // iterators. Create a copy of the participants list such that the list of - // participants can be traversed safely. + // The GetAudioFrameWithMuted() callback may result in the participant being + // removed from additionalParticipantList_. If that happens it will + // invalidate any iterators. Create a copy of the participants list such + // that the list of participants can be traversed safely. MixerParticipantList additionalParticipantList; additionalParticipantList.insert(additionalParticipantList.begin(), _additionalParticipantList.begin(), @@ -741,10 +742,10 @@ void AudioConferenceMixerImpl::GetAdditionalAudio( return; } audioFrame->sample_rate_hz_ = _outputFrequency; - bool muted = false; - if((*participant)->GetAudioFrame(_id, audioFrame) != 0) { + auto ret = (*participant)->GetAudioFrameWithMuted(_id, audioFrame); + if (ret == MixerParticipant::AudioFrameInfo::kError) { WEBRTC_TRACE(kTraceWarning, kTraceAudioMixerServer, _id, - "failed to GetAudioFrame() from participant"); + "failed to GetAudioFrameWithMuted() from participant"); _audioFramePool->PushMemory(audioFrame); continue; } @@ -753,7 +754,8 @@ void AudioConferenceMixerImpl::GetAdditionalAudio( _audioFramePool->PushMemory(audioFrame); continue; } - additionalFramesList->push_back(FrameAndMuteInfo(audioFrame, muted)); + additionalFramesList->push_back(FrameAndMuteInfo( + audioFrame, ret == MixerParticipant::AudioFrameInfo::kMuted)); } } diff --git a/webrtc/voice_engine/channel.cc b/webrtc/voice_engine/channel.cc index 339a6a52ff..abc843aef3 100644 --- a/webrtc/voice_engine/channel.cc +++ b/webrtc/voice_engine/channel.cc @@ -476,7 +476,9 @@ bool Channel::OnRecoveredPacket(const uint8_t* rtp_packet, return ReceivePacket(rtp_packet, rtp_packet_length, header, false); } -int32_t Channel::GetAudioFrame(int32_t id, AudioFrame* audioFrame) { +MixerParticipant::AudioFrameInfo Channel::GetAudioFrameWithMuted( + int32_t id, + AudioFrame* audioFrame) { if (event_log_) { unsigned int ssrc; RTC_CHECK_EQ(GetLocalSSRC(ssrc), 0); @@ -492,7 +494,7 @@ int32_t Channel::GetAudioFrame(int32_t id, AudioFrame* audioFrame) { // error so that the audio mixer module doesn't add it to the mix. As // a result, it won't be played out and the actions skipped here are // irrelevant. - return -1; + return MixerParticipant::AudioFrameInfo::kError; } RTC_DCHECK(!muted); @@ -621,7 +623,8 @@ int32_t Channel::GetAudioFrame(int32_t id, AudioFrame* audioFrame) { } } - return 0; + return muted ? MixerParticipant::AudioFrameInfo::kMuted + : MixerParticipant::AudioFrameInfo::kNormal; } int32_t Channel::NeededFrequency(int32_t id) const { diff --git a/webrtc/voice_engine/channel.h b/webrtc/voice_engine/channel.h index ac49e28752..cd31e7702d 100644 --- a/webrtc/voice_engine/channel.h +++ b/webrtc/voice_engine/channel.h @@ -394,7 +394,9 @@ class Channel bool SendRtcp(const uint8_t* data, size_t len) override; // From MixerParticipant - int32_t GetAudioFrame(int32_t id, AudioFrame* audioFrame) override; + MixerParticipant::AudioFrameInfo GetAudioFrameWithMuted( + int32_t id, + AudioFrame* audioFrame) override; int32_t NeededFrequency(int32_t id) const override; // From FileCallback diff --git a/webrtc/voice_engine/voe_external_media_impl.cc b/webrtc/voice_engine/voe_external_media_impl.cc index 7b2b6a00f1..cae0715ced 100644 --- a/webrtc/voice_engine/voe_external_media_impl.cc +++ b/webrtc/voice_engine/voe_external_media_impl.cc @@ -153,7 +153,11 @@ int VoEExternalMediaImpl::GetAudioFrame(int channel, int desired_sample_rate_hz, } frame->sample_rate_hz_ = desired_sample_rate_hz == 0 ? -1 : desired_sample_rate_hz; - return channelPtr->GetAudioFrame(channel, frame); + auto ret = channelPtr->GetAudioFrameWithMuted(channel, frame); + if (ret == MixerParticipant::AudioFrameInfo::kMuted) { + frame->Mute(); + } + return ret == MixerParticipant::AudioFrameInfo::kError ? -1 : 0; } int VoEExternalMediaImpl::SetExternalMixing(int channel, bool enable) {