| 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 "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) 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 ARDCaptureController *_captureController; |
| 34 AVAudioSessionPortOverride _portOverride; | 34 AVAudioSessionPortOverride _portOverride; |
| 35 } | 35 } |
| 36 | 36 |
| 37 @synthesize videoCallView = _videoCallView; | 37 @synthesize videoCallView = _videoCallView; |
| 38 @synthesize localVideoTrack = _localVideoTrack; | |
| 39 @synthesize remoteVideoTrack = _remoteVideoTrack; | 38 @synthesize remoteVideoTrack = _remoteVideoTrack; |
| 40 @synthesize delegate = _delegate; | 39 @synthesize delegate = _delegate; |
| 41 | 40 |
| 42 - (instancetype)initForRoom:(NSString *)room | 41 - (instancetype)initForRoom:(NSString *)room |
| 43 isLoopback:(BOOL)isLoopback | 42 isLoopback:(BOOL)isLoopback |
| 44 isAudioOnly:(BOOL)isAudioOnly | 43 isAudioOnly:(BOOL)isAudioOnly |
| 45 shouldMakeAecDump:(BOOL)shouldMakeAecDump | 44 shouldMakeAecDump:(BOOL)shouldMakeAecDump |
| 46 shouldUseLevelControl:(BOOL)shouldUseLevelControl | 45 shouldUseLevelControl:(BOOL)shouldUseLevelControl |
| 47 delegate:(id<ARDVideoCallViewControllerDelegate>)delegate { | 46 delegate:(id<ARDVideoCallViewControllerDelegate>)delegate { |
| 48 if (self = [super init]) { | 47 if (self = [super init]) { |
| 49 ARDSettingsModel *settingsModel = [[ARDSettingsModel alloc] init]; | 48 ARDSettingsModel *settingsModel = [[ARDSettingsModel alloc] init]; |
| 50 _delegate = delegate; | 49 _delegate = delegate; |
| 50 |
| 51 _client = [[ARDAppClient alloc] initWithDelegate:self]; | 51 _client = [[ARDAppClient alloc] initWithDelegate:self]; |
| 52 [_client connectToRoomWithId:room | 52 [_client connectToRoomWithId:room |
| 53 settings:settingsModel | 53 settings:settingsModel |
| 54 isLoopback:isLoopback | 54 isLoopback:isLoopback |
| 55 isAudioOnly:isAudioOnly | 55 isAudioOnly:isAudioOnly |
| 56 shouldMakeAecDump:shouldMakeAecDump | 56 shouldMakeAecDump:shouldMakeAecDump |
| 57 shouldUseLevelControl:shouldUseLevelControl]; | 57 shouldUseLevelControl:shouldUseLevelControl]; |
| 58 } | 58 } |
| 59 return self; | 59 return self; |
| 60 } | 60 } |
| (...skipping 29 matching lines...) Expand all 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 _videoCallView.localVideoView.captureSession = localCapturer.captureSession; |
| 102 ARDSettingsModel *settingsModel = [[ARDSettingsModel alloc] init]; |
| 103 _captureController = |
| 104 [[ARDCaptureController alloc] initWithCapturer:localCapturer settings:sett
ingsModel]; |
| 105 [_captureController startCapture]; |
| 106 } |
| 107 |
| 108 - (void)appClient:(ARDAppClient *)client |
| 100 didReceiveLocalVideoTrack:(RTCVideoTrack *)localVideoTrack { | 109 didReceiveLocalVideoTrack:(RTCVideoTrack *)localVideoTrack { |
| 101 self.localVideoTrack = localVideoTrack; | |
| 102 } | 110 } |
| 103 | 111 |
| 104 - (void)appClient:(ARDAppClient *)client | 112 - (void)appClient:(ARDAppClient *)client |
| 105 didReceiveRemoteVideoTrack:(RTCVideoTrack *)remoteVideoTrack { | 113 didReceiveRemoteVideoTrack:(RTCVideoTrack *)remoteVideoTrack { |
| 106 self.remoteVideoTrack = remoteVideoTrack; | 114 self.remoteVideoTrack = remoteVideoTrack; |
| 107 _videoCallView.statusLabel.hidden = YES; | 115 _videoCallView.statusLabel.hidden = YES; |
| 108 } | 116 } |
| 109 | 117 |
| 110 - (void)appClient:(ARDAppClient *)client | 118 - (void)appClient:(ARDAppClient *)client |
| 111 didGetStats:(NSArray *)stats { | 119 didGetStats:(NSArray *)stats { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 123 | 131 |
| 124 #pragma mark - ARDVideoCallViewDelegate | 132 #pragma mark - ARDVideoCallViewDelegate |
| 125 | 133 |
| 126 - (void)videoCallViewDidHangup:(ARDVideoCallView *)view { | 134 - (void)videoCallViewDidHangup:(ARDVideoCallView *)view { |
| 127 [self hangup]; | 135 [self hangup]; |
| 128 } | 136 } |
| 129 | 137 |
| 130 - (void)videoCallViewDidSwitchCamera:(ARDVideoCallView *)view { | 138 - (void)videoCallViewDidSwitchCamera:(ARDVideoCallView *)view { |
| 131 // TODO(tkchin): Rate limit this so you can't tap continously on it. | 139 // TODO(tkchin): Rate limit this so you can't tap continously on it. |
| 132 // Probably through an animation. | 140 // Probably through an animation. |
| 133 [self switchCamera]; | 141 [_captureController switchCamera]; |
| 134 } | 142 } |
| 135 | 143 |
| 136 - (void)videoCallViewDidChangeRoute:(ARDVideoCallView *)view { | 144 - (void)videoCallViewDidChangeRoute:(ARDVideoCallView *)view { |
| 137 AVAudioSessionPortOverride override = AVAudioSessionPortOverrideNone; | 145 AVAudioSessionPortOverride override = AVAudioSessionPortOverrideNone; |
| 138 if (_portOverride == AVAudioSessionPortOverrideNone) { | 146 if (_portOverride == AVAudioSessionPortOverrideNone) { |
| 139 override = AVAudioSessionPortOverrideSpeaker; | 147 override = AVAudioSessionPortOverrideSpeaker; |
| 140 } | 148 } |
| 141 [RTCDispatcher dispatchAsyncOnType:RTCDispatcherTypeAudioSession | 149 [RTCDispatcher dispatchAsyncOnType:RTCDispatcherTypeAudioSession |
| 142 block:^{ | 150 block:^{ |
| 143 RTCAudioSession *session = [RTCAudioSession sharedInstance]; | 151 RTCAudioSession *session = [RTCAudioSession sharedInstance]; |
| 144 [session lockForConfiguration]; | 152 [session lockForConfiguration]; |
| 145 NSError *error = nil; | 153 NSError *error = nil; |
| 146 if ([session overrideOutputAudioPort:override error:&error]) { | 154 if ([session overrideOutputAudioPort:override error:&error]) { |
| 147 _portOverride = override; | 155 _portOverride = override; |
| 148 } else { | 156 } else { |
| 149 RTCLogError(@"Error overriding output port: %@", | 157 RTCLogError(@"Error overriding output port: %@", |
| 150 error.localizedDescription); | 158 error.localizedDescription); |
| 151 } | 159 } |
| 152 [session unlockForConfiguration]; | 160 [session unlockForConfiguration]; |
| 153 }]; | 161 }]; |
| 154 } | 162 } |
| 155 | 163 |
| 156 - (void)videoCallViewDidEnableStats:(ARDVideoCallView *)view { | 164 - (void)videoCallViewDidEnableStats:(ARDVideoCallView *)view { |
| 157 _client.shouldGetStats = YES; | 165 _client.shouldGetStats = YES; |
| 158 _videoCallView.statsView.hidden = NO; | 166 _videoCallView.statsView.hidden = NO; |
| 159 } | 167 } |
| 160 | 168 |
| 161 #pragma mark - Private | 169 #pragma mark - Private |
| 162 | 170 |
| 163 - (void)setLocalVideoTrack:(RTCVideoTrack *)localVideoTrack { | |
| 164 if (_localVideoTrack == localVideoTrack) { | |
| 165 return; | |
| 166 } | |
| 167 _localVideoTrack = nil; | |
| 168 _localVideoTrack = localVideoTrack; | |
| 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 } | |
| 176 | |
| 177 - (void)setRemoteVideoTrack:(RTCVideoTrack *)remoteVideoTrack { | 171 - (void)setRemoteVideoTrack:(RTCVideoTrack *)remoteVideoTrack { |
| 178 if (_remoteVideoTrack == remoteVideoTrack) { | 172 if (_remoteVideoTrack == remoteVideoTrack) { |
| 179 return; | 173 return; |
| 180 } | 174 } |
| 181 [_remoteVideoTrack removeRenderer:_videoCallView.remoteVideoView]; | 175 [_remoteVideoTrack removeRenderer:_videoCallView.remoteVideoView]; |
| 182 _remoteVideoTrack = nil; | 176 _remoteVideoTrack = nil; |
| 183 [_videoCallView.remoteVideoView renderFrame:nil]; | 177 [_videoCallView.remoteVideoView renderFrame:nil]; |
| 184 _remoteVideoTrack = remoteVideoTrack; | 178 _remoteVideoTrack = remoteVideoTrack; |
| 185 [_remoteVideoTrack addRenderer:_videoCallView.remoteVideoView]; | 179 [_remoteVideoTrack addRenderer:_videoCallView.remoteVideoView]; |
| 186 } | 180 } |
| 187 | 181 |
| 188 - (void)hangup { | 182 - (void)hangup { |
| 189 self.remoteVideoTrack = nil; | 183 self.remoteVideoTrack = nil; |
| 190 self.localVideoTrack = nil; | 184 _videoCallView.localVideoView.captureSession = nil; |
| 185 [_captureController stopCapture]; |
| 186 _captureController = nil; |
| 191 [_client disconnect]; | 187 [_client disconnect]; |
| 192 [_delegate viewControllerDidFinish:self]; | 188 [_delegate viewControllerDidFinish:self]; |
| 193 } | 189 } |
| 194 | 190 |
| 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 { | 191 - (NSString *)statusTextForState:(RTCIceConnectionState)state { |
| 204 switch (state) { | 192 switch (state) { |
| 205 case RTCIceConnectionStateNew: | 193 case RTCIceConnectionStateNew: |
| 206 case RTCIceConnectionStateChecking: | 194 case RTCIceConnectionStateChecking: |
| 207 return @"Connecting..."; | 195 return @"Connecting..."; |
| 208 case RTCIceConnectionStateConnected: | 196 case RTCIceConnectionStateConnected: |
| 209 case RTCIceConnectionStateCompleted: | 197 case RTCIceConnectionStateCompleted: |
| 210 case RTCIceConnectionStateFailed: | 198 case RTCIceConnectionStateFailed: |
| 211 case RTCIceConnectionStateDisconnected: | 199 case RTCIceConnectionStateDisconnected: |
| 212 case RTCIceConnectionStateClosed: | 200 case RTCIceConnectionStateClosed: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 224 UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"OK" | 212 UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"OK" |
| 225 style:UIAlertActionSty
leDefault | 213 style:UIAlertActionSty
leDefault |
| 226 handler:^(UIAlertAction
*action){ | 214 handler:^(UIAlertAction
*action){ |
| 227 }]; | 215 }]; |
| 228 | 216 |
| 229 [alert addAction:defaultAction]; | 217 [alert addAction:defaultAction]; |
| 230 [self presentViewController:alert animated:YES completion:nil]; | 218 [self presentViewController:alert animated:YES completion:nil]; |
| 231 } | 219 } |
| 232 | 220 |
| 233 @end | 221 @end |
| OLD | NEW |