blob: d6087dafb09050b33503b3e6689077d443f05200 [file] [log] [blame]
skvlad79b4b872016-04-08 17:28:55 -07001/*
2 * Copyright 2016 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#import "RTCRtpEncodingParameters+Private.h"
12
Amit Hilbuchce50b002019-03-26 10:42:28 -070013#import "helpers/NSString+StdString.h"
14
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020015@implementation RTC_OBJC_TYPE (RTCRtpEncodingParameters)
skvlad79b4b872016-04-08 17:28:55 -070016
Amit Hilbuchce50b002019-03-26 10:42:28 -070017@synthesize rid = _rid;
skvlad79b4b872016-04-08 17:28:55 -070018@synthesize isActive = _isActive;
19@synthesize maxBitrateBps = _maxBitrateBps;
Rasmus Brandta3e69e62018-06-05 10:55:56 +020020@synthesize minBitrateBps = _minBitrateBps;
Rasmus Brandt3c769412018-09-27 09:53:11 +020021@synthesize maxFramerate = _maxFramerate;
Rasmus Brandt86f78cb2018-10-03 09:34:47 +020022@synthesize numTemporalLayers = _numTemporalLayers;
Mirta Dvornicic817aec82019-02-04 14:27:49 +010023@synthesize scaleResolutionDownBy = _scaleResolutionDownBy;
deadbeef8014c752017-01-06 16:53:00 -080024@synthesize ssrc = _ssrc;
Taylor Brandstetterf05af9e2020-03-19 17:14:27 -070025@synthesize bitratePriority = _bitratePriority;
Anders Carlssoncd163802019-05-03 14:32:16 +020026@synthesize networkPriority = _networkPriority;
Yura Yaroshevichd46a1742021-04-14 16:26:14 +030027@synthesize adaptiveAudioPacketTime = _adaptiveAudioPacketTime;
skvlad79b4b872016-04-08 17:28:55 -070028
skvlad79b4b872016-04-08 17:28:55 -070029- (instancetype)init {
Yura Yaroshevich9aec8c22021-04-14 12:41:21 +030030 webrtc::RtpEncodingParameters nativeParameters;
31 return [self initWithNativeParameters:nativeParameters];
skvlad79b4b872016-04-08 17:28:55 -070032}
33
34- (instancetype)initWithNativeParameters:
35 (const webrtc::RtpEncodingParameters &)nativeParameters {
Yura Yaroshevich9aec8c22021-04-14 12:41:21 +030036 if (self = [super init]) {
Amit Hilbuchce50b002019-03-26 10:42:28 -070037 if (!nativeParameters.rid.empty()) {
38 _rid = [NSString stringForStdString:nativeParameters.rid];
39 }
skvlad79b4b872016-04-08 17:28:55 -070040 _isActive = nativeParameters.active;
deadbeefe702b302017-02-04 12:09:01 -080041 if (nativeParameters.max_bitrate_bps) {
skvlad79b4b872016-04-08 17:28:55 -070042 _maxBitrateBps =
deadbeefe702b302017-02-04 12:09:01 -080043 [NSNumber numberWithInt:*nativeParameters.max_bitrate_bps];
skvlad79b4b872016-04-08 17:28:55 -070044 }
Rasmus Brandta3e69e62018-06-05 10:55:56 +020045 if (nativeParameters.min_bitrate_bps) {
46 _minBitrateBps =
47 [NSNumber numberWithInt:*nativeParameters.min_bitrate_bps];
48 }
Rasmus Brandt3c769412018-09-27 09:53:11 +020049 if (nativeParameters.max_framerate) {
50 _maxFramerate = [NSNumber numberWithInt:*nativeParameters.max_framerate];
51 }
Rasmus Brandt86f78cb2018-10-03 09:34:47 +020052 if (nativeParameters.num_temporal_layers) {
53 _numTemporalLayers = [NSNumber numberWithInt:*nativeParameters.num_temporal_layers];
54 }
Mirta Dvornicic817aec82019-02-04 14:27:49 +010055 if (nativeParameters.scale_resolution_down_by) {
56 _scaleResolutionDownBy =
57 [NSNumber numberWithDouble:*nativeParameters.scale_resolution_down_by];
58 }
deadbeef8014c752017-01-06 16:53:00 -080059 if (nativeParameters.ssrc) {
60 _ssrc = [NSNumber numberWithUnsignedLong:*nativeParameters.ssrc];
61 }
Taylor Brandstetterf05af9e2020-03-19 17:14:27 -070062 _bitratePriority = nativeParameters.bitrate_priority;
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020063 _networkPriority = [RTC_OBJC_TYPE(RTCRtpEncodingParameters)
64 priorityFromNativePriority:nativeParameters.network_priority];
Yura Yaroshevichd46a1742021-04-14 16:26:14 +030065 _adaptiveAudioPacketTime = nativeParameters.adaptive_ptime;
skvlad79b4b872016-04-08 17:28:55 -070066 }
67 return self;
68}
69
70- (webrtc::RtpEncodingParameters)nativeParameters {
71 webrtc::RtpEncodingParameters parameters;
Amit Hilbuchce50b002019-03-26 10:42:28 -070072 if (_rid != nil) {
73 parameters.rid = [NSString stdStringForString:_rid];
74 }
skvlad79b4b872016-04-08 17:28:55 -070075 parameters.active = _isActive;
76 if (_maxBitrateBps != nil) {
Danil Chapovalov196100e2018-06-21 10:17:24 +020077 parameters.max_bitrate_bps = absl::optional<int>(_maxBitrateBps.intValue);
skvlad79b4b872016-04-08 17:28:55 -070078 }
Rasmus Brandta3e69e62018-06-05 10:55:56 +020079 if (_minBitrateBps != nil) {
Danil Chapovalov196100e2018-06-21 10:17:24 +020080 parameters.min_bitrate_bps = absl::optional<int>(_minBitrateBps.intValue);
Rasmus Brandta3e69e62018-06-05 10:55:56 +020081 }
Rasmus Brandt3c769412018-09-27 09:53:11 +020082 if (_maxFramerate != nil) {
83 parameters.max_framerate = absl::optional<int>(_maxFramerate.intValue);
84 }
Rasmus Brandt86f78cb2018-10-03 09:34:47 +020085 if (_numTemporalLayers != nil) {
86 parameters.num_temporal_layers = absl::optional<int>(_numTemporalLayers.intValue);
87 }
Mirta Dvornicic817aec82019-02-04 14:27:49 +010088 if (_scaleResolutionDownBy != nil) {
89 parameters.scale_resolution_down_by =
90 absl::optional<double>(_scaleResolutionDownBy.doubleValue);
91 }
deadbeef8014c752017-01-06 16:53:00 -080092 if (_ssrc != nil) {
Danil Chapovalov196100e2018-06-21 10:17:24 +020093 parameters.ssrc = absl::optional<uint32_t>(_ssrc.unsignedLongValue);
deadbeef8014c752017-01-06 16:53:00 -080094 }
Taylor Brandstetterf05af9e2020-03-19 17:14:27 -070095 parameters.bitrate_priority = _bitratePriority;
Taylor Brandstetter3f1aee32020-02-27 11:59:23 -080096 parameters.network_priority =
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020097 [RTC_OBJC_TYPE(RTCRtpEncodingParameters) nativePriorityFromPriority:_networkPriority];
Yura Yaroshevichd46a1742021-04-14 16:26:14 +030098 parameters.adaptive_ptime = _adaptiveAudioPacketTime;
skvlad79b4b872016-04-08 17:28:55 -070099 return parameters;
100}
101
Taylor Brandstetter3f1aee32020-02-27 11:59:23 -0800102+ (webrtc::Priority)nativePriorityFromPriority:(RTCPriority)networkPriority {
103 switch (networkPriority) {
104 case RTCPriorityVeryLow:
105 return webrtc::Priority::kVeryLow;
106 case RTCPriorityLow:
107 return webrtc::Priority::kLow;
108 case RTCPriorityMedium:
109 return webrtc::Priority::kMedium;
110 case RTCPriorityHigh:
111 return webrtc::Priority::kHigh;
112 }
113}
114
115+ (RTCPriority)priorityFromNativePriority:(webrtc::Priority)nativePriority {
116 switch (nativePriority) {
117 case webrtc::Priority::kVeryLow:
118 return RTCPriorityVeryLow;
119 case webrtc::Priority::kLow:
120 return RTCPriorityLow;
121 case webrtc::Priority::kMedium:
122 return RTCPriorityMedium;
123 case webrtc::Priority::kHigh:
124 return RTCPriorityHigh;
125 }
126}
127
skvlad79b4b872016-04-08 17:28:55 -0700128@end