blob: 62ca3fc02540a957455ff7a39953347000f23896 [file] [log] [blame]
Stefan Holmer1acbd682017-09-01 15:29:28 +02001/*
2 * Copyright (c) 2017 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 */
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020010#include "api/rtpparameters.h"
Stefan Holmer1acbd682017-09-01 15:29:28 +020011
12#include <algorithm>
Stefan Holmer1acbd682017-09-01 15:29:28 +020013#include <string>
14
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "rtc_base/checks.h"
Jonas Olsson866d6dc2018-05-14 17:30:22 +020016#include "rtc_base/strings/string_builder.h"
Stefan Holmer1acbd682017-09-01 15:29:28 +020017
18namespace webrtc {
19
Seth Hampsonf32795e2017-12-19 11:37:41 -080020const double kDefaultBitratePriority = 1.0;
21
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020022RtcpFeedback::RtcpFeedback() = default;
Stefan Holmer1acbd682017-09-01 15:29:28 +020023RtcpFeedback::RtcpFeedback(RtcpFeedbackType type) : type(type) {}
24RtcpFeedback::RtcpFeedback(RtcpFeedbackType type,
25 RtcpFeedbackMessageType message_type)
26 : type(type), message_type(message_type) {}
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020027RtcpFeedback::RtcpFeedback(const RtcpFeedback& rhs) = default;
28RtcpFeedback::~RtcpFeedback() = default;
Stefan Holmer1acbd682017-09-01 15:29:28 +020029
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020030RtpCodecCapability::RtpCodecCapability() = default;
31RtpCodecCapability::~RtpCodecCapability() = default;
Stefan Holmer1acbd682017-09-01 15:29:28 +020032
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020033RtpHeaderExtensionCapability::RtpHeaderExtensionCapability() = default;
Stefan Holmer1acbd682017-09-01 15:29:28 +020034RtpHeaderExtensionCapability::RtpHeaderExtensionCapability(
35 const std::string& uri)
36 : uri(uri) {}
37RtpHeaderExtensionCapability::RtpHeaderExtensionCapability(
38 const std::string& uri,
39 int preferred_id)
40 : uri(uri), preferred_id(preferred_id) {}
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020041RtpHeaderExtensionCapability::~RtpHeaderExtensionCapability() = default;
Stefan Holmer1acbd682017-09-01 15:29:28 +020042
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020043RtpExtension::RtpExtension() = default;
Stefan Holmer1acbd682017-09-01 15:29:28 +020044RtpExtension::RtpExtension(const std::string& uri, int id) : uri(uri), id(id) {}
45RtpExtension::RtpExtension(const std::string& uri, int id, bool encrypt)
46 : uri(uri), id(id), encrypt(encrypt) {}
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020047RtpExtension::~RtpExtension() = default;
Stefan Holmer1acbd682017-09-01 15:29:28 +020048
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020049RtpFecParameters::RtpFecParameters() = default;
Stefan Holmer1acbd682017-09-01 15:29:28 +020050RtpFecParameters::RtpFecParameters(FecMechanism mechanism)
51 : mechanism(mechanism) {}
52RtpFecParameters::RtpFecParameters(FecMechanism mechanism, uint32_t ssrc)
53 : ssrc(ssrc), mechanism(mechanism) {}
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020054RtpFecParameters::RtpFecParameters(const RtpFecParameters& rhs) = default;
55RtpFecParameters::~RtpFecParameters() = default;
Stefan Holmer1acbd682017-09-01 15:29:28 +020056
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020057RtpRtxParameters::RtpRtxParameters() = default;
Stefan Holmer1acbd682017-09-01 15:29:28 +020058RtpRtxParameters::RtpRtxParameters(uint32_t ssrc) : ssrc(ssrc) {}
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020059RtpRtxParameters::RtpRtxParameters(const RtpRtxParameters& rhs) = default;
60RtpRtxParameters::~RtpRtxParameters() = default;
Stefan Holmer1acbd682017-09-01 15:29:28 +020061
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020062RtpEncodingParameters::RtpEncodingParameters() = default;
63RtpEncodingParameters::RtpEncodingParameters(const RtpEncodingParameters& rhs) =
64 default;
65RtpEncodingParameters::~RtpEncodingParameters() = default;
Stefan Holmer1acbd682017-09-01 15:29:28 +020066
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020067RtpCodecParameters::RtpCodecParameters() = default;
68RtpCodecParameters::RtpCodecParameters(const RtpCodecParameters& rhs) = default;
69RtpCodecParameters::~RtpCodecParameters() = default;
Stefan Holmer1acbd682017-09-01 15:29:28 +020070
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020071RtpCapabilities::RtpCapabilities() = default;
72RtpCapabilities::~RtpCapabilities() = default;
Stefan Holmer1acbd682017-09-01 15:29:28 +020073
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020074RtcpParameters::RtcpParameters() = default;
75RtcpParameters::RtcpParameters(const RtcpParameters& rhs) = default;
76RtcpParameters::~RtcpParameters() = default;
Florent Castellidacec712018-05-24 16:24:21 +020077
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020078RtpParameters::RtpParameters() = default;
79RtpParameters::RtpParameters(const RtpParameters& rhs) = default;
80RtpParameters::~RtpParameters() = default;
Stefan Holmer1acbd682017-09-01 15:29:28 +020081
82std::string RtpExtension::ToString() const {
Jonas Olsson866d6dc2018-05-14 17:30:22 +020083 char buf[256];
84 rtc::SimpleStringBuilder sb(buf);
85 sb << "{uri: " << uri;
86 sb << ", id: " << id;
Stefan Holmer1acbd682017-09-01 15:29:28 +020087 if (encrypt) {
Jonas Olsson866d6dc2018-05-14 17:30:22 +020088 sb << ", encrypt";
Stefan Holmer1acbd682017-09-01 15:29:28 +020089 }
Jonas Olsson866d6dc2018-05-14 17:30:22 +020090 sb << '}';
91 return sb.str();
Stefan Holmer1acbd682017-09-01 15:29:28 +020092}
93
94const char RtpExtension::kAudioLevelUri[] =
95 "urn:ietf:params:rtp-hdrext:ssrc-audio-level";
96const int RtpExtension::kAudioLevelDefaultId = 1;
97
98const char RtpExtension::kTimestampOffsetUri[] =
99 "urn:ietf:params:rtp-hdrext:toffset";
100const int RtpExtension::kTimestampOffsetDefaultId = 2;
101
102const char RtpExtension::kAbsSendTimeUri[] =
103 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time";
104const int RtpExtension::kAbsSendTimeDefaultId = 3;
105
106const char RtpExtension::kVideoRotationUri[] = "urn:3gpp:video-orientation";
107const int RtpExtension::kVideoRotationDefaultId = 4;
108
109const char RtpExtension::kTransportSequenceNumberUri[] =
110 "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01";
111const int RtpExtension::kTransportSequenceNumberDefaultId = 5;
112
113// This extension allows applications to adaptively limit the playout delay
114// on frames as per the current needs. For example, a gaming application
115// has very different needs on end-to-end delay compared to a video-conference
116// application.
117const char RtpExtension::kPlayoutDelayUri[] =
118 "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay";
119const int RtpExtension::kPlayoutDelayDefaultId = 6;
120
121const char RtpExtension::kVideoContentTypeUri[] =
122 "http://www.webrtc.org/experiments/rtp-hdrext/video-content-type";
123const int RtpExtension::kVideoContentTypeDefaultId = 7;
124
125const char RtpExtension::kVideoTimingUri[] =
126 "http://www.webrtc.org/experiments/rtp-hdrext/video-timing";
127const int RtpExtension::kVideoTimingDefaultId = 8;
128
Steve Antonbb50ce52018-03-26 10:24:32 -0700129const char RtpExtension::kMidUri[] = "urn:ietf:params:rtp-hdrext:sdes:mid";
130const int RtpExtension::kMidDefaultId = 9;
131
Stefan Holmer1acbd682017-09-01 15:29:28 +0200132const char RtpExtension::kEncryptHeaderExtensionsUri[] =
133 "urn:ietf:params:rtp-hdrext:encrypt";
134
135const int RtpExtension::kMinId = 1;
136const int RtpExtension::kMaxId = 14;
137
138bool RtpExtension::IsSupportedForAudio(const std::string& uri) {
139 return uri == webrtc::RtpExtension::kAudioLevelUri ||
Steve Antonbb50ce52018-03-26 10:24:32 -0700140 uri == webrtc::RtpExtension::kTransportSequenceNumberUri ||
141 uri == webrtc::RtpExtension::kMidUri;
Stefan Holmer1acbd682017-09-01 15:29:28 +0200142}
143
144bool RtpExtension::IsSupportedForVideo(const std::string& uri) {
145 return uri == webrtc::RtpExtension::kTimestampOffsetUri ||
146 uri == webrtc::RtpExtension::kAbsSendTimeUri ||
147 uri == webrtc::RtpExtension::kVideoRotationUri ||
148 uri == webrtc::RtpExtension::kTransportSequenceNumberUri ||
149 uri == webrtc::RtpExtension::kPlayoutDelayUri ||
150 uri == webrtc::RtpExtension::kVideoContentTypeUri ||
Steve Antonbb50ce52018-03-26 10:24:32 -0700151 uri == webrtc::RtpExtension::kVideoTimingUri ||
152 uri == webrtc::RtpExtension::kMidUri;
Stefan Holmer1acbd682017-09-01 15:29:28 +0200153}
154
155bool RtpExtension::IsEncryptionSupported(const std::string& uri) {
156 return uri == webrtc::RtpExtension::kAudioLevelUri ||
157 uri == webrtc::RtpExtension::kTimestampOffsetUri ||
158#if !defined(ENABLE_EXTERNAL_AUTH)
159 // TODO(jbauch): Figure out a way to always allow "kAbsSendTimeUri"
160 // here and filter out later if external auth is really used in
161 // srtpfilter. External auth is used by Chromium and replaces the
162 // extension header value of "kAbsSendTimeUri", so it must not be
163 // encrypted (which can't be done by Chromium).
164 uri == webrtc::RtpExtension::kAbsSendTimeUri ||
165#endif
166 uri == webrtc::RtpExtension::kVideoRotationUri ||
167 uri == webrtc::RtpExtension::kTransportSequenceNumberUri ||
168 uri == webrtc::RtpExtension::kPlayoutDelayUri ||
Steve Antonbb50ce52018-03-26 10:24:32 -0700169 uri == webrtc::RtpExtension::kVideoContentTypeUri ||
170 uri == webrtc::RtpExtension::kMidUri;
Stefan Holmer1acbd682017-09-01 15:29:28 +0200171}
172
173const RtpExtension* RtpExtension::FindHeaderExtensionByUri(
174 const std::vector<RtpExtension>& extensions,
175 const std::string& uri) {
176 for (const auto& extension : extensions) {
177 if (extension.uri == uri) {
178 return &extension;
179 }
180 }
181 return nullptr;
182}
183
184std::vector<RtpExtension> RtpExtension::FilterDuplicateNonEncrypted(
185 const std::vector<RtpExtension>& extensions) {
186 std::vector<RtpExtension> filtered;
187 for (auto extension = extensions.begin(); extension != extensions.end();
188 ++extension) {
189 if (extension->encrypt) {
190 filtered.push_back(*extension);
191 continue;
192 }
193
194 // Only add non-encrypted extension if no encrypted with the same URI
195 // is also present...
196 if (std::find_if(extension + 1, extensions.end(),
197 [extension](const RtpExtension& check) {
198 return extension->uri == check.uri;
199 }) != extensions.end()) {
200 continue;
201 }
202
203 // ...and has not been added before.
204 if (!FindHeaderExtensionByUri(filtered, extension->uri)) {
205 filtered.push_back(*extension);
206 }
207 }
208 return filtered;
209}
210} // namespace webrtc