| OLD | NEW |
| 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 = 1080; |
| 21 static NSUInteger const kContentHeight = 720; | 21 static NSUInteger const kContentHeight = 520; |
| 22 static NSUInteger const kRoomFieldWidth = 80; | 22 static NSUInteger const kRoomFieldWidth = 80; |
| 23 static NSUInteger const kLogViewHeight = 280; | 23 static NSUInteger const kLogViewHeight = 180; |
| 24 | 24 |
| 25 @class APPRTCMainView; | 25 @class APPRTCMainView; |
| 26 @protocol APPRTCMainViewDelegate | 26 @protocol APPRTCMainViewDelegate |
| 27 | 27 |
| 28 - (void)appRTCMainView:(APPRTCMainView*)mainView | 28 - (void)appRTCMainView:(APPRTCMainView*)mainView |
| 29 didEnterRoomId:(NSString*)roomId; | 29 didEnterRoomId:(NSString*)roomId; |
| 30 | 30 |
| 31 @end | 31 @end |
| 32 | 32 |
| 33 @interface APPRTCMainView : NSView | 33 @interface APPRTCMainView : NSView |
| (...skipping 25 matching lines...) Expand all Loading... |
| 59 | 59 |
| 60 - (instancetype)initWithFrame:(NSRect)frame { | 60 - (instancetype)initWithFrame:(NSRect)frame { |
| 61 if (self = [super initWithFrame:frame]) { | 61 if (self = [super initWithFrame:frame]) { |
| 62 [self setupViews]; | 62 [self setupViews]; |
| 63 } | 63 } |
| 64 return self; | 64 return self; |
| 65 } | 65 } |
| 66 | 66 |
| 67 - (void)updateConstraints { | 67 - (void)updateConstraints { |
| 68 NSParameterAssert( | 68 NSParameterAssert( |
| 69 _roomField != nil && _scrollView != nil && _remoteVideoView != nil); | 69 _roomField != nil && _scrollView != nil && _remoteVideoView != nil |
| 70 && _localVideoView != nil); |
| 70 [self removeConstraints:[self constraints]]; | 71 [self removeConstraints:[self constraints]]; |
| 71 NSDictionary* viewsDictionary = | 72 NSDictionary* viewsDictionary = |
| 72 NSDictionaryOfVariableBindings(_roomLabel, | 73 NSDictionaryOfVariableBindings(_roomLabel, |
| 73 _roomField, | 74 _roomField, |
| 74 _scrollView, | 75 _scrollView, |
| 76 _localVideoView, |
| 75 _remoteVideoView); | 77 _remoteVideoView); |
| 76 | 78 |
| 77 NSSize remoteViewSize = [self remoteVideoViewSize]; | 79 NSSize remoteViewSize = NSMakeSize(kContentWidth, kContentHeight); |
| 80 NSSize localViewSize = NSMakeSize(200, 120); |
| 78 NSDictionary* metrics = @{ | 81 NSDictionary* metrics = @{ |
| 79 @"kLogViewHeight" : @(kLogViewHeight), | 82 @"kLogViewHeight" : @(kLogViewHeight), |
| 80 @"kRoomFieldWidth" : @(kRoomFieldWidth), | 83 @"kRoomFieldWidth" : @(kRoomFieldWidth), |
| 81 @"remoteViewWidth" : @(remoteViewSize.width), | 84 @"remoteViewWidth" : @(remoteViewSize.width), |
| 82 @"remoteViewHeight" : @(remoteViewSize.height), | 85 @"remoteViewHeight" : @(remoteViewSize.height), |
| 86 @"localViewWidth" : @(localViewSize.width), |
| 87 @"localViewHeight" : @(localViewSize.height), |
| 83 }; | 88 }; |
| 84 // Declare this separately to avoid compiler warning about splitting string | 89 // Declare this separately to avoid compiler warning about splitting string |
| 85 // within an NSArray expression. | 90 // within an NSArray expression. |
| 86 NSString* verticalConstraint = | 91 NSString* verticalConstraint = |
| 87 @"V:|-[_roomLabel]-[_roomField]-[_scrollView(kLogViewHeight)]" | 92 @"V:|-[_roomLabel]-[_roomField]-[_scrollView(kLogViewHeight)]" |
| 88 "-[_remoteVideoView(remoteViewHeight)]-|"; | 93 "-[_remoteVideoView(remoteViewHeight)]-|"; |
| 89 NSArray* constraintFormats = @[ | 94 NSArray* constraintFormats = @[ |
| 90 verticalConstraint, | 95 verticalConstraint, |
| 96 @"V:|-(>=100)-[_localVideoView(localViewHeight)]-30-|", |
| 91 @"|-[_roomLabel]", | 97 @"|-[_roomLabel]", |
| 92 @"|-[_roomField(kRoomFieldWidth)]", | 98 @"|-[_roomField(kRoomFieldWidth)]", |
| 93 @"|-[_scrollView(remoteViewWidth)]-|", | 99 @"|-[_scrollView(remoteViewWidth)]-|", |
| 94 @"|-[_remoteVideoView(remoteViewWidth)]-|", | 100 @"|-[_remoteVideoView(remoteViewWidth)]-|", |
| 101 @"|-30-[_localVideoView(localViewWidth)]-(>=100)-|", |
| 95 ]; | 102 ]; |
| 96 for (NSString* constraintFormat in constraintFormats) { | 103 for (NSString* constraintFormat in constraintFormats) { |
| 97 NSArray* constraints = | 104 NSArray* constraints = |
| 98 [NSLayoutConstraint constraintsWithVisualFormat:constraintFormat | 105 [NSLayoutConstraint constraintsWithVisualFormat:constraintFormat |
| 99 options:0 | 106 options:0 |
| 100 metrics:metrics | 107 metrics:metrics |
| 101 views:viewsDictionary]; | 108 views:viewsDictionary]; |
| 102 for (NSLayoutConstraint* constraint in constraints) { | 109 for (NSLayoutConstraint* constraint in constraints) { |
| 103 [self addConstraint:constraint]; | 110 [self addConstraint:constraint]; |
| 104 } | 111 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 127 | 134 |
| 128 - (void)videoView:(RTCNSGLVideoView*)videoView | 135 - (void)videoView:(RTCNSGLVideoView*)videoView |
| 129 didChangeVideoSize:(NSSize)size { | 136 didChangeVideoSize:(NSSize)size { |
| 130 if (videoView == _remoteVideoView) { | 137 if (videoView == _remoteVideoView) { |
| 131 _remoteVideoSize = size; | 138 _remoteVideoSize = size; |
| 132 } else if (videoView == _localVideoView) { | 139 } else if (videoView == _localVideoView) { |
| 133 _localVideoSize = size; | 140 _localVideoSize = size; |
| 134 } else { | 141 } else { |
| 135 return; | 142 return; |
| 136 } | 143 } |
| 137 [self setNeedsUpdateConstraints:YES]; | 144 //[self setNeedsUpdateConstraints:YES]; |
| 138 } | 145 } |
| 139 | 146 |
| 140 #pragma mark - Private | 147 #pragma mark - Private |
| 141 | 148 |
| 142 - (void)setupViews { | 149 - (void)setupViews { |
| 143 NSParameterAssert([[self subviews] count] == 0); | 150 NSParameterAssert([[self subviews] count] == 0); |
| 144 | 151 |
| 145 _roomLabel = [[NSTextField alloc] initWithFrame:NSZeroRect]; | 152 _roomLabel = [[NSTextField alloc] initWithFrame:NSZeroRect]; |
| 146 [_roomLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; | 153 [_roomLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; |
| 147 [_roomLabel setBezeled:NO]; | 154 [_roomLabel setBezeled:NO]; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 0 | 188 0 |
| 182 }; | 189 }; |
| 183 NSOpenGLPixelFormat* pixelFormat = | 190 NSOpenGLPixelFormat* pixelFormat = |
| 184 [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes]; | 191 [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes]; |
| 185 _remoteVideoView = [[RTCNSGLVideoView alloc] initWithFrame:NSZeroRect | 192 _remoteVideoView = [[RTCNSGLVideoView alloc] initWithFrame:NSZeroRect |
| 186 pixelFormat:pixelFormat]; | 193 pixelFormat:pixelFormat]; |
| 187 [_remoteVideoView setTranslatesAutoresizingMaskIntoConstraints:NO]; | 194 [_remoteVideoView setTranslatesAutoresizingMaskIntoConstraints:NO]; |
| 188 _remoteVideoView.delegate = self; | 195 _remoteVideoView.delegate = self; |
| 189 [self addSubview:_remoteVideoView]; | 196 [self addSubview:_remoteVideoView]; |
| 190 | 197 |
| 191 // TODO(tkchin): create local video view. | 198 _localVideoView = [[RTCNSGLVideoView alloc] initWithFrame:NSZeroRect |
| 192 // https://code.google.com/p/webrtc/issues/detail?id=3417. | 199 pixelFormat:pixelFormat]; |
| 200 [_localVideoView setTranslatesAutoresizingMaskIntoConstraints:NO]; |
| 201 _localVideoView.delegate = self; |
| 202 [self addSubview:_localVideoView]; |
| 193 } | 203 } |
| 194 | 204 |
| 195 - (NSSize)remoteVideoViewSize { | 205 - (NSSize)remoteVideoViewSize { |
| 196 if (_remoteVideoSize.width > 0 && _remoteVideoSize.height > 0) { | 206 if (_remoteVideoSize.width > 0 && _remoteVideoSize.height > 0) { |
| 197 return _remoteVideoSize; | 207 return _remoteVideoSize; |
| 198 } else { | 208 } else { |
| 199 return NSMakeSize(kContentWidth, kContentHeight); | 209 return NSMakeSize(kContentWidth, kContentHeight); |
| 200 } | 210 } |
| 201 } | 211 } |
| 202 | 212 |
| 203 - (NSSize)localVideoViewSize { | 213 - (NSSize)localVideoViewSize { |
| 204 return NSZeroSize; | 214 if (_localVideoSize.width > 0 && _localVideoSize.height > 0) { |
| 215 return _localVideoSize; |
| 216 } else { |
| 217 return NSMakeSize(200, 120); |
| 218 } |
| 205 } | 219 } |
| 206 | 220 |
| 207 @end | 221 @end |
| 208 | 222 |
| 209 @interface APPRTCViewController () | 223 @interface APPRTCViewController () |
| 210 <ARDAppClientDelegate, APPRTCMainViewDelegate> | 224 <ARDAppClientDelegate, APPRTCMainViewDelegate> |
| 211 @property(nonatomic, readonly) APPRTCMainView* mainView; | 225 @property(nonatomic, readonly) APPRTCMainView* mainView; |
| 212 @end | 226 @end |
| 213 | 227 |
| 214 @implementation APPRTCViewController { | 228 @implementation APPRTCViewController { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 } | 265 } |
| 252 } | 266 } |
| 253 | 267 |
| 254 - (void)appClient:(ARDAppClient *)client | 268 - (void)appClient:(ARDAppClient *)client |
| 255 didChangeConnectionState:(RTCIceConnectionState)state { | 269 didChangeConnectionState:(RTCIceConnectionState)state { |
| 256 } | 270 } |
| 257 | 271 |
| 258 - (void)appClient:(ARDAppClient *)client | 272 - (void)appClient:(ARDAppClient *)client |
| 259 didReceiveLocalVideoTrack:(RTCVideoTrack *)localVideoTrack { | 273 didReceiveLocalVideoTrack:(RTCVideoTrack *)localVideoTrack { |
| 260 _localVideoTrack = localVideoTrack; | 274 _localVideoTrack = localVideoTrack; |
| 275 [_localVideoTrack addRenderer:self.mainView.localVideoView]; |
| 261 } | 276 } |
| 262 | 277 |
| 263 - (void)appClient:(ARDAppClient *)client | 278 - (void)appClient:(ARDAppClient *)client |
| 264 didReceiveRemoteVideoTrack:(RTCVideoTrack *)remoteVideoTrack { | 279 didReceiveRemoteVideoTrack:(RTCVideoTrack *)remoteVideoTrack { |
| 265 _remoteVideoTrack = remoteVideoTrack; | 280 _remoteVideoTrack = remoteVideoTrack; |
| 266 [_remoteVideoTrack addRenderer:self.mainView.remoteVideoView]; | 281 [_remoteVideoTrack addRenderer:self.mainView.remoteVideoView]; |
| 267 } | 282 } |
| 268 | 283 |
| 269 - (void)appClient:(ARDAppClient *)client | 284 - (void)appClient:(ARDAppClient *)client |
| 270 didError:(NSError *)error { | 285 didError:(NSError *)error { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 _remoteVideoTrack = nil; | 318 _remoteVideoTrack = nil; |
| 304 [self.mainView.remoteVideoView renderFrame:nil]; | 319 [self.mainView.remoteVideoView renderFrame:nil]; |
| 305 } | 320 } |
| 306 | 321 |
| 307 - (void)disconnect { | 322 - (void)disconnect { |
| 308 [self resetUI]; | 323 [self resetUI]; |
| 309 [_client disconnect]; | 324 [_client disconnect]; |
| 310 } | 325 } |
| 311 | 326 |
| 312 @end | 327 @end |
| OLD | NEW |