Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: webrtc/examples/objc/AppRTCDemo/ARDAppClient.m

Issue 1888633002: Added the API to create an RTCRtpSender to the Objective C wrapper. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Code review feedback Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 kARDMediaTypeAudio = @"audio";
53 static NSString * const kARDMediaTypeVideo = @"video";
54 static NSString * const kARDMediaStreamId = @"ARDAMS";
55 static NSString * const kARDAudioTrackId = @"ARDAMSa0";
56 static NSString * const kARDVideoTrackId = @"ARDAMSv0";
51 57
52 // TODO(tkchin): Remove guard once rtc_sdk_common_objc compiles on Mac. 58 // TODO(tkchin): Remove guard once rtc_sdk_common_objc compiles on Mac.
53 #if defined(WEBRTC_IOS) 59 #if defined(WEBRTC_IOS)
54 // TODO(tkchin): Add this as a UI option. 60 // TODO(tkchin): Add this as a UI option.
55 static BOOL const kARDAppClientEnableTracing = NO; 61 static BOOL const kARDAppClientEnableTracing = NO;
56 #endif 62 #endif
57 63
58 // We need a proxy to NSTimer because it causes a strong retain cycle. When 64 // 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. 65 // using the proxy, |invalidate| must be called before it properly deallocs.
60 @interface ARDTimerProxy : NSObject 66 @interface ARDTimerProxy : NSObject
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 } 504 }
499 self.state = kARDAppClientStateConnected; 505 self.state = kARDAppClientStateConnected;
500 506
501 // Create peer connection. 507 // Create peer connection.
502 RTCMediaConstraints *constraints = [self defaultPeerConnectionConstraints]; 508 RTCMediaConstraints *constraints = [self defaultPeerConnectionConstraints];
503 RTCConfiguration *config = [[RTCConfiguration alloc] init]; 509 RTCConfiguration *config = [[RTCConfiguration alloc] init];
504 config.iceServers = _iceServers; 510 config.iceServers = _iceServers;
505 _peerConnection = [_factory peerConnectionWithConfiguration:config 511 _peerConnection = [_factory peerConnectionWithConfiguration:config
506 constraints:constraints 512 constraints:constraints
507 delegate:self]; 513 delegate:self];
508 // Create AV media stream and add it to the peer connection. 514 // Create AV senders.
509 RTCMediaStream *localStream = [self createLocalMediaStream]; 515 [self createAudioSender];
510 [_peerConnection addStream:localStream]; 516 [self createVideoSender];
511 if (_isInitiator) { 517 if (_isInitiator) {
512 // Send offer. 518 // Send offer.
513 __weak ARDAppClient *weakSelf = self; 519 __weak ARDAppClient *weakSelf = self;
514 [_peerConnection offerForConstraints:[self defaultOfferConstraints] 520 [_peerConnection offerForConstraints:[self defaultOfferConstraints]
515 completionHandler:^(RTCSessionDescription *sdp, 521 completionHandler:^(RTCSessionDescription *sdp,
516 NSError *error) { 522 NSError *error) {
517 ARDAppClient *strongSelf = weakSelf; 523 ARDAppClient *strongSelf = weakSelf;
518 [strongSelf peerConnection:strongSelf.peerConnection 524 [strongSelf peerConnection:strongSelf.peerConnection
519 didCreateSessionDescription:sdp 525 didCreateSessionDescription:sdp
520 error:error]; 526 error:error];
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 if (messageError) { 605 if (messageError) {
600 [strongSelf.delegate appClient:strongSelf didError:messageError]; 606 [strongSelf.delegate appClient:strongSelf didError:messageError];
601 return; 607 return;
602 } 608 }
603 }]; 609 }];
604 } else { 610 } else {
605 [_channel sendMessage:message]; 611 [_channel sendMessage:message];
606 } 612 }
607 } 613 }
608 614
609 - (RTCMediaStream *)createLocalMediaStream { 615 - (RTCRtpSender *)createVideoSender {
610 RTCMediaStream *localStream = [_factory mediaStreamWithStreamId:@"ARDAMS"]; 616 RTCRtpSender *sender = [_peerConnection senderWithKind:kARDMediaTypeVideo
611 RTCVideoTrack *localVideoTrack = [self createLocalVideoTrack]; 617 streamId:kARDMediaStreamId];
612 if (localVideoTrack) { 618 RTCVideoTrack *track = [self createLocalVideoTrack];
613 [localStream addVideoTrack:localVideoTrack]; 619 if (track) {
614 [_delegate appClient:self didReceiveLocalVideoTrack:localVideoTrack]; 620 sender.track = track;
621 [_delegate appClient:self didReceiveLocalVideoTrack:track];
615 } 622 }
616 RTCAudioTrack *localAudioTrack = 623 return sender;
617 [_factory audioTrackWithTrackId:@"ARDAMSa0"]; 624 }
618 [localStream addAudioTrack:localAudioTrack]; 625
619 return localStream; 626 - (RTCRtpSender *)createAudioSender {
627 RTCRtpSender *sender = [_peerConnection senderWithKind:kARDMediaTypeAudio
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698