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 "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 "ARDSettingsModel.h" | 16 #import "ARDSettingsModel.h" |
17 #import "ARDVideoCallView.h" | 17 #import "ARDVideoCallView.h" |
18 #import "WebRTC/RTCAVFoundationVideoSource.h" | 18 #import "WebRTC/RTCAVFoundationVideoSource.h" |
19 #import "WebRTC/RTCDispatcher.h" | 19 #import "WebRTC/RTCDispatcher.h" |
20 #import "WebRTC/RTCLogging.h" | 20 #import "WebRTC/RTCLogging.h" |
21 #import "WebRTC/RTCMediaConstraints.h" | 21 #import "WebRTC/RTCMediaConstraints.h" |
22 | 22 |
23 @interface ARDVideoCallViewController () <ARDAppClientDelegate, | 23 @interface ARDVideoCallViewController () <ARDAppClientDelegate, |
24 ARDVideoCallViewDelegate> | 24 ARDVideoCallViewDelegate> |
25 @property(nonatomic, strong) RTCVideoTrack *localVideoTrack; | 25 @property(nonatomic, strong) RTCCameraVideoCapturer *localCapturer; |
26 @property(nonatomic, strong) RTCVideoTrack *remoteVideoTrack; | 26 @property(nonatomic, strong) RTCVideoTrack *remoteVideoTrack; |
27 @property(nonatomic, readonly) ARDVideoCallView *videoCallView; | 27 @property(nonatomic, readonly) ARDVideoCallView *videoCallView; |
28 @end | 28 @end |
29 | 29 |
30 @implementation ARDVideoCallViewController { | 30 @implementation ARDVideoCallViewController { |
31 ARDAppClient *_client; | 31 ARDAppClient *_client; |
32 RTCVideoTrack *_remoteVideoTrack; | 32 RTCVideoTrack *_remoteVideoTrack; |
33 RTCVideoTrack *_localVideoTrack; | 33 RTCCameraVideoCapturer *_localCapturer; |
34 AVAudioSessionPortOverride _portOverride; | 34 AVAudioSessionPortOverride _portOverride; |
35 } | 35 } |
36 | 36 |
| 37 @synthesize localCapturer = _localCapturer; |
37 @synthesize videoCallView = _videoCallView; | 38 @synthesize videoCallView = _videoCallView; |
38 @synthesize localVideoTrack = _localVideoTrack; | |
39 @synthesize remoteVideoTrack = _remoteVideoTrack; | 39 @synthesize remoteVideoTrack = _remoteVideoTrack; |
40 @synthesize delegate = _delegate; | 40 @synthesize delegate = _delegate; |
41 | 41 |
42 - (instancetype)initForRoom:(NSString *)room | 42 - (instancetype)initForRoom:(NSString *)room |
43 isLoopback:(BOOL)isLoopback | 43 isLoopback:(BOOL)isLoopback |
44 isAudioOnly:(BOOL)isAudioOnly | 44 isAudioOnly:(BOOL)isAudioOnly |
45 shouldMakeAecDump:(BOOL)shouldMakeAecDump | 45 shouldMakeAecDump:(BOOL)shouldMakeAecDump |
46 shouldUseLevelControl:(BOOL)shouldUseLevelControl | 46 shouldUseLevelControl:(BOOL)shouldUseLevelControl |
47 delegate:(id<ARDVideoCallViewControllerDelegate>)delegate { | 47 delegate:(id<ARDVideoCallViewControllerDelegate>)delegate { |
48 if (self = [super init]) { | 48 if (self = [super init]) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 RTCLog(@"ICE state changed: %ld", (long)state); | 90 RTCLog(@"ICE state changed: %ld", (long)state); |
91 __weak ARDVideoCallViewController *weakSelf = self; | 91 __weak ARDVideoCallViewController *weakSelf = self; |
92 dispatch_async(dispatch_get_main_queue(), ^{ | 92 dispatch_async(dispatch_get_main_queue(), ^{ |
93 ARDVideoCallViewController *strongSelf = weakSelf; | 93 ARDVideoCallViewController *strongSelf = weakSelf; |
94 strongSelf.videoCallView.statusLabel.text = | 94 strongSelf.videoCallView.statusLabel.text = |
95 [strongSelf statusTextForState:state]; | 95 [strongSelf statusTextForState:state]; |
96 }); | 96 }); |
97 } | 97 } |
98 | 98 |
99 - (void)appClient:(ARDAppClient *)client | 99 - (void)appClient:(ARDAppClient *)client |
| 100 didCreateLocalCapturer:(RTCCameraVideoCapturer *)localCapturer { |
| 101 self.localCapturer = localCapturer; |
| 102 } |
| 103 |
| 104 - (void)appClient:(ARDAppClient *)client |
100 didReceiveLocalVideoTrack:(RTCVideoTrack *)localVideoTrack { | 105 didReceiveLocalVideoTrack:(RTCVideoTrack *)localVideoTrack { |
101 self.localVideoTrack = localVideoTrack; | |
102 } | 106 } |
103 | 107 |
104 - (void)appClient:(ARDAppClient *)client | 108 - (void)appClient:(ARDAppClient *)client |
105 didReceiveRemoteVideoTrack:(RTCVideoTrack *)remoteVideoTrack { | 109 didReceiveRemoteVideoTrack:(RTCVideoTrack *)remoteVideoTrack { |
106 self.remoteVideoTrack = remoteVideoTrack; | 110 self.remoteVideoTrack = remoteVideoTrack; |
107 _videoCallView.statusLabel.hidden = YES; | 111 _videoCallView.statusLabel.hidden = YES; |
108 } | 112 } |
109 | 113 |
110 - (void)appClient:(ARDAppClient *)client | 114 - (void)appClient:(ARDAppClient *)client |
111 didGetStats:(NSArray *)stats { | 115 didGetStats:(NSArray *)stats { |
(...skipping 11 matching lines...) Expand all Loading... |
123 | 127 |
124 #pragma mark - ARDVideoCallViewDelegate | 128 #pragma mark - ARDVideoCallViewDelegate |
125 | 129 |
126 - (void)videoCallViewDidHangup:(ARDVideoCallView *)view { | 130 - (void)videoCallViewDidHangup:(ARDVideoCallView *)view { |
127 [self hangup]; | 131 [self hangup]; |
128 } | 132 } |
129 | 133 |
130 - (void)videoCallViewDidSwitchCamera:(ARDVideoCallView *)view { | 134 - (void)videoCallViewDidSwitchCamera:(ARDVideoCallView *)view { |
131 // TODO(tkchin): Rate limit this so you can't tap continously on it. | 135 // TODO(tkchin): Rate limit this so you can't tap continously on it. |
132 // Probably through an animation. | 136 // Probably through an animation. |
133 [self switchCamera]; | 137 [_client switchCamera]; |
134 } | 138 } |
135 | 139 |
136 - (void)videoCallViewDidChangeRoute:(ARDVideoCallView *)view { | 140 - (void)videoCallViewDidChangeRoute:(ARDVideoCallView *)view { |
137 AVAudioSessionPortOverride override = AVAudioSessionPortOverrideNone; | 141 AVAudioSessionPortOverride override = AVAudioSessionPortOverrideNone; |
138 if (_portOverride == AVAudioSessionPortOverrideNone) { | 142 if (_portOverride == AVAudioSessionPortOverrideNone) { |
139 override = AVAudioSessionPortOverrideSpeaker; | 143 override = AVAudioSessionPortOverrideSpeaker; |
140 } | 144 } |
141 [RTCDispatcher dispatchAsyncOnType:RTCDispatcherTypeAudioSession | 145 [RTCDispatcher dispatchAsyncOnType:RTCDispatcherTypeAudioSession |
142 block:^{ | 146 block:^{ |
143 RTCAudioSession *session = [RTCAudioSession sharedInstance]; | 147 RTCAudioSession *session = [RTCAudioSession sharedInstance]; |
144 [session lockForConfiguration]; | 148 [session lockForConfiguration]; |
145 NSError *error = nil; | 149 NSError *error = nil; |
146 if ([session overrideOutputAudioPort:override error:&error]) { | 150 if ([session overrideOutputAudioPort:override error:&error]) { |
147 _portOverride = override; | 151 _portOverride = override; |
148 } else { | 152 } else { |
149 RTCLogError(@"Error overriding output port: %@", | 153 RTCLogError(@"Error overriding output port: %@", |
150 error.localizedDescription); | 154 error.localizedDescription); |
151 } | 155 } |
152 [session unlockForConfiguration]; | 156 [session unlockForConfiguration]; |
153 }]; | 157 }]; |
154 } | 158 } |
155 | 159 |
156 - (void)videoCallViewDidEnableStats:(ARDVideoCallView *)view { | 160 - (void)videoCallViewDidEnableStats:(ARDVideoCallView *)view { |
157 _client.shouldGetStats = YES; | 161 _client.shouldGetStats = YES; |
158 _videoCallView.statsView.hidden = NO; | 162 _videoCallView.statsView.hidden = NO; |
159 } | 163 } |
160 | 164 |
161 #pragma mark - Private | 165 #pragma mark - Private |
162 | 166 |
163 - (void)setLocalVideoTrack:(RTCVideoTrack *)localVideoTrack { | 167 - (void)setLocalCapturer:(RTCCameraVideoCapturer *)localCapturer { |
164 if (_localVideoTrack == localVideoTrack) { | 168 if (_localCapturer == localCapturer) { |
165 return; | 169 return; |
166 } | 170 } |
167 _localVideoTrack = nil; | 171 _localCapturer = localCapturer; |
168 _localVideoTrack = localVideoTrack; | 172 _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 } | 173 } |
176 | 174 |
177 - (void)setRemoteVideoTrack:(RTCVideoTrack *)remoteVideoTrack { | 175 - (void)setRemoteVideoTrack:(RTCVideoTrack *)remoteVideoTrack { |
178 if (_remoteVideoTrack == remoteVideoTrack) { | 176 if (_remoteVideoTrack == remoteVideoTrack) { |
179 return; | 177 return; |
180 } | 178 } |
181 [_remoteVideoTrack removeRenderer:_videoCallView.remoteVideoView]; | 179 [_remoteVideoTrack removeRenderer:_videoCallView.remoteVideoView]; |
182 _remoteVideoTrack = nil; | 180 _remoteVideoTrack = nil; |
183 [_videoCallView.remoteVideoView renderFrame:nil]; | 181 [_videoCallView.remoteVideoView renderFrame:nil]; |
184 _remoteVideoTrack = remoteVideoTrack; | 182 _remoteVideoTrack = remoteVideoTrack; |
185 [_remoteVideoTrack addRenderer:_videoCallView.remoteVideoView]; | 183 [_remoteVideoTrack addRenderer:_videoCallView.remoteVideoView]; |
186 } | 184 } |
187 | 185 |
188 - (void)hangup { | 186 - (void)hangup { |
189 self.remoteVideoTrack = nil; | 187 self.remoteVideoTrack = nil; |
190 self.localVideoTrack = nil; | 188 self.localCapturer = nil; |
191 [_client disconnect]; | 189 [_client disconnect]; |
192 [_delegate viewControllerDidFinish:self]; | 190 [_delegate viewControllerDidFinish:self]; |
193 } | 191 } |
194 | 192 |
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 { | 193 - (NSString *)statusTextForState:(RTCIceConnectionState)state { |
204 switch (state) { | 194 switch (state) { |
205 case RTCIceConnectionStateNew: | 195 case RTCIceConnectionStateNew: |
206 case RTCIceConnectionStateChecking: | 196 case RTCIceConnectionStateChecking: |
207 return @"Connecting..."; | 197 return @"Connecting..."; |
208 case RTCIceConnectionStateConnected: | 198 case RTCIceConnectionStateConnected: |
209 case RTCIceConnectionStateCompleted: | 199 case RTCIceConnectionStateCompleted: |
210 case RTCIceConnectionStateFailed: | 200 case RTCIceConnectionStateFailed: |
211 case RTCIceConnectionStateDisconnected: | 201 case RTCIceConnectionStateDisconnected: |
212 case RTCIceConnectionStateClosed: | 202 case RTCIceConnectionStateClosed: |
(...skipping 11 matching lines...) Expand all Loading... |
224 UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"OK" | 214 UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"OK" |
225 style:UIAlertActionSty
leDefault | 215 style:UIAlertActionSty
leDefault |
226 handler:^(UIAlertAction
*action){ | 216 handler:^(UIAlertAction
*action){ |
227 }]; | 217 }]; |
228 | 218 |
229 [alert addAction:defaultAction]; | 219 [alert addAction:defaultAction]; |
230 [self presentViewController:alert animated:YES completion:nil]; | 220 [self presentViewController:alert animated:YES completion:nil]; |
231 } | 221 } |
232 | 222 |
233 @end | 223 @end |
OLD | NEW |