From 314bc5f8e4075468b0812a547692036541b0e819 Mon Sep 17 00:00:00 2001 From: kthelgason Date: Wed, 31 Aug 2016 10:23:27 -0700 Subject: [PATCH] Add local capturer on mac BUG=webrtc:3417 Review-Url: https://codereview.webrtc.org/2283743003 Cr-Commit-Position: refs/heads/master@{#14004} --- .../examples/objc/AppRTCDemo/ARDAppClient.m | 9 +---- .../objc/AppRTCDemo/mac/APPRTCAppDelegate.m | 4 +-- .../AppRTCDemo/mac/APPRTCViewController.m | 36 ++++++++++++------- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/webrtc/examples/objc/AppRTCDemo/ARDAppClient.m b/webrtc/examples/objc/AppRTCDemo/ARDAppClient.m index 9f61951670..1020621cc1 100644 --- a/webrtc/examples/objc/AppRTCDemo/ARDAppClient.m +++ b/webrtc/examples/objc/AppRTCDemo/ARDAppClient.m @@ -10,9 +10,7 @@ #import "ARDAppClient+Internal.h" -#if defined(WEBRTC_IOS) #import "WebRTC/RTCAVFoundationVideoSource.h" -#endif #import "WebRTC/RTCAudioTrack.h" #import "WebRTC/RTCConfiguration.h" #import "WebRTC/RTCFileLogger.h" @@ -53,14 +51,11 @@ static NSString * const kARDMediaStreamId = @"ARDAMS"; static NSString * const kARDAudioTrackId = @"ARDAMSa0"; static NSString * const kARDVideoTrackId = @"ARDAMSv0"; -// TODO(tkchin): Remove guard once rtc_sdk_common_objc compiles on Mac. -#if defined(WEBRTC_IOS) // TODO(tkchin): Add these as UI options. static BOOL const kARDAppClientEnableTracing = NO; static BOOL const kARDAppClientEnableRtcEventLog = YES; static int64_t const kARDAppClientAecDumpMaxSizeInBytes = 5e6; // 5 MB. static int64_t const kARDAppClientRtcEventLogMaxSizeInBytes = 5e6; // 5 MB. -#endif // We need a proxy to NSTimer because it causes a strong retain cycle. When // using the proxy, |invalidate| must be called before it properly deallocs. @@ -698,9 +693,7 @@ static int64_t const kARDAppClientRtcEventLogMaxSizeInBytes = 5e6; // 5 MB. // The iOS simulator doesn't provide any sort of camera capture // support or emulation (http://goo.gl/rHAnC1) so don't bother // trying to open a local stream. - // TODO(tkchin): local video capture for OSX. See - // https://code.google.com/p/webrtc/issues/detail?id=3417. -#if !TARGET_IPHONE_SIMULATOR && TARGET_OS_IPHONE +#if !TARGET_IPHONE_SIMULATOR if (!_isAudioOnly) { RTCMediaConstraints *mediaConstraints = [self defaultMediaStreamConstraints]; diff --git a/webrtc/examples/objc/AppRTCDemo/mac/APPRTCAppDelegate.m b/webrtc/examples/objc/AppRTCDemo/mac/APPRTCAppDelegate.m index e79519acc2..20e6c274c1 100644 --- a/webrtc/examples/objc/AppRTCDemo/mac/APPRTCAppDelegate.m +++ b/webrtc/examples/objc/AppRTCDemo/mac/APPRTCAppDelegate.m @@ -13,10 +13,8 @@ #endif #import "APPRTCAppDelegate.h" - -#import "WebRTC/RTCSSLAdapter.h" - #import "APPRTCViewController.h" +#import "WebRTC/RTCSSLAdapter.h" @interface APPRTCAppDelegate () @end diff --git a/webrtc/examples/objc/AppRTCDemo/mac/APPRTCViewController.m b/webrtc/examples/objc/AppRTCDemo/mac/APPRTCViewController.m index 0f5bc386d7..710b8a5ea4 100644 --- a/webrtc/examples/objc/AppRTCDemo/mac/APPRTCViewController.m +++ b/webrtc/examples/objc/AppRTCDemo/mac/APPRTCViewController.m @@ -21,6 +21,7 @@ static NSUInteger const kContentWidth = 1280; static NSUInteger const kContentHeight = 720; static NSUInteger const kRoomFieldWidth = 80; static NSUInteger const kLogViewHeight = 280; +static NSUInteger const kPreviewWidth = 490; @class APPRTCMainView; @protocol APPRTCMainViewDelegate @@ -74,14 +75,18 @@ static NSUInteger const kLogViewHeight = 280; NSDictionaryOfVariableBindings(_roomLabel, _roomField, _scrollView, - _remoteVideoView); + _remoteVideoView, + _localVideoView); NSSize remoteViewSize = [self remoteVideoViewSize]; NSDictionary* metrics = @{ @"kLogViewHeight" : @(kLogViewHeight), + @"kPreviewWidth" : @(kPreviewWidth), @"kRoomFieldWidth" : @(kRoomFieldWidth), @"remoteViewWidth" : @(remoteViewSize.width), @"remoteViewHeight" : @(remoteViewSize.height), + @"localViewHeight" : @(remoteViewSize.height), + @"scrollViewWidth" : @(kContentWidth - kPreviewWidth), }; // Declare this separately to avoid compiler warning about splitting string // within an NSArray expression. @@ -90,10 +95,14 @@ static NSUInteger const kLogViewHeight = 280; "-[_remoteVideoView(remoteViewHeight)]-|"; NSArray* constraintFormats = @[ verticalConstraint, + @"V:[_localVideoView]-[_remoteVideoView]", + @"V:[_localVideoView(kLogViewHeight)]", @"|-[_roomLabel]", @"|-[_roomField(kRoomFieldWidth)]", - @"|-[_scrollView(remoteViewWidth)]-|", + @"|-[_scrollView(scrollViewWidth)]", + @"[_scrollView]-[_localVideoView]", @"|-[_remoteVideoView(remoteViewWidth)]-|", + @"[_localVideoView(kPreviewWidth)]-|", ]; for (NSString* constraintFormat in constraintFormats) { NSArray* constraints = @@ -190,20 +199,17 @@ static NSUInteger const kLogViewHeight = 280; _remoteVideoView.delegate = self; [self addSubview:_remoteVideoView]; - // TODO(tkchin): create local video view. - // https://code.google.com/p/webrtc/issues/detail?id=3417. + _localVideoView = [[RTCNSGLVideoView alloc] initWithFrame:NSZeroRect + pixelFormat:pixelFormat]; + [_localVideoView setTranslatesAutoresizingMaskIntoConstraints:NO]; + _localVideoView.delegate = self; + [self addSubview:_localVideoView]; } - (NSSize)remoteVideoViewSize { - if (_remoteVideoSize.width > 0 && _remoteVideoSize.height > 0) { - return _remoteVideoSize; - } else { - return NSMakeSize(kContentWidth, kContentHeight); - } -} - -- (NSSize)localVideoViewSize { - return NSZeroSize; + NSInteger width = MAX(_remoteVideoSize.width, kContentWidth); + NSInteger height = (width/16) * 9; + return NSMakeSize(width, height); } @end @@ -260,6 +266,7 @@ static NSUInteger const kLogViewHeight = 280; - (void)appClient:(ARDAppClient *)client didReceiveLocalVideoTrack:(RTCVideoTrack *)localVideoTrack { _localVideoTrack = localVideoTrack; + [_localVideoTrack addRenderer:self.mainView.localVideoView]; } - (void)appClient:(ARDAppClient *)client @@ -306,8 +313,11 @@ static NSUInteger const kLogViewHeight = 280; - (void)resetUI { [_remoteVideoTrack removeRenderer:self.mainView.remoteVideoView]; + [_localVideoTrack removeRenderer:self.mainView.localVideoView]; _remoteVideoTrack = nil; + _localVideoTrack = nil; [self.mainView.remoteVideoView renderFrame:nil]; + [self.mainView.localVideoView renderFrame:nil]; } - (void)disconnect {