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

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

Issue 2492693003: Propagate bitrate setting to RTCRtpSender. (Closed)
Patch Set: Address comments Created 4 years, 1 month 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
« no previous file with comments | « no previous file | webrtc/examples/objc/AppRTCMobile/ios/ARDSettingsModel.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 static NSString * const kARDAppClientErrorDomain = @"ARDAppClient"; 43 static NSString * const kARDAppClientErrorDomain = @"ARDAppClient";
44 static NSInteger const kARDAppClientErrorUnknown = -1; 44 static NSInteger const kARDAppClientErrorUnknown = -1;
45 static NSInteger const kARDAppClientErrorRoomFull = -2; 45 static NSInteger const kARDAppClientErrorRoomFull = -2;
46 static NSInteger const kARDAppClientErrorCreateSDP = -3; 46 static NSInteger const kARDAppClientErrorCreateSDP = -3;
47 static NSInteger const kARDAppClientErrorSetSDP = -4; 47 static NSInteger const kARDAppClientErrorSetSDP = -4;
48 static NSInteger const kARDAppClientErrorInvalidClient = -5; 48 static NSInteger const kARDAppClientErrorInvalidClient = -5;
49 static NSInteger const kARDAppClientErrorInvalidRoom = -6; 49 static NSInteger const kARDAppClientErrorInvalidRoom = -6;
50 static NSString * const kARDMediaStreamId = @"ARDAMS"; 50 static NSString * const kARDMediaStreamId = @"ARDAMS";
51 static NSString * const kARDAudioTrackId = @"ARDAMSa0"; 51 static NSString * const kARDAudioTrackId = @"ARDAMSa0";
52 static NSString * const kARDVideoTrackId = @"ARDAMSv0"; 52 static NSString * const kARDVideoTrackId = @"ARDAMSv0";
53 static NSString * const kARDVideoTrackKind = @"video";
53 54
54 // TODO(tkchin): Add these as UI options. 55 // TODO(tkchin): Add these as UI options.
55 static BOOL const kARDAppClientEnableTracing = NO; 56 static BOOL const kARDAppClientEnableTracing = NO;
56 static BOOL const kARDAppClientEnableRtcEventLog = YES; 57 static BOOL const kARDAppClientEnableRtcEventLog = YES;
57 static int64_t const kARDAppClientAecDumpMaxSizeInBytes = 5e6; // 5 MB. 58 static int64_t const kARDAppClientAecDumpMaxSizeInBytes = 5e6; // 5 MB.
58 static int64_t const kARDAppClientRtcEventLogMaxSizeInBytes = 5e6; // 5 MB. 59 static int64_t const kARDAppClientRtcEventLogMaxSizeInBytes = 5e6; // 5 MB.
60 static int const kKbpsMultiplier = 1000;
59 61
60 // 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
61 // using the proxy, |invalidate| must be called before it properly deallocs. 63 // using the proxy, |invalidate| must be called before it properly deallocs.
62 @interface ARDTimerProxy : NSObject 64 @interface ARDTimerProxy : NSObject
63 65
64 - (instancetype)initWithInterval:(NSTimeInterval)interval 66 - (instancetype)initWithInterval:(NSTimeInterval)interval
65 repeats:(BOOL)repeats 67 repeats:(BOOL)repeats
66 timerHandler:(void (^)(void))timerHandler; 68 timerHandler:(void (^)(void))timerHandler;
67 - (void)invalidate; 69 - (void)invalidate;
68 70
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 [_peerConnection setLocalDescription:sdpPreferringH264 471 [_peerConnection setLocalDescription:sdpPreferringH264
470 completionHandler:^(NSError *error) { 472 completionHandler:^(NSError *error) {
471 ARDAppClient *strongSelf = weakSelf; 473 ARDAppClient *strongSelf = weakSelf;
472 [strongSelf peerConnection:strongSelf.peerConnection 474 [strongSelf peerConnection:strongSelf.peerConnection
473 didSetSessionDescriptionWithError:error]; 475 didSetSessionDescriptionWithError:error];
474 }]; 476 }];
475 ARDSessionDescriptionMessage *message = 477 ARDSessionDescriptionMessage *message =
476 [[ARDSessionDescriptionMessage alloc] 478 [[ARDSessionDescriptionMessage alloc]
477 initWithDescription:sdpPreferringH264]; 479 initWithDescription:sdpPreferringH264];
478 [self sendSignalingMessage:message]; 480 [self sendSignalingMessage:message];
481 [self setMaxBitrateForPeerConnectionVideoSender];
479 }); 482 });
480 } 483 }
481 484
482 - (void)peerConnection:(RTCPeerConnection *)peerConnection 485 - (void)peerConnection:(RTCPeerConnection *)peerConnection
483 didSetSessionDescriptionWithError:(NSError *)error { 486 didSetSessionDescriptionWithError:(NSError *)error {
484 dispatch_async(dispatch_get_main_queue(), ^{ 487 dispatch_async(dispatch_get_main_queue(), ^{
485 if (error) { 488 if (error) {
486 RTCLogError(@"Failed to set session description. Error: %@", error); 489 RTCLogError(@"Failed to set session description. Error: %@", error);
487 [self disconnect]; 490 [self disconnect];
488 NSDictionary *userInfo = @{ 491 NSDictionary *userInfo = @{
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 }]; 676 }];
674 } else { 677 } else {
675 [_channel sendMessage:message]; 678 [_channel sendMessage:message];
676 } 679 }
677 } 680 }
678 681
679 - (RTCRtpSender *)createVideoSender { 682 - (RTCRtpSender *)createVideoSender {
680 RTCRtpSender *sender = 683 RTCRtpSender *sender =
681 [_peerConnection senderWithKind:kRTCMediaStreamTrackKindVideo 684 [_peerConnection senderWithKind:kRTCMediaStreamTrackKindVideo
682 streamId:kARDMediaStreamId]; 685 streamId:kARDMediaStreamId];
683
684 [self setMaxBitrate:_maxBitrate forVideoSender:sender];
685
686 RTCVideoTrack *track = [self createLocalVideoTrack]; 686 RTCVideoTrack *track = [self createLocalVideoTrack];
687 if (track) { 687 if (track) {
688 sender.track = track; 688 sender.track = track;
689 [_delegate appClient:self didReceiveLocalVideoTrack:track]; 689 [_delegate appClient:self didReceiveLocalVideoTrack:track];
690 } 690 }
691
691 return sender; 692 return sender;
692 } 693 }
693 694
694 - (void)setMaxBitrate:(NSNumber *)maxBitrate forVideoSender:(RTCRtpSender *)send er { 695 - (void)setMaxBitrateForPeerConnectionVideoSender {
695 for (RTCRtpEncodingParameters *encoding in sender.parameters.encodings) { 696 for (RTCRtpSender *sender in _peerConnection.senders) {
696 encoding.maxBitrateBps = maxBitrate; 697 if (sender.track != nil) {
698 if ([sender.track.kind isEqualToString:kARDVideoTrackKind]) {
699 [self setMaxBitrate:_maxBitrate forVideoSender:sender];
700 }
701 }
697 } 702 }
698 } 703 }
699 704
705 - (void)setMaxBitrate:(NSNumber *)maxBitrate forVideoSender:(RTCRtpSender *)send er {
706 if (maxBitrate.intValue <= 0) {
707 return;
708 }
709
710 RTCRtpParameters *parametersToModify = sender.parameters;
711 for (RTCRtpEncodingParameters *encoding in parametersToModify.encodings) {
712 encoding.maxBitrateBps = @(maxBitrate.intValue * kKbpsMultiplier);
713 }
714 [sender setParameters:parametersToModify];
715 }
716
700 - (RTCRtpSender *)createAudioSender { 717 - (RTCRtpSender *)createAudioSender {
701 RTCMediaConstraints *constraints = [self defaultMediaAudioConstraints]; 718 RTCMediaConstraints *constraints = [self defaultMediaAudioConstraints];
702 RTCAudioSource *source = [_factory audioSourceWithConstraints:constraints]; 719 RTCAudioSource *source = [_factory audioSourceWithConstraints:constraints];
703 RTCAudioTrack *track = [_factory audioTrackWithSource:source 720 RTCAudioTrack *track = [_factory audioTrackWithSource:source
704 trackId:kARDAudioTrackId]; 721 trackId:kARDAudioTrackId];
705 RTCRtpSender *sender = 722 RTCRtpSender *sender =
706 [_peerConnection senderWithKind:kRTCMediaStreamTrackKindAudio 723 [_peerConnection senderWithKind:kRTCMediaStreamTrackKindAudio
707 streamId:kARDMediaStreamId]; 724 streamId:kARDMediaStreamId];
708 sender.track = track; 725 sender.track = track;
709 return sender; 726 return sender;
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 code:kARDAppClientErrorInvalidRoom 871 code:kARDAppClientErrorInvalidRoom
855 userInfo:@{ 872 userInfo:@{
856 NSLocalizedDescriptionKey: @"Invalid room.", 873 NSLocalizedDescriptionKey: @"Invalid room.",
857 }]; 874 }];
858 break; 875 break;
859 } 876 }
860 return error; 877 return error;
861 } 878 }
862 879
863 @end 880 @end
OLDNEW
« no previous file with comments | « no previous file | webrtc/examples/objc/AppRTCMobile/ios/ARDSettingsModel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698