Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(362)

Side by Side Diff: webrtc/examples/objc/AppRTCDemo/mac/APPRTCViewController.m

Issue 2283743003: Add local capturer on mac (Closed)
Patch Set: rebase to master Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/examples/objc/AppRTCDemo/mac/APPRTCAppDelegate.m ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2014 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #import "APPRTCViewController.h" 11 #import "APPRTCViewController.h"
12 12
13 #import <AVFoundation/AVFoundation.h> 13 #import <AVFoundation/AVFoundation.h>
14 14
15 #import "WebRTC/RTCNSGLVideoView.h" 15 #import "WebRTC/RTCNSGLVideoView.h"
16 #import "WebRTC/RTCVideoTrack.h" 16 #import "WebRTC/RTCVideoTrack.h"
17 17
18 #import "ARDAppClient.h" 18 #import "ARDAppClient.h"
19 19
20 static NSUInteger const kContentWidth = 1280; 20 static NSUInteger const kContentWidth = 1280;
21 static NSUInteger const kContentHeight = 720; 21 static NSUInteger const kContentHeight = 720;
22 static NSUInteger const kRoomFieldWidth = 80; 22 static NSUInteger const kRoomFieldWidth = 80;
23 static NSUInteger const kLogViewHeight = 280; 23 static NSUInteger const kLogViewHeight = 280;
24 static NSUInteger const kPreviewWidth = 490;
24 25
25 @class APPRTCMainView; 26 @class APPRTCMainView;
26 @protocol APPRTCMainViewDelegate 27 @protocol APPRTCMainViewDelegate
27 28
28 - (void)appRTCMainView:(APPRTCMainView*)mainView 29 - (void)appRTCMainView:(APPRTCMainView*)mainView
29 didEnterRoomId:(NSString*)roomId; 30 didEnterRoomId:(NSString*)roomId;
30 31
31 @end 32 @end
32 33
33 @interface APPRTCMainView : NSView 34 @interface APPRTCMainView : NSView
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 } 68 }
68 69
69 - (void)updateConstraints { 70 - (void)updateConstraints {
70 NSParameterAssert( 71 NSParameterAssert(
71 _roomField != nil && _scrollView != nil && _remoteVideoView != nil); 72 _roomField != nil && _scrollView != nil && _remoteVideoView != nil);
72 [self removeConstraints:[self constraints]]; 73 [self removeConstraints:[self constraints]];
73 NSDictionary* viewsDictionary = 74 NSDictionary* viewsDictionary =
74 NSDictionaryOfVariableBindings(_roomLabel, 75 NSDictionaryOfVariableBindings(_roomLabel,
75 _roomField, 76 _roomField,
76 _scrollView, 77 _scrollView,
77 _remoteVideoView); 78 _remoteVideoView,
79 _localVideoView);
78 80
79 NSSize remoteViewSize = [self remoteVideoViewSize]; 81 NSSize remoteViewSize = [self remoteVideoViewSize];
80 NSDictionary* metrics = @{ 82 NSDictionary* metrics = @{
81 @"kLogViewHeight" : @(kLogViewHeight), 83 @"kLogViewHeight" : @(kLogViewHeight),
84 @"kPreviewWidth" : @(kPreviewWidth),
82 @"kRoomFieldWidth" : @(kRoomFieldWidth), 85 @"kRoomFieldWidth" : @(kRoomFieldWidth),
83 @"remoteViewWidth" : @(remoteViewSize.width), 86 @"remoteViewWidth" : @(remoteViewSize.width),
84 @"remoteViewHeight" : @(remoteViewSize.height), 87 @"remoteViewHeight" : @(remoteViewSize.height),
88 @"localViewHeight" : @(remoteViewSize.height),
89 @"scrollViewWidth" : @(kContentWidth - kPreviewWidth),
85 }; 90 };
86 // Declare this separately to avoid compiler warning about splitting string 91 // Declare this separately to avoid compiler warning about splitting string
87 // within an NSArray expression. 92 // within an NSArray expression.
88 NSString* verticalConstraint = 93 NSString* verticalConstraint =
89 @"V:|-[_roomLabel]-[_roomField]-[_scrollView(kLogViewHeight)]" 94 @"V:|-[_roomLabel]-[_roomField]-[_scrollView(kLogViewHeight)]"
90 "-[_remoteVideoView(remoteViewHeight)]-|"; 95 "-[_remoteVideoView(remoteViewHeight)]-|";
91 NSArray* constraintFormats = @[ 96 NSArray* constraintFormats = @[
92 verticalConstraint, 97 verticalConstraint,
98 @"V:[_localVideoView]-[_remoteVideoView]",
99 @"V:[_localVideoView(kLogViewHeight)]",
93 @"|-[_roomLabel]", 100 @"|-[_roomLabel]",
94 @"|-[_roomField(kRoomFieldWidth)]", 101 @"|-[_roomField(kRoomFieldWidth)]",
95 @"|-[_scrollView(remoteViewWidth)]-|", 102 @"|-[_scrollView(scrollViewWidth)]",
103 @"[_scrollView]-[_localVideoView]",
96 @"|-[_remoteVideoView(remoteViewWidth)]-|", 104 @"|-[_remoteVideoView(remoteViewWidth)]-|",
105 @"[_localVideoView(kPreviewWidth)]-|",
97 ]; 106 ];
98 for (NSString* constraintFormat in constraintFormats) { 107 for (NSString* constraintFormat in constraintFormats) {
99 NSArray* constraints = 108 NSArray* constraints =
100 [NSLayoutConstraint constraintsWithVisualFormat:constraintFormat 109 [NSLayoutConstraint constraintsWithVisualFormat:constraintFormat
101 options:0 110 options:0
102 metrics:metrics 111 metrics:metrics
103 views:viewsDictionary]; 112 views:viewsDictionary];
104 for (NSLayoutConstraint* constraint in constraints) { 113 for (NSLayoutConstraint* constraint in constraints) {
105 [self addConstraint:constraint]; 114 [self addConstraint:constraint];
106 } 115 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 0 192 0
184 }; 193 };
185 NSOpenGLPixelFormat* pixelFormat = 194 NSOpenGLPixelFormat* pixelFormat =
186 [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes]; 195 [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
187 _remoteVideoView = [[RTCNSGLVideoView alloc] initWithFrame:NSZeroRect 196 _remoteVideoView = [[RTCNSGLVideoView alloc] initWithFrame:NSZeroRect
188 pixelFormat:pixelFormat]; 197 pixelFormat:pixelFormat];
189 [_remoteVideoView setTranslatesAutoresizingMaskIntoConstraints:NO]; 198 [_remoteVideoView setTranslatesAutoresizingMaskIntoConstraints:NO];
190 _remoteVideoView.delegate = self; 199 _remoteVideoView.delegate = self;
191 [self addSubview:_remoteVideoView]; 200 [self addSubview:_remoteVideoView];
192 201
193 // TODO(tkchin): create local video view. 202 _localVideoView = [[RTCNSGLVideoView alloc] initWithFrame:NSZeroRect
194 // https://code.google.com/p/webrtc/issues/detail?id=3417. 203 pixelFormat:pixelFormat];
204 [_localVideoView setTranslatesAutoresizingMaskIntoConstraints:NO];
205 _localVideoView.delegate = self;
206 [self addSubview:_localVideoView];
195 } 207 }
196 208
197 - (NSSize)remoteVideoViewSize { 209 - (NSSize)remoteVideoViewSize {
198 if (_remoteVideoSize.width > 0 && _remoteVideoSize.height > 0) { 210 NSInteger width = MAX(_remoteVideoSize.width, kContentWidth);
199 return _remoteVideoSize; 211 NSInteger height = (width/16) * 9;
200 } else { 212 return NSMakeSize(width, height);
201 return NSMakeSize(kContentWidth, kContentHeight);
202 }
203 }
204
205 - (NSSize)localVideoViewSize {
206 return NSZeroSize;
207 } 213 }
208 214
209 @end 215 @end
210 216
211 @interface APPRTCViewController () 217 @interface APPRTCViewController ()
212 <ARDAppClientDelegate, APPRTCMainViewDelegate> 218 <ARDAppClientDelegate, APPRTCMainViewDelegate>
213 @property(nonatomic, readonly) APPRTCMainView* mainView; 219 @property(nonatomic, readonly) APPRTCMainView* mainView;
214 @end 220 @end
215 221
216 @implementation APPRTCViewController { 222 @implementation APPRTCViewController {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 } 259 }
254 } 260 }
255 261
256 - (void)appClient:(ARDAppClient *)client 262 - (void)appClient:(ARDAppClient *)client
257 didChangeConnectionState:(RTCIceConnectionState)state { 263 didChangeConnectionState:(RTCIceConnectionState)state {
258 } 264 }
259 265
260 - (void)appClient:(ARDAppClient *)client 266 - (void)appClient:(ARDAppClient *)client
261 didReceiveLocalVideoTrack:(RTCVideoTrack *)localVideoTrack { 267 didReceiveLocalVideoTrack:(RTCVideoTrack *)localVideoTrack {
262 _localVideoTrack = localVideoTrack; 268 _localVideoTrack = localVideoTrack;
269 [_localVideoTrack addRenderer:self.mainView.localVideoView];
263 } 270 }
264 271
265 - (void)appClient:(ARDAppClient *)client 272 - (void)appClient:(ARDAppClient *)client
266 didReceiveRemoteVideoTrack:(RTCVideoTrack *)remoteVideoTrack { 273 didReceiveRemoteVideoTrack:(RTCVideoTrack *)remoteVideoTrack {
267 _remoteVideoTrack = remoteVideoTrack; 274 _remoteVideoTrack = remoteVideoTrack;
268 [_remoteVideoTrack addRenderer:self.mainView.remoteVideoView]; 275 [_remoteVideoTrack addRenderer:self.mainView.remoteVideoView];
269 } 276 }
270 277
271 - (void)appClient:(ARDAppClient *)client 278 - (void)appClient:(ARDAppClient *)client
272 didError:(NSError *)error { 279 didError:(NSError *)error {
(...skipping 26 matching lines...) Expand all
299 } 306 }
300 307
301 - (void)showAlertWithMessage:(NSString*)message { 308 - (void)showAlertWithMessage:(NSString*)message {
302 NSAlert* alert = [[NSAlert alloc] init]; 309 NSAlert* alert = [[NSAlert alloc] init];
303 [alert setMessageText:message]; 310 [alert setMessageText:message];
304 [alert runModal]; 311 [alert runModal];
305 } 312 }
306 313
307 - (void)resetUI { 314 - (void)resetUI {
308 [_remoteVideoTrack removeRenderer:self.mainView.remoteVideoView]; 315 [_remoteVideoTrack removeRenderer:self.mainView.remoteVideoView];
316 [_localVideoTrack removeRenderer:self.mainView.localVideoView];
309 _remoteVideoTrack = nil; 317 _remoteVideoTrack = nil;
318 _localVideoTrack = nil;
310 [self.mainView.remoteVideoView renderFrame:nil]; 319 [self.mainView.remoteVideoView renderFrame:nil];
320 [self.mainView.localVideoView renderFrame:nil];
311 } 321 }
312 322
313 - (void)disconnect { 323 - (void)disconnect {
314 [self resetUI]; 324 [self resetUI];
315 [_client disconnect]; 325 [_client disconnect];
316 } 326 }
317 327
318 @end 328 @end
OLDNEW
« no previous file with comments | « webrtc/examples/objc/AppRTCDemo/mac/APPRTCAppDelegate.m ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698