OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2014 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 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 _timerHandler(); | 93 _timerHandler(); |
94 } | 94 } |
95 | 95 |
96 @end | 96 @end |
97 | 97 |
98 @implementation ARDAppClient { | 98 @implementation ARDAppClient { |
99 RTCFileLogger *_fileLogger; | 99 RTCFileLogger *_fileLogger; |
100 ARDTimerProxy *_statsTimer; | 100 ARDTimerProxy *_statsTimer; |
101 RTCMediaConstraints *_cameraConstraints; | 101 RTCMediaConstraints *_cameraConstraints; |
102 NSNumber *_maxBitrate; | 102 NSNumber *_maxBitrate; |
| 103 NSString *_videoCodec; |
103 } | 104 } |
104 | 105 |
105 @synthesize shouldGetStats = _shouldGetStats; | 106 @synthesize shouldGetStats = _shouldGetStats; |
106 @synthesize state = _state; | 107 @synthesize state = _state; |
107 @synthesize delegate = _delegate; | 108 @synthesize delegate = _delegate; |
108 @synthesize roomServerClient = _roomServerClient; | 109 @synthesize roomServerClient = _roomServerClient; |
109 @synthesize channel = _channel; | 110 @synthesize channel = _channel; |
110 @synthesize loopbackChannel = _loopbackChannel; | 111 @synthesize loopbackChannel = _loopbackChannel; |
111 @synthesize turnClient = _turnClient; | 112 @synthesize turnClient = _turnClient; |
112 @synthesize peerConnection = _peerConnection; | 113 @synthesize peerConnection = _peerConnection; |
113 @synthesize factory = _factory; | 114 @synthesize factory = _factory; |
114 @synthesize messageQueue = _messageQueue; | 115 @synthesize messageQueue = _messageQueue; |
115 @synthesize isTurnComplete = _isTurnComplete; | 116 @synthesize isTurnComplete = _isTurnComplete; |
116 @synthesize hasReceivedSdp = _hasReceivedSdp; | 117 @synthesize hasReceivedSdp = _hasReceivedSdp; |
117 @synthesize roomId = _roomId; | 118 @synthesize roomId = _roomId; |
118 @synthesize clientId = _clientId; | 119 @synthesize clientId = _clientId; |
119 @synthesize isInitiator = _isInitiator; | 120 @synthesize isInitiator = _isInitiator; |
120 @synthesize iceServers = _iceServers; | 121 @synthesize iceServers = _iceServers; |
121 @synthesize webSocketURL = _websocketURL; | 122 @synthesize webSocketURL = _websocketURL; |
122 @synthesize webSocketRestURL = _websocketRestURL; | 123 @synthesize webSocketRestURL = _websocketRestURL; |
123 @synthesize defaultPeerConnectionConstraints = | 124 @synthesize defaultPeerConnectionConstraints = |
124 _defaultPeerConnectionConstraints; | 125 _defaultPeerConnectionConstraints; |
125 @synthesize isLoopback = _isLoopback; | 126 @synthesize isLoopback = _isLoopback; |
126 @synthesize isAudioOnly = _isAudioOnly; | 127 @synthesize isAudioOnly = _isAudioOnly; |
127 @synthesize shouldMakeAecDump = _shouldMakeAecDump; | 128 @synthesize shouldMakeAecDump = _shouldMakeAecDump; |
128 @synthesize shouldUseLevelControl = _shouldUseLevelControl; | 129 @synthesize shouldUseLevelControl = _shouldUseLevelControl; |
129 | 130 |
130 - (instancetype)init { | 131 - (instancetype)init { |
131 return [self initWithDelegate:nil]; | 132 return [self initWithDelegate:nil preferVideoCodec:@"H264"]; |
132 } | 133 } |
133 | 134 |
134 - (instancetype)initWithDelegate:(id<ARDAppClientDelegate>)delegate { | 135 - (instancetype)initWithDelegate:(id<ARDAppClientDelegate>)delegate |
| 136 preferVideoCodec:(NSString *)codec { |
135 if (self = [super init]) { | 137 if (self = [super init]) { |
136 _roomServerClient = [[ARDAppEngineClient alloc] init]; | 138 _roomServerClient = [[ARDAppEngineClient alloc] init]; |
137 _delegate = delegate; | 139 _delegate = delegate; |
| 140 _videoCodec = codec; |
138 NSURL *turnRequestURL = [NSURL URLWithString:kARDIceServerRequestUrl]; | 141 NSURL *turnRequestURL = [NSURL URLWithString:kARDIceServerRequestUrl]; |
139 _turnClient = [[ARDTURNClient alloc] initWithURL:turnRequestURL]; | 142 _turnClient = [[ARDTURNClient alloc] initWithURL:turnRequestURL]; |
140 [self configure]; | 143 [self configure]; |
141 } | 144 } |
142 return self; | 145 return self; |
143 } | 146 } |
144 | 147 |
145 // TODO(tkchin): Provide signaling channel factory interface so we can recreate | 148 // TODO(tkchin): Provide signaling channel factory interface so we can recreate |
146 // channel if we need to on network failure. Also, make this the default public | 149 // channel if we need to on network failure. Also, make this the default public |
147 // constructor. | 150 // constructor. |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 NSDictionary *userInfo = @{ | 448 NSDictionary *userInfo = @{ |
446 NSLocalizedDescriptionKey: @"Failed to create session description.", | 449 NSLocalizedDescriptionKey: @"Failed to create session description.", |
447 }; | 450 }; |
448 NSError *sdpError = | 451 NSError *sdpError = |
449 [[NSError alloc] initWithDomain:kARDAppClientErrorDomain | 452 [[NSError alloc] initWithDomain:kARDAppClientErrorDomain |
450 code:kARDAppClientErrorCreateSDP | 453 code:kARDAppClientErrorCreateSDP |
451 userInfo:userInfo]; | 454 userInfo:userInfo]; |
452 [_delegate appClient:self didError:sdpError]; | 455 [_delegate appClient:self didError:sdpError]; |
453 return; | 456 return; |
454 } | 457 } |
455 // Prefer H264 if available. | 458 // Prefer codec from settings if available. |
456 RTCSessionDescription *sdpPreferringH264 = | 459 RTCSessionDescription *sdpPreferringCodec = |
457 [ARDSDPUtils descriptionForDescription:sdp | 460 [ARDSDPUtils descriptionForDescription:sdp |
458 preferredVideoCodec:@"H264"]; | 461 preferredVideoCodec:_videoCodec]; |
459 __weak ARDAppClient *weakSelf = self; | 462 __weak ARDAppClient *weakSelf = self; |
460 [_peerConnection setLocalDescription:sdpPreferringH264 | 463 [_peerConnection setLocalDescription:sdpPreferringCodec |
461 completionHandler:^(NSError *error) { | 464 completionHandler:^(NSError *error) { |
462 ARDAppClient *strongSelf = weakSelf; | 465 ARDAppClient *strongSelf = weakSelf; |
463 [strongSelf peerConnection:strongSelf.peerConnection | 466 [strongSelf peerConnection:strongSelf.peerConnection |
464 didSetSessionDescriptionWithError:error]; | 467 didSetSessionDescriptionWithError:error]; |
465 }]; | 468 }]; |
466 ARDSessionDescriptionMessage *message = | 469 ARDSessionDescriptionMessage *message = |
467 [[ARDSessionDescriptionMessage alloc] | 470 [[ARDSessionDescriptionMessage alloc] |
468 initWithDescription:sdpPreferringH264]; | 471 initWithDescription:sdpPreferringCodec]; |
469 [self sendSignalingMessage:message]; | 472 [self sendSignalingMessage:message]; |
470 [self setMaxBitrateForPeerConnectionVideoSender]; | 473 [self setMaxBitrateForPeerConnectionVideoSender]; |
471 }); | 474 }); |
472 } | 475 } |
473 | 476 |
474 - (void)peerConnection:(RTCPeerConnection *)peerConnection | 477 - (void)peerConnection:(RTCPeerConnection *)peerConnection |
475 didSetSessionDescriptionWithError:(NSError *)error { | 478 didSetSessionDescriptionWithError:(NSError *)error { |
476 dispatch_async(dispatch_get_main_queue(), ^{ | 479 dispatch_async(dispatch_get_main_queue(), ^{ |
477 if (error) { | 480 if (error) { |
478 RTCLogError(@"Failed to set session description. Error: %@", error); | 481 RTCLogError(@"Failed to set session description. Error: %@", error); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 // Processes the given signaling message based on its type. | 602 // Processes the given signaling message based on its type. |
600 - (void)processSignalingMessage:(ARDSignalingMessage *)message { | 603 - (void)processSignalingMessage:(ARDSignalingMessage *)message { |
601 NSParameterAssert(_peerConnection || | 604 NSParameterAssert(_peerConnection || |
602 message.type == kARDSignalingMessageTypeBye); | 605 message.type == kARDSignalingMessageTypeBye); |
603 switch (message.type) { | 606 switch (message.type) { |
604 case kARDSignalingMessageTypeOffer: | 607 case kARDSignalingMessageTypeOffer: |
605 case kARDSignalingMessageTypeAnswer: { | 608 case kARDSignalingMessageTypeAnswer: { |
606 ARDSessionDescriptionMessage *sdpMessage = | 609 ARDSessionDescriptionMessage *sdpMessage = |
607 (ARDSessionDescriptionMessage *)message; | 610 (ARDSessionDescriptionMessage *)message; |
608 RTCSessionDescription *description = sdpMessage.sessionDescription; | 611 RTCSessionDescription *description = sdpMessage.sessionDescription; |
609 // Prefer H264 if available. | 612 // Prefer codec from settings if available. |
610 RTCSessionDescription *sdpPreferringH264 = | 613 RTCSessionDescription *sdpPreferringCodec = |
611 [ARDSDPUtils descriptionForDescription:description | 614 [ARDSDPUtils descriptionForDescription:description |
612 preferredVideoCodec:@"H264"]; | 615 preferredVideoCodec:_videoCodec]; |
613 __weak ARDAppClient *weakSelf = self; | 616 __weak ARDAppClient *weakSelf = self; |
614 [_peerConnection setRemoteDescription:sdpPreferringH264 | 617 [_peerConnection setRemoteDescription:sdpPreferringCodec |
615 completionHandler:^(NSError *error) { | 618 completionHandler:^(NSError *error) { |
616 ARDAppClient *strongSelf = weakSelf; | 619 ARDAppClient *strongSelf = weakSelf; |
617 [strongSelf peerConnection:strongSelf.peerConnection | 620 [strongSelf peerConnection:strongSelf.peerConnection |
618 didSetSessionDescriptionWithError:error]; | 621 didSetSessionDescriptionWithError:error]; |
619 }]; | 622 }]; |
620 break; | 623 break; |
621 } | 624 } |
622 case kARDSignalingMessageTypeCandidate: { | 625 case kARDSignalingMessageTypeCandidate: { |
623 ARDICECandidateMessage *candidateMessage = | 626 ARDICECandidateMessage *candidateMessage = |
624 (ARDICECandidateMessage *)message; | 627 (ARDICECandidateMessage *)message; |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 code:kARDAppClientErrorInvalidRoom | 857 code:kARDAppClientErrorInvalidRoom |
855 userInfo:@{ | 858 userInfo:@{ |
856 NSLocalizedDescriptionKey: @"Invalid room.", | 859 NSLocalizedDescriptionKey: @"Invalid room.", |
857 }]; | 860 }]; |
858 break; | 861 break; |
859 } | 862 } |
860 return error; | 863 return error; |
861 } | 864 } |
862 | 865 |
863 @end | 866 @end |
OLD | NEW |