pbos@webrtc.org | 1e92b0a | 2014-05-15 09:35:06 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 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 | #include "webrtc/config.h" |
| 11 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 12 | #include <algorithm> |
pbos@webrtc.org | 1e92b0a | 2014-05-15 09:35:06 +0000 | [diff] [blame] | 13 | #include <sstream> |
| 14 | #include <string> |
| 15 | |
Edward Lemur | c20978e | 2017-07-06 19:44:34 +0200 | [diff] [blame] | 16 | #include "webrtc/rtc_base/checks.h" |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 17 | |
pbos@webrtc.org | 1e92b0a | 2014-05-15 09:35:06 +0000 | [diff] [blame] | 18 | namespace webrtc { |
solenberg | 971cab0 | 2016-06-14 10:02:41 -0700 | [diff] [blame] | 19 | std::string NackConfig::ToString() const { |
| 20 | std::stringstream ss; |
| 21 | ss << "{rtp_history_ms: " << rtp_history_ms; |
| 22 | ss << '}'; |
| 23 | return ss.str(); |
| 24 | } |
| 25 | |
brandtr | b5f2c3f | 2016-10-04 23:28:39 -0700 | [diff] [blame] | 26 | std::string UlpfecConfig::ToString() const { |
pbos@webrtc.org | 1e92b0a | 2014-05-15 09:35:06 +0000 | [diff] [blame] | 27 | std::stringstream ss; |
| 28 | ss << "{ulpfec_payload_type: " << ulpfec_payload_type; |
| 29 | ss << ", red_payload_type: " << red_payload_type; |
Stefan Holmer | 1088001 | 2016-02-03 13:29:59 +0100 | [diff] [blame] | 30 | ss << ", red_rtx_payload_type: " << red_rtx_payload_type; |
pbos@webrtc.org | 1e92b0a | 2014-05-15 09:35:06 +0000 | [diff] [blame] | 31 | ss << '}'; |
| 32 | return ss.str(); |
| 33 | } |
| 34 | |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 35 | bool UlpfecConfig::operator==(const UlpfecConfig& other) const { |
| 36 | return ulpfec_payload_type == other.ulpfec_payload_type && |
| 37 | red_payload_type == other.red_payload_type && |
| 38 | red_rtx_payload_type == other.red_rtx_payload_type; |
| 39 | } |
| 40 | |
pbos@webrtc.org | 1e92b0a | 2014-05-15 09:35:06 +0000 | [diff] [blame] | 41 | std::string RtpExtension::ToString() const { |
| 42 | std::stringstream ss; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 43 | ss << "{uri: " << uri; |
pbos@webrtc.org | 1e92b0a | 2014-05-15 09:35:06 +0000 | [diff] [blame] | 44 | ss << ", id: " << id; |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 45 | if (encrypt) { |
| 46 | ss << ", encrypt"; |
| 47 | } |
pbos@webrtc.org | 1e92b0a | 2014-05-15 09:35:06 +0000 | [diff] [blame] | 48 | ss << '}'; |
| 49 | return ss.str(); |
| 50 | } |
| 51 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 52 | const char* RtpExtension::kAudioLevelUri = |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 53 | "urn:ietf:params:rtp-hdrext:ssrc-audio-level"; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 54 | const int RtpExtension::kAudioLevelDefaultId = 1; |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 55 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 56 | const char* RtpExtension::kTimestampOffsetUri = |
| 57 | "urn:ietf:params:rtp-hdrext:toffset"; |
| 58 | const int RtpExtension::kTimestampOffsetDefaultId = 2; |
| 59 | |
| 60 | const char* RtpExtension::kAbsSendTimeUri = |
| 61 | "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time"; |
| 62 | const int RtpExtension::kAbsSendTimeDefaultId = 3; |
| 63 | |
| 64 | const char* RtpExtension::kVideoRotationUri = "urn:3gpp:video-orientation"; |
| 65 | const int RtpExtension::kVideoRotationDefaultId = 4; |
| 66 | |
| 67 | const char* RtpExtension::kTransportSequenceNumberUri = |
| 68 | "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01"; |
| 69 | const int RtpExtension::kTransportSequenceNumberDefaultId = 5; |
| 70 | |
isheriff | 6b4b5f3 | 2016-06-08 00:24:21 -0700 | [diff] [blame] | 71 | // This extension allows applications to adaptively limit the playout delay |
| 72 | // on frames as per the current needs. For example, a gaming application |
| 73 | // has very different needs on end-to-end delay compared to a video-conference |
| 74 | // application. |
| 75 | const char* RtpExtension::kPlayoutDelayUri = |
| 76 | "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay"; |
| 77 | const int RtpExtension::kPlayoutDelayDefaultId = 6; |
| 78 | |
ilnik | f53f47f | 2017-04-26 02:35:31 -0700 | [diff] [blame] | 79 | const char* RtpExtension::kVideoContentTypeUri = |
| 80 | "http://www.webrtc.org/experiments/rtp-hdrext/video-content-type"; |
| 81 | const int RtpExtension::kVideoContentTypeDefaultId = 7; |
| 82 | |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 83 | const char* RtpExtension::kVideoTimingUri = |
| 84 | "http://www.webrtc.org/experiments/rtp-hdrext/video-timing"; |
| 85 | const int RtpExtension::kVideoTimingDefaultId = 8; |
| 86 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 87 | const char* RtpExtension::kEncryptHeaderExtensionsUri = |
| 88 | "urn:ietf:params:rtp-hdrext:encrypt"; |
| 89 | |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 90 | const int RtpExtension::kMinId = 1; |
| 91 | const int RtpExtension::kMaxId = 14; |
| 92 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 93 | bool RtpExtension::IsSupportedForAudio(const std::string& uri) { |
solenberg | d4adce4 | 2016-11-17 06:26:52 -0800 | [diff] [blame] | 94 | return uri == webrtc::RtpExtension::kAudioLevelUri || |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 95 | uri == webrtc::RtpExtension::kTransportSequenceNumberUri; |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 96 | } |
| 97 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 98 | bool RtpExtension::IsSupportedForVideo(const std::string& uri) { |
| 99 | return uri == webrtc::RtpExtension::kTimestampOffsetUri || |
| 100 | uri == webrtc::RtpExtension::kAbsSendTimeUri || |
| 101 | uri == webrtc::RtpExtension::kVideoRotationUri || |
isheriff | 6b4b5f3 | 2016-06-08 00:24:21 -0700 | [diff] [blame] | 102 | uri == webrtc::RtpExtension::kTransportSequenceNumberUri || |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 103 | uri == webrtc::RtpExtension::kPlayoutDelayUri || |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 104 | uri == webrtc::RtpExtension::kVideoContentTypeUri || |
| 105 | uri == webrtc::RtpExtension::kVideoTimingUri; |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 106 | } |
| 107 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 108 | bool RtpExtension::IsEncryptionSupported(const std::string& uri) { |
| 109 | return uri == webrtc::RtpExtension::kAudioLevelUri || |
| 110 | uri == webrtc::RtpExtension::kTimestampOffsetUri || |
| 111 | #if !defined(ENABLE_EXTERNAL_AUTH) |
| 112 | // TODO(jbauch): Figure out a way to always allow "kAbsSendTimeUri" |
| 113 | // here and filter out later if external auth is really used in |
| 114 | // srtpfilter. External auth is used by Chromium and replaces the |
| 115 | // extension header value of "kAbsSendTimeUri", so it must not be |
| 116 | // encrypted (which can't be done by Chromium). |
| 117 | uri == webrtc::RtpExtension::kAbsSendTimeUri || |
| 118 | #endif |
| 119 | uri == webrtc::RtpExtension::kVideoRotationUri || |
| 120 | uri == webrtc::RtpExtension::kTransportSequenceNumberUri || |
| 121 | uri == webrtc::RtpExtension::kPlayoutDelayUri || |
| 122 | uri == webrtc::RtpExtension::kVideoContentTypeUri; |
| 123 | } |
| 124 | |
| 125 | const RtpExtension* RtpExtension::FindHeaderExtensionByUri( |
| 126 | const std::vector<RtpExtension>& extensions, |
| 127 | const std::string& uri) { |
| 128 | for (const auto& extension : extensions) { |
| 129 | if (extension.uri == uri) { |
| 130 | return &extension; |
| 131 | } |
| 132 | } |
| 133 | return nullptr; |
| 134 | } |
| 135 | |
| 136 | std::vector<RtpExtension> RtpExtension::FilterDuplicateNonEncrypted( |
| 137 | const std::vector<RtpExtension>& extensions) { |
| 138 | std::vector<RtpExtension> filtered; |
| 139 | for (auto extension = extensions.begin(); extension != extensions.end(); |
| 140 | ++extension) { |
| 141 | if (extension->encrypt) { |
| 142 | filtered.push_back(*extension); |
| 143 | continue; |
| 144 | } |
| 145 | |
| 146 | // Only add non-encrypted extension if no encrypted with the same URI |
| 147 | // is also present... |
| 148 | if (std::find_if(extension + 1, extensions.end(), |
| 149 | [extension](const RtpExtension& check) { |
| 150 | return extension->uri == check.uri; |
| 151 | }) != extensions.end()) { |
| 152 | continue; |
| 153 | } |
| 154 | |
| 155 | // ...and has not been added before. |
| 156 | if (!FindHeaderExtensionByUri(filtered, extension->uri)) { |
| 157 | filtered.push_back(*extension); |
| 158 | } |
| 159 | } |
| 160 | return filtered; |
| 161 | } |
| 162 | |
kwiberg@webrtc.org | ac2d27d | 2015-02-26 13:59:22 +0000 | [diff] [blame] | 163 | VideoStream::VideoStream() |
| 164 | : width(0), |
| 165 | height(0), |
| 166 | max_framerate(-1), |
| 167 | min_bitrate_bps(-1), |
| 168 | target_bitrate_bps(-1), |
| 169 | max_bitrate_bps(-1), |
| 170 | max_qp(-1) {} |
| 171 | |
| 172 | VideoStream::~VideoStream() = default; |
| 173 | |
pbos@webrtc.org | 1e92b0a | 2014-05-15 09:35:06 +0000 | [diff] [blame] | 174 | std::string VideoStream::ToString() const { |
| 175 | std::stringstream ss; |
| 176 | ss << "{width: " << width; |
| 177 | ss << ", height: " << height; |
| 178 | ss << ", max_framerate: " << max_framerate; |
| 179 | ss << ", min_bitrate_bps:" << min_bitrate_bps; |
| 180 | ss << ", target_bitrate_bps:" << target_bitrate_bps; |
| 181 | ss << ", max_bitrate_bps:" << max_bitrate_bps; |
| 182 | ss << ", max_qp: " << max_qp; |
| 183 | |
pbos@webrtc.org | 931e3da | 2014-11-06 09:35:08 +0000 | [diff] [blame] | 184 | ss << ", temporal_layer_thresholds_bps: ["; |
pbos@webrtc.org | b7ed779 | 2014-10-31 13:08:10 +0000 | [diff] [blame] | 185 | for (size_t i = 0; i < temporal_layer_thresholds_bps.size(); ++i) { |
| 186 | ss << temporal_layer_thresholds_bps[i]; |
| 187 | if (i != temporal_layer_thresholds_bps.size() - 1) |
pbos@webrtc.org | 931e3da | 2014-11-06 09:35:08 +0000 | [diff] [blame] | 188 | ss << ", "; |
pbos@webrtc.org | 1e92b0a | 2014-05-15 09:35:06 +0000 | [diff] [blame] | 189 | } |
pbos@webrtc.org | 931e3da | 2014-11-06 09:35:08 +0000 | [diff] [blame] | 190 | ss << ']'; |
pbos@webrtc.org | 1e92b0a | 2014-05-15 09:35:06 +0000 | [diff] [blame] | 191 | |
| 192 | ss << '}'; |
| 193 | return ss.str(); |
| 194 | } |
pbos@webrtc.org | ad3b5a5 | 2014-10-24 09:23:21 +0000 | [diff] [blame] | 195 | |
kwiberg@webrtc.org | ac2d27d | 2015-02-26 13:59:22 +0000 | [diff] [blame] | 196 | VideoEncoderConfig::VideoEncoderConfig() |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 197 | : content_type(ContentType::kRealtimeVideo), |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 198 | encoder_specific_settings(nullptr), |
skvlad | 3abb764 | 2016-06-16 12:08:03 -0700 | [diff] [blame] | 199 | min_transmit_bitrate_bps(0), |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 200 | max_bitrate_bps(0), |
| 201 | number_of_streams(0) {} |
kwiberg@webrtc.org | ac2d27d | 2015-02-26 13:59:22 +0000 | [diff] [blame] | 202 | |
solenberg | 940b6d6 | 2016-10-25 11:19:07 -0700 | [diff] [blame] | 203 | VideoEncoderConfig::VideoEncoderConfig(VideoEncoderConfig&&) = default; |
| 204 | |
kwiberg@webrtc.org | ac2d27d | 2015-02-26 13:59:22 +0000 | [diff] [blame] | 205 | VideoEncoderConfig::~VideoEncoderConfig() = default; |
| 206 | |
pbos@webrtc.org | ad3b5a5 | 2014-10-24 09:23:21 +0000 | [diff] [blame] | 207 | std::string VideoEncoderConfig::ToString() const { |
| 208 | std::stringstream ss; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 209 | ss << "{content_type: "; |
pbos@webrtc.org | ad3b5a5 | 2014-10-24 09:23:21 +0000 | [diff] [blame] | 210 | switch (content_type) { |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 211 | case ContentType::kRealtimeVideo: |
pbos@webrtc.org | ad3b5a5 | 2014-10-24 09:23:21 +0000 | [diff] [blame] | 212 | ss << "kRealtimeVideo"; |
| 213 | break; |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 214 | case ContentType::kScreen: |
pbos@webrtc.org | ad3b5a5 | 2014-10-24 09:23:21 +0000 | [diff] [blame] | 215 | ss << "kScreenshare"; |
| 216 | break; |
| 217 | } |
| 218 | ss << ", encoder_specific_settings: "; |
| 219 | ss << (encoder_specific_settings != NULL ? "(ptr)" : "NULL"); |
| 220 | |
| 221 | ss << ", min_transmit_bitrate_bps: " << min_transmit_bitrate_bps; |
| 222 | ss << '}'; |
| 223 | return ss.str(); |
| 224 | } |
| 225 | |
solenberg | 940b6d6 | 2016-10-25 11:19:07 -0700 | [diff] [blame] | 226 | VideoEncoderConfig::VideoEncoderConfig(const VideoEncoderConfig&) = default; |
| 227 | |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 228 | void VideoEncoderConfig::EncoderSpecificSettings::FillEncoderSpecificSettings( |
| 229 | VideoCodec* codec) const { |
| 230 | if (codec->codecType == kVideoCodecH264) { |
hta | 527d347 | 2016-11-16 23:23:04 -0800 | [diff] [blame] | 231 | FillVideoCodecH264(codec->H264()); |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 232 | } else if (codec->codecType == kVideoCodecVP8) { |
hta | 527d347 | 2016-11-16 23:23:04 -0800 | [diff] [blame] | 233 | FillVideoCodecVp8(codec->VP8()); |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 234 | } else if (codec->codecType == kVideoCodecVP9) { |
hta | 527d347 | 2016-11-16 23:23:04 -0800 | [diff] [blame] | 235 | FillVideoCodecVp9(codec->VP9()); |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 236 | } else { |
| 237 | RTC_NOTREACHED() << "Encoder specifics set/used for unknown codec type."; |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | void VideoEncoderConfig::EncoderSpecificSettings::FillVideoCodecH264( |
| 242 | VideoCodecH264* h264_settings) const { |
| 243 | RTC_NOTREACHED(); |
| 244 | } |
| 245 | |
| 246 | void VideoEncoderConfig::EncoderSpecificSettings::FillVideoCodecVp8( |
| 247 | VideoCodecVP8* vp8_settings) const { |
| 248 | RTC_NOTREACHED(); |
| 249 | } |
| 250 | |
| 251 | void VideoEncoderConfig::EncoderSpecificSettings::FillVideoCodecVp9( |
| 252 | VideoCodecVP9* vp9_settings) const { |
| 253 | RTC_NOTREACHED(); |
| 254 | } |
| 255 | |
| 256 | VideoEncoderConfig::H264EncoderSpecificSettings::H264EncoderSpecificSettings( |
| 257 | const VideoCodecH264& specifics) |
| 258 | : specifics_(specifics) {} |
| 259 | |
| 260 | void VideoEncoderConfig::H264EncoderSpecificSettings::FillVideoCodecH264( |
| 261 | VideoCodecH264* h264_settings) const { |
| 262 | *h264_settings = specifics_; |
| 263 | } |
| 264 | |
| 265 | VideoEncoderConfig::Vp8EncoderSpecificSettings::Vp8EncoderSpecificSettings( |
| 266 | const VideoCodecVP8& specifics) |
| 267 | : specifics_(specifics) {} |
| 268 | |
| 269 | void VideoEncoderConfig::Vp8EncoderSpecificSettings::FillVideoCodecVp8( |
| 270 | VideoCodecVP8* vp8_settings) const { |
| 271 | *vp8_settings = specifics_; |
| 272 | } |
| 273 | |
| 274 | VideoEncoderConfig::Vp9EncoderSpecificSettings::Vp9EncoderSpecificSettings( |
| 275 | const VideoCodecVP9& specifics) |
| 276 | : specifics_(specifics) {} |
| 277 | |
| 278 | void VideoEncoderConfig::Vp9EncoderSpecificSettings::FillVideoCodecVp9( |
| 279 | VideoCodecVP9* vp9_settings) const { |
| 280 | *vp9_settings = specifics_; |
| 281 | } |
| 282 | |
pbos@webrtc.org | 1e92b0a | 2014-05-15 09:35:06 +0000 | [diff] [blame] | 283 | } // namespace webrtc |