blob: 6fef212245646df2b9cd5fbc82abe5c2d4e2941a [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
skvlad79b4b872016-04-08 17:28:55 -070015@implementation RTCRtpEncodingParameters
16
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;
Anders Carlssoncd163802019-05-03 14:32:16 +020025@synthesize networkPriority = _networkPriority;
skvlad79b4b872016-04-08 17:28:55 -070026
skvlad79b4b872016-04-08 17:28:55 -070027- (instancetype)init {
28 return [super init];
29}
30
31- (instancetype)initWithNativeParameters:
32 (const webrtc::RtpEncodingParameters &)nativeParameters {
33 if (self = [self init]) {
Amit Hilbuchce50b002019-03-26 10:42:28 -070034 if (!nativeParameters.rid.empty()) {
35 _rid = [NSString stringForStdString:nativeParameters.rid];
36 }
skvlad79b4b872016-04-08 17:28:55 -070037 _isActive = nativeParameters.active;
deadbeefe702b302017-02-04 12:09:01 -080038 if (nativeParameters.max_bitrate_bps) {
skvlad79b4b872016-04-08 17:28:55 -070039 _maxBitrateBps =
deadbeefe702b302017-02-04 12:09:01 -080040 [NSNumber numberWithInt:*nativeParameters.max_bitrate_bps];
skvlad79b4b872016-04-08 17:28:55 -070041 }
Rasmus Brandta3e69e62018-06-05 10:55:56 +020042 if (nativeParameters.min_bitrate_bps) {
43 _minBitrateBps =
44 [NSNumber numberWithInt:*nativeParameters.min_bitrate_bps];
45 }
Rasmus Brandt3c769412018-09-27 09:53:11 +020046 if (nativeParameters.max_framerate) {
47 _maxFramerate = [NSNumber numberWithInt:*nativeParameters.max_framerate];
48 }
Rasmus Brandt86f78cb2018-10-03 09:34:47 +020049 if (nativeParameters.num_temporal_layers) {
50 _numTemporalLayers = [NSNumber numberWithInt:*nativeParameters.num_temporal_layers];
51 }
Mirta Dvornicic817aec82019-02-04 14:27:49 +010052 if (nativeParameters.scale_resolution_down_by) {
53 _scaleResolutionDownBy =
54 [NSNumber numberWithDouble:*nativeParameters.scale_resolution_down_by];
55 }
deadbeef8014c752017-01-06 16:53:00 -080056 if (nativeParameters.ssrc) {
57 _ssrc = [NSNumber numberWithUnsignedLong:*nativeParameters.ssrc];
58 }
Taylor Brandstetter3f1aee32020-02-27 11:59:23 -080059 _networkPriority =
60 [RTCRtpEncodingParameters priorityFromNativePriority:nativeParameters.network_priority];
skvlad79b4b872016-04-08 17:28:55 -070061 }
62 return self;
63}
64
65- (webrtc::RtpEncodingParameters)nativeParameters {
66 webrtc::RtpEncodingParameters parameters;
Amit Hilbuchce50b002019-03-26 10:42:28 -070067 if (_rid != nil) {
68 parameters.rid = [NSString stdStringForString:_rid];
69 }
skvlad79b4b872016-04-08 17:28:55 -070070 parameters.active = _isActive;
71 if (_maxBitrateBps != nil) {
Danil Chapovalov196100e2018-06-21 10:17:24 +020072 parameters.max_bitrate_bps = absl::optional<int>(_maxBitrateBps.intValue);
skvlad79b4b872016-04-08 17:28:55 -070073 }
Rasmus Brandta3e69e62018-06-05 10:55:56 +020074 if (_minBitrateBps != nil) {
Danil Chapovalov196100e2018-06-21 10:17:24 +020075 parameters.min_bitrate_bps = absl::optional<int>(_minBitrateBps.intValue);
Rasmus Brandta3e69e62018-06-05 10:55:56 +020076 }
Rasmus Brandt3c769412018-09-27 09:53:11 +020077 if (_maxFramerate != nil) {
78 parameters.max_framerate = absl::optional<int>(_maxFramerate.intValue);
79 }
Rasmus Brandt86f78cb2018-10-03 09:34:47 +020080 if (_numTemporalLayers != nil) {
81 parameters.num_temporal_layers = absl::optional<int>(_numTemporalLayers.intValue);
82 }
Mirta Dvornicic817aec82019-02-04 14:27:49 +010083 if (_scaleResolutionDownBy != nil) {
84 parameters.scale_resolution_down_by =
85 absl::optional<double>(_scaleResolutionDownBy.doubleValue);
86 }
deadbeef8014c752017-01-06 16:53:00 -080087 if (_ssrc != nil) {
Danil Chapovalov196100e2018-06-21 10:17:24 +020088 parameters.ssrc = absl::optional<uint32_t>(_ssrc.unsignedLongValue);
deadbeef8014c752017-01-06 16:53:00 -080089 }
Taylor Brandstetter3f1aee32020-02-27 11:59:23 -080090 parameters.network_priority =
91 [RTCRtpEncodingParameters nativePriorityFromPriority:_networkPriority];
skvlad79b4b872016-04-08 17:28:55 -070092 return parameters;
93}
94
Taylor Brandstetter3f1aee32020-02-27 11:59:23 -080095+ (webrtc::Priority)nativePriorityFromPriority:(RTCPriority)networkPriority {
96 switch (networkPriority) {
97 case RTCPriorityVeryLow:
98 return webrtc::Priority::kVeryLow;
99 case RTCPriorityLow:
100 return webrtc::Priority::kLow;
101 case RTCPriorityMedium:
102 return webrtc::Priority::kMedium;
103 case RTCPriorityHigh:
104 return webrtc::Priority::kHigh;
105 }
106}
107
108+ (RTCPriority)priorityFromNativePriority:(webrtc::Priority)nativePriority {
109 switch (nativePriority) {
110 case webrtc::Priority::kVeryLow:
111 return RTCPriorityVeryLow;
112 case webrtc::Priority::kLow:
113 return RTCPriorityLow;
114 case webrtc::Priority::kMedium:
115 return RTCPriorityMedium;
116 case webrtc::Priority::kHigh:
117 return RTCPriorityHigh;
118 }
119}
120
skvlad79b4b872016-04-08 17:28:55 -0700121@end