blob: 96308da56876c35cfbf5bf4f8c9175e82810ca90 [file] [log] [blame]
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +00001/*
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
jbauch5869f502017-06-29 12:31:36 -070012#include <algorithm>
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +000013#include <sstream>
14#include <string>
15
Edward Lemurc20978e2017-07-06 19:44:34 +020016#include "webrtc/rtc_base/checks.h"
kthelgason29a44e32016-09-27 03:52:02 -070017
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +000018namespace webrtc {
solenberg971cab02016-06-14 10:02:41 -070019std::string NackConfig::ToString() const {
20 std::stringstream ss;
21 ss << "{rtp_history_ms: " << rtp_history_ms;
22 ss << '}';
23 return ss.str();
24}
25
brandtrb5f2c3f2016-10-04 23:28:39 -070026std::string UlpfecConfig::ToString() const {
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +000027 std::stringstream ss;
28 ss << "{ulpfec_payload_type: " << ulpfec_payload_type;
29 ss << ", red_payload_type: " << red_payload_type;
Stefan Holmer10880012016-02-03 13:29:59 +010030 ss << ", red_rtx_payload_type: " << red_rtx_payload_type;
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +000031 ss << '}';
32 return ss.str();
33}
34
brandtr468da7c2016-11-22 02:16:47 -080035bool 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.org1e92b0a2014-05-15 09:35:06 +000041std::string RtpExtension::ToString() const {
42 std::stringstream ss;
isheriff6f8d6862016-05-26 11:24:55 -070043 ss << "{uri: " << uri;
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +000044 ss << ", id: " << id;
jbauch5869f502017-06-29 12:31:36 -070045 if (encrypt) {
46 ss << ", encrypt";
47 }
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +000048 ss << '}';
49 return ss.str();
50}
51
isheriff6f8d6862016-05-26 11:24:55 -070052const char* RtpExtension::kAudioLevelUri =
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020053 "urn:ietf:params:rtp-hdrext:ssrc-audio-level";
isheriff6f8d6862016-05-26 11:24:55 -070054const int RtpExtension::kAudioLevelDefaultId = 1;
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020055
isheriff6f8d6862016-05-26 11:24:55 -070056const char* RtpExtension::kTimestampOffsetUri =
57 "urn:ietf:params:rtp-hdrext:toffset";
58const int RtpExtension::kTimestampOffsetDefaultId = 2;
59
60const char* RtpExtension::kAbsSendTimeUri =
61 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time";
62const int RtpExtension::kAbsSendTimeDefaultId = 3;
63
64const char* RtpExtension::kVideoRotationUri = "urn:3gpp:video-orientation";
65const int RtpExtension::kVideoRotationDefaultId = 4;
66
67const char* RtpExtension::kTransportSequenceNumberUri =
68 "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01";
69const int RtpExtension::kTransportSequenceNumberDefaultId = 5;
70
isheriff6b4b5f32016-06-08 00:24:21 -070071// 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.
75const char* RtpExtension::kPlayoutDelayUri =
76 "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay";
77const int RtpExtension::kPlayoutDelayDefaultId = 6;
78
ilnikf53f47f2017-04-26 02:35:31 -070079const char* RtpExtension::kVideoContentTypeUri =
80 "http://www.webrtc.org/experiments/rtp-hdrext/video-content-type";
81const int RtpExtension::kVideoContentTypeDefaultId = 7;
82
ilnik04f4d122017-06-19 07:18:55 -070083const char* RtpExtension::kVideoTimingUri =
84 "http://www.webrtc.org/experiments/rtp-hdrext/video-timing";
85const int RtpExtension::kVideoTimingDefaultId = 8;
86
jbauch5869f502017-06-29 12:31:36 -070087const char* RtpExtension::kEncryptHeaderExtensionsUri =
88 "urn:ietf:params:rtp-hdrext:encrypt";
89
deadbeefe814a0d2017-02-25 18:15:09 -080090const int RtpExtension::kMinId = 1;
91const int RtpExtension::kMaxId = 14;
92
isheriff6f8d6862016-05-26 11:24:55 -070093bool RtpExtension::IsSupportedForAudio(const std::string& uri) {
solenbergd4adce42016-11-17 06:26:52 -080094 return uri == webrtc::RtpExtension::kAudioLevelUri ||
isheriff6f8d6862016-05-26 11:24:55 -070095 uri == webrtc::RtpExtension::kTransportSequenceNumberUri;
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020096}
97
isheriff6f8d6862016-05-26 11:24:55 -070098bool RtpExtension::IsSupportedForVideo(const std::string& uri) {
99 return uri == webrtc::RtpExtension::kTimestampOffsetUri ||
100 uri == webrtc::RtpExtension::kAbsSendTimeUri ||
101 uri == webrtc::RtpExtension::kVideoRotationUri ||
isheriff6b4b5f32016-06-08 00:24:21 -0700102 uri == webrtc::RtpExtension::kTransportSequenceNumberUri ||
ilnik00d802b2017-04-11 10:34:31 -0700103 uri == webrtc::RtpExtension::kPlayoutDelayUri ||
ilnik04f4d122017-06-19 07:18:55 -0700104 uri == webrtc::RtpExtension::kVideoContentTypeUri ||
105 uri == webrtc::RtpExtension::kVideoTimingUri;
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200106}
107
jbauch5869f502017-06-29 12:31:36 -0700108bool 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
125const 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
136std::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.orgac2d27d2015-02-26 13:59:22 +0000163VideoStream::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
172VideoStream::~VideoStream() = default;
173
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +0000174std::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.org931e3da2014-11-06 09:35:08 +0000184 ss << ", temporal_layer_thresholds_bps: [";
pbos@webrtc.orgb7ed7792014-10-31 13:08:10 +0000185 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.org931e3da2014-11-06 09:35:08 +0000188 ss << ", ";
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +0000189 }
pbos@webrtc.org931e3da2014-11-06 09:35:08 +0000190 ss << ']';
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +0000191
192 ss << '}';
193 return ss.str();
194}
pbos@webrtc.orgad3b5a52014-10-24 09:23:21 +0000195
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +0000196VideoEncoderConfig::VideoEncoderConfig()
Erik Språng143cec12015-04-28 10:01:41 +0200197 : content_type(ContentType::kRealtimeVideo),
kthelgason29a44e32016-09-27 03:52:02 -0700198 encoder_specific_settings(nullptr),
skvlad3abb7642016-06-16 12:08:03 -0700199 min_transmit_bitrate_bps(0),
perkjfa10b552016-10-02 23:45:26 -0700200 max_bitrate_bps(0),
201 number_of_streams(0) {}
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +0000202
solenberg940b6d62016-10-25 11:19:07 -0700203VideoEncoderConfig::VideoEncoderConfig(VideoEncoderConfig&&) = default;
204
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +0000205VideoEncoderConfig::~VideoEncoderConfig() = default;
206
pbos@webrtc.orgad3b5a52014-10-24 09:23:21 +0000207std::string VideoEncoderConfig::ToString() const {
208 std::stringstream ss;
perkjfa10b552016-10-02 23:45:26 -0700209 ss << "{content_type: ";
pbos@webrtc.orgad3b5a52014-10-24 09:23:21 +0000210 switch (content_type) {
Erik Språng143cec12015-04-28 10:01:41 +0200211 case ContentType::kRealtimeVideo:
pbos@webrtc.orgad3b5a52014-10-24 09:23:21 +0000212 ss << "kRealtimeVideo";
213 break;
Erik Språng143cec12015-04-28 10:01:41 +0200214 case ContentType::kScreen:
pbos@webrtc.orgad3b5a52014-10-24 09:23:21 +0000215 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
solenberg940b6d62016-10-25 11:19:07 -0700226VideoEncoderConfig::VideoEncoderConfig(const VideoEncoderConfig&) = default;
227
kthelgason29a44e32016-09-27 03:52:02 -0700228void VideoEncoderConfig::EncoderSpecificSettings::FillEncoderSpecificSettings(
229 VideoCodec* codec) const {
230 if (codec->codecType == kVideoCodecH264) {
hta527d3472016-11-16 23:23:04 -0800231 FillVideoCodecH264(codec->H264());
kthelgason29a44e32016-09-27 03:52:02 -0700232 } else if (codec->codecType == kVideoCodecVP8) {
hta527d3472016-11-16 23:23:04 -0800233 FillVideoCodecVp8(codec->VP8());
kthelgason29a44e32016-09-27 03:52:02 -0700234 } else if (codec->codecType == kVideoCodecVP9) {
hta527d3472016-11-16 23:23:04 -0800235 FillVideoCodecVp9(codec->VP9());
kthelgason29a44e32016-09-27 03:52:02 -0700236 } else {
237 RTC_NOTREACHED() << "Encoder specifics set/used for unknown codec type.";
238 }
239}
240
241void VideoEncoderConfig::EncoderSpecificSettings::FillVideoCodecH264(
242 VideoCodecH264* h264_settings) const {
243 RTC_NOTREACHED();
244}
245
246void VideoEncoderConfig::EncoderSpecificSettings::FillVideoCodecVp8(
247 VideoCodecVP8* vp8_settings) const {
248 RTC_NOTREACHED();
249}
250
251void VideoEncoderConfig::EncoderSpecificSettings::FillVideoCodecVp9(
252 VideoCodecVP9* vp9_settings) const {
253 RTC_NOTREACHED();
254}
255
256VideoEncoderConfig::H264EncoderSpecificSettings::H264EncoderSpecificSettings(
257 const VideoCodecH264& specifics)
258 : specifics_(specifics) {}
259
260void VideoEncoderConfig::H264EncoderSpecificSettings::FillVideoCodecH264(
261 VideoCodecH264* h264_settings) const {
262 *h264_settings = specifics_;
263}
264
265VideoEncoderConfig::Vp8EncoderSpecificSettings::Vp8EncoderSpecificSettings(
266 const VideoCodecVP8& specifics)
267 : specifics_(specifics) {}
268
269void VideoEncoderConfig::Vp8EncoderSpecificSettings::FillVideoCodecVp8(
270 VideoCodecVP8* vp8_settings) const {
271 *vp8_settings = specifics_;
272}
273
274VideoEncoderConfig::Vp9EncoderSpecificSettings::Vp9EncoderSpecificSettings(
275 const VideoCodecVP9& specifics)
276 : specifics_(specifics) {}
277
278void VideoEncoderConfig::Vp9EncoderSpecificSettings::FillVideoCodecVp9(
279 VideoCodecVP9* vp9_settings) const {
280 *vp9_settings = specifics_;
281}
282
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +0000283} // namespace webrtc