skvlad | 79b4b87 | 2016-04-08 17:28:55 -0700 | [diff] [blame] | 1 | /* |
| 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; |
deadbeef | 8014c75 | 2017-01-06 16:53:00 -0800 | [diff] [blame] | 17 | @synthesize ssrc = _ssrc; |
skvlad | 79b4b87 | 2016-04-08 17:28:55 -0700 | [diff] [blame] | 18 | |
| 19 | static const int kBitrateUnlimited = -1; |
| 20 | |
| 21 | - (instancetype)init { |
| 22 | return [super init]; |
| 23 | } |
| 24 | |
| 25 | - (instancetype)initWithNativeParameters: |
| 26 | (const webrtc::RtpEncodingParameters &)nativeParameters { |
| 27 | if (self = [self init]) { |
| 28 | _isActive = nativeParameters.active; |
| 29 | // TODO(skvlad): Replace with rtc::Optional once the C++ code is updated. |
| 30 | if (nativeParameters.max_bitrate_bps != kBitrateUnlimited) { |
| 31 | _maxBitrateBps = |
| 32 | [NSNumber numberWithInt:nativeParameters.max_bitrate_bps]; |
| 33 | } |
deadbeef | 8014c75 | 2017-01-06 16:53:00 -0800 | [diff] [blame] | 34 | if (nativeParameters.ssrc) { |
| 35 | _ssrc = [NSNumber numberWithUnsignedLong:*nativeParameters.ssrc]; |
| 36 | } |
skvlad | 79b4b87 | 2016-04-08 17:28:55 -0700 | [diff] [blame] | 37 | } |
| 38 | return self; |
| 39 | } |
| 40 | |
| 41 | - (webrtc::RtpEncodingParameters)nativeParameters { |
| 42 | webrtc::RtpEncodingParameters parameters; |
| 43 | parameters.active = _isActive; |
| 44 | if (_maxBitrateBps != nil) { |
| 45 | parameters.max_bitrate_bps = _maxBitrateBps.intValue; |
| 46 | } |
deadbeef | 8014c75 | 2017-01-06 16:53:00 -0800 | [diff] [blame] | 47 | if (_ssrc != nil) { |
| 48 | parameters.ssrc = rtc::Optional<uint32_t>(_ssrc.unsignedLongValue); |
| 49 | } |
skvlad | 79b4b87 | 2016-04-08 17:28:55 -0700 | [diff] [blame] | 50 | return parameters; |
| 51 | } |
| 52 | |
| 53 | @end |