-
Notifications
You must be signed in to change notification settings - Fork 4
/
config.cc
336 lines (283 loc) · 11 KB
/
config.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
/*
* Copyright (c) 2014 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.
*/
#include "webrtc/config.h"
#include <algorithm>
#include <sstream>
#include <string>
#include "webrtc/rtc_base/base64.h"
#include "webrtc/rtc_base/checks.h"
namespace webrtc {
std::string NackConfig::ToString() const {
std::stringstream ss;
ss << "{rtp_history_ms: " << rtp_history_ms;
ss << '}';
return ss.str();
}
std::string UlpfecConfig::ToString() const {
std::stringstream ss;
ss << "{ulpfec_payload_type: " << ulpfec_payload_type;
ss << ", red_payload_type: " << red_payload_type;
ss << ", red_rtx_payload_type: " << red_rtx_payload_type;
ss << '}';
return ss.str();
}
bool UlpfecConfig::operator==(const UlpfecConfig& other) const {
return ulpfec_payload_type == other.ulpfec_payload_type &&
red_payload_type == other.red_payload_type &&
red_rtx_payload_type == other.red_rtx_payload_type;
}
std::string RtpExtension::ToString() const {
std::stringstream ss;
ss << "{uri: " << uri;
ss << ", id: " << id;
if (encrypt) {
ss << ", encrypt";
}
ss << '}';
return ss.str();
}
const char* RtpExtension::kAudioLevelUri =
"urn:ietf:params:rtp-hdrext:ssrc-audio-level";
const int RtpExtension::kAudioLevelDefaultId = 1;
const char* RtpExtension::kTimestampOffsetUri =
"urn:ietf:params:rtp-hdrext:toffset";
const int RtpExtension::kTimestampOffsetDefaultId = 2;
const char* RtpExtension::kAbsSendTimeUri =
"http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time";
const int RtpExtension::kAbsSendTimeDefaultId = 3;
const char* RtpExtension::kVideoRotationUri = "urn:3gpp:video-orientation";
const int RtpExtension::kVideoRotationDefaultId = 4;
const char* RtpExtension::kTransportSequenceNumberUri =
"http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01";
const int RtpExtension::kTransportSequenceNumberDefaultId = 5;
// This extension allows applications to adaptively limit the playout delay
// on frames as per the current needs. For example, a gaming application
// has very different needs on end-to-end delay compared to a video-conference
// application.
const char* RtpExtension::kPlayoutDelayUri =
"http://www.webrtc.org/experiments/rtp-hdrext/playout-delay";
const int RtpExtension::kPlayoutDelayDefaultId = 6;
const char* RtpExtension::kVideoContentTypeUri =
"http://www.webrtc.org/experiments/rtp-hdrext/video-content-type";
const int RtpExtension::kVideoContentTypeDefaultId = 7;
const char* RtpExtension::kVideoTimingUri =
"http://www.webrtc.org/experiments/rtp-hdrext/video-timing";
const int RtpExtension::kVideoTimingDefaultId = 8;
const char* RtpExtension::kEncryptHeaderExtensionsUri =
"urn:ietf:params:rtp-hdrext:encrypt";
// This extensions provides meta-information about the RTP streams outside the
// encrypted media payload, an RTP switch can do codec-agnostic
// selective forwarding without decrypting the payload
const char* RtpExtension::kFrameMarkingUri =
"urn:ietf:params:rtp-hdrext:framemarking";
const int RtpExtension::kFrameMarkingDefaultId = 9;
const int RtpExtension::kMinId = 1;
const int RtpExtension::kMaxId = 14;
bool RtpExtension::IsSupportedForAudio(const std::string& uri) {
return uri == webrtc::RtpExtension::kAudioLevelUri ||
uri == webrtc::RtpExtension::kTransportSequenceNumberUri;
}
bool RtpExtension::IsSupportedForVideo(const std::string& uri) {
return uri == webrtc::RtpExtension::kTimestampOffsetUri ||
uri == webrtc::RtpExtension::kAbsSendTimeUri ||
uri == webrtc::RtpExtension::kVideoRotationUri ||
uri == webrtc::RtpExtension::kTransportSequenceNumberUri ||
uri == webrtc::RtpExtension::kPlayoutDelayUri ||
uri == webrtc::RtpExtension::kVideoContentTypeUri ||
uri == webrtc::RtpExtension::kVideoTimingUri ||
uri == webrtc::RtpExtension::kFrameMarkingUri;
}
bool RtpExtension::IsEncryptionSupported(const std::string& uri) {
return uri == webrtc::RtpExtension::kAudioLevelUri ||
uri == webrtc::RtpExtension::kTimestampOffsetUri ||
#if !defined(ENABLE_EXTERNAL_AUTH)
// TODO(jbauch): Figure out a way to always allow "kAbsSendTimeUri"
// here and filter out later if external auth is really used in
// srtpfilter. External auth is used by Chromium and replaces the
// extension header value of "kAbsSendTimeUri", so it must not be
// encrypted (which can't be done by Chromium).
uri == webrtc::RtpExtension::kAbsSendTimeUri ||
#endif
uri == webrtc::RtpExtension::kVideoRotationUri ||
uri == webrtc::RtpExtension::kTransportSequenceNumberUri ||
uri == webrtc::RtpExtension::kPlayoutDelayUri ||
uri == webrtc::RtpExtension::kVideoContentTypeUri;
}
const RtpExtension* RtpExtension::FindHeaderExtensionByUri(
const std::vector<RtpExtension>& extensions,
const std::string& uri) {
for (const auto& extension : extensions) {
if (extension.uri == uri) {
return &extension;
}
}
return nullptr;
}
std::vector<RtpExtension> RtpExtension::FilterDuplicateNonEncrypted(
const std::vector<RtpExtension>& extensions) {
std::vector<RtpExtension> filtered;
for (auto extension = extensions.begin(); extension != extensions.end();
++extension) {
if (extension->encrypt) {
filtered.push_back(*extension);
continue;
}
// Only add non-encrypted extension if no encrypted with the same URI
// is also present...
if (std::find_if(extension + 1, extensions.end(),
[extension](const RtpExtension& check) {
return extension->uri == check.uri;
}) != extensions.end()) {
continue;
}
// ...and has not been added before.
if (!FindHeaderExtensionByUri(filtered, extension->uri)) {
filtered.push_back(*extension);
}
}
return filtered;
}
VideoStream::VideoStream()
: width(0),
height(0),
max_framerate(-1),
min_bitrate_bps(-1),
target_bitrate_bps(-1),
max_bitrate_bps(-1),
max_qp(-1) {}
VideoStream::~VideoStream() = default;
std::string VideoStream::ToString() const {
std::stringstream ss;
ss << "{width: " << width;
ss << ", height: " << height;
ss << ", max_framerate: " << max_framerate;
ss << ", min_bitrate_bps:" << min_bitrate_bps;
ss << ", target_bitrate_bps:" << target_bitrate_bps;
ss << ", max_bitrate_bps:" << max_bitrate_bps;
ss << ", max_qp: " << max_qp;
ss << ", temporal_layer_thresholds_bps: [";
for (size_t i = 0; i < temporal_layer_thresholds_bps.size(); ++i) {
ss << temporal_layer_thresholds_bps[i];
if (i != temporal_layer_thresholds_bps.size() - 1)
ss << ", ";
}
ss << ']';
ss << '}';
return ss.str();
}
VideoEncoderConfig::VideoEncoderConfig()
: content_type(ContentType::kRealtimeVideo),
encoder_specific_settings(nullptr),
min_transmit_bitrate_bps(0),
max_bitrate_bps(0),
number_of_streams(0) {}
VideoEncoderConfig::VideoEncoderConfig(VideoEncoderConfig&&) = default;
VideoEncoderConfig::~VideoEncoderConfig() = default;
std::string VideoEncoderConfig::ToString() const {
std::stringstream ss;
ss << "{content_type: ";
switch (content_type) {
case ContentType::kRealtimeVideo:
ss << "kRealtimeVideo";
break;
case ContentType::kScreen:
ss << "kScreenshare";
break;
}
ss << ", encoder_specific_settings: ";
ss << (encoder_specific_settings != NULL ? "(ptr)" : "NULL");
ss << ", min_transmit_bitrate_bps: " << min_transmit_bitrate_bps;
ss << '}';
return ss.str();
}
VideoEncoderConfig::VideoEncoderConfig(const VideoEncoderConfig&) = default;
void VideoEncoderConfig::EncoderSpecificSettings::FillEncoderSpecificSettings(
VideoCodec* codec) const {
if (codec->codecType == kVideoCodecH264) {
FillVideoCodecH264(codec->H264());
} else if (codec->codecType == kVideoCodecVP8) {
FillVideoCodecVp8(codec->VP8());
} else if (codec->codecType == kVideoCodecVP9) {
FillVideoCodecVp9(codec->VP9());
} else {
RTC_NOTREACHED() << "Encoder specifics set/used for unknown codec type.";
}
}
void VideoEncoderConfig::EncoderSpecificSettings::FillVideoCodecH264(
VideoCodecH264* h264_settings) const {
RTC_NOTREACHED();
}
void VideoEncoderConfig::EncoderSpecificSettings::FillVideoCodecVp8(
VideoCodecVP8* vp8_settings) const {
RTC_NOTREACHED();
}
void VideoEncoderConfig::EncoderSpecificSettings::FillVideoCodecVp9(
VideoCodecVP9* vp9_settings) const {
RTC_NOTREACHED();
}
VideoEncoderConfig::H264EncoderSpecificSettings::H264EncoderSpecificSettings(
const VideoCodecH264& specifics)
: specifics_(specifics) {}
void VideoEncoderConfig::H264EncoderSpecificSettings::FillVideoCodecH264(
VideoCodecH264* h264_settings) const {
*h264_settings = specifics_;
}
VideoEncoderConfig::Vp8EncoderSpecificSettings::Vp8EncoderSpecificSettings(
const VideoCodecVP8& specifics)
: specifics_(specifics) {}
void VideoEncoderConfig::Vp8EncoderSpecificSettings::FillVideoCodecVp8(
VideoCodecVP8* vp8_settings) const {
*vp8_settings = specifics_;
}
VideoEncoderConfig::Vp9EncoderSpecificSettings::Vp9EncoderSpecificSettings(
const VideoCodecVP9& specifics)
: specifics_(specifics) {}
void VideoEncoderConfig::Vp9EncoderSpecificSettings::FillVideoCodecVp9(
VideoCodecVP9* vp9_settings) const {
*vp9_settings = specifics_;
}
bool MediaCryptoKey::Parse(const std::string& suite, const std::string& str) {
size_t len;
// Get suite from name
int crypto_suite = rtc::SrtpCryptoSuiteFromName(suite);
if (crypto_suite == rtc::SRTP_INVALID_CRYPTO_SUITE) {
LOG(LS_WARNING) << "Failed to parse MediaCryptoKey: invalid suite "
<< suite;
return false;
}
// Decode the key
if (!rtc::Base64::DecodeFromArray(str.c_str(), str.length(),
rtc::Base64::DecodeOption::DO_STRICT,
&buffer, &len)) {
LOG(LS_WARNING) << "Failed to parse MediaCryptoKey: base64 decode failed";
return false;
}
// Check ley size
int expected_key_len;
int expected_salt_len;
if (!rtc::GetSrtpKeyAndSaltLengths(crypto_suite, &expected_key_len,
&expected_salt_len)) {
// This should never happen.
LOG(LS_WARNING) << "Failed to parse MediaCryptoKey: unsupported"
<< " cipher suite without length information "
<< crypto_suite;
return false;
}
size_t expected = static_cast<size_t>(expected_key_len + expected_salt_len);
if (buffer.size() != expected) {
LOG(LS_WARNING) << "Failed to create SRTP session: invalid key,"
<< " key length" << buffer.size() << " expected"
<< expected;
return false;
}
type = crypto_suite;
return true;
}
} // namespace webrtc