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

Side by Side Diff: webrtc/examples/objc/AppRTCDemo/ios/ARDVideoCallView.m

Issue 1289623005: Add stats overlay to iOS AppRTCDemo. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 4 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
OLDNEW
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 21
21 @interface ARDVideoCallView () <RTCEAGLVideoViewDelegate> 22 @interface ARDVideoCallView () <RTCEAGLVideoViewDelegate>
22 @end 23 @end
23 24
24 @implementation ARDVideoCallView { 25 @implementation ARDVideoCallView {
25 UIButton *_cameraSwitchButton; 26 UIButton *_cameraSwitchButton;
26 UIButton *_hangupButton; 27 UIButton *_hangupButton;
27 CGSize _localVideoSize; 28 CGSize _localVideoSize;
28 CGSize _remoteVideoSize; 29 CGSize _remoteVideoSize;
29 BOOL _useRearCamera; 30 BOOL _useRearCamera;
30 } 31 }
31 32
32 @synthesize statusLabel = _statusLabel; 33 @synthesize statusLabel = _statusLabel;
33 @synthesize localVideoView = _localVideoView; 34 @synthesize localVideoView = _localVideoView;
34 @synthesize remoteVideoView = _remoteVideoView; 35 @synthesize remoteVideoView = _remoteVideoView;
36 @synthesize statsView = _statsView;
35 @synthesize delegate = _delegate; 37 @synthesize delegate = _delegate;
36 38
37 - (instancetype)initWithFrame:(CGRect)frame { 39 - (instancetype)initWithFrame:(CGRect)frame {
38 if (self = [super initWithFrame:frame]) { 40 if (self = [super initWithFrame:frame]) {
39 _remoteVideoView = [[RTCEAGLVideoView alloc] initWithFrame:CGRectZero]; 41 _remoteVideoView = [[RTCEAGLVideoView alloc] initWithFrame:CGRectZero];
40 _remoteVideoView.delegate = self; 42 _remoteVideoView.delegate = self;
41 [self addSubview:_remoteVideoView]; 43 [self addSubview:_remoteVideoView];
42 44
43 // TODO(tkchin): replace this with a view that renders layer from 45 // TODO(tkchin): replace this with a view that renders layer from
44 // AVCaptureSession. 46 // AVCaptureSession.
45 _localVideoView = [[RTCEAGLVideoView alloc] initWithFrame:CGRectZero]; 47 _localVideoView = [[RTCEAGLVideoView alloc] initWithFrame:CGRectZero];
46 _localVideoView.delegate = self; 48 _localVideoView.delegate = self;
47 [self addSubview:_localVideoView]; 49 [self addSubview:_localVideoView];
48 50
51 _statsView = [[ARDStatsView alloc] initWithFrame:CGRectZero];
52 _statsView.hidden = YES;
53 [self addSubview:_statsView];
54
49 // TODO(tkchin): don't display this if we can't actually do camera switch. 55 // TODO(tkchin): don't display this if we can't actually do camera switch.
50 _cameraSwitchButton = [UIButton buttonWithType:UIButtonTypeCustom]; 56 _cameraSwitchButton = [UIButton buttonWithType:UIButtonTypeCustom];
51 _cameraSwitchButton.backgroundColor = [UIColor whiteColor]; 57 _cameraSwitchButton.backgroundColor = [UIColor whiteColor];
52 _cameraSwitchButton.layer.cornerRadius = kButtonSize / 2; 58 _cameraSwitchButton.layer.cornerRadius = kButtonSize / 2;
53 _cameraSwitchButton.layer.masksToBounds = YES; 59 _cameraSwitchButton.layer.masksToBounds = YES;
54 UIImage *image = [UIImage imageNamed:@"ic_switch_video_black_24dp.png"]; 60 UIImage *image = [UIImage imageNamed:@"ic_switch_video_black_24dp.png"];
55 [_cameraSwitchButton setImage:image forState:UIControlStateNormal]; 61 [_cameraSwitchButton setImage:image forState:UIControlStateNormal];
56 [_cameraSwitchButton addTarget:self 62 [_cameraSwitchButton addTarget:self
57 action:@selector(onCameraSwitch:) 63 action:@selector(onCameraSwitch:)
58 forControlEvents:UIControlEventTouchUpInside]; 64 forControlEvents:UIControlEventTouchUpInside];
59 [self addSubview:_cameraSwitchButton]; 65 [self addSubview:_cameraSwitchButton];
60 66
61 _hangupButton = [UIButton buttonWithType:UIButtonTypeCustom]; 67 _hangupButton = [UIButton buttonWithType:UIButtonTypeCustom];
62 _hangupButton.backgroundColor = [UIColor redColor]; 68 _hangupButton.backgroundColor = [UIColor redColor];
63 _hangupButton.layer.cornerRadius = kButtonSize / 2; 69 _hangupButton.layer.cornerRadius = kButtonSize / 2;
64 _hangupButton.layer.masksToBounds = YES; 70 _hangupButton.layer.masksToBounds = YES;
65 image = [UIImage imageForName:@"ic_call_end_black_24dp.png" 71 image = [UIImage imageForName:@"ic_call_end_black_24dp.png"
66 color:[UIColor whiteColor]]; 72 color:[UIColor whiteColor]];
67 [_hangupButton setImage:image forState:UIControlStateNormal]; 73 [_hangupButton setImage:image forState:UIControlStateNormal];
68 [_hangupButton addTarget:self 74 [_hangupButton addTarget:self
69 action:@selector(onHangup:) 75 action:@selector(onHangup:)
70 forControlEvents:UIControlEventTouchUpInside]; 76 forControlEvents:UIControlEventTouchUpInside];
71 [self addSubview:_hangupButton]; 77 [self addSubview:_hangupButton];
72 78
73 _statusLabel = [[UILabel alloc] initWithFrame:CGRectZero]; 79 _statusLabel = [[UILabel alloc] initWithFrame:CGRectZero];
74 _statusLabel.font = [UIFont fontWithName:@"Roboto" size:16]; 80 _statusLabel.font = [UIFont fontWithName:@"Roboto" size:16];
75 _statusLabel.textColor = [UIColor whiteColor]; 81 _statusLabel.textColor = [UIColor whiteColor];
76 [self addSubview:_statusLabel]; 82 [self addSubview:_statusLabel];
83
84 UITapGestureRecognizer *tapRecognizer =
85 [[UITapGestureRecognizer alloc]
86 initWithTarget:self
87 action:@selector(didTripleTap:)];
88 tapRecognizer.numberOfTapsRequired = 3;
89 [self addGestureRecognizer:tapRecognizer];
77 } 90 }
78 return self; 91 return self;
79 } 92 }
80 93
81 - (void)layoutSubviews { 94 - (void)layoutSubviews {
82 CGRect bounds = self.bounds; 95 CGRect bounds = self.bounds;
83 if (_remoteVideoSize.width > 0 && _remoteVideoSize.height > 0) { 96 if (_remoteVideoSize.width > 0 && _remoteVideoSize.height > 0) {
84 // Aspect fill remote video into bounds. 97 // Aspect fill remote video into bounds.
85 CGRect remoteVideoFrame = 98 CGRect remoteVideoFrame =
86 AVMakeRectWithAspectRatioInsideRect(_remoteVideoSize, bounds); 99 AVMakeRectWithAspectRatioInsideRect(_remoteVideoSize, bounds);
(...skipping 24 matching lines...) Expand all
111 // Place the view in the bottom right. 124 // Place the view in the bottom right.
112 localVideoFrame.origin.x = CGRectGetMaxX(bounds) 125 localVideoFrame.origin.x = CGRectGetMaxX(bounds)
113 - localVideoFrame.size.width - kLocalVideoViewPadding; 126 - localVideoFrame.size.width - kLocalVideoViewPadding;
114 localVideoFrame.origin.y = CGRectGetMaxY(bounds) 127 localVideoFrame.origin.y = CGRectGetMaxY(bounds)
115 - localVideoFrame.size.height - kLocalVideoViewPadding; 128 - localVideoFrame.size.height - kLocalVideoViewPadding;
116 _localVideoView.frame = localVideoFrame; 129 _localVideoView.frame = localVideoFrame;
117 } else { 130 } else {
118 _localVideoView.frame = bounds; 131 _localVideoView.frame = bounds;
119 } 132 }
120 133
134 // Place stats at the top.
135 CGSize statsSize = [_statsView sizeThatFits:bounds.size];
136 _statsView.frame = CGRectMake(CGRectGetMinX(bounds),
137 CGRectGetMinY(bounds) + kStatusBarHeight,
138 statsSize.width, statsSize.height);
139
121 // Place hangup button in the bottom left. 140 // Place hangup button in the bottom left.
122 _hangupButton.frame = 141 _hangupButton.frame =
123 CGRectMake(CGRectGetMinX(bounds) + kButtonPadding, 142 CGRectMake(CGRectGetMinX(bounds) + kButtonPadding,
124 CGRectGetMaxY(bounds) - kButtonPadding - 143 CGRectGetMaxY(bounds) - kButtonPadding -
125 kButtonSize, 144 kButtonSize,
126 kButtonSize, 145 kButtonSize,
127 kButtonSize); 146 kButtonSize);
128 147
129 // Place button to the right of hangup button. 148 // Place button to the right of hangup button.
130 CGRect cameraSwitchFrame = _hangupButton.frame; 149 CGRect cameraSwitchFrame = _hangupButton.frame;
(...skipping 21 matching lines...) Expand all
152 #pragma mark - Private 171 #pragma mark - Private
153 172
154 - (void)onCameraSwitch:(id)sender { 173 - (void)onCameraSwitch:(id)sender {
155 [_delegate videoCallViewDidSwitchCamera:self]; 174 [_delegate videoCallViewDidSwitchCamera:self];
156 } 175 }
157 176
158 - (void)onHangup:(id)sender { 177 - (void)onHangup:(id)sender {
159 [_delegate videoCallViewDidHangup:self]; 178 [_delegate videoCallViewDidHangup:self];
160 } 179 }
161 180
181 - (void)didTripleTap:(UITapGestureRecognizer *)recognizer {
182 [_delegate videoCallViewDidEnableStats:self];
183 }
184
162 @end 185 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698