From 2bdcfadc8abd418a30dd5cdf54ba45a429d3d9bf Mon Sep 17 00:00:00 2001 From: terelius Date: Tue, 26 Jan 2016 02:29:50 -0800 Subject: [PATCH] Revert of Removing webrtc::AudioFrame::energy_. (patchset #2 id:20001 of https://codereview.webrtc.org/1589953002/ ) Reason for revert: The change breaks google3 tests for buzz/mediaengines/sae/audio_mixer. Original issue's description: > Remove webrtc::AudioFrame::energy_. > > BUG=webrtc:3315 > > Committed: https://crrev.com/bacae81a1d91ae7b2a4bde37a66ab70513449989 > Cr-Commit-Position: refs/heads/master@{#11372} TBR=kjellander@webrtc.org,henrik.lundin@webrtc.org,tommi@webrtc.org,minyue@webrtc.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=webrtc:3315 Review URL: https://codereview.webrtc.org/1634143002 Cr-Commit-Position: refs/heads/master@{#11377} --- .../source/audio_conference_mixer_impl.cc | 21 +++++++++++++++---- .../source/audio_conference_mixer_impl.h | 4 ++++ .../source/audio_frame_manipulator.cc | 8 +++---- .../source/audio_frame_manipulator.h | 4 +--- webrtc/modules/include/module_common_types.h | 15 +++++++++++-- 5 files changed, 39 insertions(+), 13 deletions(-) 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 9411a9a47e..afb060f46d 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 @@ -583,16 +583,17 @@ void AudioConferenceMixerImpl::UpdateToMix( // There are already more active participants than should be // mixed. Only keep the ones with the highest energy. AudioFrameList::iterator replaceItem; - uint32_t lowestEnergy = CalculateEnergy(*audioFrame); + CalculateEnergy(*audioFrame); + uint32_t lowestEnergy = audioFrame->energy_; bool found_replace_item = false; for (AudioFrameList::iterator iter = activeList.begin(); iter != activeList.end(); ++iter) { - const uint32_t energy = CalculateEnergy(**iter); - if(energy < lowestEnergy) { + CalculateEnergy(**iter); + if((*iter)->energy_ < lowestEnergy) { replaceItem = iter; - lowestEnergy = energy; + lowestEnergy = (*iter)->energy_; found_replace_item = true; } } @@ -782,6 +783,18 @@ void AudioConferenceMixerImpl::ClearAudioFrameList( audioFrameList->clear(); } +void AudioConferenceMixerImpl::UpdateVADPositiveParticipants( + AudioFrameList* mixList) const { + WEBRTC_TRACE(kTraceStream, kTraceAudioMixerServer, _id, + "UpdateVADPositiveParticipants(mixList)"); + + for (AudioFrameList::const_iterator iter = mixList->begin(); + iter != mixList->end(); + ++iter) { + CalculateEnergy(**iter); + } +} + bool AudioConferenceMixerImpl::IsParticipantInList( const MixerParticipant& participant, const MixerParticipantList& participantList) const { diff --git a/webrtc/modules/audio_conference_mixer/source/audio_conference_mixer_impl.h b/webrtc/modules/audio_conference_mixer/source/audio_conference_mixer_impl.h index 0fab84ba81..2466112769 100644 --- a/webrtc/modules/audio_conference_mixer/source/audio_conference_mixer_impl.h +++ b/webrtc/modules/audio_conference_mixer/source/audio_conference_mixer_impl.h @@ -116,6 +116,10 @@ private: // Clears audioFrameList and reclaims all memory associated with it. void ClearAudioFrameList(AudioFrameList* audioFrameList) const; + // Update the list of MixerParticipants who have a positive VAD. mixList + // should be a list of AudioFrames + void UpdateVADPositiveParticipants(AudioFrameList* mixList) const; + // This function returns true if it finds the MixerParticipant in the // specified list of MixerParticipants. bool IsParticipantInList(const MixerParticipant& participant, diff --git a/webrtc/modules/audio_conference_mixer/source/audio_frame_manipulator.cc b/webrtc/modules/audio_conference_mixer/source/audio_frame_manipulator.cc index 1e679af914..9c5d3b939d 100644 --- a/webrtc/modules/audio_conference_mixer/source/audio_frame_manipulator.cc +++ b/webrtc/modules/audio_conference_mixer/source/audio_frame_manipulator.cc @@ -39,16 +39,16 @@ const size_t rampSize = sizeof(rampArray)/sizeof(rampArray[0]); } // namespace namespace webrtc { -uint32_t CalculateEnergy(const AudioFrame& audioFrame) +void CalculateEnergy(AudioFrame& audioFrame) { - uint32_t energy = 0; + audioFrame.energy_ = 0; for(size_t position = 0; position < audioFrame.samples_per_channel_; position++) { // TODO(andrew): this can easily overflow. - energy += audioFrame.data_[position] * audioFrame.data_[position]; + audioFrame.energy_ += audioFrame.data_[position] * + audioFrame.data_[position]; } - return energy; } void RampIn(AudioFrame& audioFrame) diff --git a/webrtc/modules/audio_conference_mixer/source/audio_frame_manipulator.h b/webrtc/modules/audio_conference_mixer/source/audio_frame_manipulator.h index c136597fc3..2da3a4d0d1 100644 --- a/webrtc/modules/audio_conference_mixer/source/audio_frame_manipulator.h +++ b/webrtc/modules/audio_conference_mixer/source/audio_frame_manipulator.h @@ -11,13 +11,11 @@ #ifndef WEBRTC_MODULES_AUDIO_CONFERENCE_MIXER_SOURCE_AUDIO_FRAME_MANIPULATOR_H_ #define WEBRTC_MODULES_AUDIO_CONFERENCE_MIXER_SOURCE_AUDIO_FRAME_MANIPULATOR_H_ -#include "webrtc/typedefs.h" - namespace webrtc { class AudioFrame; // Updates the audioFrame's energy (based on its samples). -uint32_t CalculateEnergy(const AudioFrame& audioFrame); +void CalculateEnergy(AudioFrame& audioFrame); // Apply linear step function that ramps in/out the audio samples in audioFrame void RampIn(AudioFrame& audioFrame); diff --git a/webrtc/modules/include/module_common_types.h b/webrtc/modules/include/module_common_types.h index 706eea3685..89c5f1b49b 100644 --- a/webrtc/modules/include/module_common_types.h +++ b/webrtc/modules/include/module_common_types.h @@ -508,7 +508,7 @@ class AudioFrame { void UpdateFrame(int id, uint32_t timestamp, const int16_t* data, size_t samples_per_channel, int sample_rate_hz, SpeechType speech_type, VADActivity vad_activity, - size_t num_channels = 1); + size_t num_channels = 1, uint32_t energy = -1); AudioFrame& Append(const AudioFrame& rhs); @@ -535,6 +535,11 @@ class AudioFrame { size_t num_channels_; SpeechType speech_type_; VADActivity vad_activity_; + // Note that there is no guarantee that |energy_| is correct. Any user of this + // member must verify that the value is correct. + // TODO(henrike) Remove |energy_|. + // See https://code.google.com/p/webrtc/issues/detail?id=3315. + uint32_t energy_; bool interleaved_; private: @@ -558,6 +563,7 @@ inline void AudioFrame::Reset() { num_channels_ = 0; speech_type_ = kUndefined; vad_activity_ = kVadUnknown; + energy_ = 0xffffffff; interleaved_ = true; } @@ -568,7 +574,8 @@ inline void AudioFrame::UpdateFrame(int id, int sample_rate_hz, SpeechType speech_type, VADActivity vad_activity, - size_t num_channels) { + size_t num_channels, + uint32_t energy) { id_ = id; timestamp_ = timestamp; samples_per_channel_ = samples_per_channel; @@ -576,6 +583,7 @@ inline void AudioFrame::UpdateFrame(int id, speech_type_ = speech_type; vad_activity_ = vad_activity; num_channels_ = num_channels; + energy_ = energy; const size_t length = samples_per_channel * num_channels; assert(length <= kMaxDataSizeSamples); @@ -598,6 +606,7 @@ inline void AudioFrame::CopyFrom(const AudioFrame& src) { speech_type_ = src.speech_type_; vad_activity_ = src.vad_activity_; num_channels_ = src.num_channels_; + energy_ = src.energy_; interleaved_ = src.interleaved_; const size_t length = samples_per_channel_ * num_channels_; @@ -692,6 +701,7 @@ inline AudioFrame& AudioFrame::operator+=(const AudioFrame& rhs) { data_[i] = ClampToInt16(wrap_guard); } } + energy_ = 0xffffffff; return *this; } @@ -715,6 +725,7 @@ inline AudioFrame& AudioFrame::operator-=(const AudioFrame& rhs) { static_cast(data_[i]) - static_cast(rhs.data_[i]); data_[i] = ClampToInt16(wrap_guard); } + energy_ = 0xffffffff; return *this; }