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

Side by Side Diff: webrtc/examples/objc/AppRTCMobile/ios/ARDVideoCallViewController.m

Issue 2778163005: Use new RTCCameraVideoCapturer in AppRTCMobile. (Closed)
Patch Set: Rename remaining media constraint references. Created 3 years, 8 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 "ARDVideoCallViewController.h" 11 #import "ARDVideoCallViewController.h"
12 12
13 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSession.h" 13 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSession.h"
14 14
15 #import "ARDAppClient.h" 15 #import "ARDAppClient.h"
16 #import "ARDCaptureController.h"
16 #import "ARDSettingsModel.h" 17 #import "ARDSettingsModel.h"
17 #import "ARDVideoCallView.h" 18 #import "ARDVideoCallView.h"
18 #import "WebRTC/RTCAVFoundationVideoSource.h" 19 #import "WebRTC/RTCAVFoundationVideoSource.h"
19 #import "WebRTC/RTCDispatcher.h" 20 #import "WebRTC/RTCDispatcher.h"
20 #import "WebRTC/RTCLogging.h" 21 #import "WebRTC/RTCLogging.h"
21 #import "WebRTC/RTCMediaConstraints.h" 22 #import "WebRTC/RTCMediaConstraints.h"
22 23
23 @interface ARDVideoCallViewController () <ARDAppClientDelegate, 24 @interface ARDVideoCallViewController () <ARDAppClientDelegate,
24 ARDVideoCallViewDelegate> 25 ARDVideoCallViewDelegate>
25 @property(nonatomic, strong) RTCVideoTrack *localVideoTrack; 26 @property(nonatomic, strong) RTCCameraVideoCapturer *localCapturer;
26 @property(nonatomic, strong) RTCVideoTrack *remoteVideoTrack; 27 @property(nonatomic, strong) RTCVideoTrack *remoteVideoTrack;
27 @property(nonatomic, readonly) ARDVideoCallView *videoCallView; 28 @property(nonatomic, readonly) ARDVideoCallView *videoCallView;
28 @end 29 @end
29 30
30 @implementation ARDVideoCallViewController { 31 @implementation ARDVideoCallViewController {
31 ARDAppClient *_client; 32 ARDAppClient *_client;
32 RTCVideoTrack *_remoteVideoTrack; 33 RTCVideoTrack *_remoteVideoTrack;
33 RTCVideoTrack *_localVideoTrack; 34 ARDCaptureController *_captureController;
34 AVAudioSessionPortOverride _portOverride; 35 AVAudioSessionPortOverride _portOverride;
35 } 36 }
36 37
38 @synthesize localCapturer = _localCapturer;
37 @synthesize videoCallView = _videoCallView; 39 @synthesize videoCallView = _videoCallView;
38 @synthesize localVideoTrack = _localVideoTrack;
39 @synthesize remoteVideoTrack = _remoteVideoTrack; 40 @synthesize remoteVideoTrack = _remoteVideoTrack;
40 @synthesize delegate = _delegate; 41 @synthesize delegate = _delegate;
41 42
42 - (instancetype)initForRoom:(NSString *)room 43 - (instancetype)initForRoom:(NSString *)room
43 isLoopback:(BOOL)isLoopback 44 isLoopback:(BOOL)isLoopback
44 isAudioOnly:(BOOL)isAudioOnly 45 isAudioOnly:(BOOL)isAudioOnly
45 shouldMakeAecDump:(BOOL)shouldMakeAecDump 46 shouldMakeAecDump:(BOOL)shouldMakeAecDump
46 shouldUseLevelControl:(BOOL)shouldUseLevelControl 47 shouldUseLevelControl:(BOOL)shouldUseLevelControl
47 delegate:(id<ARDVideoCallViewControllerDelegate>)delegate { 48 delegate:(id<ARDVideoCallViewControllerDelegate>)delegate {
48 if (self = [super init]) { 49 if (self = [super init]) {
49 ARDSettingsModel *settingsModel = [[ARDSettingsModel alloc] init]; 50 ARDSettingsModel *settingsModel = [[ARDSettingsModel alloc] init];
50 _delegate = delegate; 51 _delegate = delegate;
52
51 _client = [[ARDAppClient alloc] initWithDelegate:self]; 53 _client = [[ARDAppClient alloc] initWithDelegate:self];
52 [_client connectToRoomWithId:room 54 [_client connectToRoomWithId:room
53 settings:settingsModel 55 settings:settingsModel
54 isLoopback:isLoopback 56 isLoopback:isLoopback
55 isAudioOnly:isAudioOnly 57 isAudioOnly:isAudioOnly
56 shouldMakeAecDump:shouldMakeAecDump 58 shouldMakeAecDump:shouldMakeAecDump
57 shouldUseLevelControl:shouldUseLevelControl]; 59 shouldUseLevelControl:shouldUseLevelControl];
58 } 60 }
59 return self; 61 return self;
60 } 62 }
(...skipping 29 matching lines...) Expand all
90 RTCLog(@"ICE state changed: %ld", (long)state); 92 RTCLog(@"ICE state changed: %ld", (long)state);
91 __weak ARDVideoCallViewController *weakSelf = self; 93 __weak ARDVideoCallViewController *weakSelf = self;
92 dispatch_async(dispatch_get_main_queue(), ^{ 94 dispatch_async(dispatch_get_main_queue(), ^{
93 ARDVideoCallViewController *strongSelf = weakSelf; 95 ARDVideoCallViewController *strongSelf = weakSelf;
94 strongSelf.videoCallView.statusLabel.text = 96 strongSelf.videoCallView.statusLabel.text =
95 [strongSelf statusTextForState:state]; 97 [strongSelf statusTextForState:state];
96 }); 98 });
97 } 99 }
98 100
99 - (void)appClient:(ARDAppClient *)client 101 - (void)appClient:(ARDAppClient *)client
102 didCreateLocalCapturer:(RTCCameraVideoCapturer *)localCapturer {
103 ARDSettingsModel *settingsModel = [[ARDSettingsModel alloc] init];
104 _captureController =
105 [[ARDCaptureController alloc] initWithCapturer:localCapturer settings:sett ingsModel];
106 [_captureController startCapture];
daniela-webrtc 2017/04/04 12:25:21 I'd add [_capturerController stopCapture] in [self
sakal 2017/04/05 12:35:49 Done.
107 }
108
109 - (void)appClient:(ARDAppClient *)client
100 didReceiveLocalVideoTrack:(RTCVideoTrack *)localVideoTrack { 110 didReceiveLocalVideoTrack:(RTCVideoTrack *)localVideoTrack {
101 self.localVideoTrack = localVideoTrack;
102 } 111 }
103 112
104 - (void)appClient:(ARDAppClient *)client 113 - (void)appClient:(ARDAppClient *)client
105 didReceiveRemoteVideoTrack:(RTCVideoTrack *)remoteVideoTrack { 114 didReceiveRemoteVideoTrack:(RTCVideoTrack *)remoteVideoTrack {
106 self.remoteVideoTrack = remoteVideoTrack; 115 self.remoteVideoTrack = remoteVideoTrack;
107 _videoCallView.statusLabel.hidden = YES; 116 _videoCallView.statusLabel.hidden = YES;
108 } 117 }
109 118
110 - (void)appClient:(ARDAppClient *)client 119 - (void)appClient:(ARDAppClient *)client
111 didGetStats:(NSArray *)stats { 120 didGetStats:(NSArray *)stats {
(...skipping 11 matching lines...) Expand all
123 132
124 #pragma mark - ARDVideoCallViewDelegate 133 #pragma mark - ARDVideoCallViewDelegate
125 134
126 - (void)videoCallViewDidHangup:(ARDVideoCallView *)view { 135 - (void)videoCallViewDidHangup:(ARDVideoCallView *)view {
127 [self hangup]; 136 [self hangup];
128 } 137 }
129 138
130 - (void)videoCallViewDidSwitchCamera:(ARDVideoCallView *)view { 139 - (void)videoCallViewDidSwitchCamera:(ARDVideoCallView *)view {
131 // TODO(tkchin): Rate limit this so you can't tap continously on it. 140 // TODO(tkchin): Rate limit this so you can't tap continously on it.
132 // Probably through an animation. 141 // Probably through an animation.
133 [self switchCamera]; 142 [_captureController switchCamera];
134 } 143 }
135 144
136 - (void)videoCallViewDidChangeRoute:(ARDVideoCallView *)view { 145 - (void)videoCallViewDidChangeRoute:(ARDVideoCallView *)view {
137 AVAudioSessionPortOverride override = AVAudioSessionPortOverrideNone; 146 AVAudioSessionPortOverride override = AVAudioSessionPortOverrideNone;
138 if (_portOverride == AVAudioSessionPortOverrideNone) { 147 if (_portOverride == AVAudioSessionPortOverrideNone) {
139 override = AVAudioSessionPortOverrideSpeaker; 148 override = AVAudioSessionPortOverrideSpeaker;
140 } 149 }
141 [RTCDispatcher dispatchAsyncOnType:RTCDispatcherTypeAudioSession 150 [RTCDispatcher dispatchAsyncOnType:RTCDispatcherTypeAudioSession
142 block:^{ 151 block:^{
143 RTCAudioSession *session = [RTCAudioSession sharedInstance]; 152 RTCAudioSession *session = [RTCAudioSession sharedInstance];
144 [session lockForConfiguration]; 153 [session lockForConfiguration];
145 NSError *error = nil; 154 NSError *error = nil;
146 if ([session overrideOutputAudioPort:override error:&error]) { 155 if ([session overrideOutputAudioPort:override error:&error]) {
147 _portOverride = override; 156 _portOverride = override;
148 } else { 157 } else {
149 RTCLogError(@"Error overriding output port: %@", 158 RTCLogError(@"Error overriding output port: %@",
150 error.localizedDescription); 159 error.localizedDescription);
151 } 160 }
152 [session unlockForConfiguration]; 161 [session unlockForConfiguration];
153 }]; 162 }];
154 } 163 }
155 164
156 - (void)videoCallViewDidEnableStats:(ARDVideoCallView *)view { 165 - (void)videoCallViewDidEnableStats:(ARDVideoCallView *)view {
157 _client.shouldGetStats = YES; 166 _client.shouldGetStats = YES;
158 _videoCallView.statsView.hidden = NO; 167 _videoCallView.statsView.hidden = NO;
159 } 168 }
160 169
161 #pragma mark - Private 170 #pragma mark - Private
162 171
163 - (void)setLocalVideoTrack:(RTCVideoTrack *)localVideoTrack { 172 - (void)setLocalCapturer:(RTCCameraVideoCapturer *)localCapturer {
daniela-webrtc 2017/04/04 12:25:20 I don't see this being called anywhere except on 1
daniela-webrtc 2017/04/04 12:25:21 Also, we don't need to keep reference to the RTCCa
sakal 2017/04/05 12:35:49 Done.
164 if (_localVideoTrack == localVideoTrack) { 173 if (_localCapturer == localCapturer) {
165 return; 174 return;
166 } 175 }
167 _localVideoTrack = nil; 176 _localCapturer = localCapturer;
168 _localVideoTrack = localVideoTrack; 177 _videoCallView.localVideoView.captureSession = localCapturer.captureSession;
169 RTCAVFoundationVideoSource *source = nil;
170 if ([localVideoTrack.source
171 isKindOfClass:[RTCAVFoundationVideoSource class]]) {
172 source = (RTCAVFoundationVideoSource*)localVideoTrack.source;
173 }
174 _videoCallView.localVideoView.captureSession = source.captureSession;
175 } 178 }
176 179
177 - (void)setRemoteVideoTrack:(RTCVideoTrack *)remoteVideoTrack { 180 - (void)setRemoteVideoTrack:(RTCVideoTrack *)remoteVideoTrack {
178 if (_remoteVideoTrack == remoteVideoTrack) { 181 if (_remoteVideoTrack == remoteVideoTrack) {
179 return; 182 return;
180 } 183 }
181 [_remoteVideoTrack removeRenderer:_videoCallView.remoteVideoView]; 184 [_remoteVideoTrack removeRenderer:_videoCallView.remoteVideoView];
182 _remoteVideoTrack = nil; 185 _remoteVideoTrack = nil;
183 [_videoCallView.remoteVideoView renderFrame:nil]; 186 [_videoCallView.remoteVideoView renderFrame:nil];
184 _remoteVideoTrack = remoteVideoTrack; 187 _remoteVideoTrack = remoteVideoTrack;
185 [_remoteVideoTrack addRenderer:_videoCallView.remoteVideoView]; 188 [_remoteVideoTrack addRenderer:_videoCallView.remoteVideoView];
186 } 189 }
187 190
188 - (void)hangup { 191 - (void)hangup {
189 self.remoteVideoTrack = nil; 192 self.remoteVideoTrack = nil;
190 self.localVideoTrack = nil; 193 self.localCapturer = nil;
191 [_client disconnect]; 194 [_client disconnect];
192 [_delegate viewControllerDidFinish:self]; 195 [_delegate viewControllerDidFinish:self];
193 } 196 }
194 197
195 - (void)switchCamera {
196 RTCVideoSource* source = self.localVideoTrack.source;
197 if ([source isKindOfClass:[RTCAVFoundationVideoSource class]]) {
198 RTCAVFoundationVideoSource* avSource = (RTCAVFoundationVideoSource*)source;
199 avSource.useBackCamera = !avSource.useBackCamera;
200 }
201 }
202
203 - (NSString *)statusTextForState:(RTCIceConnectionState)state { 198 - (NSString *)statusTextForState:(RTCIceConnectionState)state {
204 switch (state) { 199 switch (state) {
205 case RTCIceConnectionStateNew: 200 case RTCIceConnectionStateNew:
206 case RTCIceConnectionStateChecking: 201 case RTCIceConnectionStateChecking:
207 return @"Connecting..."; 202 return @"Connecting...";
208 case RTCIceConnectionStateConnected: 203 case RTCIceConnectionStateConnected:
209 case RTCIceConnectionStateCompleted: 204 case RTCIceConnectionStateCompleted:
210 case RTCIceConnectionStateFailed: 205 case RTCIceConnectionStateFailed:
211 case RTCIceConnectionStateDisconnected: 206 case RTCIceConnectionStateDisconnected:
212 case RTCIceConnectionStateClosed: 207 case RTCIceConnectionStateClosed:
(...skipping 11 matching lines...) Expand all
224 UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"OK" 219 UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"OK"
225 style:UIAlertActionSty leDefault 220 style:UIAlertActionSty leDefault
226 handler:^(UIAlertAction *action){ 221 handler:^(UIAlertAction *action){
227 }]; 222 }];
228 223
229 [alert addAction:defaultAction]; 224 [alert addAction:defaultAction];
230 [self presentViewController:alert animated:YES completion:nil]; 225 [self presentViewController:alert animated:YES completion:nil];
231 } 226 }
232 227
233 @end 228 @end
OLDNEW
« no previous file with comments | « webrtc/examples/objc/AppRTCMobile/ios/ARDVideoCallView.m ('k') | webrtc/examples/objc/AppRTCMobile/mac/APPRTCViewController.m » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698