From 9932e255eae9fbb3cc31aae34b04d4564934c474 Mon Sep 17 00:00:00 2001 From: Magnus Jedvert Date: Wed, 7 Jun 2017 16:31:06 +0200 Subject: [PATCH] ObjC: Marshal all VideoTrackSource methods to the signaling thread This CL makes sure the real VideoTrackSourceInterface implementation is destroyed on the signaling thread and marshals all method calls to the signaling thread. This is done using VideoTrackSourceProxy. Bug: webrtc:7767 Change-Id: Iba3b67bb32a684ba289bc8b9981585ea58084359 Reviewed-on: https://chromium-review.googlesource.com/526634 Commit-Queue: Magnus Jedvert Reviewed-by: Niels Moller Cr-Commit-Position: refs/heads/master@{#18476} --- .../PeerConnection/RTCPeerConnectionFactory.mm | 6 +++++- .../Classes/PeerConnection/RTCVideoSource.mm | 13 ++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/webrtc/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactory.mm b/webrtc/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactory.mm index 72a97ea48c..a883587af2 100644 --- a/webrtc/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactory.mm +++ b/webrtc/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactory.mm @@ -23,6 +23,7 @@ #include "Video/objcvideotracksource.h" #include "VideoToolbox/videocodecfactory.h" +#include "webrtc/api/videosourceproxy.h" @implementation RTCPeerConnectionFactory { std::unique_ptr _networkThread; @@ -91,7 +92,10 @@ - (RTCVideoSource *)videoSource { rtc::scoped_refptr objcVideoTrackSource( new rtc::RefCountedObject()); - return [[RTCVideoSource alloc] initWithNativeVideoSource:objcVideoTrackSource]; + return [[RTCVideoSource alloc] + initWithNativeVideoSource:webrtc::VideoTrackSourceProxy::Create(_signalingThread.get(), + _workerThread.get(), + objcVideoTrackSource)]; } - (RTCVideoTrack *)videoTrackWithSource:(RTCVideoSource *)source diff --git a/webrtc/sdk/objc/Framework/Classes/PeerConnection/RTCVideoSource.mm b/webrtc/sdk/objc/Framework/Classes/PeerConnection/RTCVideoSource.mm index ef95e65ce1..cdc77b343b 100644 --- a/webrtc/sdk/objc/Framework/Classes/PeerConnection/RTCVideoSource.mm +++ b/webrtc/sdk/objc/Framework/Classes/PeerConnection/RTCVideoSource.mm @@ -10,9 +10,17 @@ #import "RTCVideoSource+Private.h" +#include "webrtc/api/videosourceproxy.h" #include "webrtc/base/checks.h" #include "webrtc/sdk/objc/Framework/Classes/Video/objcvideotracksource.h" +static webrtc::ObjcVideoTrackSource *getObjcVideoSource( + const rtc::scoped_refptr nativeSource) { + webrtc::VideoTrackSourceProxy *proxy_source = + static_cast(nativeSource.get()); + return static_cast(proxy_source->internal()); +} + // TODO(magjed): Refactor this class and target ObjcVideoTrackSource only once // RTCAVFoundationVideoSource is gone. See http://crbug/webrtc/7177 for more // info. @@ -43,12 +51,11 @@ } - (void)capturer:(RTCVideoCapturer *)capturer didCaptureVideoFrame:(RTCVideoFrame *)frame { - static_cast(_nativeVideoSource.get())->OnCapturedFrame(frame); + getObjcVideoSource(_nativeVideoSource)->OnCapturedFrame(frame); } - (void)adaptOutputFormatToWidth:(int)width height:(int)height fps:(int)fps { - static_cast(_nativeVideoSource.get()) - ->OnOutputFormatRequest(width, height, fps); + getObjcVideoSource(_nativeVideoSource)->OnOutputFormatRequest(width, height, fps); } #pragma mark - Private