From c82d0902e1f1e902223df3452f9a2a3b7fdb71f4 Mon Sep 17 00:00:00 2001 From: nisse Date: Mon, 23 May 2016 00:39:35 -0700 Subject: [PATCH] Don't do a thread jump for incoming frames. We're now supposed to accept incoming frames from any thread. BUG=webrtc:5902 Review-Url: https://codereview.webrtc.org/1987663002 Cr-Commit-Position: refs/heads/master@{#12844} --- webrtc/api/androidvideocapturer.cc | 5 ++++- .../api/java/jni/androidvideocapturer_jni.cc | 19 +++++++++++++------ webrtc/media/base/videobroadcaster.cc | 1 - 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/webrtc/api/androidvideocapturer.cc b/webrtc/api/androidvideocapturer.cc index 71a94fedb0..ae81a8dafa 100644 --- a/webrtc/api/androidvideocapturer.cc +++ b/webrtc/api/androidvideocapturer.cc @@ -180,7 +180,10 @@ void AndroidVideoCapturer::OnIncomingFrame( const rtc::scoped_refptr& buffer, int rotation, int64_t time_stamp) { - RTC_CHECK(thread_checker_.CalledOnValidThread()); + // NOTE: The frame_factory hack isn't thread safe. It works because + // all calls to this method are from the same Java thread. In + // addition, calls are currently syncronized on the caller's + // AndroidVideoCapturerJni:capturer_lock_. frame_factory_->UpdateCapturedFrame(buffer, rotation, time_stamp); SignalFrameCaptured(this, frame_factory_->GetCapturedFrame()); frame_factory_->ClearCapturedFrame(); diff --git a/webrtc/api/java/jni/androidvideocapturer_jni.cc b/webrtc/api/java/jni/androidvideocapturer_jni.cc index 615fcb32d8..5b4a92c6e8 100644 --- a/webrtc/api/java/jni/androidvideocapturer_jni.cc +++ b/webrtc/api/java/jni/androidvideocapturer_jni.cc @@ -181,9 +181,13 @@ void AndroidVideoCapturerJni::OnMemoryBufferFrame(void* video_frame, buffer->MutableData(webrtc::kUPlane), buffer->stride(webrtc::kUPlane), buffer->MutableData(webrtc::kVPlane), buffer->stride(webrtc::kVPlane), width, height); - AsyncCapturerInvoke("OnIncomingFrame", - &webrtc::AndroidVideoCapturer::OnIncomingFrame, - buffer, rotation, timestamp_ns); + + rtc::CritScope cs(&capturer_lock_); + if (!capturer_) { + LOG(LS_WARNING) << "OnMemoryBufferFrame() called for closed capturer."; + return; + } + capturer_->OnIncomingFrame(buffer, rotation, timestamp_ns); } void AndroidVideoCapturerJni::OnTextureFrame(int width, @@ -194,9 +198,12 @@ void AndroidVideoCapturerJni::OnTextureFrame(int width, rtc::scoped_refptr buffer( surface_texture_helper_->CreateTextureFrame(width, height, handle)); - AsyncCapturerInvoke("OnIncomingFrame", - &webrtc::AndroidVideoCapturer::OnIncomingFrame, - buffer, rotation, timestamp_ns); + rtc::CritScope cs(&capturer_lock_); + if (!capturer_) { + LOG(LS_WARNING) << "OnTextureFrame() called for closed capturer."; + return; + } + capturer_->OnIncomingFrame(buffer, rotation, timestamp_ns); } void AndroidVideoCapturerJni::OnOutputFormatRequest(int width, diff --git a/webrtc/media/base/videobroadcaster.cc b/webrtc/media/base/videobroadcaster.cc index 18c38b731d..20e8c976c7 100644 --- a/webrtc/media/base/videobroadcaster.cc +++ b/webrtc/media/base/videobroadcaster.cc @@ -40,7 +40,6 @@ void VideoBroadcaster::RemoveSink( } bool VideoBroadcaster::frame_wanted() const { - RTC_DCHECK(thread_checker_.CalledOnValidThread()); rtc::CritScope cs(&sinks_and_wants_lock_); return !sink_pairs().empty(); }