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 |
11 #import "ARDAppClient+Internal.h" | 11 #import "ARDAppClient+Internal.h" |
12 | 12 |
13 #import "WebRTC/RTCAVFoundationVideoSource.h" | 13 #import "WebRTC/RTCAVFoundationVideoSource.h" |
14 #import "WebRTC/RTCAudioTrack.h" | 14 #import "WebRTC/RTCAudioTrack.h" |
15 #import "WebRTC/RTCCameraVideoCapturer.h" | 15 #import "WebRTC/RTCCameraVideoCapturer.h" |
16 #import "WebRTC/RTCConfiguration.h" | 16 #import "WebRTC/RTCConfiguration.h" |
17 #import "WebRTC/RTCFileLogger.h" | 17 #import "WebRTC/RTCFileLogger.h" |
18 #import "WebRTC/RTCIceServer.h" | 18 #import "WebRTC/RTCIceServer.h" |
19 #import "WebRTC/RTCLogging.h" | 19 #import "WebRTC/RTCLogging.h" |
20 #import "WebRTC/RTCMediaConstraints.h" | 20 #import "WebRTC/RTCMediaConstraints.h" |
21 #import "WebRTC/RTCMediaStream.h" | 21 #import "WebRTC/RTCMediaStream.h" |
22 #import "WebRTC/RTCPeerConnectionFactory.h" | 22 #import "WebRTC/RTCPeerConnectionFactory.h" |
23 #import "WebRTC/RTCRtpSender.h" | 23 #import "WebRTC/RTCRtpSender.h" |
24 #import "WebRTC/RTCTracing.h" | 24 #import "WebRTC/RTCTracing.h" |
25 #import "WebRTC/RTCVideoTrack.h" | 25 #import "WebRTC/RTCVideoTrack.h" |
26 | 26 |
27 #import "ARDAppEngineClient.h" | 27 #import "ARDAppEngineClient.h" |
| 28 #import "ARDBitrateAllocationStrategy.h" |
28 #import "ARDJoinResponse.h" | 29 #import "ARDJoinResponse.h" |
29 #import "ARDMessageResponse.h" | 30 #import "ARDMessageResponse.h" |
30 #import "ARDSDPUtils.h" | 31 #import "ARDSDPUtils.h" |
31 #import "ARDSettingsModel.h" | 32 #import "ARDSettingsModel.h" |
32 #import "ARDSignalingMessage.h" | 33 #import "ARDSignalingMessage.h" |
33 #import "ARDTURNClient+Internal.h" | 34 #import "ARDTURNClient+Internal.h" |
34 #import "ARDUtilities.h" | 35 #import "ARDUtilities.h" |
35 #import "ARDWebSocketChannel.h" | 36 #import "ARDWebSocketChannel.h" |
36 #import "RTCIceCandidate+JSON.h" | 37 #import "RTCIceCandidate+JSON.h" |
37 #import "RTCSessionDescription+JSON.h" | 38 #import "RTCSessionDescription+JSON.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 _timerHandler(); | 97 _timerHandler(); |
97 } | 98 } |
98 | 99 |
99 @end | 100 @end |
100 | 101 |
101 @implementation ARDAppClient { | 102 @implementation ARDAppClient { |
102 RTCFileLogger *_fileLogger; | 103 RTCFileLogger *_fileLogger; |
103 ARDTimerProxy *_statsTimer; | 104 ARDTimerProxy *_statsTimer; |
104 ARDSettingsModel *_settings; | 105 ARDSettingsModel *_settings; |
105 RTCVideoTrack *_localVideoTrack; | 106 RTCVideoTrack *_localVideoTrack; |
| 107 ARDBitrateAllocationStrategy *_bitrateAllocationStrategy; |
106 } | 108 } |
107 | 109 |
108 @synthesize shouldGetStats = _shouldGetStats; | 110 @synthesize shouldGetStats = _shouldGetStats; |
109 @synthesize state = _state; | 111 @synthesize state = _state; |
110 @synthesize delegate = _delegate; | 112 @synthesize delegate = _delegate; |
111 @synthesize roomServerClient = _roomServerClient; | 113 @synthesize roomServerClient = _roomServerClient; |
112 @synthesize channel = _channel; | 114 @synthesize channel = _channel; |
113 @synthesize loopbackChannel = _loopbackChannel; | 115 @synthesize loopbackChannel = _loopbackChannel; |
114 @synthesize turnClient = _turnClient; | 116 @synthesize turnClient = _turnClient; |
115 @synthesize peerConnection = _peerConnection; | 117 @synthesize peerConnection = _peerConnection; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 } | 295 } |
294 // Disconnect from collider. | 296 // Disconnect from collider. |
295 _channel = nil; | 297 _channel = nil; |
296 } | 298 } |
297 _clientId = nil; | 299 _clientId = nil; |
298 _roomId = nil; | 300 _roomId = nil; |
299 _isInitiator = NO; | 301 _isInitiator = NO; |
300 _hasReceivedSdp = NO; | 302 _hasReceivedSdp = NO; |
301 _messageQueue = [NSMutableArray array]; | 303 _messageQueue = [NSMutableArray array]; |
302 _localVideoTrack = nil; | 304 _localVideoTrack = nil; |
| 305 _bitrateAllocationStrategy = nil; |
| 306 |
303 #if defined(WEBRTC_IOS) | 307 #if defined(WEBRTC_IOS) |
304 [_factory stopAecDump]; | 308 [_factory stopAecDump]; |
305 [_peerConnection stopRtcEventLog]; | 309 [_peerConnection stopRtcEventLog]; |
306 #endif | 310 #endif |
307 [_peerConnection close]; | 311 [_peerConnection close]; |
308 _peerConnection = nil; | 312 _peerConnection = nil; |
309 self.state = kARDAppClientStateDisconnected; | 313 self.state = kARDAppClientStateDisconnected; |
310 #if defined(WEBRTC_IOS) | 314 #if defined(WEBRTC_IOS) |
311 if (kARDAppClientEnableTracing) { | 315 if (kARDAppClientEnableTracing) { |
312 RTCStopInternalCapture(); | 316 RTCStopInternalCapture(); |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 } | 529 } |
526 self.state = kARDAppClientStateConnected; | 530 self.state = kARDAppClientStateConnected; |
527 | 531 |
528 // Create peer connection. | 532 // Create peer connection. |
529 RTCMediaConstraints *constraints = [self defaultPeerConnectionConstraints]; | 533 RTCMediaConstraints *constraints = [self defaultPeerConnectionConstraints]; |
530 RTCConfiguration *config = [[RTCConfiguration alloc] init]; | 534 RTCConfiguration *config = [[RTCConfiguration alloc] init]; |
531 config.iceServers = _iceServers; | 535 config.iceServers = _iceServers; |
532 _peerConnection = [_factory peerConnectionWithConfiguration:config | 536 _peerConnection = [_factory peerConnectionWithConfiguration:config |
533 constraints:constraints | 537 constraints:constraints |
534 delegate:self]; | 538 delegate:self]; |
| 539 |
| 540 // Create bitrate allocation strategy |
| 541 _bitrateAllocationStrategy = [ARDBitrateAllocationStrategy new]; |
| 542 [_bitrateAllocationStrategy setAudioPriorityStrategy:_peerConnection |
| 543 audioTrackId:kARDAudioTrackId]; |
| 544 |
535 // Create AV senders. | 545 // Create AV senders. |
536 [self createMediaSenders]; | 546 [self createMediaSenders]; |
| 547 |
537 if (_isInitiator) { | 548 if (_isInitiator) { |
538 // Send offer. | 549 // Send offer. |
539 __weak ARDAppClient *weakSelf = self; | 550 __weak ARDAppClient *weakSelf = self; |
540 [_peerConnection offerForConstraints:[self defaultOfferConstraints] | 551 [_peerConnection offerForConstraints:[self defaultOfferConstraints] |
541 completionHandler:^(RTCSessionDescription *sdp, | 552 completionHandler:^(RTCSessionDescription *sdp, |
542 NSError *error) { | 553 NSError *error) { |
543 ARDAppClient *strongSelf = weakSelf; | 554 ARDAppClient *strongSelf = weakSelf; |
544 [strongSelf peerConnection:strongSelf.peerConnection | 555 [strongSelf peerConnection:strongSelf.peerConnection |
545 didCreateSessionDescription:sdp | 556 didCreateSessionDescription:sdp |
546 error:error]; | 557 error:error]; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 } | 691 } |
681 | 692 |
682 - (void)createMediaSenders { | 693 - (void)createMediaSenders { |
683 RTCMediaConstraints *constraints = [self defaultMediaAudioConstraints]; | 694 RTCMediaConstraints *constraints = [self defaultMediaAudioConstraints]; |
684 RTCAudioSource *source = [_factory audioSourceWithConstraints:constraints]; | 695 RTCAudioSource *source = [_factory audioSourceWithConstraints:constraints]; |
685 RTCAudioTrack *track = [_factory audioTrackWithSource:source | 696 RTCAudioTrack *track = [_factory audioTrackWithSource:source |
686 trackId:kARDAudioTrackId]; | 697 trackId:kARDAudioTrackId]; |
687 RTCMediaStream *stream = [_factory mediaStreamWithStreamId:kARDMediaStreamId]; | 698 RTCMediaStream *stream = [_factory mediaStreamWithStreamId:kARDMediaStreamId]; |
688 [stream addAudioTrack:track]; | 699 [stream addAudioTrack:track]; |
689 _localVideoTrack = [self createLocalVideoTrack]; | 700 _localVideoTrack = [self createLocalVideoTrack]; |
690 if(_localVideoTrack) { | 701 if (_localVideoTrack) { |
691 [stream addVideoTrack:_localVideoTrack]; | 702 [stream addVideoTrack:_localVideoTrack]; |
692 } | 703 } |
693 [_peerConnection addStream:stream]; | 704 [_peerConnection addStream:stream]; |
694 } | 705 } |
695 | 706 |
696 - (RTCVideoTrack *)createLocalVideoTrack { | 707 - (RTCVideoTrack *)createLocalVideoTrack { |
697 RTCVideoTrack* localVideoTrack = nil; | 708 RTCVideoTrack* localVideoTrack = nil; |
698 // The iOS simulator doesn't provide any sort of camera capture | 709 // The iOS simulator doesn't provide any sort of camera capture |
699 // support or emulation (http://goo.gl/rHAnC1) so don't bother | 710 // support or emulation (http://goo.gl/rHAnC1) so don't bother |
700 // trying to open a local stream. | 711 // trying to open a local stream. |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 code:kARDAppClientErrorInvalidRoom | 839 code:kARDAppClientErrorInvalidRoom |
829 userInfo:@{ | 840 userInfo:@{ |
830 NSLocalizedDescriptionKey: @"Invalid room.", | 841 NSLocalizedDescriptionKey: @"Invalid room.", |
831 }]; | 842 }]; |
832 break; | 843 break; |
833 } | 844 } |
834 return error; | 845 return error; |
835 } | 846 } |
836 | 847 |
837 @end | 848 @end |
OLD | NEW |