From a4da771914347fdebf4ebb4b1d4008184510442b Mon Sep 17 00:00:00 2001 From: "glaznev@webrtc.org" Date: Mon, 14 Jul 2014 17:01:53 +0000 Subject: [PATCH] Fix deadlock in Android stopCapture() call. BUG=3467 R=braveyao@webrtc.org Review URL: https://webrtc-codereview.appspot.com/18789004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@6673 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../modules/video_capture/android/video_capture_android.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/webrtc/modules/video_capture/android/video_capture_android.cc b/webrtc/modules/video_capture/android/video_capture_android.cc index 6f0200e62..4bc14e5ae 100644 --- a/webrtc/modules/video_capture/android/video_capture_android.cc +++ b/webrtc/modules/video_capture/android/video_capture_android.cc @@ -130,6 +130,8 @@ VideoCaptureModule* VideoCaptureImpl::Create( int32_t VideoCaptureAndroid::OnIncomingFrame(uint8_t* videoFrame, int32_t videoFrameLength, int64_t captureTime) { + if (!_captureStarted) + return 0; return IncomingFrame( videoFrame, videoFrameLength, _captureCapability, captureTime); } @@ -209,13 +211,16 @@ int32_t VideoCaptureAndroid::StartCapture( } int32_t VideoCaptureAndroid::StopCapture() { - CriticalSectionScoped cs(&_apiCs); + _apiCs.Enter(); AttachThreadScoped ats(g_jvm); JNIEnv* env = ats.env(); memset(&_requestedCapability, 0, sizeof(_requestedCapability)); memset(&_captureCapability, 0, sizeof(_captureCapability)); _captureStarted = false; + // Exit critical section to avoid blocking camera thread inside + // onIncomingFrame() call. + _apiCs.Leave(); jmethodID j_stop = env->GetMethodID(g_java_capturer_class, "stopCapture", "()Z");