blob: dd07e94e19e09c4af8fa72a14b8b7f5be1be04e4 [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
13@implementation RTCRtpEncodingParameters
14
15@synthesize isActive = _isActive;
16@synthesize maxBitrateBps = _maxBitrateBps;
Rasmus Brandta3e69e62018-06-05 10:55:56 +020017@synthesize minBitrateBps = _minBitrateBps;
Rasmus Brandt3c769412018-09-27 09:53:11 +020018@synthesize maxFramerate = _maxFramerate;
Rasmus Brandt86f78cb2018-10-03 09:34:47 +020019@synthesize numTemporalLayers = _numTemporalLayers;
Mirta Dvornicic817aec82019-02-04 14:27:49 +010020@synthesize scaleResolutionDownBy = _scaleResolutionDownBy;
deadbeef8014c752017-01-06 16:53:00 -080021@synthesize ssrc = _ssrc;
skvlad79b4b872016-04-08 17:28:55 -070022
skvlad79b4b872016-04-08 17:28:55 -070023- (instancetype)init {
24 return [super init];
25}
26
27- (instancetype)initWithNativeParameters:
28 (const webrtc::RtpEncodingParameters &)nativeParameters {
29 if (self = [self init]) {
30 _isActive = nativeParameters.active;
deadbeefe702b302017-02-04 12:09:01 -080031 if (nativeParameters.max_bitrate_bps) {
skvlad79b4b872016-04-08 17:28:55 -070032 _maxBitrateBps =
deadbeefe702b302017-02-04 12:09:01 -080033 [NSNumber numberWithInt:*nativeParameters.max_bitrate_bps];
skvlad79b4b872016-04-08 17:28:55 -070034 }
Rasmus Brandta3e69e62018-06-05 10:55:56 +020035 if (nativeParameters.min_bitrate_bps) {
36 _minBitrateBps =
37 [NSNumber numberWithInt:*nativeParameters.min_bitrate_bps];
38 }
Rasmus Brandt3c769412018-09-27 09:53:11 +020039 if (nativeParameters.max_framerate) {
40 _maxFramerate = [NSNumber numberWithInt:*nativeParameters.max_framerate];
41 }
Rasmus Brandt86f78cb2018-10-03 09:34:47 +020042 if (nativeParameters.num_temporal_layers) {
43 _numTemporalLayers = [NSNumber numberWithInt:*nativeParameters.num_temporal_layers];
44 }
Mirta Dvornicic817aec82019-02-04 14:27:49 +010045 if (nativeParameters.scale_resolution_down_by) {
46 _scaleResolutionDownBy =
47 [NSNumber numberWithDouble:*nativeParameters.scale_resolution_down_by];
48 }
deadbeef8014c752017-01-06 16:53:00 -080049 if (nativeParameters.ssrc) {
50 _ssrc = [NSNumber numberWithUnsignedLong:*nativeParameters.ssrc];
51 }
skvlad79b4b872016-04-08 17:28:55 -070052 }
53 return self;
54}
55
56- (webrtc::RtpEncodingParameters)nativeParameters {
57 webrtc::RtpEncodingParameters parameters;
58 parameters.active = _isActive;
59 if (_maxBitrateBps != nil) {
Danil Chapovalov196100e2018-06-21 10:17:24 +020060 parameters.max_bitrate_bps = absl::optional<int>(_maxBitrateBps.intValue);
skvlad79b4b872016-04-08 17:28:55 -070061 }
Rasmus Brandta3e69e62018-06-05 10:55:56 +020062 if (_minBitrateBps != nil) {
Danil Chapovalov196100e2018-06-21 10:17:24 +020063 parameters.min_bitrate_bps = absl::optional<int>(_minBitrateBps.intValue);
Rasmus Brandta3e69e62018-06-05 10:55:56 +020064 }
Rasmus Brandt3c769412018-09-27 09:53:11 +020065 if (_maxFramerate != nil) {
66 parameters.max_framerate = absl::optional<int>(_maxFramerate.intValue);
67 }
Rasmus Brandt86f78cb2018-10-03 09:34:47 +020068 if (_numTemporalLayers != nil) {
69 parameters.num_temporal_layers = absl::optional<int>(_numTemporalLayers.intValue);
70 }
Mirta Dvornicic817aec82019-02-04 14:27:49 +010071 if (_scaleResolutionDownBy != nil) {
72 parameters.scale_resolution_down_by =
73 absl::optional<double>(_scaleResolutionDownBy.doubleValue);
74 }
deadbeef8014c752017-01-06 16:53:00 -080075 if (_ssrc != nil) {
Danil Chapovalov196100e2018-06-21 10:17:24 +020076 parameters.ssrc = absl::optional<uint32_t>(_ssrc.unsignedLongValue);
deadbeef8014c752017-01-06 16:53:00 -080077 }
skvlad79b4b872016-04-08 17:28:55 -070078 return parameters;
79}
80
81@end