blob: 9b76ac525fcb86164a9b1c9f3ad0292ae9cbccdc [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 "RTCRtpParameters+Private.h"
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -070012
Florent Castellidacec712018-05-24 16:24:21 +020013#import "RTCRtcpParameters+Private.h"
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -070014#import "RTCRtpCodecParameters+Private.h"
skvlad79b4b872016-04-08 17:28:55 -070015#import "RTCRtpEncodingParameters+Private.h"
Florent Castelliabe301f2018-06-12 18:33:49 +020016#import "RTCRtpHeaderExtension+Private.h"
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020017#import "helpers/NSString+StdString.h"
skvlad79b4b872016-04-08 17:28:55 -070018
19@implementation RTCRtpParameters
20
Florent Castellicebf50f2018-05-03 15:31:53 +020021@synthesize transactionId = _transactionId;
Florent Castellidacec712018-05-24 16:24:21 +020022@synthesize rtcp = _rtcp;
Florent Castelliabe301f2018-06-12 18:33:49 +020023@synthesize headerExtensions = _headerExtensions;
skvlad79b4b872016-04-08 17:28:55 -070024@synthesize encodings = _encodings;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -070025@synthesize codecs = _codecs;
skvlad79b4b872016-04-08 17:28:55 -070026
27- (instancetype)init {
28 return [super init];
29}
30
31- (instancetype)initWithNativeParameters:
32 (const webrtc::RtpParameters &)nativeParameters {
33 if (self = [self init]) {
Florent Castellicebf50f2018-05-03 15:31:53 +020034 _transactionId = [NSString stringForStdString:nativeParameters.transaction_id];
Florent Castellidacec712018-05-24 16:24:21 +020035 _rtcp = [[RTCRtcpParameters alloc] initWithNativeParameters:nativeParameters.rtcp];
Florent Castelliabe301f2018-06-12 18:33:49 +020036
37 NSMutableArray *headerExtensions = [[NSMutableArray alloc] init];
38 for (const auto &headerExtension : nativeParameters.header_extensions) {
39 [headerExtensions
40 addObject:[[RTCRtpHeaderExtension alloc] initWithNativeParameters:headerExtension]];
41 }
42 _headerExtensions = headerExtensions;
43
skvlad79b4b872016-04-08 17:28:55 -070044 NSMutableArray *encodings = [[NSMutableArray alloc] init];
45 for (const auto &encoding : nativeParameters.encodings) {
46 [encodings addObject:[[RTCRtpEncodingParameters alloc]
47 initWithNativeParameters:encoding]];
48 }
49 _encodings = encodings;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -070050
51 NSMutableArray *codecs = [[NSMutableArray alloc] init];
52 for (const auto &codec : nativeParameters.codecs) {
53 [codecs addObject:[[RTCRtpCodecParameters alloc]
54 initWithNativeParameters:codec]];
55 }
56 _codecs = codecs;
skvlad79b4b872016-04-08 17:28:55 -070057 }
58 return self;
59}
60
61- (webrtc::RtpParameters)nativeParameters {
Florent Castellicebf50f2018-05-03 15:31:53 +020062 webrtc::RtpParameters parameters;
63 parameters.transaction_id = [NSString stdStringForString:_transactionId];
Florent Castellidacec712018-05-24 16:24:21 +020064 parameters.rtcp = [_rtcp nativeParameters];
Florent Castelliabe301f2018-06-12 18:33:49 +020065 for (RTCRtpHeaderExtension *headerExtension in _headerExtensions) {
66 parameters.header_extensions.push_back(headerExtension.nativeParameters);
67 }
skvlad79b4b872016-04-08 17:28:55 -070068 for (RTCRtpEncodingParameters *encoding in _encodings) {
69 parameters.encodings.push_back(encoding.nativeParameters);
70 }
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -070071 for (RTCRtpCodecParameters *codec in _codecs) {
72 parameters.codecs.push_back(codec.nativeParameters);
73 }
skvlad79b4b872016-04-08 17:28:55 -070074 return parameters;
75}
76
77@end