blob: e73e1724e5f2f7e59a6c6eed9dd4a028bb7d091c [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;
skvlad79b4b872016-04-08 17:28:55 -070025
skvlad79b4b872016-04-08 17:28:55 -070026- (instancetype)init {
27 return [super init];
28}
29
30- (instancetype)initWithNativeParameters:
31 (const webrtc::RtpEncodingParameters &)nativeParameters {
32 if (self = [self init]) {
Amit Hilbuchce50b002019-03-26 10:42:28 -070033 if (!nativeParameters.rid.empty()) {
34 _rid = [NSString stringForStdString:nativeParameters.rid];
35 }
skvlad79b4b872016-04-08 17:28:55 -070036 _isActive = nativeParameters.active;
deadbeefe702b302017-02-04 12:09:01 -080037 if (nativeParameters.max_bitrate_bps) {
skvlad79b4b872016-04-08 17:28:55 -070038 _maxBitrateBps =
deadbeefe702b302017-02-04 12:09:01 -080039 [NSNumber numberWithInt:*nativeParameters.max_bitrate_bps];
skvlad79b4b872016-04-08 17:28:55 -070040 }
Rasmus Brandta3e69e62018-06-05 10:55:56 +020041 if (nativeParameters.min_bitrate_bps) {
42 _minBitrateBps =
43 [NSNumber numberWithInt:*nativeParameters.min_bitrate_bps];
44 }
Rasmus Brandt3c769412018-09-27 09:53:11 +020045 if (nativeParameters.max_framerate) {
46 _maxFramerate = [NSNumber numberWithInt:*nativeParameters.max_framerate];
47 }
Rasmus Brandt86f78cb2018-10-03 09:34:47 +020048 if (nativeParameters.num_temporal_layers) {
49 _numTemporalLayers = [NSNumber numberWithInt:*nativeParameters.num_temporal_layers];
50 }
Mirta Dvornicic817aec82019-02-04 14:27:49 +010051 if (nativeParameters.scale_resolution_down_by) {
52 _scaleResolutionDownBy =
53 [NSNumber numberWithDouble:*nativeParameters.scale_resolution_down_by];
54 }
deadbeef8014c752017-01-06 16:53:00 -080055 if (nativeParameters.ssrc) {
56 _ssrc = [NSNumber numberWithUnsignedLong:*nativeParameters.ssrc];
57 }
skvlad79b4b872016-04-08 17:28:55 -070058 }
59 return self;
60}
61
62- (webrtc::RtpEncodingParameters)nativeParameters {
63 webrtc::RtpEncodingParameters parameters;
Amit Hilbuchce50b002019-03-26 10:42:28 -070064 if (_rid != nil) {
65 parameters.rid = [NSString stdStringForString:_rid];
66 }
skvlad79b4b872016-04-08 17:28:55 -070067 parameters.active = _isActive;
68 if (_maxBitrateBps != nil) {
Danil Chapovalov196100e2018-06-21 10:17:24 +020069 parameters.max_bitrate_bps = absl::optional<int>(_maxBitrateBps.intValue);
skvlad79b4b872016-04-08 17:28:55 -070070 }
Rasmus Brandta3e69e62018-06-05 10:55:56 +020071 if (_minBitrateBps != nil) {
Danil Chapovalov196100e2018-06-21 10:17:24 +020072 parameters.min_bitrate_bps = absl::optional<int>(_minBitrateBps.intValue);
Rasmus Brandta3e69e62018-06-05 10:55:56 +020073 }
Rasmus Brandt3c769412018-09-27 09:53:11 +020074 if (_maxFramerate != nil) {
75 parameters.max_framerate = absl::optional<int>(_maxFramerate.intValue);
76 }
Rasmus Brandt86f78cb2018-10-03 09:34:47 +020077 if (_numTemporalLayers != nil) {
78 parameters.num_temporal_layers = absl::optional<int>(_numTemporalLayers.intValue);
79 }
Mirta Dvornicic817aec82019-02-04 14:27:49 +010080 if (_scaleResolutionDownBy != nil) {
81 parameters.scale_resolution_down_by =
82 absl::optional<double>(_scaleResolutionDownBy.doubleValue);
83 }
deadbeef8014c752017-01-06 16:53:00 -080084 if (_ssrc != nil) {
Danil Chapovalov196100e2018-06-21 10:17:24 +020085 parameters.ssrc = absl::optional<uint32_t>(_ssrc.unsignedLongValue);
deadbeef8014c752017-01-06 16:53:00 -080086 }
skvlad79b4b872016-04-08 17:28:55 -070087 return parameters;
88}
89
90@end