diff options
author | xians@chromium.org <xians@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-12 11:03:24 +0000 |
---|---|---|
committer | xians@chromium.org <xians@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-12 11:03:24 +0000 |
commit | 03711d7e937a4cc7d2c0d8fc5f4dc21981dc43b3 (patch) | |
tree | 01d304d8c0ef40823773461590edc9301342dca2 /content/renderer/media | |
parent | cf5813ec2376946cbf7389ae2ce3d86d063b3c03 (diff) | |
download | chromium_src-03711d7e937a4cc7d2c0d8fc5f4dc21981dc43b3.zip chromium_src-03711d7e937a4cc7d2c0d8fc5f4dc21981dc43b3.tar.gz chromium_src-03711d7e937a4cc7d2c0d8fc5f4dc21981dc43b3.tar.bz2 |
remove the race related to output_delay_ms_ in ADM and races in the unittests.
Review URL: http://codereview.chromium.org/8799011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114002 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/renderer/media')
-rw-r--r-- | content/renderer/media/webrtc_audio_device_impl.cc | 33 | ||||
-rw-r--r-- | content/renderer/media/webrtc_audio_device_impl.h | 4 | ||||
-rw-r--r-- | content/renderer/media/webrtc_audio_device_unittest.cc | 31 |
3 files changed, 52 insertions, 16 deletions
diff --git a/content/renderer/media/webrtc_audio_device_impl.cc b/content/renderer/media/webrtc_audio_device_impl.cc index 1039fd2..8e5b307 100644 --- a/content/renderer/media/webrtc_audio_device_impl.cc +++ b/content/renderer/media/webrtc_audio_device_impl.cc @@ -65,8 +65,11 @@ void WebRtcAudioDeviceImpl::Render( size_t audio_delay_milliseconds) { DCHECK_LE(number_of_frames, output_buffer_size_); - // Store the reported audio delay locally. - output_delay_ms_ = audio_delay_milliseconds; + { + base::AutoLock auto_lock(lock_); + // Store the reported audio delay locally. + output_delay_ms_ = audio_delay_milliseconds; + } const int channels = audio_data.size(); DCHECK_LE(channels, output_channels_); @@ -119,8 +122,13 @@ void WebRtcAudioDeviceImpl::Capture( size_t audio_delay_milliseconds) { DCHECK_LE(number_of_frames, input_buffer_size_); - // Store the reported audio delay locally. - input_delay_ms_ = audio_delay_milliseconds; + int output_delay_ms = 0; + { + base::AutoLock auto_lock(lock_); + // Store the reported audio delay locally. + input_delay_ms_ = audio_delay_milliseconds; + output_delay_ms = output_delay_ms_; + } const int channels = audio_data.size(); DCHECK_LE(channels, input_channels_); @@ -156,7 +164,7 @@ void WebRtcAudioDeviceImpl::Capture( bytes_per_sample_, channels, samples_per_sec, - input_delay_ms_ + output_delay_ms_, + input_delay_ms_ + output_delay_ms, 0, // clock_drift 0, // current_mic_level new_mic_level); // not used @@ -642,12 +650,17 @@ int32_t WebRtcAudioDeviceImpl::StopRecording() { DVLOG(1) << "StopRecording()"; DCHECK(audio_input_device_); - base::AutoLock auto_lock(lock_); - if (!recording_) { - // webrtc::VoiceEngine assumes that it is OK to call Stop() just in case. - return 0; + { + base::AutoLock auto_lock(lock_); + if (!recording_) { + // webrtc::VoiceEngine assumes that it is OK to call Stop() just in case. + return 0; + } } + audio_input_device_->Stop(); + + base::AutoLock auto_lock(lock_); recording_ = false; return 0; } @@ -890,12 +903,14 @@ int32_t WebRtcAudioDeviceImpl::PlayoutBuffer(BufferType* type, int32_t WebRtcAudioDeviceImpl::PlayoutDelay(uint16_t* delay_ms) const { // Report the cached output delay value. + base::AutoLock auto_lock(lock_); *delay_ms = static_cast<uint16_t>(output_delay_ms_); return 0; } int32_t WebRtcAudioDeviceImpl::RecordingDelay(uint16_t* delay_ms) const { // Report the cached output delay value. + base::AutoLock auto_lock(lock_); *delay_ms = static_cast<uint16_t>(input_delay_ms_); return 0; } diff --git a/content/renderer/media/webrtc_audio_device_impl.h b/content/renderer/media/webrtc_audio_device_impl.h index fac2024..cad0bf0 100644 --- a/content/renderer/media/webrtc_audio_device_impl.h +++ b/content/renderer/media/webrtc_audio_device_impl.h @@ -321,8 +321,8 @@ class CONTENT_EXPORT WebRtcAudioDeviceImpl // on the input/capture side. int session_id_; - // Protects |recording_|. - base::Lock lock_; + // Protects |recording_|, |output_delay_ms_|, |input_delay_ms_|. + mutable base::Lock lock_; int bytes_per_sample_; diff --git a/content/renderer/media/webrtc_audio_device_unittest.cc b/content/renderer/media/webrtc_audio_device_unittest.cc index 8a7f498..bd11fb8 100644 --- a/content/renderer/media/webrtc_audio_device_unittest.cc +++ b/content/renderer/media/webrtc_audio_device_unittest.cc @@ -107,6 +107,7 @@ class WebRTCMediaProcessImpl : public webrtc::VoEMediaProcess { const int length, const int sampling_freq, const bool is_stereo) { + base::AutoLock auto_lock(lock_); channel_id_ = channel; type_ = type; packet_size_ = length; @@ -118,11 +119,30 @@ class WebRTCMediaProcessImpl : public webrtc::VoEMediaProcess { } } - int channel_id() const { return channel_id_; } - int type() const { return type_; } - int packet_size() const { return packet_size_; } - int sample_rate() const { return sample_rate_; } - int channels() const { return channels_; } + int channel_id() const { + base::AutoLock auto_lock(lock_); + return channel_id_; + } + + int type() const { + base::AutoLock auto_lock(lock_); + return type_; + } + + int packet_size() const { + base::AutoLock auto_lock(lock_); + return packet_size_; + } + + int sample_rate() const { + base::AutoLock auto_lock(lock_); + return sample_rate_; + } + + int channels() const { + base::AutoLock auto_lock(lock_); + return channels_; + } private: base::WaitableEvent* event_; @@ -131,6 +151,7 @@ class WebRTCMediaProcessImpl : public webrtc::VoEMediaProcess { int packet_size_; int sample_rate_; int channels_; + mutable base::Lock lock_; DISALLOW_COPY_AND_ASSIGN(WebRTCMediaProcessImpl); }; |