From 63420669746cfca6ed1d902c68c656b79ffa5a1b Mon Sep 17 00:00:00 2001 From: "wu@webrtc.org" Date: Thu, 17 Oct 2013 18:28:55 +0000 Subject: [PATCH] Fix tsan failures in channel.cc regarding to the volume settings. BUG=2461 TEST=try bots R=xians@webrtc.org Review URL: https://webrtc-codereview.appspot.com/2377004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@4992 4adac7df-926f-26a2-2b94-8c16560cd09d --- tools/valgrind-webrtc/tsan/suppressions.txt | 47 --------------------- webrtc/voice_engine/channel.cc | 30 ++++++++++--- webrtc/voice_engine/channel.h | 1 + 3 files changed, 25 insertions(+), 53 deletions(-) diff --git a/tools/valgrind-webrtc/tsan/suppressions.txt b/tools/valgrind-webrtc/tsan/suppressions.txt index 7101c017f7..65bb634413 100644 --- a/tools/valgrind-webrtc/tsan/suppressions.txt +++ b/tools/valgrind-webrtc/tsan/suppressions.txt @@ -47,26 +47,6 @@ fun:webrtc::ThreadPosix::Run fun:webrtc::StartThread } -{ - bug_2461_1 - ThreadSanitizer:Race - fun:webrtc::voe::Channel::SetChannelOutputVolumeScaling - fun:webrtc::VoEVolumeControlImpl::SetChannelOutputVolumeScaling - fun:cricket::WebRtcVoiceMediaChannel::SetOutputScaling - fun:cricket::VoiceChannel::SetOutputScaling_w - fun:cricket::VoiceChannel::OnMessage - ... -} -{ - bug_2461_2 - ThreadSanitizer:Race - fun:webrtc::voe::Channel::SetOutputVolumePan - fun:webrtc::VoEVolumeControlImpl::SetOutputVolumePan - fun:cricket::WebRtcVoiceMediaChannel::SetOutputScaling - fun:cricket::VoiceChannel::SetOutputScaling_w - fun:cricket::VoiceChannel::OnMessage - ... -} { bug_2497 ThreadSanitizer:Race @@ -146,16 +126,6 @@ fun:webrtc::ThreadPosix::Run fun:StartThread } -{ - bug_1205_12 - ThreadSanitizer:Race - fun:webrtc::voe::Channel::GetAudioFrame - fun:webrtc::AudioConferenceMixerImpl::UpdateToMix - fun:webrtc::AudioConferenceMixerImpl::Process - fun:webrtc::voe::OutputMixer::MixActiveChannels - fun:webrtc::VoEBaseImpl::NeedMorePlayData - ... -} { bug_1205_22 ThreadSanitizer:Race @@ -164,23 +134,6 @@ fun:webrtc::ThreadPosix::Run fun:StartThread } -{ - bug_1205_25 - ThreadSanitizer:Race - fun:webrtc::AudioCodingModuleImpl::PlayoutData10Ms - fun:webrtc::voe::Channel::GetAudioFrame - fun:webrtc::AudioConferenceMixerImpl::UpdateToMix - fun:webrtc::AudioConferenceMixerImpl::Process - fun:webrtc::voe::OutputMixer::MixActiveChannels - fun:webrtc::VoEBaseImpl::NeedMorePlayData - fun:FakeAudioCaptureModule::ReceiveFrameP - fun:FakeAudioCaptureModule::ProcessFrameP - fun:FakeAudioCaptureModule::OnMessage - fun:talk_base::MessageQueue::Dispatch - fun:talk_base::Thread::ProcessMessages - fun:talk_base::Thread::Run - fun:talk_base::Thread::PreRun -} { bug_1205_26 ThreadSanitizer:Race diff --git a/webrtc/voice_engine/channel.cc b/webrtc/voice_engine/channel.cc index 49a7442ae1..4ef3ed82cc 100644 --- a/webrtc/voice_engine/channel.cc +++ b/webrtc/voice_engine/channel.cc @@ -703,16 +703,26 @@ int32_t Channel::GetAudioFrame(int32_t id, AudioFrame& audioFrame) ApmProcessRx(audioFrame); } - // Output volume scaling - if (_outputGain < 0.99f || _outputGain > 1.01f) + float output_gain = 1.0f; + float left_pan = 1.0f; + float right_pan = 1.0f; { - AudioFrameOperations::ScaleWithSat(_outputGain, audioFrame); + CriticalSectionScoped cs(&volume_settings_critsect_); + output_gain = _outputGain; + left_pan = _panLeft; + right_pan= _panRight; + } + + // Output volume scaling + if (output_gain < 0.99f || output_gain > 1.01f) + { + AudioFrameOperations::ScaleWithSat(output_gain, audioFrame); } // Scale left and/or right channel(s) if stereo and master balance is // active - if (_panLeft != 1.0f || _panRight != 1.0f) + if (left_pan != 1.0f || right_pan != 1.0f) { if (audioFrame.num_channels_ == 1) { @@ -725,7 +735,7 @@ int32_t Channel::GetAudioFrame(int32_t id, AudioFrame& audioFrame) // Do the panning operation (the audio frame contains stereo at this // stage) - AudioFrameOperations::Scale(_panLeft, _panRight, audioFrame); + AudioFrameOperations::Scale(left_pan, right_pan, audioFrame); } // Mix decoded PCM output with file if file mixing is enabled @@ -905,6 +915,7 @@ Channel::Channel(int32_t channelId, const Config& config) : _fileCritSect(*CriticalSectionWrapper::CreateCriticalSection()), _callbackCritSect(*CriticalSectionWrapper::CreateCriticalSection()), + volume_settings_critsect_(*CriticalSectionWrapper::CreateCriticalSection()), _instanceId(instanceId), _channelId(channelId), rtp_header_parser_(RtpHeaderParser::Create()), @@ -1103,6 +1114,7 @@ Channel::~Channel() delete [] _decryptionRTCPBufferPtr; delete &_callbackCritSect; delete &_fileCritSect; + delete &volume_settings_critsect_; } int32_t @@ -2957,6 +2969,7 @@ Channel::GetSpeechOutputLevelFullRange(uint32_t& level) const int Channel::SetMute(bool enable) { + CriticalSectionScoped cs(&volume_settings_critsect_); WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), "Channel::SetMute(enable=%d)", enable); _mute = enable; @@ -2966,12 +2979,14 @@ Channel::SetMute(bool enable) bool Channel::Mute() const { + CriticalSectionScoped cs(&volume_settings_critsect_); return _mute; } int Channel::SetOutputVolumePan(float left, float right) { + CriticalSectionScoped cs(&volume_settings_critsect_); WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), "Channel::SetOutputVolumePan()"); _panLeft = left; @@ -2982,6 +2997,7 @@ Channel::SetOutputVolumePan(float left, float right) int Channel::GetOutputVolumePan(float& left, float& right) const { + CriticalSectionScoped cs(&volume_settings_critsect_); left = _panLeft; right = _panRight; WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, @@ -2993,6 +3009,7 @@ Channel::GetOutputVolumePan(float& left, float& right) const int Channel::SetChannelOutputVolumeScaling(float scaling) { + CriticalSectionScoped cs(&volume_settings_critsect_); WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), "Channel::SetChannelOutputVolumeScaling()"); _outputGain = scaling; @@ -3002,6 +3019,7 @@ Channel::SetChannelOutputVolumeScaling(float scaling) int Channel::GetChannelOutputVolumeScaling(float& scaling) const { + CriticalSectionScoped cs(&volume_settings_critsect_); scaling = _outputGain; WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_instanceId,_channelId), @@ -4397,7 +4415,7 @@ Channel::PrepareEncodeAndSend(int mixingFrequency) MixOrReplaceAudioWithFile(mixingFrequency); } - if (_mute) + if (Mute()) { AudioFrameOperations::Mute(_audioFrame); } diff --git a/webrtc/voice_engine/channel.h b/webrtc/voice_engine/channel.h index 2e5ac5317b..39d36a871b 100644 --- a/webrtc/voice_engine/channel.h +++ b/webrtc/voice_engine/channel.h @@ -447,6 +447,7 @@ private: CriticalSectionWrapper& _fileCritSect; CriticalSectionWrapper& _callbackCritSect; + CriticalSectionWrapper& volume_settings_critsect_; uint32_t _instanceId; int32_t _channelId;