blob: 82d96590fb9655ea7885305724893116f67af29f [file] [log] [blame]
deadbeefe814a0d2017-02-25 18:15:09 -08001/*
2 * Copyright 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 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "ortc/testrtpparameters.h"
deadbeefe814a0d2017-02-25 18:15:09 -080012
13#include <algorithm>
14#include <utility>
15
16namespace webrtc {
17
18RtpParameters MakeMinimalOpusParameters() {
19 RtpParameters parameters;
20 RtpCodecParameters opus_codec;
21 opus_codec.name = "opus";
22 opus_codec.kind = cricket::MEDIA_TYPE_AUDIO;
23 opus_codec.payload_type = 111;
24 opus_codec.clock_rate.emplace(48000);
25 opus_codec.num_channels.emplace(2);
26 parameters.codecs.push_back(std::move(opus_codec));
27 RtpEncodingParameters encoding;
28 encoding.codec_payload_type.emplace(111);
29 parameters.encodings.push_back(std::move(encoding));
30 return parameters;
31}
32
33RtpParameters MakeMinimalIsacParameters() {
34 RtpParameters parameters;
35 RtpCodecParameters isac_codec;
36 isac_codec.name = "ISAC";
37 isac_codec.kind = cricket::MEDIA_TYPE_AUDIO;
38 isac_codec.payload_type = 103;
39 isac_codec.clock_rate.emplace(16000);
40 parameters.codecs.push_back(std::move(isac_codec));
41 RtpEncodingParameters encoding;
42 encoding.codec_payload_type.emplace(111);
43 parameters.encodings.push_back(std::move(encoding));
44 return parameters;
45}
46
47RtpParameters MakeMinimalOpusParametersWithSsrc(uint32_t ssrc) {
48 RtpParameters parameters = MakeMinimalOpusParameters();
49 parameters.encodings[0].ssrc.emplace(ssrc);
50 return parameters;
51}
52
53RtpParameters MakeMinimalIsacParametersWithSsrc(uint32_t ssrc) {
54 RtpParameters parameters = MakeMinimalIsacParameters();
55 parameters.encodings[0].ssrc.emplace(ssrc);
56 return parameters;
57}
58
59RtpParameters MakeMinimalVideoParameters(const char* codec_name) {
60 RtpParameters parameters;
61 RtpCodecParameters vp8_codec;
62 vp8_codec.name = codec_name;
63 vp8_codec.kind = cricket::MEDIA_TYPE_VIDEO;
64 vp8_codec.payload_type = 96;
65 parameters.codecs.push_back(std::move(vp8_codec));
66 RtpEncodingParameters encoding;
67 encoding.codec_payload_type.emplace(96);
68 parameters.encodings.push_back(std::move(encoding));
69 return parameters;
70}
71
72RtpParameters MakeMinimalVp8Parameters() {
73 return MakeMinimalVideoParameters("VP8");
74}
75
76RtpParameters MakeMinimalVp9Parameters() {
77 return MakeMinimalVideoParameters("VP9");
78}
79
80RtpParameters MakeMinimalVp8ParametersWithSsrc(uint32_t ssrc) {
81 RtpParameters parameters = MakeMinimalVp8Parameters();
82 parameters.encodings[0].ssrc.emplace(ssrc);
83 return parameters;
84}
85
86RtpParameters MakeMinimalVp9ParametersWithSsrc(uint32_t ssrc) {
87 RtpParameters parameters = MakeMinimalVp9Parameters();
88 parameters.encodings[0].ssrc.emplace(ssrc);
89 return parameters;
90}
91
92// Note: Currently, these "WithNoSsrc" methods are identical to the normal
93// "MakeMinimal" methods, but with the added guarantee that they will never be
94// changed to include an SSRC.
95
96RtpParameters MakeMinimalOpusParametersWithNoSsrc() {
97 RtpParameters parameters = MakeMinimalOpusParameters();
98 RTC_DCHECK(!parameters.encodings[0].ssrc);
99 return parameters;
100}
101
102RtpParameters MakeMinimalIsacParametersWithNoSsrc() {
103 RtpParameters parameters = MakeMinimalIsacParameters();
104 RTC_DCHECK(!parameters.encodings[0].ssrc);
105 return parameters;
106}
107
108RtpParameters MakeMinimalVp8ParametersWithNoSsrc() {
109 RtpParameters parameters = MakeMinimalVp8Parameters();
110 RTC_DCHECK(!parameters.encodings[0].ssrc);
111 return parameters;
112}
113
114RtpParameters MakeMinimalVp9ParametersWithNoSsrc() {
115 RtpParameters parameters = MakeMinimalVp9Parameters();
116 RTC_DCHECK(!parameters.encodings[0].ssrc);
117 return parameters;
118}
119
120// Make audio parameters with all the available properties configured and
121// features used, and with multiple codecs offered. Obtained by taking a
122// snapshot of a default PeerConnection offer (and adding other things, like
123// bitrate limit).
124//
125// See "MakeFullOpusParameters"/"MakeFullIsacParameters" below.
126RtpParameters MakeFullAudioParameters(int preferred_payload_type) {
127 RtpParameters parameters;
128
129 RtpCodecParameters opus_codec;
130 opus_codec.name = "opus";
131 opus_codec.kind = cricket::MEDIA_TYPE_AUDIO;
132 opus_codec.payload_type = 111;
133 opus_codec.clock_rate.emplace(48000);
134 opus_codec.num_channels.emplace(2);
135 opus_codec.parameters["minptime"] = "10";
136 opus_codec.parameters["useinbandfec"] = "1";
137 opus_codec.parameters["usedtx"] = "1";
138 opus_codec.parameters["stereo"] = "1";
139 opus_codec.rtcp_feedback.emplace_back(RtcpFeedbackType::TRANSPORT_CC);
140 parameters.codecs.push_back(std::move(opus_codec));
141
142 RtpCodecParameters isac_codec;
143 isac_codec.name = "ISAC";
144 isac_codec.kind = cricket::MEDIA_TYPE_AUDIO;
145 isac_codec.payload_type = 103;
146 isac_codec.clock_rate.emplace(16000);
147 parameters.codecs.push_back(std::move(isac_codec));
148
149 RtpCodecParameters cn_codec;
150 cn_codec.name = "CN";
151 cn_codec.kind = cricket::MEDIA_TYPE_AUDIO;
152 cn_codec.payload_type = 106;
153 cn_codec.clock_rate.emplace(32000);
154 parameters.codecs.push_back(std::move(cn_codec));
155
156 RtpCodecParameters dtmf_codec;
157 dtmf_codec.name = "telephone-event";
158 dtmf_codec.kind = cricket::MEDIA_TYPE_AUDIO;
159 dtmf_codec.payload_type = 126;
160 dtmf_codec.clock_rate.emplace(8000);
161 parameters.codecs.push_back(std::move(dtmf_codec));
162
163 // "codec_payload_type" isn't implemented, so we need to reorder codecs to
164 // cause one to be used.
165 // TODO(deadbeef): Remove this when it becomes unnecessary.
deadbeef8179a7c2017-06-27 07:52:50 -0700166 auto it = std::find_if(parameters.codecs.begin(), parameters.codecs.end(),
167 [preferred_payload_type](const RtpCodecParameters& p) {
168 return p.payload_type == preferred_payload_type;
169 });
170 RtpCodecParameters preferred = *it;
171 parameters.codecs.erase(it);
172 parameters.codecs.insert(parameters.codecs.begin(), preferred);
deadbeefe814a0d2017-02-25 18:15:09 -0800173
174 // Intentionally leave out SSRC so one's chosen automatically.
175 RtpEncodingParameters encoding;
176 encoding.codec_payload_type.emplace(preferred_payload_type);
177 encoding.dtx.emplace(DtxStatus::ENABLED);
178 // 20 kbps.
179 encoding.max_bitrate_bps.emplace(20000);
180 parameters.encodings.push_back(std::move(encoding));
181
182 parameters.header_extensions.emplace_back(
183 "urn:ietf:params:rtp-hdrext:ssrc-audio-level", 1);
184 return parameters;
185}
186
187RtpParameters MakeFullOpusParameters() {
188 return MakeFullAudioParameters(111);
189}
190
191RtpParameters MakeFullIsacParameters() {
192 return MakeFullAudioParameters(103);
193}
194
195// Make video parameters with all the available properties configured and
196// features used, and with multiple codecs offered. Obtained by taking a
197// snapshot of a default PeerConnection offer (and adding other things, like
198// bitrate limit).
199//
200// See "MakeFullVp8Parameters"/"MakeFullVp9Parameters" below.
201RtpParameters MakeFullVideoParameters(int preferred_payload_type) {
202 RtpParameters parameters;
203
204 RtpCodecParameters vp8_codec;
205 vp8_codec.name = "VP8";
206 vp8_codec.kind = cricket::MEDIA_TYPE_VIDEO;
207 vp8_codec.payload_type = 100;
208 vp8_codec.clock_rate.emplace(90000);
209 vp8_codec.rtcp_feedback.emplace_back(RtcpFeedbackType::CCM,
210 RtcpFeedbackMessageType::FIR);
211 vp8_codec.rtcp_feedback.emplace_back(RtcpFeedbackType::NACK,
212 RtcpFeedbackMessageType::GENERIC_NACK);
213 vp8_codec.rtcp_feedback.emplace_back(RtcpFeedbackType::NACK,
214 RtcpFeedbackMessageType::PLI);
215 vp8_codec.rtcp_feedback.emplace_back(RtcpFeedbackType::REMB);
216 vp8_codec.rtcp_feedback.emplace_back(RtcpFeedbackType::TRANSPORT_CC);
217 parameters.codecs.push_back(std::move(vp8_codec));
218
219 RtpCodecParameters vp8_rtx_codec;
220 vp8_rtx_codec.name = "rtx";
221 vp8_rtx_codec.kind = cricket::MEDIA_TYPE_VIDEO;
222 vp8_rtx_codec.payload_type = 96;
223 vp8_rtx_codec.clock_rate.emplace(90000);
224 vp8_rtx_codec.parameters["apt"] = "100";
225 parameters.codecs.push_back(std::move(vp8_rtx_codec));
226
227 RtpCodecParameters vp9_codec;
228 vp9_codec.name = "VP9";
229 vp9_codec.kind = cricket::MEDIA_TYPE_VIDEO;
230 vp9_codec.payload_type = 101;
231 vp9_codec.clock_rate.emplace(90000);
232 vp9_codec.rtcp_feedback.emplace_back(RtcpFeedbackType::CCM,
233 RtcpFeedbackMessageType::FIR);
234 vp9_codec.rtcp_feedback.emplace_back(RtcpFeedbackType::NACK,
235 RtcpFeedbackMessageType::GENERIC_NACK);
236 vp9_codec.rtcp_feedback.emplace_back(RtcpFeedbackType::NACK,
237 RtcpFeedbackMessageType::PLI);
238 vp9_codec.rtcp_feedback.emplace_back(RtcpFeedbackType::REMB);
239 vp9_codec.rtcp_feedback.emplace_back(RtcpFeedbackType::TRANSPORT_CC);
240 parameters.codecs.push_back(std::move(vp9_codec));
241
242 RtpCodecParameters vp9_rtx_codec;
243 vp9_rtx_codec.name = "rtx";
244 vp9_rtx_codec.kind = cricket::MEDIA_TYPE_VIDEO;
245 vp9_rtx_codec.payload_type = 97;
246 vp9_rtx_codec.clock_rate.emplace(90000);
247 vp9_rtx_codec.parameters["apt"] = "101";
248 parameters.codecs.push_back(std::move(vp9_rtx_codec));
249
250 RtpCodecParameters red_codec;
251 red_codec.name = "red";
252 red_codec.kind = cricket::MEDIA_TYPE_VIDEO;
253 red_codec.payload_type = 116;
254 red_codec.clock_rate.emplace(90000);
255 parameters.codecs.push_back(std::move(red_codec));
256
257 RtpCodecParameters red_rtx_codec;
258 red_rtx_codec.name = "rtx";
259 red_rtx_codec.kind = cricket::MEDIA_TYPE_VIDEO;
260 red_rtx_codec.payload_type = 98;
261 red_rtx_codec.clock_rate.emplace(90000);
262 red_rtx_codec.parameters["apt"] = "116";
263 parameters.codecs.push_back(std::move(red_rtx_codec));
264
265 RtpCodecParameters ulpfec_codec;
266 ulpfec_codec.name = "ulpfec";
267 ulpfec_codec.kind = cricket::MEDIA_TYPE_VIDEO;
268 ulpfec_codec.payload_type = 117;
269 ulpfec_codec.clock_rate.emplace(90000);
270 parameters.codecs.push_back(std::move(ulpfec_codec));
271
272 // "codec_payload_type" isn't implemented, so we need to reorder codecs to
273 // cause one to be used.
274 // TODO(deadbeef): Remove this when it becomes unnecessary.
deadbeef8179a7c2017-06-27 07:52:50 -0700275 auto it = std::find_if(parameters.codecs.begin(), parameters.codecs.end(),
276 [preferred_payload_type](const RtpCodecParameters& p) {
277 return p.payload_type == preferred_payload_type;
278 });
279 RtpCodecParameters preferred = *it;
280 parameters.codecs.erase(it);
281 parameters.codecs.insert(parameters.codecs.begin(), preferred);
deadbeefe814a0d2017-02-25 18:15:09 -0800282
283 // Intentionally leave out SSRC so one's chosen automatically.
284 RtpEncodingParameters encoding;
285 encoding.codec_payload_type.emplace(preferred_payload_type);
286 encoding.fec.emplace(FecMechanism::RED_AND_ULPFEC);
287 // Will create default RtxParameters, with unset SSRC.
288 encoding.rtx.emplace();
289 // 100 kbps.
290 encoding.max_bitrate_bps.emplace(100000);
291 parameters.encodings.push_back(std::move(encoding));
292
293 parameters.header_extensions.emplace_back(
294 "urn:ietf:params:rtp-hdrext:toffset", 2);
295 parameters.header_extensions.emplace_back(
296 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time", 3);
297 parameters.header_extensions.emplace_back("urn:3gpp:video-orientation", 4);
298 parameters.header_extensions.emplace_back(
299 "http://www.ietf.org/id/"
300 "draft-holmer-rmcat-transport-wide-cc-extensions-01",
301 5);
302 parameters.header_extensions.emplace_back(
303 "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay", 6);
304 return parameters;
305}
306
307RtpParameters MakeFullVp8Parameters() {
308 return MakeFullVideoParameters(100);
309}
310
311RtpParameters MakeFullVp9Parameters() {
312 return MakeFullVideoParameters(101);
313}
314
315} // namespace webrtc