Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 10 | #include "api/rtpparameters.h" |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 11 | |
| 12 | #include <algorithm> |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 13 | #include <string> |
| 14 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #include "rtc_base/checks.h" |
Jonas Olsson | 866d6dc | 2018-05-14 17:30:22 +0200 | [diff] [blame] | 16 | #include "rtc_base/strings/string_builder.h" |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 17 | |
| 18 | namespace webrtc { |
| 19 | |
Seth Hampson | f32795e | 2017-12-19 11:37:41 -0800 | [diff] [blame] | 20 | const double kDefaultBitratePriority = 1.0; |
| 21 | |
Mirko Bonadei | 2ffed6d | 2018-07-20 11:09:32 +0200 | [diff] [blame] | 22 | RtcpFeedback::RtcpFeedback() = default; |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 23 | RtcpFeedback::RtcpFeedback(RtcpFeedbackType type) : type(type) {} |
| 24 | RtcpFeedback::RtcpFeedback(RtcpFeedbackType type, |
| 25 | RtcpFeedbackMessageType message_type) |
| 26 | : type(type), message_type(message_type) {} |
Mirko Bonadei | 2ffed6d | 2018-07-20 11:09:32 +0200 | [diff] [blame] | 27 | RtcpFeedback::RtcpFeedback(const RtcpFeedback& rhs) = default; |
| 28 | RtcpFeedback::~RtcpFeedback() = default; |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 29 | |
Mirko Bonadei | 2ffed6d | 2018-07-20 11:09:32 +0200 | [diff] [blame] | 30 | RtpCodecCapability::RtpCodecCapability() = default; |
| 31 | RtpCodecCapability::~RtpCodecCapability() = default; |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 32 | |
Mirko Bonadei | 2ffed6d | 2018-07-20 11:09:32 +0200 | [diff] [blame] | 33 | RtpHeaderExtensionCapability::RtpHeaderExtensionCapability() = default; |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 34 | RtpHeaderExtensionCapability::RtpHeaderExtensionCapability( |
| 35 | const std::string& uri) |
| 36 | : uri(uri) {} |
| 37 | RtpHeaderExtensionCapability::RtpHeaderExtensionCapability( |
| 38 | const std::string& uri, |
| 39 | int preferred_id) |
| 40 | : uri(uri), preferred_id(preferred_id) {} |
Mirko Bonadei | 2ffed6d | 2018-07-20 11:09:32 +0200 | [diff] [blame] | 41 | RtpHeaderExtensionCapability::~RtpHeaderExtensionCapability() = default; |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 42 | |
Mirko Bonadei | 2ffed6d | 2018-07-20 11:09:32 +0200 | [diff] [blame] | 43 | RtpExtension::RtpExtension() = default; |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 44 | RtpExtension::RtpExtension(const std::string& uri, int id) : uri(uri), id(id) {} |
| 45 | RtpExtension::RtpExtension(const std::string& uri, int id, bool encrypt) |
| 46 | : uri(uri), id(id), encrypt(encrypt) {} |
Mirko Bonadei | 2ffed6d | 2018-07-20 11:09:32 +0200 | [diff] [blame] | 47 | RtpExtension::~RtpExtension() = default; |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 48 | |
Mirko Bonadei | 2ffed6d | 2018-07-20 11:09:32 +0200 | [diff] [blame] | 49 | RtpFecParameters::RtpFecParameters() = default; |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 50 | RtpFecParameters::RtpFecParameters(FecMechanism mechanism) |
| 51 | : mechanism(mechanism) {} |
| 52 | RtpFecParameters::RtpFecParameters(FecMechanism mechanism, uint32_t ssrc) |
| 53 | : ssrc(ssrc), mechanism(mechanism) {} |
Mirko Bonadei | 2ffed6d | 2018-07-20 11:09:32 +0200 | [diff] [blame] | 54 | RtpFecParameters::RtpFecParameters(const RtpFecParameters& rhs) = default; |
| 55 | RtpFecParameters::~RtpFecParameters() = default; |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 56 | |
Mirko Bonadei | 2ffed6d | 2018-07-20 11:09:32 +0200 | [diff] [blame] | 57 | RtpRtxParameters::RtpRtxParameters() = default; |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 58 | RtpRtxParameters::RtpRtxParameters(uint32_t ssrc) : ssrc(ssrc) {} |
Mirko Bonadei | 2ffed6d | 2018-07-20 11:09:32 +0200 | [diff] [blame] | 59 | RtpRtxParameters::RtpRtxParameters(const RtpRtxParameters& rhs) = default; |
| 60 | RtpRtxParameters::~RtpRtxParameters() = default; |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 61 | |
Mirko Bonadei | 2ffed6d | 2018-07-20 11:09:32 +0200 | [diff] [blame] | 62 | RtpEncodingParameters::RtpEncodingParameters() = default; |
| 63 | RtpEncodingParameters::RtpEncodingParameters(const RtpEncodingParameters& rhs) = |
| 64 | default; |
| 65 | RtpEncodingParameters::~RtpEncodingParameters() = default; |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 66 | |
Mirko Bonadei | 2ffed6d | 2018-07-20 11:09:32 +0200 | [diff] [blame] | 67 | RtpCodecParameters::RtpCodecParameters() = default; |
| 68 | RtpCodecParameters::RtpCodecParameters(const RtpCodecParameters& rhs) = default; |
| 69 | RtpCodecParameters::~RtpCodecParameters() = default; |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 70 | |
Mirko Bonadei | 2ffed6d | 2018-07-20 11:09:32 +0200 | [diff] [blame] | 71 | RtpCapabilities::RtpCapabilities() = default; |
| 72 | RtpCapabilities::~RtpCapabilities() = default; |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 73 | |
Mirko Bonadei | 2ffed6d | 2018-07-20 11:09:32 +0200 | [diff] [blame] | 74 | RtcpParameters::RtcpParameters() = default; |
| 75 | RtcpParameters::RtcpParameters(const RtcpParameters& rhs) = default; |
| 76 | RtcpParameters::~RtcpParameters() = default; |
Florent Castelli | dacec71 | 2018-05-24 16:24:21 +0200 | [diff] [blame] | 77 | |
Mirko Bonadei | 2ffed6d | 2018-07-20 11:09:32 +0200 | [diff] [blame] | 78 | RtpParameters::RtpParameters() = default; |
| 79 | RtpParameters::RtpParameters(const RtpParameters& rhs) = default; |
| 80 | RtpParameters::~RtpParameters() = default; |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 81 | |
| 82 | std::string RtpExtension::ToString() const { |
Jonas Olsson | 866d6dc | 2018-05-14 17:30:22 +0200 | [diff] [blame] | 83 | char buf[256]; |
| 84 | rtc::SimpleStringBuilder sb(buf); |
| 85 | sb << "{uri: " << uri; |
| 86 | sb << ", id: " << id; |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 87 | if (encrypt) { |
Jonas Olsson | 866d6dc | 2018-05-14 17:30:22 +0200 | [diff] [blame] | 88 | sb << ", encrypt"; |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 89 | } |
Jonas Olsson | 866d6dc | 2018-05-14 17:30:22 +0200 | [diff] [blame] | 90 | sb << '}'; |
| 91 | return sb.str(); |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | const char RtpExtension::kAudioLevelUri[] = |
| 95 | "urn:ietf:params:rtp-hdrext:ssrc-audio-level"; |
| 96 | const int RtpExtension::kAudioLevelDefaultId = 1; |
| 97 | |
| 98 | const char RtpExtension::kTimestampOffsetUri[] = |
| 99 | "urn:ietf:params:rtp-hdrext:toffset"; |
| 100 | const int RtpExtension::kTimestampOffsetDefaultId = 2; |
| 101 | |
| 102 | const char RtpExtension::kAbsSendTimeUri[] = |
| 103 | "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time"; |
| 104 | const int RtpExtension::kAbsSendTimeDefaultId = 3; |
| 105 | |
| 106 | const char RtpExtension::kVideoRotationUri[] = "urn:3gpp:video-orientation"; |
| 107 | const int RtpExtension::kVideoRotationDefaultId = 4; |
| 108 | |
| 109 | const char RtpExtension::kTransportSequenceNumberUri[] = |
| 110 | "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01"; |
| 111 | const 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. |
| 117 | const char RtpExtension::kPlayoutDelayUri[] = |
| 118 | "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay"; |
| 119 | const int RtpExtension::kPlayoutDelayDefaultId = 6; |
| 120 | |
| 121 | const char RtpExtension::kVideoContentTypeUri[] = |
| 122 | "http://www.webrtc.org/experiments/rtp-hdrext/video-content-type"; |
| 123 | const int RtpExtension::kVideoContentTypeDefaultId = 7; |
| 124 | |
| 125 | const char RtpExtension::kVideoTimingUri[] = |
| 126 | "http://www.webrtc.org/experiments/rtp-hdrext/video-timing"; |
| 127 | const int RtpExtension::kVideoTimingDefaultId = 8; |
| 128 | |
Steve Anton | bb50ce5 | 2018-03-26 10:24:32 -0700 | [diff] [blame] | 129 | const char RtpExtension::kMidUri[] = "urn:ietf:params:rtp-hdrext:sdes:mid"; |
| 130 | const int RtpExtension::kMidDefaultId = 9; |
| 131 | |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 132 | const char RtpExtension::kEncryptHeaderExtensionsUri[] = |
| 133 | "urn:ietf:params:rtp-hdrext:encrypt"; |
| 134 | |
| 135 | const int RtpExtension::kMinId = 1; |
| 136 | const int RtpExtension::kMaxId = 14; |
| 137 | |
| 138 | bool RtpExtension::IsSupportedForAudio(const std::string& uri) { |
| 139 | return uri == webrtc::RtpExtension::kAudioLevelUri || |
Steve Anton | bb50ce5 | 2018-03-26 10:24:32 -0700 | [diff] [blame] | 140 | uri == webrtc::RtpExtension::kTransportSequenceNumberUri || |
| 141 | uri == webrtc::RtpExtension::kMidUri; |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | bool 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 Anton | bb50ce5 | 2018-03-26 10:24:32 -0700 | [diff] [blame] | 151 | uri == webrtc::RtpExtension::kVideoTimingUri || |
| 152 | uri == webrtc::RtpExtension::kMidUri; |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | bool 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 Anton | bb50ce5 | 2018-03-26 10:24:32 -0700 | [diff] [blame] | 169 | uri == webrtc::RtpExtension::kVideoContentTypeUri || |
| 170 | uri == webrtc::RtpExtension::kMidUri; |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | const 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 | |
| 184 | std::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 |