| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2015 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 "ARDVideoCallView.h" | 11 #import "ARDVideoCallView.h" |
| 12 | 12 |
| 13 #import <AVFoundation/AVFoundation.h> | 13 #import <AVFoundation/AVFoundation.h> |
| 14 #import "UIImage+ARDUtilities.h" | 14 #import "UIImage+ARDUtilities.h" |
| 15 | 15 |
| 16 static CGFloat const kButtonPadding = 16; | 16 static CGFloat const kButtonPadding = 16; |
| 17 static CGFloat const kButtonSize = 48; | 17 static CGFloat const kButtonSize = 48; |
| 18 static CGFloat const kLocalVideoViewSize = 120; | 18 static CGFloat const kLocalVideoViewSize = 120; |
| 19 static CGFloat const kLocalVideoViewPadding = 8; | 19 static CGFloat const kLocalVideoViewPadding = 8; |
| 20 static CGFloat const kStatusBarHeight = 20; | 20 static CGFloat const kStatusBarHeight = 20; |
| 21 | 21 |
| 22 @interface ARDVideoCallView () <RTCEAGLVideoViewDelegate> | 22 @interface ARDVideoCallView () <RTCEAGLVideoViewDelegate> |
| 23 @end | 23 @end |
| 24 | 24 |
| 25 @implementation ARDVideoCallView { | 25 @implementation ARDVideoCallView { |
| 26 UIButton *_cameraSwitchButton; | 26 UIButton *_cameraSwitchButton; |
| 27 UIButton *_hangupButton; | 27 UIButton *_hangupButton; |
| 28 CGSize _localVideoSize; | |
| 29 CGSize _remoteVideoSize; | 28 CGSize _remoteVideoSize; |
| 30 BOOL _useRearCamera; | 29 BOOL _useRearCamera; |
| 31 } | 30 } |
| 32 | 31 |
| 33 @synthesize statusLabel = _statusLabel; | 32 @synthesize statusLabel = _statusLabel; |
| 34 @synthesize localVideoView = _localVideoView; | 33 @synthesize localVideoView = _localVideoView; |
| 35 @synthesize remoteVideoView = _remoteVideoView; | 34 @synthesize remoteVideoView = _remoteVideoView; |
| 36 @synthesize statsView = _statsView; | 35 @synthesize statsView = _statsView; |
| 37 @synthesize delegate = _delegate; | 36 @synthesize delegate = _delegate; |
| 38 | 37 |
| 39 - (instancetype)initWithFrame:(CGRect)frame { | 38 - (instancetype)initWithFrame:(CGRect)frame { |
| 40 if (self = [super initWithFrame:frame]) { | 39 if (self = [super initWithFrame:frame]) { |
| 41 _remoteVideoView = [[RTCEAGLVideoView alloc] initWithFrame:CGRectZero]; | 40 _remoteVideoView = [[RTCEAGLVideoView alloc] initWithFrame:CGRectZero]; |
| 42 _remoteVideoView.delegate = self; | 41 _remoteVideoView.delegate = self; |
| 43 [self addSubview:_remoteVideoView]; | 42 [self addSubview:_remoteVideoView]; |
| 44 | 43 |
| 45 // TODO(tkchin): replace this with a view that renders layer from | 44 _localVideoView = [[RTCCameraPreviewView alloc] initWithFrame:CGRectZero]; |
| 46 // AVCaptureSession. | |
| 47 _localVideoView = [[RTCEAGLVideoView alloc] initWithFrame:CGRectZero]; | |
| 48 _localVideoView.delegate = self; | |
| 49 [self addSubview:_localVideoView]; | 45 [self addSubview:_localVideoView]; |
| 50 | 46 |
| 51 _statsView = [[ARDStatsView alloc] initWithFrame:CGRectZero]; | 47 _statsView = [[ARDStatsView alloc] initWithFrame:CGRectZero]; |
| 52 _statsView.hidden = YES; | 48 _statsView.hidden = YES; |
| 53 [self addSubview:_statsView]; | 49 [self addSubview:_statsView]; |
| 54 | 50 |
| 55 // TODO(tkchin): don't display this if we can't actually do camera switch. | 51 // TODO(tkchin): don't display this if we can't actually do camera switch. |
| 56 _cameraSwitchButton = [UIButton buttonWithType:UIButtonTypeCustom]; | 52 _cameraSwitchButton = [UIButton buttonWithType:UIButtonTypeCustom]; |
| 57 _cameraSwitchButton.backgroundColor = [UIColor whiteColor]; | 53 _cameraSwitchButton.backgroundColor = [UIColor whiteColor]; |
| 58 _cameraSwitchButton.layer.cornerRadius = kButtonSize / 2; | 54 _cameraSwitchButton.layer.cornerRadius = kButtonSize / 2; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 } | 103 } |
| 108 remoteVideoFrame.size.height *= scale; | 104 remoteVideoFrame.size.height *= scale; |
| 109 remoteVideoFrame.size.width *= scale; | 105 remoteVideoFrame.size.width *= scale; |
| 110 _remoteVideoView.frame = remoteVideoFrame; | 106 _remoteVideoView.frame = remoteVideoFrame; |
| 111 _remoteVideoView.center = | 107 _remoteVideoView.center = |
| 112 CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds)); | 108 CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds)); |
| 113 } else { | 109 } else { |
| 114 _remoteVideoView.frame = bounds; | 110 _remoteVideoView.frame = bounds; |
| 115 } | 111 } |
| 116 | 112 |
| 117 if (_localVideoSize.width && _localVideoSize.height > 0) { | 113 // Aspect fit local video view into a square box. |
| 118 // Aspect fit local video view into a square box. | 114 CGRect localVideoFrame = |
| 119 CGRect localVideoFrame = | 115 CGRectMake(0, 0, kLocalVideoViewSize, kLocalVideoViewSize); |
| 120 CGRectMake(0, 0, kLocalVideoViewSize, kLocalVideoViewSize); | 116 // Place the view in the bottom right. |
| 121 localVideoFrame = | 117 localVideoFrame.origin.x = CGRectGetMaxX(bounds) |
| 122 AVMakeRectWithAspectRatioInsideRect(_localVideoSize, localVideoFrame); | 118 - localVideoFrame.size.width - kLocalVideoViewPadding; |
| 123 | 119 localVideoFrame.origin.y = CGRectGetMaxY(bounds) |
| 124 // Place the view in the bottom right. | 120 - localVideoFrame.size.height - kLocalVideoViewPadding; |
| 125 localVideoFrame.origin.x = CGRectGetMaxX(bounds) | 121 _localVideoView.frame = localVideoFrame; |
| 126 - localVideoFrame.size.width - kLocalVideoViewPadding; | |
| 127 localVideoFrame.origin.y = CGRectGetMaxY(bounds) | |
| 128 - localVideoFrame.size.height - kLocalVideoViewPadding; | |
| 129 _localVideoView.frame = localVideoFrame; | |
| 130 } else { | |
| 131 _localVideoView.frame = bounds; | |
| 132 } | |
| 133 | 122 |
| 134 // Place stats at the top. | 123 // Place stats at the top. |
| 135 CGSize statsSize = [_statsView sizeThatFits:bounds.size]; | 124 CGSize statsSize = [_statsView sizeThatFits:bounds.size]; |
| 136 _statsView.frame = CGRectMake(CGRectGetMinX(bounds), | 125 _statsView.frame = CGRectMake(CGRectGetMinX(bounds), |
| 137 CGRectGetMinY(bounds) + kStatusBarHeight, | 126 CGRectGetMinY(bounds) + kStatusBarHeight, |
| 138 statsSize.width, statsSize.height); | 127 statsSize.width, statsSize.height); |
| 139 | 128 |
| 140 // Place hangup button in the bottom left. | 129 // Place hangup button in the bottom left. |
| 141 _hangupButton.frame = | 130 _hangupButton.frame = |
| 142 CGRectMake(CGRectGetMinX(bounds) + kButtonPadding, | 131 CGRectMake(CGRectGetMinX(bounds) + kButtonPadding, |
| 143 CGRectGetMaxY(bounds) - kButtonPadding - | 132 CGRectGetMaxY(bounds) - kButtonPadding - |
| 144 kButtonSize, | 133 kButtonSize, |
| 145 kButtonSize, | 134 kButtonSize, |
| 146 kButtonSize); | 135 kButtonSize); |
| 147 | 136 |
| 148 // Place button to the right of hangup button. | 137 // Place button to the right of hangup button. |
| 149 CGRect cameraSwitchFrame = _hangupButton.frame; | 138 CGRect cameraSwitchFrame = _hangupButton.frame; |
| 150 cameraSwitchFrame.origin.x = | 139 cameraSwitchFrame.origin.x = |
| 151 CGRectGetMaxX(cameraSwitchFrame) + kButtonPadding; | 140 CGRectGetMaxX(cameraSwitchFrame) + kButtonPadding; |
| 152 _cameraSwitchButton.frame = cameraSwitchFrame; | 141 _cameraSwitchButton.frame = cameraSwitchFrame; |
| 153 | 142 |
| 154 [_statusLabel sizeToFit]; | 143 [_statusLabel sizeToFit]; |
| 155 _statusLabel.center = | 144 _statusLabel.center = |
| 156 CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds)); | 145 CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds)); |
| 157 } | 146 } |
| 158 | 147 |
| 159 #pragma mark - RTCEAGLVideoViewDelegate | 148 #pragma mark - RTCEAGLVideoViewDelegate |
| 160 | 149 |
| 161 - (void)videoView:(RTCEAGLVideoView*)videoView didChangeVideoSize:(CGSize)size { | 150 - (void)videoView:(RTCEAGLVideoView*)videoView didChangeVideoSize:(CGSize)size { |
| 162 if (videoView == _localVideoView) { | 151 if (videoView == _remoteVideoView) { |
| 163 _localVideoSize = size; | |
| 164 _localVideoView.hidden = CGSizeEqualToSize(CGSizeZero, _localVideoSize); | |
| 165 } else if (videoView == _remoteVideoView) { | |
| 166 _remoteVideoSize = size; | 152 _remoteVideoSize = size; |
| 167 } | 153 } |
| 168 [self setNeedsLayout]; | 154 [self setNeedsLayout]; |
| 169 } | 155 } |
| 170 | 156 |
| 171 #pragma mark - Private | 157 #pragma mark - Private |
| 172 | 158 |
| 173 - (void)onCameraSwitch:(id)sender { | 159 - (void)onCameraSwitch:(id)sender { |
| 174 [_delegate videoCallViewDidSwitchCamera:self]; | 160 [_delegate videoCallViewDidSwitchCamera:self]; |
| 175 } | 161 } |
| 176 | 162 |
| 177 - (void)onHangup:(id)sender { | 163 - (void)onHangup:(id)sender { |
| 178 [_delegate videoCallViewDidHangup:self]; | 164 [_delegate videoCallViewDidHangup:self]; |
| 179 } | 165 } |
| 180 | 166 |
| 181 - (void)didTripleTap:(UITapGestureRecognizer *)recognizer { | 167 - (void)didTripleTap:(UITapGestureRecognizer *)recognizer { |
| 182 [_delegate videoCallViewDidEnableStats:self]; | 168 [_delegate videoCallViewDidEnableStats:self]; |
| 183 } | 169 } |
| 184 | 170 |
| 185 @end | 171 @end |
| OLD | NEW |