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 #if defined(WEBRTC_IOS) | 13 #if defined(WEBRTC_IOS) |
14 #import "WebRTC/RTCAVFoundationVideoSource.h" | 14 #import "WebRTC/RTCAVFoundationVideoSource.h" |
15 #import "WebRTC/RTCTracing.h" | 15 #import "WebRTC/RTCTracing.h" |
16 #endif | 16 #endif |
17 #import "WebRTC/RTCAudioTrack.h" | 17 #import "WebRTC/RTCAudioTrack.h" |
18 #import "WebRTC/RTCConfiguration.h" | 18 #import "WebRTC/RTCConfiguration.h" |
19 #import "WebRTC/RTCFileLogger.h" | 19 #import "WebRTC/RTCFileLogger.h" |
20 #import "WebRTC/RTCIceServer.h" | 20 #import "WebRTC/RTCIceServer.h" |
21 #import "WebRTC/RTCLogging.h" | 21 #import "WebRTC/RTCLogging.h" |
22 #import "WebRTC/RTCMediaConstraints.h" | 22 #import "WebRTC/RTCMediaConstraints.h" |
23 #import "WebRTC/RTCMediaStream.h" | 23 #import "WebRTC/RTCMediaStream.h" |
24 #import "WebRTC/RTCPeerConnectionFactory.h" | 24 #import "WebRTC/RTCPeerConnectionFactory.h" |
| 25 #import "WebRTC/RTCRtpSender.h" |
25 | 26 |
26 #import "ARDAppEngineClient.h" | 27 #import "ARDAppEngineClient.h" |
27 #import "ARDCEODTURNClient.h" | 28 #import "ARDCEODTURNClient.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 "ARDSignalingMessage.h" | 32 #import "ARDSignalingMessage.h" |
32 #import "ARDUtilities.h" | 33 #import "ARDUtilities.h" |
33 #import "ARDWebSocketChannel.h" | 34 #import "ARDWebSocketChannel.h" |
34 #import "RTCIceCandidate+JSON.h" | 35 #import "RTCIceCandidate+JSON.h" |
35 #import "RTCSessionDescription+JSON.h" | 36 #import "RTCSessionDescription+JSON.h" |
36 | 37 |
37 static NSString * const kARDDefaultSTUNServerUrl = | 38 static NSString * const kARDDefaultSTUNServerUrl = |
38 @"stun:stun.l.google.com:19302"; | 39 @"stun:stun.l.google.com:19302"; |
39 // TODO(tkchin): figure out a better username for CEOD statistics. | 40 // TODO(tkchin): figure out a better username for CEOD statistics. |
40 static NSString * const kARDTurnRequestUrl = | 41 static NSString * const kARDTurnRequestUrl = |
41 @"https://computeengineondemand.appspot.com" | 42 @"https://computeengineondemand.appspot.com" |
42 @"/turn?username=iapprtc&key=4080218913"; | 43 @"/turn?username=iapprtc&key=4080218913"; |
43 | 44 |
44 static NSString * const kARDAppClientErrorDomain = @"ARDAppClient"; | 45 static NSString * const kARDAppClientErrorDomain = @"ARDAppClient"; |
45 static NSInteger const kARDAppClientErrorUnknown = -1; | 46 static NSInteger const kARDAppClientErrorUnknown = -1; |
46 static NSInteger const kARDAppClientErrorRoomFull = -2; | 47 static NSInteger const kARDAppClientErrorRoomFull = -2; |
47 static NSInteger const kARDAppClientErrorCreateSDP = -3; | 48 static NSInteger const kARDAppClientErrorCreateSDP = -3; |
48 static NSInteger const kARDAppClientErrorSetSDP = -4; | 49 static NSInteger const kARDAppClientErrorSetSDP = -4; |
49 static NSInteger const kARDAppClientErrorInvalidClient = -5; | 50 static NSInteger const kARDAppClientErrorInvalidClient = -5; |
50 static NSInteger const kARDAppClientErrorInvalidRoom = -6; | 51 static NSInteger const kARDAppClientErrorInvalidRoom = -6; |
| 52 static NSString * const kARDMediaStreamId = @"ARDAMS"; |
| 53 static NSString * const kARDAudioTrackId = @"ARDAMSa0"; |
| 54 static NSString * const kARDVideoTrackId = @"ARDAMSv0"; |
51 | 55 |
52 // TODO(tkchin): Remove guard once rtc_sdk_common_objc compiles on Mac. | 56 // TODO(tkchin): Remove guard once rtc_sdk_common_objc compiles on Mac. |
53 #if defined(WEBRTC_IOS) | 57 #if defined(WEBRTC_IOS) |
54 // TODO(tkchin): Add this as a UI option. | 58 // TODO(tkchin): Add this as a UI option. |
55 static BOOL const kARDAppClientEnableTracing = NO; | 59 static BOOL const kARDAppClientEnableTracing = NO; |
56 #endif | 60 #endif |
57 | 61 |
58 // We need a proxy to NSTimer because it causes a strong retain cycle. When | 62 // We need a proxy to NSTimer because it causes a strong retain cycle. When |
59 // using the proxy, |invalidate| must be called before it properly deallocs. | 63 // using the proxy, |invalidate| must be called before it properly deallocs. |
60 @interface ARDTimerProxy : NSObject | 64 @interface ARDTimerProxy : NSObject |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 } | 502 } |
499 self.state = kARDAppClientStateConnected; | 503 self.state = kARDAppClientStateConnected; |
500 | 504 |
501 // Create peer connection. | 505 // Create peer connection. |
502 RTCMediaConstraints *constraints = [self defaultPeerConnectionConstraints]; | 506 RTCMediaConstraints *constraints = [self defaultPeerConnectionConstraints]; |
503 RTCConfiguration *config = [[RTCConfiguration alloc] init]; | 507 RTCConfiguration *config = [[RTCConfiguration alloc] init]; |
504 config.iceServers = _iceServers; | 508 config.iceServers = _iceServers; |
505 _peerConnection = [_factory peerConnectionWithConfiguration:config | 509 _peerConnection = [_factory peerConnectionWithConfiguration:config |
506 constraints:constraints | 510 constraints:constraints |
507 delegate:self]; | 511 delegate:self]; |
508 // Create AV media stream and add it to the peer connection. | 512 // Create AV senders. |
509 RTCMediaStream *localStream = [self createLocalMediaStream]; | 513 [self createAudioSender]; |
510 [_peerConnection addStream:localStream]; | 514 [self createVideoSender]; |
511 if (_isInitiator) { | 515 if (_isInitiator) { |
512 // Send offer. | 516 // Send offer. |
513 __weak ARDAppClient *weakSelf = self; | 517 __weak ARDAppClient *weakSelf = self; |
514 [_peerConnection offerForConstraints:[self defaultOfferConstraints] | 518 [_peerConnection offerForConstraints:[self defaultOfferConstraints] |
515 completionHandler:^(RTCSessionDescription *sdp, | 519 completionHandler:^(RTCSessionDescription *sdp, |
516 NSError *error) { | 520 NSError *error) { |
517 ARDAppClient *strongSelf = weakSelf; | 521 ARDAppClient *strongSelf = weakSelf; |
518 [strongSelf peerConnection:strongSelf.peerConnection | 522 [strongSelf peerConnection:strongSelf.peerConnection |
519 didCreateSessionDescription:sdp | 523 didCreateSessionDescription:sdp |
520 error:error]; | 524 error:error]; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 if (messageError) { | 603 if (messageError) { |
600 [strongSelf.delegate appClient:strongSelf didError:messageError]; | 604 [strongSelf.delegate appClient:strongSelf didError:messageError]; |
601 return; | 605 return; |
602 } | 606 } |
603 }]; | 607 }]; |
604 } else { | 608 } else { |
605 [_channel sendMessage:message]; | 609 [_channel sendMessage:message]; |
606 } | 610 } |
607 } | 611 } |
608 | 612 |
609 - (RTCMediaStream *)createLocalMediaStream { | 613 - (RTCRtpSender *)createVideoSender { |
610 RTCMediaStream *localStream = [_factory mediaStreamWithStreamId:@"ARDAMS"]; | 614 RTCRtpSender *sender = |
611 RTCVideoTrack *localVideoTrack = [self createLocalVideoTrack]; | 615 [_peerConnection senderWithKind:kRTCMediaStreamTrackKindVideo |
612 if (localVideoTrack) { | 616 streamId:kARDMediaStreamId]; |
613 [localStream addVideoTrack:localVideoTrack]; | 617 RTCVideoTrack *track = [self createLocalVideoTrack]; |
614 [_delegate appClient:self didReceiveLocalVideoTrack:localVideoTrack]; | 618 if (track) { |
| 619 sender.track = track; |
| 620 [_delegate appClient:self didReceiveLocalVideoTrack:track]; |
615 } | 621 } |
616 RTCAudioTrack *localAudioTrack = | 622 return sender; |
617 [_factory audioTrackWithTrackId:@"ARDAMSa0"]; | 623 } |
618 [localStream addAudioTrack:localAudioTrack]; | 624 |
619 return localStream; | 625 - (RTCRtpSender *)createAudioSender { |
| 626 RTCRtpSender *sender = |
| 627 [_peerConnection senderWithKind:kRTCMediaStreamTrackKindAudio |
| 628 streamId:kARDMediaStreamId]; |
| 629 RTCAudioTrack *track = [_factory audioTrackWithTrackId:kARDAudioTrackId]; |
| 630 sender.track = track; |
| 631 return sender; |
620 } | 632 } |
621 | 633 |
622 - (RTCVideoTrack *)createLocalVideoTrack { | 634 - (RTCVideoTrack *)createLocalVideoTrack { |
623 RTCVideoTrack* localVideoTrack = nil; | 635 RTCVideoTrack* localVideoTrack = nil; |
624 // The iOS simulator doesn't provide any sort of camera capture | 636 // The iOS simulator doesn't provide any sort of camera capture |
625 // support or emulation (http://goo.gl/rHAnC1) so don't bother | 637 // support or emulation (http://goo.gl/rHAnC1) so don't bother |
626 // trying to open a local stream. | 638 // trying to open a local stream. |
627 // TODO(tkchin): local video capture for OSX. See | 639 // TODO(tkchin): local video capture for OSX. See |
628 // https://code.google.com/p/webrtc/issues/detail?id=3417. | 640 // https://code.google.com/p/webrtc/issues/detail?id=3417. |
629 #if !TARGET_IPHONE_SIMULATOR && TARGET_OS_IPHONE | 641 #if !TARGET_IPHONE_SIMULATOR && TARGET_OS_IPHONE |
630 if (!_isAudioOnly) { | 642 if (!_isAudioOnly) { |
631 RTCMediaConstraints *mediaConstraints = | 643 RTCMediaConstraints *mediaConstraints = |
632 [self defaultMediaStreamConstraints]; | 644 [self defaultMediaStreamConstraints]; |
633 RTCAVFoundationVideoSource *source = | 645 RTCAVFoundationVideoSource *source = |
634 [_factory avFoundationVideoSourceWithConstraints:mediaConstraints]; | 646 [_factory avFoundationVideoSourceWithConstraints:mediaConstraints]; |
635 localVideoTrack = | 647 localVideoTrack = |
636 [_factory videoTrackWithSource:source | 648 [_factory videoTrackWithSource:source |
637 trackId:@"ARDAMSv0"]; | 649 trackId:kARDVideoTrackId]; |
638 } | 650 } |
639 #endif | 651 #endif |
640 return localVideoTrack; | 652 return localVideoTrack; |
641 } | 653 } |
642 | 654 |
643 #pragma mark - Collider methods | 655 #pragma mark - Collider methods |
644 | 656 |
645 - (void)registerWithColliderIfReady { | 657 - (void)registerWithColliderIfReady { |
646 if (!self.hasJoinedRoomServerRoom) { | 658 if (!self.hasJoinedRoomServerRoom) { |
647 return; | 659 return; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 code:kARDAppClientErrorInvalidRoom | 772 code:kARDAppClientErrorInvalidRoom |
761 userInfo:@{ | 773 userInfo:@{ |
762 NSLocalizedDescriptionKey: @"Invalid room.", | 774 NSLocalizedDescriptionKey: @"Invalid room.", |
763 }]; | 775 }]; |
764 break; | 776 break; |
765 } | 777 } |
766 return error; | 778 return error; |
767 } | 779 } |
768 | 780 |
769 @end | 781 @end |
OLD | NEW |