| 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 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 self.state = kARDAppClientStateConnected; | 525 self.state = kARDAppClientStateConnected; |
| 526 | 526 |
| 527 // Create peer connection. | 527 // Create peer connection. |
| 528 RTCMediaConstraints *constraints = [self defaultPeerConnectionConstraints]; | 528 RTCMediaConstraints *constraints = [self defaultPeerConnectionConstraints]; |
| 529 RTCConfiguration *config = [[RTCConfiguration alloc] init]; | 529 RTCConfiguration *config = [[RTCConfiguration alloc] init]; |
| 530 config.iceServers = _iceServers; | 530 config.iceServers = _iceServers; |
| 531 _peerConnection = [_factory peerConnectionWithConfiguration:config | 531 _peerConnection = [_factory peerConnectionWithConfiguration:config |
| 532 constraints:constraints | 532 constraints:constraints |
| 533 delegate:self]; | 533 delegate:self]; |
| 534 // Create AV senders. | 534 // Create AV senders. |
| 535 [self createAudioSender]; | 535 [self createMediaSenders]; |
| 536 [self createVideoSender]; | |
| 537 if (_isInitiator) { | 536 if (_isInitiator) { |
| 538 // Send offer. | 537 // Send offer. |
| 539 __weak ARDAppClient *weakSelf = self; | 538 __weak ARDAppClient *weakSelf = self; |
| 540 [_peerConnection offerForConstraints:[self defaultOfferConstraints] | 539 [_peerConnection offerForConstraints:[self defaultOfferConstraints] |
| 541 completionHandler:^(RTCSessionDescription *sdp, | 540 completionHandler:^(RTCSessionDescription *sdp, |
| 542 NSError *error) { | 541 NSError *error) { |
| 543 ARDAppClient *strongSelf = weakSelf; | 542 ARDAppClient *strongSelf = weakSelf; |
| 544 [strongSelf peerConnection:strongSelf.peerConnection | 543 [strongSelf peerConnection:strongSelf.peerConnection |
| 545 didCreateSessionDescription:sdp | 544 didCreateSessionDescription:sdp |
| 546 error:error]; | 545 error:error]; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 if (messageError) { | 649 if (messageError) { |
| 651 [strongSelf.delegate appClient:strongSelf didError:messageError]; | 650 [strongSelf.delegate appClient:strongSelf didError:messageError]; |
| 652 return; | 651 return; |
| 653 } | 652 } |
| 654 }]; | 653 }]; |
| 655 } else { | 654 } else { |
| 656 [_channel sendMessage:message]; | 655 [_channel sendMessage:message]; |
| 657 } | 656 } |
| 658 } | 657 } |
| 659 | 658 |
| 660 - (RTCRtpSender *)createVideoSender { | |
| 661 RTCRtpSender *sender = | |
| 662 [_peerConnection senderWithKind:kRTCMediaStreamTrackKindVideo | |
| 663 streamId:kARDMediaStreamId]; | |
| 664 _localVideoTrack = [self createLocalVideoTrack]; | |
| 665 if (_localVideoTrack) { | |
| 666 sender.track = _localVideoTrack; | |
| 667 [_delegate appClient:self didReceiveLocalVideoTrack:_localVideoTrack]; | |
| 668 } | |
| 669 | |
| 670 return sender; | |
| 671 } | |
| 672 | |
| 673 - (void)setMaxBitrateForPeerConnectionVideoSender { | 659 - (void)setMaxBitrateForPeerConnectionVideoSender { |
| 674 for (RTCRtpSender *sender in _peerConnection.senders) { | 660 for (RTCRtpSender *sender in _peerConnection.senders) { |
| 675 if (sender.track != nil) { | 661 if (sender.track != nil) { |
| 676 if ([sender.track.kind isEqualToString:kARDVideoTrackKind]) { | 662 if ([sender.track.kind isEqualToString:kARDVideoTrackKind]) { |
| 677 [self setMaxBitrate:[_settings currentMaxBitrateSettingFromStore] forVid
eoSender:sender]; | 663 [self setMaxBitrate:[_settings currentMaxBitrateSettingFromStore] forVid
eoSender:sender]; |
| 678 } | 664 } |
| 679 } | 665 } |
| 680 } | 666 } |
| 681 } | 667 } |
| 682 | 668 |
| 683 - (void)setMaxBitrate:(NSNumber *)maxBitrate forVideoSender:(RTCRtpSender *)send
er { | 669 - (void)setMaxBitrate:(NSNumber *)maxBitrate forVideoSender:(RTCRtpSender *)send
er { |
| 684 if (maxBitrate.intValue <= 0) { | 670 if (maxBitrate.intValue <= 0) { |
| 685 return; | 671 return; |
| 686 } | 672 } |
| 687 | 673 |
| 688 RTCRtpParameters *parametersToModify = sender.parameters; | 674 RTCRtpParameters *parametersToModify = sender.parameters; |
| 689 for (RTCRtpEncodingParameters *encoding in parametersToModify.encodings) { | 675 for (RTCRtpEncodingParameters *encoding in parametersToModify.encodings) { |
| 690 encoding.maxBitrateBps = @(maxBitrate.intValue * kKbpsMultiplier); | 676 encoding.maxBitrateBps = @(maxBitrate.intValue * kKbpsMultiplier); |
| 691 } | 677 } |
| 692 [sender setParameters:parametersToModify]; | 678 [sender setParameters:parametersToModify]; |
| 693 } | 679 } |
| 694 | 680 |
| 695 - (RTCRtpSender *)createAudioSender { | 681 - (void)createMediaSenders { |
| 696 RTCMediaConstraints *constraints = [self defaultMediaAudioConstraints]; | 682 RTCMediaConstraints *constraints = [self defaultMediaAudioConstraints]; |
| 697 RTCAudioSource *source = [_factory audioSourceWithConstraints:constraints]; | 683 RTCAudioSource *source = [_factory audioSourceWithConstraints:constraints]; |
| 698 RTCAudioTrack *track = [_factory audioTrackWithSource:source | 684 RTCAudioTrack *track = [_factory audioTrackWithSource:source |
| 699 trackId:kARDAudioTrackId]; | 685 trackId:kARDAudioTrackId]; |
| 700 RTCRtpSender *sender = | 686 RTCMediaStream *stream = [_factory mediaStreamWithStreamId:kARDMediaStreamId]; |
| 701 [_peerConnection senderWithKind:kRTCMediaStreamTrackKindAudio | 687 [stream addAudioTrack:track]; |
| 702 streamId:kARDMediaStreamId]; | 688 _localVideoTrack = [self createLocalVideoTrack]; |
| 703 sender.track = track; | 689 if(_localVideoTrack) { |
| 704 return sender; | 690 [stream addVideoTrack:_localVideoTrack]; |
| 691 } |
| 692 [_peerConnection addStream:stream]; |
| 705 } | 693 } |
| 706 | 694 |
| 707 - (RTCVideoTrack *)createLocalVideoTrack { | 695 - (RTCVideoTrack *)createLocalVideoTrack { |
| 708 RTCVideoTrack* localVideoTrack = nil; | 696 RTCVideoTrack* localVideoTrack = nil; |
| 709 // The iOS simulator doesn't provide any sort of camera capture | 697 // The iOS simulator doesn't provide any sort of camera capture |
| 710 // support or emulation (http://goo.gl/rHAnC1) so don't bother | 698 // support or emulation (http://goo.gl/rHAnC1) so don't bother |
| 711 // trying to open a local stream. | 699 // trying to open a local stream. |
| 712 #if !TARGET_IPHONE_SIMULATOR | 700 #if !TARGET_IPHONE_SIMULATOR |
| 713 if (![_settings currentAudioOnlySettingFromStore]) { | 701 if (![_settings currentAudioOnlySettingFromStore]) { |
| 714 RTCVideoSource *source = [_factory videoSource]; | 702 RTCVideoSource *source = [_factory videoSource]; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 code:kARDAppClientErrorInvalidRoom | 827 code:kARDAppClientErrorInvalidRoom |
| 840 userInfo:@{ | 828 userInfo:@{ |
| 841 NSLocalizedDescriptionKey: @"Invalid room.", | 829 NSLocalizedDescriptionKey: @"Invalid room.", |
| 842 }]; | 830 }]; |
| 843 break; | 831 break; |
| 844 } | 832 } |
| 845 return error; | 833 return error; |
| 846 } | 834 } |
| 847 | 835 |
| 848 @end | 836 @end |
| OLD | NEW |