From 47183ba60bddfcdd1494d88f3c1fefc62eb9445b Mon Sep 17 00:00:00 2001 From: Per Date: Fri, 3 Jun 2016 13:05:18 +0200 Subject: [PATCH] Handle Android stop capturer race. With the current order of stop capture processing on Android, OnMemoryBufferFrame and OnTextureFrame may be called halfway through Stop(). They must therefore check for the case of a null capturer_. There used to be such checks, but they were accidantally removed in commit #12895, cl https://codereview.webrtc.org/1973873003. BUG=webrtc:5966 R=perkj@webrtc.org, sakal@webrtc.org Review URL: https://codereview.webrtc.org/2033943004 . Cr-Commit-Position: refs/heads/master@{#13031} --- webrtc/api/java/jni/androidvideocapturer_jni.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/webrtc/api/java/jni/androidvideocapturer_jni.cc b/webrtc/api/java/jni/androidvideocapturer_jni.cc index 0abc9c0d51..3ebf3464fb 100644 --- a/webrtc/api/java/jni/androidvideocapturer_jni.cc +++ b/webrtc/api/java/jni/androidvideocapturer_jni.cc @@ -89,6 +89,10 @@ void AndroidVideoCapturerJni::Stop() { LOG(LS_INFO) << "AndroidVideoCapturerJni stop"; RTC_DCHECK(thread_checker_.CalledOnValidThread()); { + // TODO(nisse): Consider moving this block until *after* the call to + // stopCapturer. stopCapturer should ensure that we get no + // more frames, and then we shouldn't need the if (!capturer_) + // checks in OnMemoryBufferFrame and OnTextureFrame. rtc::CritScope cs(&capturer_lock_); // Destroying |invoker_| will cancel all pending calls to |capturer_|. invoker_ = nullptr; @@ -172,7 +176,10 @@ void AndroidVideoCapturerJni::OnMemoryBufferFrame(void* video_frame, RTC_DCHECK(rotation == 0 || rotation == 90 || rotation == 180 || rotation == 270); rtc::CritScope cs(&capturer_lock_); - + if (!capturer_) { + LOG(LS_WARNING) << "OnMemoryBufferFrame() called for closed capturer."; + return; + } int adapted_width; int adapted_height; int crop_width; @@ -252,7 +259,10 @@ void AndroidVideoCapturerJni::OnTextureFrame(int width, RTC_DCHECK(rotation == 0 || rotation == 90 || rotation == 180 || rotation == 270); rtc::CritScope cs(&capturer_lock_); - + if (!capturer_) { + LOG(LS_WARNING) << "OnTextureFrame() called for closed capturer."; + return; + } int adapted_width; int adapted_height; int crop_width;