From c14b728b71278ea4c83e09be0a973be0f31ed707 Mon Sep 17 00:00:00 2001 From: "braveyao@webrtc.org" Date: Thu, 18 Apr 2013 09:32:07 +0000 Subject: [PATCH] Add lock to prevent possible rare race condition in Win coreAudio capture implementation. BUG = TEST = voe_auto_test Review URL: https://webrtc-codereview.appspot.com/1320011 git-svn-id: http://webrtc.googlecode.com/svn/trunk@3868 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../audio_device/win/audio_device_core_win.cc | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/webrtc/modules/audio_device/win/audio_device_core_win.cc b/webrtc/modules/audio_device/win/audio_device_core_win.cc index 0d4c60d51..d5174789c 100644 --- a/webrtc/modules/audio_device/win/audio_device_core_win.cc +++ b/webrtc/modules/audio_device/win/audio_device_core_win.cc @@ -3677,8 +3677,8 @@ Exit: if (FAILED(hr)) { - _UnLock(); _ptrClientOut->Stop(); + _UnLock(); _TraceCOMError(hr); } @@ -3690,19 +3690,23 @@ Exit: } } + _Lock(); + if (keepPlaying) { - hr = _ptrClientOut->Stop(); - if (FAILED(hr)) + if (_ptrClientOut != NULL) { - _TraceCOMError(hr); + hr = _ptrClientOut->Stop(); + if (FAILED(hr)) + { + _TraceCOMError(hr); + } + hr = _ptrClientOut->Reset(); + if (FAILED(hr)) + { + _TraceCOMError(hr); + } } - hr = _ptrClientOut->Reset(); - if (FAILED(hr)) - { - _TraceCOMError(hr); - } - // Trigger callback from module process thread _playError = 1; WEBRTC_TRACE(kTraceError, kTraceUtility, _id, "kPlayoutError message posted: rendering thread has ended pre-maturely"); @@ -3712,6 +3716,8 @@ Exit: WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "_Rendering thread is now terminated properly"); } + _UnLock(); + return (DWORD)hr; } @@ -4177,13 +4183,15 @@ DWORD AudioDeviceWindowsCore::DoCaptureThread() Exit: if (FAILED(hr)) { - _UnLock(); _ptrClientIn->Stop(); + _UnLock(); _TraceCOMError(hr); } RevertCaptureThreadPriority(); + _Lock(); + if (keepRecording) { if (_ptrClientIn != NULL) @@ -4212,6 +4220,8 @@ Exit: SAFE_RELEASE(_ptrClientIn); SAFE_RELEASE(_ptrCaptureClient); + _UnLock(); + if (syncBuffer) { delete [] syncBuffer;