Add HeaderExtensions to RtpParameters

Bug: webrtc:7580
Change-Id: I4fcf3e8bc4975a6b2baa6f24a17c254d2bf521d9
Reviewed-on: https://webrtc-review.googlesource.com/78288
Commit-Queue: Florent Castelli <orphis@webrtc.org>
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Reviewed-by: Anders Carlsson <andersc@webrtc.org>
Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23584}
diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCRtpHeaderExtension+Private.h b/sdk/objc/Framework/Classes/PeerConnection/RTCRtpHeaderExtension+Private.h
new file mode 100644
index 0000000..0bc236b
--- /dev/null
+++ b/sdk/objc/Framework/Classes/PeerConnection/RTCRtpHeaderExtension+Private.h
@@ -0,0 +1,27 @@
+/*
+ *  Copyright 2018 The WebRTC project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a BSD-style license
+ *  that can be found in the LICENSE file in the root of the source
+ *  tree. An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+
+#import "WebRTC/RTCRtpHeaderExtension.h"
+
+#include "api/rtpparameters.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface RTCRtpHeaderExtension ()
+
+/** Returns the equivalent native RtpExtension structure. */
+@property(nonatomic, readonly) webrtc::RtpExtension nativeParameters;
+
+/** Initialize the object with a native RtpExtension structure. */
+- (instancetype)initWithNativeParameters:(const webrtc::RtpExtension &)nativeParameters;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCRtpHeaderExtension.mm b/sdk/objc/Framework/Classes/PeerConnection/RTCRtpHeaderExtension.mm
new file mode 100644
index 0000000..3f448d7
--- /dev/null
+++ b/sdk/objc/Framework/Classes/PeerConnection/RTCRtpHeaderExtension.mm
@@ -0,0 +1,42 @@
+/*
+ *  Copyright 2018 The WebRTC project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a BSD-style license
+ *  that can be found in the LICENSE file in the root of the source
+ *  tree. An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+
+#import "RTCRtpHeaderExtension+Private.h"
+
+#import "NSString+StdString.h"
+
+@implementation RTCRtpHeaderExtension
+
+@synthesize uri = _uri;
+@synthesize id = _id;
+@synthesize encrypted = _encrypted;
+
+- (instancetype)init {
+  return [super init];
+}
+
+- (instancetype)initWithNativeParameters:(const webrtc::RtpExtension &)nativeParameters {
+  if (self = [self init]) {
+    _uri = [NSString stringForStdString:nativeParameters.uri];
+    _id = nativeParameters.id;
+    _encrypted = nativeParameters.encrypt;
+  }
+  return self;
+}
+
+- (webrtc::RtpExtension)nativeParameters {
+  webrtc::RtpExtension extension;
+  extension.uri = [NSString stdStringForString:_uri];
+  extension.id = _id;
+  extension.encrypt = _encrypted;
+  return extension;
+}
+
+@end
diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCRtpParameters.mm b/sdk/objc/Framework/Classes/PeerConnection/RTCRtpParameters.mm
index 7c00b08..97800ca 100644
--- a/sdk/objc/Framework/Classes/PeerConnection/RTCRtpParameters.mm
+++ b/sdk/objc/Framework/Classes/PeerConnection/RTCRtpParameters.mm
@@ -14,11 +14,13 @@
 #import "RTCRtcpParameters+Private.h"
 #import "RTCRtpCodecParameters+Private.h"
 #import "RTCRtpEncodingParameters+Private.h"
+#import "RTCRtpHeaderExtension+Private.h"
 
 @implementation RTCRtpParameters
 
 @synthesize transactionId = _transactionId;
 @synthesize rtcp = _rtcp;
+@synthesize headerExtensions = _headerExtensions;
 @synthesize encodings = _encodings;
 @synthesize codecs = _codecs;
 
@@ -31,6 +33,14 @@
   if (self = [self init]) {
     _transactionId = [NSString stringForStdString:nativeParameters.transaction_id];
     _rtcp = [[RTCRtcpParameters alloc] initWithNativeParameters:nativeParameters.rtcp];
+
+    NSMutableArray *headerExtensions = [[NSMutableArray alloc] init];
+    for (const auto &headerExtension : nativeParameters.header_extensions) {
+      [headerExtensions
+          addObject:[[RTCRtpHeaderExtension alloc] initWithNativeParameters:headerExtension]];
+    }
+    _headerExtensions = headerExtensions;
+
     NSMutableArray *encodings = [[NSMutableArray alloc] init];
     for (const auto &encoding : nativeParameters.encodings) {
       [encodings addObject:[[RTCRtpEncodingParameters alloc]
@@ -52,6 +62,9 @@
   webrtc::RtpParameters parameters;
   parameters.transaction_id = [NSString stdStringForString:_transactionId];
   parameters.rtcp = [_rtcp nativeParameters];
+  for (RTCRtpHeaderExtension *headerExtension in _headerExtensions) {
+    parameters.header_extensions.push_back(headerExtension.nativeParameters);
+  }
   for (RTCRtpEncodingParameters *encoding in _encodings) {
     parameters.encodings.push_back(encoding.nativeParameters);
   }
diff --git a/sdk/objc/Framework/Headers/WebRTC/RTCRtpHeaderExtension.h b/sdk/objc/Framework/Headers/WebRTC/RTCRtpHeaderExtension.h
new file mode 100644
index 0000000..b89eb06
--- /dev/null
+++ b/sdk/objc/Framework/Headers/WebRTC/RTCRtpHeaderExtension.h
@@ -0,0 +1,33 @@
+/*
+ *  Copyright 2018 The WebRTC project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a BSD-style license
+ *  that can be found in the LICENSE file in the root of the source
+ *  tree. An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+
+#import <Foundation/Foundation.h>
+
+#import <WebRTC/RTCMacros.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+RTC_EXPORT
+@interface RTCRtpHeaderExtension : NSObject
+
+/** The URI of the RTP header extension, as defined in RFC5285. */
+@property(nonatomic, readonly, copy) NSString *uri;
+
+/** The value put in the RTP packet to identify the header extension. */
+@property(nonatomic, readonly) int id;
+
+/** Whether the header extension is encrypted or not. */
+@property(nonatomic, readonly, getter=isEncrypted) BOOL encrypted;
+
+- (instancetype)init NS_DESIGNATED_INITIALIZER;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/sdk/objc/Framework/Headers/WebRTC/RTCRtpParameters.h b/sdk/objc/Framework/Headers/WebRTC/RTCRtpParameters.h
index 02ce981..8f09934 100644
--- a/sdk/objc/Framework/Headers/WebRTC/RTCRtpParameters.h
+++ b/sdk/objc/Framework/Headers/WebRTC/RTCRtpParameters.h
@@ -14,6 +14,7 @@
 #import <WebRTC/RTCRtcpParameters.h>
 #import <WebRTC/RTCRtpCodecParameters.h>
 #import <WebRTC/RTCRtpEncodingParameters.h>
+#import <WebRTC/RTCRtpHeaderExtension.h>
 
 NS_ASSUME_NONNULL_BEGIN
 
@@ -26,6 +27,9 @@
 /** Parameters used for RTCP. */
 @property(nonatomic, readonly, copy) RTCRtcpParameters *rtcp;
 
+/** An array containing parameters for RTP header extensions. */
+@property(nonatomic, readonly, copy) NSArray<RTCRtpHeaderExtension *> *headerExtensions;
+
 /** The currently active encodings in the order of preference. */
 @property(nonatomic, copy) NSArray<RTCRtpEncodingParameters *> *encodings;