blob: 266fd3dfd66155dd6f545bd542dd88f80c838cb8 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:361/*
kjellanderb24317b2016-02-10 15:54:432 * Copyright 2011 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:363 *
kjellanderb24317b2016-02-10 15:54:434 * 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.
henrike@webrtc.org28e20752013-07-10 00:45:369 */
10
Yves Gerey3e707812018-11-28 15:47:4911#include <stdio.h>
12#include <string.h>
Jonas Olssona4d87372019-07-05 17:08:3313
Harald Alvestrand4d7160e2019-04-12 05:01:2914#include <algorithm>
Yves Gerey3e707812018-11-28 15:47:4915#include <cstdint>
16#include <map>
kwibergd1fe2812016-04-27 13:47:2917#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:3618#include <string>
Yves Gerey3e707812018-11-28 15:47:4919#include <utility>
henrike@webrtc.org28e20752013-07-10 00:45:3620#include <vector>
21
Steve Anton64b626b2019-01-29 01:25:2622#include "absl/algorithm/container.h"
Piotr (Peter) Slatalab1ae10b2019-03-01 19:14:0523#include "absl/memory/memory.h"
Steve Anton1c9c9fc2019-02-14 23:13:0924#include "absl/strings/str_replace.h"
Yves Gerey3e707812018-11-28 15:47:4925#include "api/array_view.h"
Steve Anton10542f22019-01-11 17:11:0026#include "api/crypto_params.h"
27#include "api/jsep_session_description.h"
28#include "api/media_types.h"
29#include "api/rtp_parameters.h"
30#include "api/rtp_transceiver_interface.h"
Yves Gerey3e707812018-11-28 15:47:4931#include "media/base/codec.h"
Steve Anton10542f22019-01-11 17:11:0032#include "media/base/media_constants.h"
33#include "media/base/stream_params.h"
34#include "p2p/base/p2p_constants.h"
Yves Gerey665174f2018-06-19 13:03:0535#include "p2p/base/port.h"
Steve Anton10542f22019-01-11 17:11:0036#include "p2p/base/transport_description.h"
37#include "p2p/base/transport_info.h"
38#include "pc/media_session.h"
39#include "pc/session_description.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3140#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 17:11:0041#include "rtc_base/message_digest.h"
42#include "rtc_base/socket_address.h"
43#include "rtc_base/ssl_fingerprint.h"
44#include "rtc_base/string_encode.h"
Steve Anton06817cd2018-12-18 23:55:3045#include "test/gmock.h"
Yves Gerey3e707812018-11-28 15:47:4946#include "test/gtest.h"
Patrik Höglund563934e2017-09-15 07:04:2847
ossu7bb87ee2017-01-23 12:56:2548#ifdef WEBRTC_ANDROID
Steve Anton10542f22019-01-11 17:11:0049#include "pc/test/android_test_initializer.h"
ossu7bb87ee2017-01-23 12:56:2550#endif
Steve Anton10542f22019-01-11 17:11:0051#include "pc/webrtc_sdp.h"
henrike@webrtc.org28e20752013-07-10 00:45:3652
53using cricket::AudioCodec;
54using cricket::AudioContentDescription;
55using cricket::Candidate;
Steve Anton06817cd2018-12-18 23:55:3056using cricket::ContentGroup;
henrike@webrtc.org28e20752013-07-10 00:45:3657using cricket::ContentInfo;
58using cricket::CryptoParams;
henrike@webrtc.org28e20752013-07-10 00:45:3659using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
60using cricket::ICE_CANDIDATE_COMPONENT_RTP;
61using cricket::kFecSsrcGroupSemantics;
62using cricket::LOCAL_PORT_TYPE;
Steve Anton5adfafd2017-12-21 00:34:0063using cricket::MediaProtocolType;
Steve Anton06817cd2018-12-18 23:55:3064using cricket::RELAY_PORT_TYPE;
Amit Hilbuchc57d5732018-12-11 23:30:1165using cricket::RidDescription;
66using cricket::RidDirection;
Harald Alvestrand5fc28b12019-05-13 11:36:1667using cricket::SctpDataContentDescription;
Steve Anton06817cd2018-12-18 23:55:3068using cricket::SessionDescription;
Amit Hilbucha2012042018-12-03 19:35:0569using cricket::SimulcastDescription;
70using cricket::SimulcastLayer;
henrike@webrtc.org28e20752013-07-10 00:45:3671using cricket::StreamParams;
72using cricket::STUN_PORT_TYPE;
73using cricket::TransportDescription;
74using cricket::TransportInfo;
75using cricket::VideoCodec;
76using cricket::VideoContentDescription;
Steve Anton06817cd2018-12-18 23:55:3077using ::testing::ElementsAre;
78using ::testing::Field;
henrike@webrtc.org28e20752013-07-10 00:45:3679using webrtc::IceCandidateCollection;
80using webrtc::IceCandidateInterface;
81using webrtc::JsepIceCandidate;
82using webrtc::JsepSessionDescription;
isheriff6f8d6862016-05-26 18:24:5583using webrtc::RtpExtension;
Steve Anton4e70a722017-11-28 22:57:1084using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:3685using webrtc::SdpParseError;
Steve Antona3a92c22017-12-07 18:27:4186using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:3687using webrtc::SessionDescriptionInterface;
88
89typedef std::vector<AudioCodec> AudioCodecs;
90typedef std::vector<Candidate> Candidates;
91
Peter Boström0c4e06b2015-10-07 10:23:2192static const uint32_t kDefaultSctpPort = 5000;
zstein4b2e0822017-02-18 03:48:3893static const uint16_t kUnusualSctpPort = 9556;
henrike@webrtc.org28e20752013-07-10 00:45:3694static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 10:23:2195static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 23:17:1496static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:3697static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 23:17:1498static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:3699static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 10:23:21100static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36101static const char kCandidateFoundation1[] = "a0+B/1";
102static const char kCandidateFoundation2[] = "a0+B/2";
103static const char kCandidateFoundation3[] = "a0+B/3";
104static const char kCandidateFoundation4[] = "a0+B/4";
105static const char kAttributeCryptoVoice[] =
106 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
107 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
108 "dummy_session_params\r\n";
109static const char kAttributeCryptoVideo[] =
110 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
111 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
Yves Gerey665174f2018-06-19 13:03:05112static const char kFingerprint[] =
113 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36114 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n";
Johannes Kron0854eb62018-10-10 20:33:20115static const char kExtmapAllowMixed[] = "a=extmap-allow-mixed\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36116static const int kExtmapId = 1;
117static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
118static const char kExtmap[] =
119 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
120static const char kExtmapWithDirectionAndAttribute[] =
121 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
jbauch5869f502017-06-29 19:31:36122static const char kExtmapWithDirectionAndAttributeEncrypted[] =
123 "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt "
124 "http://example.com/082005/ext.htm#ttime a1 a2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36125
Peter Boström0c4e06b2015-10-07 10:23:21126static const uint8_t kIdentityDigest[] = {
127 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
128 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36129
lally@webrtc.org34807282015-02-24 20:19:39130static const char kDtlsSctp[] = "DTLS/SCTP";
131static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
132static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35133
henrike@webrtc.org28e20752013-07-10 00:45:36134struct CodecParams {
135 int max_ptime;
136 int ptime;
137 int min_ptime;
138 int sprop_stereo;
139 int stereo;
140 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59141 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36142};
143
deadbeef9d3584c2016-02-17 01:54:10144// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
145// instead of "a=crypto", and have an explicit test for adding "a=crypto".
146// Currently it's the other way around.
147
henrike@webrtc.org28e20752013-07-10 00:45:36148// Reference sdp string
149static const char kSdpFullString[] =
150 "v=0\r\n"
151 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
152 "s=-\r\n"
153 "t=0 0\r\n"
Emil Lundmark801c9992021-01-19 12:06:32154 "a=extmap-allow-mixed\r\n"
deadbeef9d3584c2016-02-17 01:54:10155 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36156 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
157 "c=IN IP4 74.125.127.126\r\n"
158 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
159 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
160 "generation 2\r\n"
161 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
162 "generation 2\r\n"
163 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
164 "generation 2\r\n"
165 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
166 "generation 2\r\n"
167 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
168 "raddr 192.168.1.5 rport 2346 "
169 "generation 2\r\n"
170 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
171 "raddr 192.168.1.5 rport 2348 "
172 "generation 2\r\n"
173 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
174 "a=mid:audio_content_name\r\n"
175 "a=sendrecv\r\n"
176 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 20:37:51177 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36178 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
179 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
180 "dummy_session_params\r\n"
181 "a=rtpmap:111 opus/48000/2\r\n"
182 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41183 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36184 "a=ssrc:1 cname:stream_1_cname\r\n"
185 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04186 "a=ssrc:1 mslabel:local_stream_1\r\n"
187 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36188 "m=video 3457 RTP/SAVPF 120\r\n"
189 "c=IN IP4 74.125.224.39\r\n"
190 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
191 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
192 "generation 2\r\n"
193 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
194 "generation 2\r\n"
195 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
196 "generation 2\r\n"
197 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
198 "generation 2\r\n"
199 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
200 "generation 2\r\n"
201 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
202 "generation 2\r\n"
203 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
204 "a=mid:video_content_name\r\n"
205 "a=sendrecv\r\n"
206 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
207 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
208 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-17 01:54:10209 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36210 "a=ssrc:2 cname:stream_1_cname\r\n"
211 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04212 "a=ssrc:2 mslabel:local_stream_1\r\n"
213 "a=ssrc:2 label:video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36214 "a=ssrc:3 cname:stream_1_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04215 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
216 "a=ssrc:3 mslabel:local_stream_1\r\n"
217 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36218
219// SDP reference string without the candidates.
220static const char kSdpString[] =
221 "v=0\r\n"
222 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
223 "s=-\r\n"
224 "t=0 0\r\n"
Emil Lundmark801c9992021-01-19 12:06:32225 "a=extmap-allow-mixed\r\n"
deadbeef9d3584c2016-02-17 01:54:10226 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22227 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06228 "c=IN IP4 0.0.0.0\r\n"
229 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36230 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
231 "a=mid:audio_content_name\r\n"
232 "a=sendrecv\r\n"
233 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 20:37:51234 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36235 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
236 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
237 "dummy_session_params\r\n"
238 "a=rtpmap:111 opus/48000/2\r\n"
239 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41240 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36241 "a=ssrc:1 cname:stream_1_cname\r\n"
242 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04243 "a=ssrc:1 mslabel:local_stream_1\r\n"
244 "a=ssrc:1 label:audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22245 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06246 "c=IN IP4 0.0.0.0\r\n"
247 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36248 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
249 "a=mid:video_content_name\r\n"
250 "a=sendrecv\r\n"
251 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
252 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
253 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-17 01:54:10254 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36255 "a=ssrc:2 cname:stream_1_cname\r\n"
256 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04257 "a=ssrc:2 mslabel:local_stream_1\r\n"
258 "a=ssrc:2 label:video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36259 "a=ssrc:3 cname:stream_1_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04260 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
261 "a=ssrc:3 mslabel:local_stream_1\r\n"
262 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36263
Harald Alvestrand5fc28b12019-05-13 11:36:16264// draft-ietf-mmusic-sctp-sdp-03
henrike@webrtc.org28e20752013-07-10 00:45:36265static const char kSdpSctpDataChannelString[] =
Guido Urdanetacecf87f2019-05-31 10:17:38266 "m=application 9 UDP/DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06267 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36268 "a=ice-ufrag:ufrag_data\r\n"
269 "a=ice-pwd:pwd_data\r\n"
270 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33271 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36272
lally@webrtc.orgec97c652015-02-24 20:18:48273// draft-ietf-mmusic-sctp-sdp-12
Harald Alvestrand48cce4d2019-04-11 08:41:24274// Note - this is invalid per draft-ietf-mmusic-sctp-sdp-26,
275// since the separator after "sctp-port" needs to be a colon.
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56276static const char kSdpSctpDataChannelStringWithSctpPort[] =
Guido Urdanetacecf87f2019-05-31 10:17:38277 "m=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\n"
lally@webrtc.orgc7848b72015-02-24 20:19:26278 "a=sctp-port 5000\r\n"
279 "c=IN IP4 0.0.0.0\r\n"
280 "a=ice-ufrag:ufrag_data\r\n"
281 "a=ice-pwd:pwd_data\r\n"
282 "a=mid:data_content_name\r\n";
283
Harald Alvestrand48cce4d2019-04-11 08:41:24284// draft-ietf-mmusic-sctp-sdp-26
lally69f57602015-10-08 17:15:04285static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
Guido Urdanetacecf87f2019-05-31 10:17:38286 "m=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\n"
lally69f57602015-10-08 17:15:04287 "a=sctp-port:5000\r\n"
288 "c=IN IP4 0.0.0.0\r\n"
289 "a=ice-ufrag:ufrag_data\r\n"
290 "a=ice-pwd:pwd_data\r\n"
291 "a=mid:data_content_name\r\n";
292
henrike@webrtc.org28e20752013-07-10 00:45:36293static const char kSdpSctpDataChannelWithCandidatesString[] =
Guido Urdanetacecf87f2019-05-31 10:17:38294 "m=application 2345 UDP/DTLS/SCTP 5000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36295 "c=IN IP4 74.125.127.126\r\n"
296 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
297 "generation 2\r\n"
298 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
299 "generation 2\r\n"
300 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
301 "raddr 192.168.1.5 rport 2346 "
302 "generation 2\r\n"
303 "a=ice-ufrag:ufrag_data\r\n"
304 "a=ice-pwd:pwd_data\r\n"
305 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33306 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36307
jiayl@webrtc.org9c16c392014-05-01 18:30:30308static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04309 "v=0\r\n"
310 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
311 "s=-\r\n"
312 "t=0 0\r\n"
313 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22314 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06315 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04316 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22317 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06318 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04319 "a=x-google-flag:conference\r\n";
320
jiayl@webrtc.orge7d47a12014-08-05 19:19:05321static const char kSdpSessionString[] =
322 "v=0\r\n"
323 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
324 "s=-\r\n"
325 "t=0 0\r\n"
326 "a=msid-semantic: WMS local_stream\r\n";
327
328static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22329 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06330 "c=IN IP4 0.0.0.0\r\n"
331 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05332 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
333 "a=mid:audio_content_name\r\n"
334 "a=sendrecv\r\n"
335 "a=rtpmap:111 opus/48000/2\r\n"
336 "a=ssrc:1 cname:stream_1_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04337 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
338 "a=ssrc:1 mslabel:local_stream\r\n"
339 "a=ssrc:1 label:audio_track_id_1\r\n";
jiayl@webrtc.orge7d47a12014-08-05 19:19:05340
341static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22342 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06343 "c=IN IP4 0.0.0.0\r\n"
344 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05345 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
346 "a=mid:video_content_name\r\n"
347 "a=sendrecv\r\n"
348 "a=rtpmap:120 VP8/90000\r\n"
349 "a=ssrc:2 cname:stream_1_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04350 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
351 "a=ssrc:2 mslabel:local_stream\r\n"
352 "a=ssrc:2 label:video_track_id_1\r\n";
jiayl@webrtc.orge7d47a12014-08-05 19:19:05353
deadbeef25ed4352016-12-13 02:37:36354// Reference sdp string using bundle-only.
355static const char kBundleOnlySdpFullString[] =
356 "v=0\r\n"
357 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
358 "s=-\r\n"
359 "t=0 0\r\n"
Emil Lundmark801c9992021-01-19 12:06:32360 "a=extmap-allow-mixed\r\n"
deadbeef25ed4352016-12-13 02:37:36361 "a=group:BUNDLE audio_content_name video_content_name\r\n"
362 "a=msid-semantic: WMS local_stream_1\r\n"
363 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
364 "c=IN IP4 74.125.127.126\r\n"
365 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
366 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
367 "generation 2\r\n"
368 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
369 "generation 2\r\n"
370 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
371 "generation 2\r\n"
372 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
373 "generation 2\r\n"
374 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
375 "raddr 192.168.1.5 rport 2346 "
376 "generation 2\r\n"
377 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
378 "raddr 192.168.1.5 rport 2348 "
379 "generation 2\r\n"
380 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
381 "a=mid:audio_content_name\r\n"
382 "a=sendrecv\r\n"
383 "a=rtcp-mux\r\n"
384 "a=rtcp-rsize\r\n"
385 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
386 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
387 "dummy_session_params\r\n"
388 "a=rtpmap:111 opus/48000/2\r\n"
389 "a=rtpmap:103 ISAC/16000\r\n"
390 "a=rtpmap:104 ISAC/32000\r\n"
391 "a=ssrc:1 cname:stream_1_cname\r\n"
392 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04393 "a=ssrc:1 mslabel:local_stream_1\r\n"
394 "a=ssrc:1 label:audio_track_id_1\r\n"
deadbeef25ed4352016-12-13 02:37:36395 "m=video 0 RTP/SAVPF 120\r\n"
396 "c=IN IP4 0.0.0.0\r\n"
397 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
398 "a=bundle-only\r\n"
399 "a=mid:video_content_name\r\n"
400 "a=sendrecv\r\n"
401 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
402 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
403 "a=rtpmap:120 VP8/90000\r\n"
404 "a=ssrc-group:FEC 2 3\r\n"
405 "a=ssrc:2 cname:stream_1_cname\r\n"
406 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04407 "a=ssrc:2 mslabel:local_stream_1\r\n"
408 "a=ssrc:2 label:video_track_id_1\r\n"
deadbeef25ed4352016-12-13 02:37:36409 "a=ssrc:3 cname:stream_1_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04410 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
411 "a=ssrc:3 mslabel:local_stream_1\r\n"
412 "a=ssrc:3 label:video_track_id_1\r\n";
deadbeef25ed4352016-12-13 02:37:36413
deadbeef9d3584c2016-02-17 01:54:10414// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
415// tracks.
416static const char kPlanBSdpFullString[] =
417 "v=0\r\n"
418 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
419 "s=-\r\n"
420 "t=0 0\r\n"
Emil Lundmark801c9992021-01-19 12:06:32421 "a=extmap-allow-mixed\r\n"
deadbeef9d3584c2016-02-17 01:54:10422 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
423 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
424 "c=IN IP4 74.125.127.126\r\n"
425 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
426 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
427 "generation 2\r\n"
428 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
429 "generation 2\r\n"
430 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
431 "generation 2\r\n"
432 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
433 "generation 2\r\n"
434 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
435 "raddr 192.168.1.5 rport 2346 "
436 "generation 2\r\n"
437 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
438 "raddr 192.168.1.5 rport 2348 "
439 "generation 2\r\n"
440 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
441 "a=mid:audio_content_name\r\n"
442 "a=sendrecv\r\n"
443 "a=rtcp-mux\r\n"
444 "a=rtcp-rsize\r\n"
445 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
446 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
447 "dummy_session_params\r\n"
448 "a=rtpmap:111 opus/48000/2\r\n"
449 "a=rtpmap:103 ISAC/16000\r\n"
450 "a=rtpmap:104 ISAC/32000\r\n"
451 "a=ssrc:1 cname:stream_1_cname\r\n"
452 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04453 "a=ssrc:1 mslabel:local_stream_1\r\n"
454 "a=ssrc:1 label:audio_track_id_1\r\n"
deadbeef9d3584c2016-02-17 01:54:10455 "a=ssrc:4 cname:stream_2_cname\r\n"
456 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
Artem Titovf0a34f22020-03-16 17:52:04457 "a=ssrc:4 mslabel:local_stream_2\r\n"
458 "a=ssrc:4 label:audio_track_id_2\r\n"
deadbeef9d3584c2016-02-17 01:54:10459 "m=video 3457 RTP/SAVPF 120\r\n"
460 "c=IN IP4 74.125.224.39\r\n"
461 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
462 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
463 "generation 2\r\n"
464 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
465 "generation 2\r\n"
466 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
467 "generation 2\r\n"
468 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
469 "generation 2\r\n"
470 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
471 "generation 2\r\n"
472 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
473 "generation 2\r\n"
474 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
475 "a=mid:video_content_name\r\n"
476 "a=sendrecv\r\n"
477 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
478 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
479 "a=rtpmap:120 VP8/90000\r\n"
480 "a=ssrc-group:FEC 2 3\r\n"
481 "a=ssrc:2 cname:stream_1_cname\r\n"
482 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04483 "a=ssrc:2 mslabel:local_stream_1\r\n"
484 "a=ssrc:2 label:video_track_id_1\r\n"
deadbeef9d3584c2016-02-17 01:54:10485 "a=ssrc:3 cname:stream_1_cname\r\n"
486 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04487 "a=ssrc:3 mslabel:local_stream_1\r\n"
488 "a=ssrc:3 label:video_track_id_1\r\n"
deadbeef9d3584c2016-02-17 01:54:10489 "a=ssrc:5 cname:stream_2_cname\r\n"
490 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
Artem Titovf0a34f22020-03-16 17:52:04491 "a=ssrc:5 mslabel:local_stream_2\r\n"
492 "a=ssrc:5 label:video_track_id_2\r\n"
deadbeef9d3584c2016-02-17 01:54:10493 "a=ssrc:6 cname:stream_2_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04494 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
495 "a=ssrc:6 mslabel:local_stream_2\r\n"
496 "a=ssrc:6 label:video_track_id_3\r\n";
deadbeef9d3584c2016-02-17 01:54:10497
498// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
499// tracks.
500static const char kUnifiedPlanSdpFullString[] =
501 "v=0\r\n"
502 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
503 "s=-\r\n"
504 "t=0 0\r\n"
Emil Lundmark801c9992021-01-19 12:06:32505 "a=extmap-allow-mixed\r\n"
deadbeef9d3584c2016-02-17 01:54:10506 "a=msid-semantic: WMS local_stream_1\r\n"
507 // Audio track 1, stream 1 (with candidates).
508 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
509 "c=IN IP4 74.125.127.126\r\n"
510 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
511 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
512 "generation 2\r\n"
513 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
514 "generation 2\r\n"
515 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
516 "generation 2\r\n"
517 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
518 "generation 2\r\n"
519 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
520 "raddr 192.168.1.5 rport 2346 "
521 "generation 2\r\n"
522 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
523 "raddr 192.168.1.5 rport 2348 "
524 "generation 2\r\n"
525 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
526 "a=mid:audio_content_name\r\n"
527 "a=msid:local_stream_1 audio_track_id_1\r\n"
528 "a=sendrecv\r\n"
529 "a=rtcp-mux\r\n"
530 "a=rtcp-rsize\r\n"
531 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
532 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
533 "dummy_session_params\r\n"
534 "a=rtpmap:111 opus/48000/2\r\n"
535 "a=rtpmap:103 ISAC/16000\r\n"
536 "a=rtpmap:104 ISAC/32000\r\n"
537 "a=ssrc:1 cname:stream_1_cname\r\n"
538 // Video track 1, stream 1 (with candidates).
539 "m=video 3457 RTP/SAVPF 120\r\n"
540 "c=IN IP4 74.125.224.39\r\n"
541 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
542 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
543 "generation 2\r\n"
544 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
545 "generation 2\r\n"
546 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
547 "generation 2\r\n"
548 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
549 "generation 2\r\n"
550 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
551 "generation 2\r\n"
552 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
553 "generation 2\r\n"
554 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
555 "a=mid:video_content_name\r\n"
556 "a=msid:local_stream_1 video_track_id_1\r\n"
557 "a=sendrecv\r\n"
558 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
559 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
560 "a=rtpmap:120 VP8/90000\r\n"
561 "a=ssrc-group:FEC 2 3\r\n"
562 "a=ssrc:2 cname:stream_1_cname\r\n"
563 "a=ssrc:3 cname:stream_1_cname\r\n"
564 // Audio track 2, stream 2.
565 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
566 "c=IN IP4 0.0.0.0\r\n"
567 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
568 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
569 "a=mid:audio_content_name_2\r\n"
570 "a=msid:local_stream_2 audio_track_id_2\r\n"
571 "a=sendrecv\r\n"
572 "a=rtcp-mux\r\n"
573 "a=rtcp-rsize\r\n"
574 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
575 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
576 "dummy_session_params\r\n"
577 "a=rtpmap:111 opus/48000/2\r\n"
578 "a=rtpmap:103 ISAC/16000\r\n"
579 "a=rtpmap:104 ISAC/32000\r\n"
580 "a=ssrc:4 cname:stream_2_cname\r\n"
581 // Video track 2, stream 2.
582 "m=video 9 RTP/SAVPF 120\r\n"
583 "c=IN IP4 0.0.0.0\r\n"
584 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
585 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
586 "a=mid:video_content_name_2\r\n"
587 "a=msid:local_stream_2 video_track_id_2\r\n"
588 "a=sendrecv\r\n"
589 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
590 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
591 "a=rtpmap:120 VP8/90000\r\n"
592 "a=ssrc:5 cname:stream_2_cname\r\n"
593 // Video track 3, stream 2.
594 "m=video 9 RTP/SAVPF 120\r\n"
595 "c=IN IP4 0.0.0.0\r\n"
596 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
597 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
598 "a=mid:video_content_name_3\r\n"
599 "a=msid:local_stream_2 video_track_id_3\r\n"
600 "a=sendrecv\r\n"
601 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
602 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
603 "a=rtpmap:120 VP8/90000\r\n"
604 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36605
Seth Hampson5b4f0752018-04-02 23:31:36606// Unified Plan SDP reference string:
607// - audio track 1 has 1 a=msid lines
608// - audio track 2 has 2 a=msid lines
609// - audio track 3 has 1 a=msid line with the special "-" marker signifying that
610// there are 0 media stream ids.
611// This Unified Plan SDP represents a SDP that signals the msid using both
612// a=msid and a=ssrc msid semantics.
613static const char kUnifiedPlanSdpFullStringWithSpecialMsid[] =
614 "v=0\r\n"
615 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
616 "s=-\r\n"
617 "t=0 0\r\n"
Emil Lundmark801c9992021-01-19 12:06:32618 "a=extmap-allow-mixed\r\n"
Seth Hampson5b4f0752018-04-02 23:31:36619 "a=msid-semantic: WMS local_stream_1\r\n"
620 // Audio track 1, with 1 stream id.
621 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
622 "c=IN IP4 74.125.127.126\r\n"
623 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
624 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
625 "generation 2\r\n"
626 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
627 "generation 2\r\n"
628 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
629 "generation 2\r\n"
630 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
631 "generation 2\r\n"
632 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
633 "raddr 192.168.1.5 rport 2346 "
634 "generation 2\r\n"
635 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
636 "raddr 192.168.1.5 rport 2348 "
637 "generation 2\r\n"
638 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
639 "a=mid:audio_content_name\r\n"
Seth Hampson5b4f0752018-04-02 23:31:36640 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 17:25:28641 "a=msid:local_stream_1 audio_track_id_1\r\n"
Seth Hampson5b4f0752018-04-02 23:31:36642 "a=rtcp-mux\r\n"
643 "a=rtcp-rsize\r\n"
644 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
645 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
646 "dummy_session_params\r\n"
647 "a=rtpmap:111 opus/48000/2\r\n"
648 "a=rtpmap:103 ISAC/16000\r\n"
649 "a=rtpmap:104 ISAC/32000\r\n"
650 "a=ssrc:1 cname:stream_1_cname\r\n"
651 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04652 "a=ssrc:1 mslabel:local_stream_1\r\n"
653 "a=ssrc:1 label:audio_track_id_1\r\n"
Seth Hampson5b4f0752018-04-02 23:31:36654 // Audio track 2, with two stream ids.
655 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
656 "c=IN IP4 0.0.0.0\r\n"
657 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
658 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
659 "a=mid:audio_content_name_2\r\n"
Seth Hampson7fa6ee62018-10-17 17:25:28660 "a=sendrecv\r\n"
Seth Hampson5b4f0752018-04-02 23:31:36661 "a=msid:local_stream_1 audio_track_id_2\r\n"
662 "a=msid:local_stream_2 audio_track_id_2\r\n"
Seth Hampson5b4f0752018-04-02 23:31:36663 "a=rtcp-mux\r\n"
664 "a=rtcp-rsize\r\n"
665 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
666 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
667 "dummy_session_params\r\n"
668 "a=rtpmap:111 opus/48000/2\r\n"
669 "a=rtpmap:103 ISAC/16000\r\n"
670 "a=rtpmap:104 ISAC/32000\r\n"
671 "a=ssrc:4 cname:stream_1_cname\r\n"
672 // The support for Plan B msid signaling only includes the
673 // first media stream id "local_stream_1."
674 "a=ssrc:4 msid:local_stream_1 audio_track_id_2\r\n"
Artem Titovf0a34f22020-03-16 17:52:04675 "a=ssrc:4 mslabel:local_stream_1\r\n"
676 "a=ssrc:4 label:audio_track_id_2\r\n"
Seth Hampson5b4f0752018-04-02 23:31:36677 // Audio track 3, with no stream ids.
678 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
679 "c=IN IP4 0.0.0.0\r\n"
680 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
681 "a=ice-ufrag:ufrag_voice_3\r\na=ice-pwd:pwd_voice_3\r\n"
682 "a=mid:audio_content_name_3\r\n"
Seth Hampson5b4f0752018-04-02 23:31:36683 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 17:25:28684 "a=msid:- audio_track_id_3\r\n"
Seth Hampson5b4f0752018-04-02 23:31:36685 "a=rtcp-mux\r\n"
686 "a=rtcp-rsize\r\n"
687 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
688 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
689 "dummy_session_params\r\n"
690 "a=rtpmap:111 opus/48000/2\r\n"
691 "a=rtpmap:103 ISAC/16000\r\n"
692 "a=rtpmap:104 ISAC/32000\r\n"
Seth Hampson7fa6ee62018-10-17 17:25:28693 "a=ssrc:7 cname:stream_2_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04694 "a=ssrc:7 msid:- audio_track_id_3\r\n"
695 "a=ssrc:7 mslabel:-\r\n"
696 "a=ssrc:7 label:audio_track_id_3\r\n";
Seth Hampson5b4f0752018-04-02 23:31:36697
Amit Hilbuchc57d5732018-12-11 23:30:11698// SDP string for unified plan without SSRCs
699static const char kUnifiedPlanSdpFullStringNoSsrc[] =
700 "v=0\r\n"
701 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
702 "s=-\r\n"
703 "t=0 0\r\n"
704 "a=msid-semantic: WMS local_stream_1\r\n"
705 // Audio track 1, stream 1 (with candidates).
706 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
707 "c=IN IP4 74.125.127.126\r\n"
708 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
709 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
710 "generation 2\r\n"
711 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
712 "generation 2\r\n"
713 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
714 "generation 2\r\n"
715 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
716 "generation 2\r\n"
717 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
718 "raddr 192.168.1.5 rport 2346 "
719 "generation 2\r\n"
720 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
721 "raddr 192.168.1.5 rport 2348 "
722 "generation 2\r\n"
723 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
724 "a=mid:audio_content_name\r\n"
725 "a=msid:local_stream_1 audio_track_id_1\r\n"
726 "a=sendrecv\r\n"
727 "a=rtcp-mux\r\n"
728 "a=rtcp-rsize\r\n"
729 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
730 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
731 "dummy_session_params\r\n"
732 "a=rtpmap:111 opus/48000/2\r\n"
733 "a=rtpmap:103 ISAC/16000\r\n"
734 "a=rtpmap:104 ISAC/32000\r\n"
735 // Video track 1, stream 1 (with candidates).
736 "m=video 3457 RTP/SAVPF 120\r\n"
737 "c=IN IP4 74.125.224.39\r\n"
738 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
739 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
740 "generation 2\r\n"
741 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
742 "generation 2\r\n"
743 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
744 "generation 2\r\n"
745 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
746 "generation 2\r\n"
747 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
748 "generation 2\r\n"
749 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
750 "generation 2\r\n"
751 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
752 "a=mid:video_content_name\r\n"
753 "a=msid:local_stream_1 video_track_id_1\r\n"
754 "a=sendrecv\r\n"
755 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
756 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
757 "a=rtpmap:120 VP8/90000\r\n"
758 // Audio track 2, stream 2.
759 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
760 "c=IN IP4 0.0.0.0\r\n"
761 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
762 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
763 "a=mid:audio_content_name_2\r\n"
764 "a=msid:local_stream_2 audio_track_id_2\r\n"
765 "a=sendrecv\r\n"
766 "a=rtcp-mux\r\n"
767 "a=rtcp-rsize\r\n"
768 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
769 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
770 "dummy_session_params\r\n"
771 "a=rtpmap:111 opus/48000/2\r\n"
772 "a=rtpmap:103 ISAC/16000\r\n"
773 "a=rtpmap:104 ISAC/32000\r\n"
774 // Video track 2, stream 2.
775 "m=video 9 RTP/SAVPF 120\r\n"
776 "c=IN IP4 0.0.0.0\r\n"
777 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
778 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
779 "a=mid:video_content_name_2\r\n"
780 "a=msid:local_stream_2 video_track_id_2\r\n"
781 "a=sendrecv\r\n"
782 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
783 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
784 "a=rtpmap:120 VP8/90000\r\n"
785 // Video track 3, stream 2.
786 "m=video 9 RTP/SAVPF 120\r\n"
787 "c=IN IP4 0.0.0.0\r\n"
788 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
789 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
790 "a=mid:video_content_name_3\r\n"
791 "a=msid:local_stream_2 video_track_id_3\r\n"
792 "a=sendrecv\r\n"
793 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
794 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
795 "a=rtpmap:120 VP8/90000\r\n";
796
henrike@webrtc.org28e20752013-07-10 00:45:36797// One candidate reference string as per W3c spec.
798// candidate:<blah> not a=candidate:<blah>CRLF
799static const char kRawCandidate[] =
800 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
801// One candidate reference string.
802static const char kSdpOneCandidate[] =
803 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
804 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15805
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20806static const char kSdpTcpActiveCandidate[] =
807 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
808 "tcptype active generation 2";
809static const char kSdpTcpPassiveCandidate[] =
810 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
811 "tcptype passive generation 2";
812static const char kSdpTcpSOCandidate[] =
813 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
814 "tcptype so generation 2";
815static const char kSdpTcpInvalidCandidate[] =
816 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
817 "tcptype invalid generation 2";
818
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15819// One candidate reference string with IPV6 address.
820static const char kRawIPV6Candidate[] =
821 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 19:04:36822 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36823
824// One candidate reference string.
honghaiza54a0802015-12-17 02:37:23825static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36826 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-17 02:37:23827 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36828
Zach Steinb336c272018-08-09 08:16:13829static const char kRawHostnameCandidate[] =
830 "candidate:a0+B/1 1 udp 2130706432 a.test 1234 typ host generation 2";
831
henrike@webrtc.org28e20752013-07-10 00:45:36832// Session id and version
833static const char kSessionId[] = "18446744069414584320";
834static const char kSessionVersion[] = "18446462598732840960";
835
deadbeef9d3584c2016-02-17 01:54:10836// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36837static const char kIceOption1[] = "iceoption1";
838static const char kIceOption2[] = "iceoption2";
839static const char kIceOption3[] = "iceoption3";
840
deadbeef9d3584c2016-02-17 01:54:10841// ICE ufrags/passwords.
842static const char kUfragVoice[] = "ufrag_voice";
843static const char kPwdVoice[] = "pwd_voice";
844static const char kUfragVideo[] = "ufrag_video";
845static const char kPwdVideo[] = "pwd_video";
846static const char kUfragData[] = "ufrag_data";
847static const char kPwdData[] = "pwd_data";
848
849// Extra ufrags/passwords for extra unified plan m= sections.
850static const char kUfragVoice2[] = "ufrag_voice_2";
851static const char kPwdVoice2[] = "pwd_voice_2";
Seth Hampson5b4f0752018-04-02 23:31:36852static const char kUfragVoice3[] = "ufrag_voice_3";
853static const char kPwdVoice3[] = "pwd_voice_3";
deadbeef9d3584c2016-02-17 01:54:10854static const char kUfragVideo2[] = "ufrag_video_2";
855static const char kPwdVideo2[] = "pwd_video_2";
856static const char kUfragVideo3[] = "ufrag_video_3";
857static const char kPwdVideo3[] = "pwd_video_3";
858
henrike@webrtc.org28e20752013-07-10 00:45:36859// Content name
860static const char kAudioContentName[] = "audio_content_name";
861static const char kVideoContentName[] = "video_content_name";
862static const char kDataContentName[] = "data_content_name";
863
deadbeef9d3584c2016-02-17 01:54:10864// Extra content names for extra unified plan m= sections.
865static const char kAudioContentName2[] = "audio_content_name_2";
Seth Hampson5b4f0752018-04-02 23:31:36866static const char kAudioContentName3[] = "audio_content_name_3";
deadbeef9d3584c2016-02-17 01:54:10867static const char kVideoContentName2[] = "video_content_name_2";
868static const char kVideoContentName3[] = "video_content_name_3";
869
henrike@webrtc.org28e20752013-07-10 00:45:36870// MediaStream 1
Seth Hampson845e8782018-03-02 19:34:10871static const char kStreamId1[] = "local_stream_1";
henrike@webrtc.org28e20752013-07-10 00:45:36872static const char kStream1Cname[] = "stream_1_cname";
873static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 10:23:21874static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36875static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-17 01:54:10876static const uint32_t kVideoTrack1Ssrc1 = 2;
877static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36878
879// MediaStream 2
Seth Hampson845e8782018-03-02 19:34:10880static const char kStreamId2[] = "local_stream_2";
henrike@webrtc.org28e20752013-07-10 00:45:36881static const char kStream2Cname[] = "stream_2_cname";
882static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 10:23:21883static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-17 01:54:10884static const char kVideoTrackId2[] = "video_track_id_2";
885static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36886static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-17 01:54:10887static const uint32_t kVideoTrack3Ssrc = 6;
Seth Hampson5b4f0752018-04-02 23:31:36888static const char kAudioTrackId3[] = "audio_track_id_3";
889static const uint32_t kAudioTrack3Ssrc = 7;
henrike@webrtc.org28e20752013-07-10 00:45:36890
henrike@webrtc.org28e20752013-07-10 00:45:36891// Candidate
892static const char kDummyMid[] = "dummy_mid";
893static const int kDummyIndex = 123;
894
895// Misc
Steve Antona3a92c22017-12-07 18:27:41896static SdpType kDummyType = SdpType::kOffer;
henrike@webrtc.org28e20752013-07-10 00:45:36897
898// Helper functions
899
900static bool SdpDeserialize(const std::string& message,
901 JsepSessionDescription* jdesc) {
902 return webrtc::SdpDeserialize(message, jdesc, NULL);
903}
904
905static bool SdpDeserializeCandidate(const std::string& message,
906 JsepIceCandidate* candidate) {
907 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
908}
909
910// Add some extra |newlines| to the |message| after |line|.
911static void InjectAfter(const std::string& line,
912 const std::string& newlines,
913 std::string* message) {
Steve Anton1c9c9fc2019-02-14 23:13:09914 absl::StrReplaceAll({{line, line + newlines}}, message);
henrike@webrtc.org28e20752013-07-10 00:45:36915}
916
917static void Replace(const std::string& line,
918 const std::string& newlines,
919 std::string* message) {
Steve Anton1c9c9fc2019-02-14 23:13:09920 absl::StrReplaceAll({{line, newlines}}, message);
henrike@webrtc.org28e20752013-07-10 00:45:36921}
922
Philipp Hanckeb70c9532021-01-13 09:40:06923// Expect a parse failure on the line containing |bad_part| when attempting to
924// parse |bad_sdp|.
wu@webrtc.org5e760e72014-04-02 23:19:09925static void ExpectParseFailure(const std::string& bad_sdp,
926 const std::string& bad_part) {
Steve Antona3a92c22017-12-07 18:27:41927 JsepSessionDescription desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36928 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09929 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
Harald Alvestrand99bcf602021-03-03 07:44:39930 ASSERT_FALSE(ret);
931 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()))
932 << "Did not find " << bad_part << " in " << error.line;
wu@webrtc.org5e760e72014-04-02 23:19:09933}
934
935// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
936static void ExpectParseFailure(const char* good_part, const char* bad_part) {
937 std::string bad_sdp = kSdpFullString;
938 Replace(good_part, bad_part, &bad_sdp);
939 ExpectParseFailure(bad_sdp, bad_part);
940}
941
942// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
943static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
944 const std::string& newlines,
945 const std::string& bad_part) {
946 std::string bad_sdp = kSdpFullString;
947 InjectAfter(injectpoint, newlines, &bad_sdp);
948 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36949}
950
Steve Anton4e70a722017-11-28 22:57:10951static void ReplaceDirection(RtpTransceiverDirection direction,
henrike@webrtc.org28e20752013-07-10 00:45:36952 std::string* message) {
953 std::string new_direction;
954 switch (direction) {
Steve Anton4e70a722017-11-28 22:57:10955 case RtpTransceiverDirection::kInactive:
henrike@webrtc.org28e20752013-07-10 00:45:36956 new_direction = "a=inactive";
957 break;
Steve Anton4e70a722017-11-28 22:57:10958 case RtpTransceiverDirection::kSendOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36959 new_direction = "a=sendonly";
960 break;
Steve Anton4e70a722017-11-28 22:57:10961 case RtpTransceiverDirection::kRecvOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36962 new_direction = "a=recvonly";
963 break;
Steve Anton4e70a722017-11-28 22:57:10964 case RtpTransceiverDirection::kSendRecv:
Markus Handell45c104b2020-03-11 09:51:13965 new_direction = "a=sendrecv";
966 break;
967 case RtpTransceiverDirection::kStopped:
henrike@webrtc.org28e20752013-07-10 00:45:36968 default:
Markus Handell45c104b2020-03-11 09:51:13969 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36970 new_direction = "a=sendrecv";
971 break;
972 }
973 Replace("a=sendrecv", new_direction, message);
974}
975
Yves Gerey665174f2018-06-19 13:03:05976static void ReplaceRejected(bool audio_rejected,
977 bool video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36978 std::string* message) {
979 if (audio_rejected) {
deadbeef3f7219b2015-12-28 23:17:14980 Replace("m=audio 9", "m=audio 0", message);
981 Replace(kAttributeIceUfragVoice, "", message);
982 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36983 }
984 if (video_rejected) {
deadbeef3f7219b2015-12-28 23:17:14985 Replace("m=video 9", "m=video 0", message);
986 Replace(kAttributeIceUfragVideo, "", message);
987 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36988 }
989}
990
991// WebRtcSdpTest
992
Mirko Bonadei6a489f22019-04-09 13:11:12993class WebRtcSdpTest : public ::testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36994 public:
Steve Antona3a92c22017-12-07 18:27:41995 WebRtcSdpTest() : jdesc_(kDummyType) {
phoglund37ebcf02016-01-08 13:04:57996#ifdef WEBRTC_ANDROID
997 webrtc::InitializeAndroidObjects();
998#endif
henrike@webrtc.org28e20752013-07-10 00:45:36999 // AudioContentDescription
1000 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-17 01:54:101001 StreamParams audio_stream;
1002 audio_stream.id = kAudioTrackId1;
1003 audio_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 19:34:101004 audio_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-17 01:54:101005 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
1006 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 18:04:531007 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
1008 audio_desc_->set_connection_address(audio_addr);
Harald Alvestrand1716d392019-06-03 18:35:451009 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1010 absl::WrapUnique(audio_desc_));
henrike@webrtc.org28e20752013-07-10 00:45:361011
1012 // VideoContentDescription
deadbeef9d3584c2016-02-17 01:54:101013 video_desc_ = CreateVideoContentDescription();
1014 StreamParams video_stream;
1015 video_stream.id = kVideoTrackId1;
1016 video_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 19:34:101017 video_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-17 01:54:101018 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
1019 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
1020 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
1021 video_stream.ssrc_groups.push_back(ssrc_group);
1022 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 18:04:531023 rtc::SocketAddress video_addr("74.125.224.39", 3457);
1024 video_desc_->set_connection_address(video_addr);
Harald Alvestrand1716d392019-06-03 18:35:451025 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp,
1026 absl::WrapUnique(video_desc_));
henrike@webrtc.org28e20752013-07-10 00:45:361027
1028 // TransportInfo
Steve Anton06817cd2018-12-18 23:55:301029 desc_.AddTransportInfo(TransportInfo(
1030 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice)));
1031 desc_.AddTransportInfo(TransportInfo(
1032 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo)));
henrike@webrtc.org28e20752013-07-10 00:45:361033
1034 // v4 host
1035 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:521036 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:071037 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:311038 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1039 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:361040 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:071041 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:311042 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1043 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:361044 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:071045 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:311046 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1047 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:361048 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:071049 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:311050 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1051 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:361052
1053 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:521054 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:071055 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1056 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:311057 cricket::LOCAL_PORT_TYPE,
1058 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:361059 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:071060 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1061 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:311062 cricket::LOCAL_PORT_TYPE,
1063 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:361064 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:071065 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1066 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:311067 cricket::LOCAL_PORT_TYPE,
1068 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:361069 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:071070 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1071 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:311072 cricket::LOCAL_PORT_TYPE,
1073 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:361074
1075 // stun
1076 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:521077 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
1078 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:071079 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1080 address_stun, kCandidatePriority, "", "",
1081 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:311082 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:361083 candidate9.set_related_address(rel_address_stun);
1084
1085 address_stun.SetPort(port_stun++);
1086 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:071087 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1088 address_stun, kCandidatePriority, "", "",
1089 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:311090 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:361091 candidate10.set_related_address(rel_address_stun);
1092
1093 // relay
1094 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:521095 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:071096 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1097 address_relay, kCandidatePriority, "", "",
1098 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:311099 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:361100 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:071101 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1102 address_relay, kCandidatePriority, "", "",
1103 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:311104 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:361105
1106 // voice
1107 candidates_.push_back(candidate1);
1108 candidates_.push_back(candidate2);
1109 candidates_.push_back(candidate5);
1110 candidates_.push_back(candidate6);
1111 candidates_.push_back(candidate9);
1112 candidates_.push_back(candidate10);
1113
1114 // video
1115 candidates_.push_back(candidate3);
1116 candidates_.push_back(candidate4);
1117 candidates_.push_back(candidate7);
1118 candidates_.push_back(candidate8);
1119 candidates_.push_back(candidate11);
1120 candidates_.push_back(candidate12);
1121
Yves Gerey665174f2018-06-19 13:03:051122 jcandidate_.reset(
1123 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:361124
1125 // Set up JsepSessionDescription.
Harald Alvestrand4d7160e2019-04-12 05:01:291126 jdesc_.Initialize(desc_.Clone(), kSessionId, kSessionVersion);
henrike@webrtc.org28e20752013-07-10 00:45:361127 std::string mline_id;
1128 int mline_index = 0;
Yves Gerey665174f2018-06-19 13:03:051129 for (size_t i = 0; i < candidates_.size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:361130 // In this test, the audio m line index will be 0, and the video m line
1131 // will be 1.
1132 bool is_video = (i > 5);
1133 mline_id = is_video ? "video_content_name" : "audio_content_name";
1134 mline_index = is_video ? 1 : 0;
Yves Gerey665174f2018-06-19 13:03:051135 JsepIceCandidate jice(mline_id, mline_index, candidates_.at(i));
henrike@webrtc.org28e20752013-07-10 00:45:361136 jdesc_.AddCandidate(&jice);
1137 }
1138 }
1139
Seth Hampson5b4f0752018-04-02 23:31:361140 void RemoveVideoCandidates() {
deadbeef25ed4352016-12-13 02:37:361141 const IceCandidateCollection* video_candidates_collection =
1142 jdesc_.candidates(1);
1143 ASSERT_NE(nullptr, video_candidates_collection);
1144 std::vector<cricket::Candidate> video_candidates;
1145 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1146 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1147 c.set_transport_name("video_content_name");
1148 video_candidates.push_back(c);
1149 }
1150 jdesc_.RemoveCandidates(video_candidates);
Seth Hampson5b4f0752018-04-02 23:31:361151 }
1152
1153 // Turns the existing reference description into a description using
1154 // a=bundle-only. This means no transport attributes and a 0 port value on
1155 // the m= sections not associated with the BUNDLE-tag.
1156 void MakeBundleOnlyDescription() {
1157 RemoveVideoCandidates();
deadbeef25ed4352016-12-13 02:37:361158
1159 // And the rest of the transport attributes.
1160 desc_.transport_infos()[1].description.ice_ufrag.clear();
1161 desc_.transport_infos()[1].description.ice_pwd.clear();
1162 desc_.transport_infos()[1].description.connection_role =
1163 cricket::CONNECTIONROLE_NONE;
1164
1165 // Set bundle-only flag.
1166 desc_.contents()[1].bundle_only = true;
1167
1168 // Add BUNDLE group.
1169 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1170 group.AddContentName(kAudioContentName);
1171 group.AddContentName(kVideoContentName);
1172 desc_.AddGroup(group);
1173
Harald Alvestrand4d7160e2019-04-12 05:01:291174 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef25ed4352016-12-13 02:37:361175 jdesc_.session_version()));
1176 }
1177
deadbeef9d3584c2016-02-17 01:54:101178 // Turns the existing reference description into a plan B description,
1179 // with 2 audio tracks and 3 video tracks.
1180 void MakePlanBDescription() {
Harald Alvestrandb97d2fe2020-02-28 10:54:401181 audio_desc_ = new AudioContentDescription(*audio_desc_);
1182 video_desc_ = new VideoContentDescription(*video_desc_);
deadbeef9d3584c2016-02-17 01:54:101183
1184 StreamParams audio_track_2;
1185 audio_track_2.id = kAudioTrackId2;
1186 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 19:34:101187 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-17 01:54:101188 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1189 audio_desc_->AddStream(audio_track_2);
1190
1191 StreamParams video_track_2;
1192 video_track_2.id = kVideoTrackId2;
1193 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 19:34:101194 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-17 01:54:101195 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1196 video_desc_->AddStream(video_track_2);
1197
1198 StreamParams video_track_3;
1199 video_track_3.id = kVideoTrackId3;
1200 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 19:34:101201 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-17 01:54:101202 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1203 video_desc_->AddStream(video_track_3);
1204
1205 desc_.RemoveContentByName(kAudioContentName);
1206 desc_.RemoveContentByName(kVideoContentName);
Harald Alvestrand1716d392019-06-03 18:35:451207 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1208 absl::WrapUnique(audio_desc_));
1209 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp,
1210 absl::WrapUnique(video_desc_));
deadbeef9d3584c2016-02-17 01:54:101211
Harald Alvestrand4d7160e2019-04-12 05:01:291212 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef9d3584c2016-02-17 01:54:101213 jdesc_.session_version()));
1214 }
1215
1216 // Turns the existing reference description into a unified plan description,
1217 // with 2 audio tracks and 3 video tracks.
Amit Hilbuchc57d5732018-12-11 23:30:111218 void MakeUnifiedPlanDescription(bool use_ssrcs = true) {
deadbeef9d3584c2016-02-17 01:54:101219 // Audio track 2.
1220 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1221 StreamParams audio_track_2;
1222 audio_track_2.id = kAudioTrackId2;
Seth Hampson845e8782018-03-02 19:34:101223 audio_track_2.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 23:30:111224 if (use_ssrcs) {
1225 audio_track_2.cname = kStream2Cname;
1226 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1227 }
deadbeef9d3584c2016-02-17 01:54:101228 audio_desc_2->AddStream(audio_track_2);
Harald Alvestrand1716d392019-06-03 18:35:451229 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp,
1230 absl::WrapUnique(audio_desc_2));
Steve Anton06817cd2018-12-18 23:55:301231 desc_.AddTransportInfo(TransportInfo(
1232 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2)));
deadbeef9d3584c2016-02-17 01:54:101233 // Video track 2, in stream 2.
1234 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1235 StreamParams video_track_2;
1236 video_track_2.id = kVideoTrackId2;
Seth Hampson845e8782018-03-02 19:34:101237 video_track_2.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 23:30:111238 if (use_ssrcs) {
1239 video_track_2.cname = kStream2Cname;
1240 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1241 }
deadbeef9d3584c2016-02-17 01:54:101242 video_desc_2->AddStream(video_track_2);
Harald Alvestrand1716d392019-06-03 18:35:451243 desc_.AddContent(kVideoContentName2, MediaProtocolType::kRtp,
1244 absl::WrapUnique(video_desc_2));
Steve Anton06817cd2018-12-18 23:55:301245 desc_.AddTransportInfo(TransportInfo(
1246 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2)));
deadbeef9d3584c2016-02-17 01:54:101247
1248 // Video track 3, in stream 2.
1249 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1250 StreamParams video_track_3;
1251 video_track_3.id = kVideoTrackId3;
Seth Hampson845e8782018-03-02 19:34:101252 video_track_3.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 23:30:111253 if (use_ssrcs) {
1254 video_track_3.cname = kStream2Cname;
1255 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1256 }
deadbeef9d3584c2016-02-17 01:54:101257 video_desc_3->AddStream(video_track_3);
Harald Alvestrand1716d392019-06-03 18:35:451258 desc_.AddContent(kVideoContentName3, MediaProtocolType::kRtp,
1259 absl::WrapUnique(video_desc_3));
Steve Anton06817cd2018-12-18 23:55:301260 desc_.AddTransportInfo(TransportInfo(
1261 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3)));
Steve Antone831b8c2018-02-01 20:22:161262 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
deadbeef9d3584c2016-02-17 01:54:101263
Harald Alvestrand4d7160e2019-04-12 05:01:291264 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef9d3584c2016-02-17 01:54:101265 jdesc_.session_version()));
1266 }
1267
1268 // Creates an audio content description with no streams, and some default
1269 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:361270 AudioContentDescription* CreateAudioContentDescription() {
1271 AudioContentDescription* audio = new AudioContentDescription();
1272 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 20:37:511273 audio->set_rtcp_reduced_size(true);
Yves Gerey665174f2018-06-19 13:03:051274 audio->AddCrypto(CryptoParams(
1275 1, "AES_CM_128_HMAC_SHA1_32",
henrike@webrtc.org28e20752013-07-10 00:45:361276 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1277 "dummy_session_params"));
1278 audio->set_protocol(cricket::kMediaProtocolSavpf);
Philipp Hanckef2a4ec12020-07-01 19:07:321279 audio->AddCodec(AudioCodec(111, "opus", 48000, 0, 2));
ossue1405ad2017-01-23 16:55:481280 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1281 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:361282 return audio;
1283 }
1284
Seth Hampson5b4f0752018-04-02 23:31:361285 // Turns the existing reference description into a unified plan description,
1286 // with 3 audio MediaContentDescriptions with special StreamParams that
1287 // contain 0 or multiple stream ids: - audio track 1 has 1 media stream id -
1288 // audio track 2 has 2 media stream ids - audio track 3 has 0 media stream ids
Seth Hampson7fa6ee62018-10-17 17:25:281289 void MakeUnifiedPlanDescriptionMultipleStreamIds(const int msid_signaling) {
Seth Hampson5b4f0752018-04-02 23:31:361290 desc_.RemoveContentByName(kVideoContentName);
1291 desc_.RemoveTransportInfoByName(kVideoContentName);
1292 RemoveVideoCandidates();
1293
1294 // Audio track 2 has 2 media stream ids.
1295 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1296 StreamParams audio_track_2;
1297 audio_track_2.id = kAudioTrackId2;
1298 audio_track_2.cname = kStream1Cname;
1299 audio_track_2.set_stream_ids({kStreamId1, kStreamId2});
1300 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1301 audio_desc_2->AddStream(audio_track_2);
Harald Alvestrand1716d392019-06-03 18:35:451302 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp,
1303 absl::WrapUnique(audio_desc_2));
Steve Anton06817cd2018-12-18 23:55:301304 desc_.AddTransportInfo(TransportInfo(
1305 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2)));
Seth Hampson5b4f0752018-04-02 23:31:361306
1307 // Audio track 3 has no stream ids.
1308 AudioContentDescription* audio_desc_3 = CreateAudioContentDescription();
1309 StreamParams audio_track_3;
1310 audio_track_3.id = kAudioTrackId3;
1311 audio_track_3.cname = kStream2Cname;
1312 audio_track_3.set_stream_ids({});
1313 audio_track_3.ssrcs.push_back(kAudioTrack3Ssrc);
1314 audio_desc_3->AddStream(audio_track_3);
Harald Alvestrand1716d392019-06-03 18:35:451315 desc_.AddContent(kAudioContentName3, MediaProtocolType::kRtp,
1316 absl::WrapUnique(audio_desc_3));
Steve Anton06817cd2018-12-18 23:55:301317 desc_.AddTransportInfo(TransportInfo(
1318 kAudioContentName3, TransportDescription(kUfragVoice3, kPwdVoice3)));
Seth Hampson7fa6ee62018-10-17 17:25:281319 desc_.set_msid_signaling(msid_signaling);
Harald Alvestrand4d7160e2019-04-12 05:01:291320 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
Seth Hampson5b4f0752018-04-02 23:31:361321 jdesc_.session_version()));
1322 }
1323
Seth Hampson5897a6e2018-04-03 18:16:331324 // Turns the existing reference description into a unified plan description
1325 // with one audio MediaContentDescription that contains one StreamParams with
1326 // 0 ssrcs.
1327 void MakeUnifiedPlanDescriptionNoSsrcSignaling() {
1328 desc_.RemoveContentByName(kVideoContentName);
1329 desc_.RemoveContentByName(kAudioContentName);
1330 desc_.RemoveTransportInfoByName(kVideoContentName);
1331 RemoveVideoCandidates();
1332
1333 AudioContentDescription* audio_desc = CreateAudioContentDescription();
1334 StreamParams audio_track;
1335 audio_track.id = kAudioTrackId1;
1336 audio_track.set_stream_ids({kStreamId1});
1337 audio_desc->AddStream(audio_track);
Harald Alvestrand1716d392019-06-03 18:35:451338 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1339 absl::WrapUnique(audio_desc));
Seth Hampson5897a6e2018-04-03 18:16:331340
1341 // Enable signaling a=msid lines.
1342 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
Harald Alvestrand4d7160e2019-04-12 05:01:291343 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
Seth Hampson5897a6e2018-04-03 18:16:331344 jdesc_.session_version()));
1345 }
1346
deadbeef9d3584c2016-02-17 01:54:101347 // Creates a video content description with no streams, and some default
1348 // configuration.
1349 VideoContentDescription* CreateVideoContentDescription() {
1350 VideoContentDescription* video = new VideoContentDescription();
1351 video->AddCrypto(CryptoParams(
1352 1, "AES_CM_128_HMAC_SHA1_80",
1353 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1354 video->set_protocol(cricket::kMediaProtocolSavpf);
1355 video->AddCodec(
perkj26752742016-10-24 08:21:161356 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-17 01:54:101357 return video;
1358 }
1359
henrike@webrtc.org28e20752013-07-10 00:45:361360 template <class MCD>
Yves Gerey665174f2018-06-19 13:03:051361 void CompareMediaContentDescription(const MCD* cd1, const MCD* cd2) {
henrike@webrtc.org28e20752013-07-10 00:45:361362 // type
Harald Alvestrand1716d392019-06-03 18:35:451363 EXPECT_EQ(cd1->type(), cd2->type());
henrike@webrtc.org28e20752013-07-10 00:45:361364
1365 // content direction
1366 EXPECT_EQ(cd1->direction(), cd2->direction());
1367
1368 // rtcp_mux
1369 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1370
deadbeef13871492015-12-09 20:37:511371 // rtcp_reduced_size
1372 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1373
henrike@webrtc.org28e20752013-07-10 00:45:361374 // cryptos
1375 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1376 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1377 ADD_FAILURE();
1378 return;
1379 }
Yves Gerey665174f2018-06-19 13:03:051380 for (size_t i = 0; i < cd1->cryptos().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:361381 const CryptoParams c1 = cd1->cryptos().at(i);
1382 const CryptoParams c2 = cd2->cryptos().at(i);
1383 EXPECT_TRUE(c1.Matches(c2));
1384 EXPECT_EQ(c1.key_params, c2.key_params);
1385 EXPECT_EQ(c1.session_params, c2.session_params);
1386 }
lally@webrtc.orgd7b61652015-02-24 20:18:551387
henrike@webrtc.org28e20752013-07-10 00:45:361388 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:551389 // Use an equivalence class here, for old and new versions of the
1390 // protocol description.
Yves Gerey665174f2018-06-19 13:03:051391 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp ||
1392 cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1393 cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
lally@webrtc.org36300852015-02-24 20:19:351394 const bool cd2_is_also_dtls_sctp =
Yves Gerey665174f2018-06-19 13:03:051395 cd2->protocol() == cricket::kMediaProtocolDtlsSctp ||
1396 cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1397 cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
lally@webrtc.org36300852015-02-24 20:19:351398 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:551399 } else {
1400 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1401 }
henrike@webrtc.org28e20752013-07-10 00:45:361402
1403 // codecs
1404 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1405
1406 // bandwidth
1407 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1408
1409 // streams
1410 EXPECT_EQ(cd1->streams(), cd2->streams());
1411
Johannes Kron0854eb62018-10-10 20:33:201412 // extmap-allow-mixed
Johannes Kron9581bc42018-10-23 08:17:391413 EXPECT_EQ(cd1->extmap_allow_mixed_enum(), cd2->extmap_allow_mixed_enum());
Johannes Kron0854eb62018-10-10 20:33:201414
henrike@webrtc.org28e20752013-07-10 00:45:361415 // extmap
1416 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1417 cd2->rtp_header_extensions().size());
Yves Gerey665174f2018-06-19 13:03:051418 for (size_t i = 0; i < cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 18:24:551419 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1420 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:361421 EXPECT_EQ(ext1.uri, ext2.uri);
1422 EXPECT_EQ(ext1.id, ext2.id);
jbauch5869f502017-06-29 19:31:361423 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
henrike@webrtc.org28e20752013-07-10 00:45:361424 }
henrike@webrtc.org28e20752013-07-10 00:45:361425 }
1426
Amit Hilbuchc57d5732018-12-11 23:30:111427 void CompareRidDescriptionIds(const std::vector<RidDescription>& rids,
1428 const std::vector<std::string>& ids) {
1429 // Order of elements does not matter, only equivalence of sets.
1430 EXPECT_EQ(rids.size(), ids.size());
1431 for (const std::string& id : ids) {
Steve Anton64b626b2019-01-29 01:25:261432 EXPECT_EQ(1l, absl::c_count_if(rids, [id](const RidDescription& rid) {
1433 return rid.rid == id;
1434 }));
Amit Hilbuchc57d5732018-12-11 23:30:111435 }
1436 }
1437
Amit Hilbucha2012042018-12-03 19:35:051438 void CompareSimulcastDescription(const SimulcastDescription& simulcast1,
1439 const SimulcastDescription& simulcast2) {
1440 EXPECT_EQ(simulcast1.send_layers().size(), simulcast2.send_layers().size());
1441 EXPECT_EQ(simulcast1.receive_layers().size(),
1442 simulcast2.receive_layers().size());
1443 }
1444
Harald Alvestrand5fc28b12019-05-13 11:36:161445 void CompareSctpDataContentDescription(
1446 const SctpDataContentDescription* dcd1,
1447 const SctpDataContentDescription* dcd2) {
Harald Alvestrand26bf7c42019-04-23 05:20:171448 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
Harald Alvestrand5fc28b12019-05-13 11:36:161449 EXPECT_EQ(dcd1->port(), dcd2->port());
1450 EXPECT_EQ(dcd1->max_message_size(), dcd2->max_message_size());
Harald Alvestrand26bf7c42019-04-23 05:20:171451 }
1452
henrike@webrtc.org28e20752013-07-10 00:45:361453 void CompareSessionDescription(const SessionDescription& desc1,
1454 const SessionDescription& desc2) {
1455 // Compare content descriptions.
1456 if (desc1.contents().size() != desc2.contents().size()) {
1457 ADD_FAILURE();
1458 return;
1459 }
Yves Gerey665174f2018-06-19 13:03:051460 for (size_t i = 0; i < desc1.contents().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:361461 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1462 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-13 02:37:361463 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:361464 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-13 02:37:361465 EXPECT_EQ(c1.type, c2.type);
1466 EXPECT_EQ(c1.rejected, c2.rejected);
1467 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:361468
1469 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1470 if (IsAudioContent(&c1)) {
1471 const AudioContentDescription* acd1 =
Steve Antonb1c1de12017-12-21 23:14:301472 c1.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:361473 const AudioContentDescription* acd2 =
Steve Antonb1c1de12017-12-21 23:14:301474 c2.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:361475 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1476 }
1477
1478 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1479 if (IsVideoContent(&c1)) {
1480 const VideoContentDescription* vcd1 =
Steve Antonb1c1de12017-12-21 23:14:301481 c1.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:361482 const VideoContentDescription* vcd2 =
Steve Antonb1c1de12017-12-21 23:14:301483 c2.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:361484 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1485 }
1486
1487 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
Harald Alvestrand5fc28b12019-05-13 11:36:161488 if (c1.media_description()->as_sctp()) {
1489 ASSERT_TRUE(c2.media_description()->as_sctp());
1490 const SctpDataContentDescription* scd1 =
1491 c1.media_description()->as_sctp();
1492 const SctpDataContentDescription* scd2 =
1493 c2.media_description()->as_sctp();
1494 CompareSctpDataContentDescription(scd1, scd2);
henrike@webrtc.org28e20752013-07-10 00:45:361495 }
Amit Hilbucha2012042018-12-03 19:35:051496
1497 CompareSimulcastDescription(
1498 c1.media_description()->simulcast_description(),
1499 c2.media_description()->simulcast_description());
henrike@webrtc.org28e20752013-07-10 00:45:361500 }
1501
1502 // group
1503 const cricket::ContentGroups groups1 = desc1.groups();
1504 const cricket::ContentGroups groups2 = desc2.groups();
1505 EXPECT_EQ(groups1.size(), groups1.size());
1506 if (groups1.size() != groups2.size()) {
1507 ADD_FAILURE();
1508 return;
1509 }
1510 for (size_t i = 0; i < groups1.size(); ++i) {
1511 const cricket::ContentGroup group1 = groups1.at(i);
1512 const cricket::ContentGroup group2 = groups2.at(i);
1513 EXPECT_EQ(group1.semantics(), group2.semantics());
1514 const cricket::ContentNames names1 = group1.content_names();
1515 const cricket::ContentNames names2 = group2.content_names();
1516 EXPECT_EQ(names1.size(), names2.size());
1517 if (names1.size() != names2.size()) {
1518 ADD_FAILURE();
1519 return;
1520 }
1521 cricket::ContentNames::const_iterator iter1 = names1.begin();
1522 cricket::ContentNames::const_iterator iter2 = names2.begin();
1523 while (iter1 != names1.end()) {
1524 EXPECT_EQ(*iter1++, *iter2++);
1525 }
1526 }
1527
1528 // transport info
1529 const cricket::TransportInfos transports1 = desc1.transport_infos();
1530 const cricket::TransportInfos transports2 = desc2.transport_infos();
1531 EXPECT_EQ(transports1.size(), transports2.size());
1532 if (transports1.size() != transports2.size()) {
1533 ADD_FAILURE();
1534 return;
1535 }
1536 for (size_t i = 0; i < transports1.size(); ++i) {
1537 const cricket::TransportInfo transport1 = transports1.at(i);
1538 const cricket::TransportInfo transport2 = transports2.at(i);
1539 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:361540 EXPECT_EQ(transport1.description.ice_ufrag,
1541 transport2.description.ice_ufrag);
Yves Gerey665174f2018-06-19 13:03:051542 EXPECT_EQ(transport1.description.ice_pwd, transport2.description.ice_pwd);
Taylor Brandstetter2f65ec52018-05-24 18:37:281543 EXPECT_EQ(transport1.description.ice_mode,
1544 transport2.description.ice_mode);
henrike@webrtc.org28e20752013-07-10 00:45:361545 if (transport1.description.identity_fingerprint) {
1546 EXPECT_EQ(*transport1.description.identity_fingerprint,
1547 *transport2.description.identity_fingerprint);
1548 } else {
1549 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1550 transport2.description.identity_fingerprint.get());
1551 }
1552 EXPECT_EQ(transport1.description.transport_options,
1553 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:361554 }
deadbeefc80741f2015-10-22 20:14:451555
1556 // global attributes
1557 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
Johannes Kron9581bc42018-10-23 08:17:391558 EXPECT_EQ(desc1.extmap_allow_mixed(), desc2.extmap_allow_mixed());
henrike@webrtc.org28e20752013-07-10 00:45:361559 }
1560
Yves Gerey665174f2018-06-19 13:03:051561 bool CompareSessionDescription(const JsepSessionDescription& desc1,
1562 const JsepSessionDescription& desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:361563 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1564 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1565 CompareSessionDescription(*desc1.description(), *desc2.description());
1566 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1567 return false;
1568 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1569 const IceCandidateCollection* cc1 = desc1.candidates(i);
1570 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-13 02:37:361571 if (cc1->count() != cc2->count()) {
1572 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:361573 return false;
deadbeef25ed4352016-12-13 02:37:361574 }
henrike@webrtc.org28e20752013-07-10 00:45:361575 for (size_t j = 0; j < cc1->count(); ++j) {
1576 const IceCandidateInterface* c1 = cc1->at(j);
1577 const IceCandidateInterface* c2 = cc2->at(j);
1578 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1579 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1580 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1581 }
1582 }
1583 return true;
1584 }
1585
1586 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1587 // them with invalid keywords so that the parser will just ignore them.
1588 bool RemoveCandidateUfragPwd(std::string* sdp) {
Steve Anton1c9c9fc2019-02-14 23:13:091589 absl::StrReplaceAll(
1590 {{"a=ice-ufrag", "a=xice-ufrag"}, {"a=ice-pwd", "a=xice-pwd"}}, sdp);
henrike@webrtc.org28e20752013-07-10 00:45:361591 return true;
1592 }
1593
1594 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
Yves Gerey665174f2018-06-19 13:03:051595 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc,
1596 int mline_index,
1597 const std::string& ufrag,
1598 const std::string& pwd) {
henrike@webrtc.org28e20752013-07-10 00:45:361599 std::string content_name;
1600 if (mline_index == 0) {
1601 content_name = kAudioContentName;
1602 } else if (mline_index == 1) {
1603 content_name = kVideoContentName;
1604 } else {
nissec80e7412017-01-11 13:56:461605 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:361606 }
Yves Gerey665174f2018-06-19 13:03:051607 TransportInfo transport_info(content_name,
1608 TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:361609 SessionDescription* desc =
1610 const_cast<SessionDescription*>(jdesc->description());
1611 desc->RemoveTransportInfoByName(content_name);
Steve Anton06817cd2018-12-18 23:55:301612 desc->AddTransportInfo(transport_info);
henrike@webrtc.org28e20752013-07-10 00:45:361613 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1614 const IceCandidateCollection* cc = jdesc_.candidates(i);
1615 for (size_t j = 0; j < cc->count(); ++j) {
1616 if (cc->at(j)->sdp_mline_index() == mline_index) {
Yves Gerey665174f2018-06-19 13:03:051617 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(ufrag);
1618 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(pwd);
henrike@webrtc.org28e20752013-07-10 00:45:361619 }
1620 }
1621 }
1622 return true;
1623 }
1624
1625 void AddIceOptions(const std::string& content_name,
1626 const std::vector<std::string>& transport_options) {
1627 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1628 cricket::TransportInfo transport_info =
1629 *(desc_.GetTransportInfoByName(content_name));
1630 desc_.RemoveTransportInfoByName(content_name);
1631 transport_info.description.transport_options = transport_options;
1632 desc_.AddTransportInfo(transport_info);
1633 }
1634
deadbeef3f7219b2015-12-28 23:17:141635 void SetIceUfragPwd(const std::string& content_name,
1636 const std::string& ice_ufrag,
1637 const std::string& ice_pwd) {
1638 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1639 cricket::TransportInfo transport_info =
1640 *(desc_.GetTransportInfoByName(content_name));
1641 desc_.RemoveTransportInfoByName(content_name);
1642 transport_info.description.ice_ufrag = ice_ufrag;
1643 transport_info.description.ice_pwd = ice_pwd;
1644 desc_.AddTransportInfo(transport_info);
1645 }
1646
henrike@webrtc.org28e20752013-07-10 00:45:361647 void AddFingerprint() {
1648 desc_.RemoveTransportInfoByName(kAudioContentName);
1649 desc_.RemoveTransportInfoByName(kVideoContentName);
Steve Anton4905edb2018-10-16 02:27:441650 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, kIdentityDigest);
Steve Anton06817cd2018-12-18 23:55:301651 desc_.AddTransportInfo(TransportInfo(
deadbeef46eed762016-01-28 21:24:371652 kAudioContentName,
deadbeef9d3584c2016-02-17 01:54:101653 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1654 cricket::ICEMODE_FULL,
Steve Anton06817cd2018-12-18 23:55:301655 cricket::CONNECTIONROLE_NONE, &fingerprint)));
1656 desc_.AddTransportInfo(TransportInfo(
deadbeef46eed762016-01-28 21:24:371657 kVideoContentName,
deadbeef9d3584c2016-02-17 01:54:101658 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1659 cricket::ICEMODE_FULL,
Steve Anton06817cd2018-12-18 23:55:301660 cricket::CONNECTIONROLE_NONE, &fingerprint)));
henrike@webrtc.org28e20752013-07-10 00:45:361661 }
1662
jbauch5869f502017-06-29 19:31:361663 void AddExtmap(bool encrypted) {
Harald Alvestrandb97d2fe2020-02-28 10:54:401664 audio_desc_ = new AudioContentDescription(*audio_desc_);
1665 video_desc_ = new VideoContentDescription(*video_desc_);
jbauch5869f502017-06-29 19:31:361666 audio_desc_->AddRtpHeaderExtension(
1667 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1668 video_desc_->AddRtpHeaderExtension(
1669 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:361670 desc_.RemoveContentByName(kAudioContentName);
1671 desc_.RemoveContentByName(kVideoContentName);
Harald Alvestrand1716d392019-06-03 18:35:451672 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1673 absl::WrapUnique(audio_desc_));
1674 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp,
1675 absl::WrapUnique(video_desc_));
henrike@webrtc.org28e20752013-07-10 00:45:361676 }
1677
1678 void RemoveCryptos() {
1679 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1680 video_desc_->set_cryptos(std::vector<CryptoParams>());
1681 }
1682
Seth Hampson5897a6e2018-04-03 18:16:331683 // Removes everything in StreamParams from the session description that is
1684 // used for a=ssrc lines.
1685 void RemoveSsrcSignalingFromStreamParams() {
Harald Alvestrand1716d392019-06-03 18:35:451686 for (cricket::ContentInfo& content_info :
1687 jdesc_.description()->contents()) {
Seth Hampson5897a6e2018-04-03 18:16:331688 // With Unified Plan there should be one StreamParams per m= section.
1689 StreamParams& stream =
1690 content_info.media_description()->mutable_streams()[0];
1691 stream.ssrcs.clear();
1692 stream.ssrc_groups.clear();
1693 stream.cname.clear();
1694 }
1695 }
1696
Seth Hampson7fa6ee62018-10-17 17:25:281697 // Removes all a=ssrc lines from the SDP string, except for the
1698 // "a=ssrc:... cname:..." lines.
1699 void RemoveSsrcMsidLinesFromSdpString(std::string* sdp_string) {
1700 const char kAttributeSsrc[] = "a=ssrc";
1701 const char kAttributeCname[] = "cname";
1702 size_t ssrc_line_pos = sdp_string->find(kAttributeSsrc);
1703 while (ssrc_line_pos != std::string::npos) {
1704 size_t beg_line_pos = sdp_string->rfind('\n', ssrc_line_pos);
1705 size_t end_line_pos = sdp_string->find('\n', ssrc_line_pos);
1706 size_t cname_pos = sdp_string->find(kAttributeCname, ssrc_line_pos);
1707 if (cname_pos == std::string::npos || cname_pos > end_line_pos) {
1708 // Only erase a=ssrc lines that don't contain "cname".
1709 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1710 ssrc_line_pos = sdp_string->find(kAttributeSsrc, beg_line_pos);
1711 } else {
1712 // Skip the "a=ssrc:... cname" line and find the next "a=ssrc" line.
1713 ssrc_line_pos = sdp_string->find(kAttributeSsrc, end_line_pos);
1714 }
1715 }
1716 }
1717
Seth Hampson5897a6e2018-04-03 18:16:331718 // Removes all a=ssrc lines from the SDP string.
1719 void RemoveSsrcLinesFromSdpString(std::string* sdp_string) {
1720 const char kAttributeSsrc[] = "a=ssrc";
1721 while (sdp_string->find(kAttributeSsrc) != std::string::npos) {
1722 size_t pos_ssrc_attribute = sdp_string->find(kAttributeSsrc);
1723 size_t beg_line_pos = sdp_string->rfind('\n', pos_ssrc_attribute);
1724 size_t end_line_pos = sdp_string->find('\n', pos_ssrc_attribute);
1725 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1726 }
1727 }
1728
Steve Anton4e70a722017-11-28 22:57:101729 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:361730 audio_desc_->set_direction(direction);
1731 video_desc_->set_direction(direction);
1732 std::string new_sdp = kSdpFullString;
1733 ReplaceDirection(direction, &new_sdp);
1734
Harald Alvestrand4d7160e2019-04-12 05:01:291735 if (!jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:361736 jdesc_.session_version())) {
1737 return false;
1738 }
Steve Antone831b8c2018-02-01 20:22:161739 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:361740 EXPECT_EQ(new_sdp, message);
1741 return true;
1742 }
1743
1744 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
Harald Alvestrandb97d2fe2020-02-28 10:54:401745 audio_desc_ = new AudioContentDescription(*audio_desc_);
1746 video_desc_ = new VideoContentDescription(*video_desc_);
zhihuang38989e52017-03-21 18:04:531747
henrike@webrtc.org28e20752013-07-10 00:45:361748 desc_.RemoveContentByName(kAudioContentName);
1749 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-21 00:34:001750 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
Harald Alvestrand1716d392019-06-03 18:35:451751 absl::WrapUnique(audio_desc_));
Steve Anton5adfafd2017-12-21 00:34:001752 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
Harald Alvestrand1716d392019-06-03 18:35:451753 absl::WrapUnique(video_desc_));
deadbeef9d3584c2016-02-17 01:54:101754 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1755 audio_rejected ? "" : kPwdVoice);
1756 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1757 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 23:17:141758
1759 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:361760 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1761
Steve Antona3a92c22017-12-07 18:27:411762 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 18:04:531763 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 20:22:161764 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:361765 EXPECT_EQ(new_sdp, message);
1766 return true;
1767 }
1768
zstein4b2e0822017-02-18 03:48:381769 void AddSctpDataChannel(bool use_sctpmap) {
Harald Alvestrand5fc28b12019-05-13 11:36:161770 std::unique_ptr<SctpDataContentDescription> data(
1771 new SctpDataContentDescription());
1772 sctp_desc_ = data.get();
1773 sctp_desc_->set_use_sctpmap(use_sctpmap);
Guido Urdanetacecf87f2019-05-31 10:17:381774 sctp_desc_->set_protocol(cricket::kMediaProtocolUdpDtlsSctp);
Harald Alvestrand5fc28b12019-05-13 11:36:161775 sctp_desc_->set_port(kDefaultSctpPort);
Steve Anton5adfafd2017-12-21 00:34:001776 desc_.AddContent(kDataContentName, MediaProtocolType::kSctp,
Harald Alvestrand1716d392019-06-03 18:35:451777 std::move(data));
Steve Anton06817cd2018-12-18 23:55:301778 desc_.AddTransportInfo(TransportInfo(
1779 kDataContentName, TransportDescription(kUfragData, kPwdData)));
henrike@webrtc.org28e20752013-07-10 00:45:361780 }
1781
Steve Anton4e70a722017-11-28 22:57:101782 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:361783 std::string new_sdp = kSdpFullString;
1784 ReplaceDirection(direction, &new_sdp);
Steve Antona3a92c22017-12-07 18:27:411785 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:361786
1787 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1788
1789 audio_desc_->set_direction(direction);
1790 video_desc_->set_direction(direction);
Harald Alvestrand4d7160e2019-04-12 05:01:291791 if (!jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:361792 jdesc_.session_version())) {
1793 return false;
1794 }
1795 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1796 return true;
1797 }
1798
1799 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 23:17:141800 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:361801 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
Steve Antona3a92c22017-12-07 18:27:411802 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:361803 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 23:17:141804
Harald Alvestrandb97d2fe2020-02-28 10:54:401805 audio_desc_ = new AudioContentDescription(*audio_desc_);
1806 video_desc_ = new VideoContentDescription(*video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:361807 desc_.RemoveContentByName(kAudioContentName);
1808 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-21 00:34:001809 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
Harald Alvestrand1716d392019-06-03 18:35:451810 absl::WrapUnique(audio_desc_));
Steve Anton5adfafd2017-12-21 00:34:001811 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
Harald Alvestrand1716d392019-06-03 18:35:451812 absl::WrapUnique(video_desc_));
deadbeef9d3584c2016-02-17 01:54:101813 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1814 audio_rejected ? "" : kPwdVoice);
1815 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1816 video_rejected ? "" : kPwdVideo);
Steve Antona3a92c22017-12-07 18:27:411817 JsepSessionDescription jdesc_no_candidates(kDummyType);
Harald Alvestrand4d7160e2019-04-12 05:01:291818 if (!jdesc_no_candidates.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef3f7219b2015-12-28 23:17:141819 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:361820 return false;
1821 }
deadbeef3f7219b2015-12-28 23:17:141822 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:361823 return true;
1824 }
1825
Yves Gerey665174f2018-06-19 13:03:051826 void TestDeserializeExtmap(bool session_level,
1827 bool media_level,
1828 bool encrypted) {
jbauch5869f502017-06-29 19:31:361829 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 18:27:411830 JsepSessionDescription new_jdesc(SdpType::kOffer);
Harald Alvestrand4d7160e2019-04-12 05:01:291831 ASSERT_TRUE(new_jdesc.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:361832 jdesc_.session_version()));
Steve Antona3a92c22017-12-07 18:27:411833 JsepSessionDescription jdesc_with_extmap(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:361834 std::string sdp_with_extmap = kSdpString;
1835 if (session_level) {
jbauch5869f502017-06-29 19:31:361836 InjectAfter(kSessionTime,
1837 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1838 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:361839 &sdp_with_extmap);
1840 }
1841 if (media_level) {
jbauch5869f502017-06-29 19:31:361842 InjectAfter(kAttributeIcePwdVoice,
1843 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1844 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:361845 &sdp_with_extmap);
jbauch5869f502017-06-29 19:31:361846 InjectAfter(kAttributeIcePwdVideo,
1847 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1848 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:361849 &sdp_with_extmap);
1850 }
1851 // The extmap can't be present at the same time in both session level and
1852 // media level.
1853 if (session_level && media_level) {
1854 SdpParseError error;
Yves Gerey665174f2018-06-19 13:03:051855 EXPECT_FALSE(
1856 webrtc::SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap, &error));
henrike@webrtc.org28e20752013-07-10 00:45:361857 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1858 } else {
1859 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1860 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1861 }
1862 }
1863
1864 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
Yves Gerey665174f2018-06-19 13:03:051865 const std::string& name,
1866 int expected_value) {
henrike@webrtc.org28e20752013-07-10 00:45:361867 cricket::CodecParameterMap::const_iterator found = params.find(name);
1868 ASSERT_TRUE(found != params.end());
Jonas Olsson6b1985d2018-07-05 09:59:481869 EXPECT_EQ(found->second, rtc::ToString(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:361870 }
1871
1872 void TestDeserializeCodecParams(const CodecParams& params,
1873 JsepSessionDescription* jdesc_output) {
1874 std::string sdp =
1875 "v=0\r\n"
1876 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1877 "s=-\r\n"
1878 "t=0 0\r\n"
1879 // Include semantics for WebRTC Media Streams since it is supported by
1880 // this parser, and will be added to the SDP when serializing a session
1881 // description.
1882 "a=msid-semantic: WMS\r\n"
1883 // Pl type 111 preferred.
Philipp Hanckef2a4ec12020-07-01 19:07:321884 "m=audio 9 RTP/SAVPF 111 104 103 105\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:361885 // Pltype 111 listed before 103 and 104 in the map.
1886 "a=rtpmap:111 opus/48000/2\r\n"
1887 // Pltype 103 listed before 104.
1888 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:411889 "a=rtpmap:104 ISAC/32000\r\n"
Philipp Hanckef2a4ec12020-07-01 19:07:321890 "a=rtpmap:105 telephone-event/8000\r\n"
1891 "a=fmtp:105 0-15,66,70\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:151892 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:361893 std::ostringstream os;
Donald Curtis144d0182015-05-15 20:14:241894 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:151895 << "; sprop-stereo=" << params.sprop_stereo
1896 << "; useinbandfec=" << params.useinband
Jonas Olssonb2b20312020-01-14 11:11:311897 << "; maxaveragebitrate=" << params.maxaveragebitrate
1898 << "\r\n"
1899 "a=ptime:"
1900 << params.ptime
1901 << "\r\n"
1902 "a=maxptime:"
1903 << params.max_ptime << "\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:361904 sdp += os.str();
1905
stefan@webrtc.org85d27942014-06-09 12:51:391906 os.clear();
1907 os.str("");
1908 // Pl type 100 preferred.
Philipp Hanckeb7bc2432021-03-11 14:28:001909 os << "m=video 9 RTP/SAVPF 99 95 96\r\n"
1910 "a=rtpmap:96 VP9/90000\r\n" // out-of-order wrt the m= line.
Jonas Olssonb2b20312020-01-14 11:11:311911 "a=rtpmap:99 VP8/90000\r\n"
1912 "a=rtpmap:95 RTX/90000\r\n"
1913 "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:391914 sdp += os.str();
1915
henrike@webrtc.org28e20752013-07-10 00:45:361916 // Deserialize
1917 SdpParseError error;
1918 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1919
henrike@webrtc.org28e20752013-07-10 00:45:361920 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 23:14:301921 GetFirstAudioContentDescription(jdesc_output->description());
1922 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:361923 ASSERT_FALSE(acd->codecs().empty());
1924 cricket::AudioCodec opus = acd->codecs()[0];
1925 EXPECT_EQ("opus", opus.name);
1926 EXPECT_EQ(111, opus.id);
1927 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1928 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1929 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1930 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:591931 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1932 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:361933 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1934 cricket::AudioCodec codec = acd->codecs()[i];
1935 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1936 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:361937 }
stefan@webrtc.org85d27942014-06-09 12:51:391938
Philipp Hanckef2a4ec12020-07-01 19:07:321939 cricket::AudioCodec dtmf = acd->codecs()[3];
1940 EXPECT_EQ("telephone-event", dtmf.name);
1941 EXPECT_EQ(105, dtmf.id);
1942 EXPECT_EQ(3u,
1943 dtmf.params.size()); // ptime and max_ptime count as parameters.
1944 EXPECT_EQ(dtmf.params.begin()->first, "");
1945 EXPECT_EQ(dtmf.params.begin()->second, "0-15,66,70");
1946
stefan@webrtc.org85d27942014-06-09 12:51:391947 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 23:14:301948 GetFirstVideoContentDescription(jdesc_output->description());
1949 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:391950 ASSERT_FALSE(vcd->codecs().empty());
1951 cricket::VideoCodec vp8 = vcd->codecs()[0];
1952 EXPECT_EQ("VP8", vp8.name);
1953 EXPECT_EQ(99, vp8.id);
1954 cricket::VideoCodec rtx = vcd->codecs()[1];
1955 EXPECT_EQ("RTX", rtx.name);
1956 EXPECT_EQ(95, rtx.id);
1957 VerifyCodecParameter(rtx.params, "apt", vp8.id);
Philipp Hanckeb7bc2432021-03-11 14:28:001958 // VP9 is listed last in the m= line so should come after VP8 and RTX.
1959 cricket::VideoCodec vp9 = vcd->codecs()[2];
1960 EXPECT_EQ("VP9", vp9.name);
1961 EXPECT_EQ(96, vp9.id);
henrike@webrtc.org28e20752013-07-10 00:45:361962 }
1963
1964 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1965 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:461966 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:361967 "v=0\r\n"
1968 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1969 "s=-\r\n"
1970 "t=0 0\r\n"
1971 // Include semantics for WebRTC Media Streams since it is supported by
1972 // this parser, and will be added to the SDP when serializing a session
1973 // description.
1974 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:221975 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:461976 "a=rtpmap:111 opus/48000/2\r\n";
1977 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:361978 "m=video 3457 RTP/SAVPF 101\r\n"
1979 "a=rtpmap:101 VP8/90000\r\n"
Elad Alonfadb1812019-05-24 11:40:021980 "a=rtcp-fb:101 goog-lntf\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:361981 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:581982 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:461983 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:361984 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:461985 os << sdp_session_and_audio;
Yves Gerey665174f2018-06-19 13:03:051986 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:461987 os << sdp_video;
Yves Gerey665174f2018-06-19 13:03:051988 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:461989 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:361990 // Deserialize
1991 SdpParseError error;
1992 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:361993 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 23:14:301994 GetFirstAudioContentDescription(jdesc_output->description());
1995 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:361996 ASSERT_FALSE(acd->codecs().empty());
1997 cricket::AudioCodec opus = acd->codecs()[0];
1998 EXPECT_EQ(111, opus.id);
Yves Gerey665174f2018-06-19 13:03:051999 EXPECT_TRUE(opus.HasFeedbackParam(cricket::FeedbackParam(
2000 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
henrike@webrtc.org28e20752013-07-10 00:45:362001
henrike@webrtc.org28e20752013-07-10 00:45:362002 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 23:14:302003 GetFirstVideoContentDescription(jdesc_output->description());
2004 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:362005 ASSERT_FALSE(vcd->codecs().empty());
2006 cricket::VideoCodec vp8 = vcd->codecs()[0];
2007 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
2008 vp8.name.c_str());
2009 EXPECT_EQ(101, vp8.id);
Yves Gerey665174f2018-06-19 13:03:052010 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
Elad Alonfadb1812019-05-24 11:40:022011 cricket::kRtcpFbParamLntf, cricket::kParamValueEmpty)));
2012 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
Yves Gerey665174f2018-06-19 13:03:052013 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
2014 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2015 cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli)));
2016 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2017 cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty)));
2018 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2019 cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir)));
henrike@webrtc.org28e20752013-07-10 00:45:362020 }
2021
2022 // Two SDP messages can mean the same thing but be different strings, e.g.
2023 // some of the lines can be serialized in different order.
2024 // However, a deserialized description can be compared field by field and has
2025 // no order. If deserializer has already been tested, serializing then
2026 // deserializing and comparing JsepSessionDescription will test
2027 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 20:22:162028 void TestSerialize(const JsepSessionDescription& jdesc) {
2029 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 18:27:412030 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362031 SdpParseError error;
2032 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
2033 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
2034 }
2035
zhihuang38989e52017-03-21 18:04:532036 // Calling 'Initialize' with a copy of the inner SessionDescription will
2037 // create a copy of the JsepSessionDescription without candidates. The
2038 // 'connection address' field, previously set from the candidates, must also
2039 // be reset.
2040 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
2041 rtc::SocketAddress audio_addr("0.0.0.0", 9);
2042 rtc::SocketAddress video_addr("0.0.0.0", 9);
2043 audio_desc_->set_connection_address(audio_addr);
2044 video_desc_->set_connection_address(video_addr);
Harald Alvestrand4d7160e2019-04-12 05:01:292045 ASSERT_TRUE(jdesc->Initialize(desc_.Clone(), kSessionId, kSessionVersion));
zhihuang38989e52017-03-21 18:04:532046 }
2047
henrike@webrtc.org28e20752013-07-10 00:45:362048 protected:
2049 SessionDescription desc_;
2050 AudioContentDescription* audio_desc_;
2051 VideoContentDescription* video_desc_;
Harald Alvestrand5fc28b12019-05-13 11:36:162052 SctpDataContentDescription* sctp_desc_;
henrike@webrtc.org28e20752013-07-10 00:45:362053 Candidates candidates_;
kwibergd1fe2812016-04-27 13:47:292054 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:362055 JsepSessionDescription jdesc_;
2056};
2057
2058void TestMismatch(const std::string& string1, const std::string& string2) {
2059 int position = 0;
2060 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
2061 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:492062 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:362063 break;
2064 }
2065 }
2066 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
2067 << " character\n"
Jonas Olssonb2b20312020-01-14 11:11:312068 " 1: "
2069 << string1.substr(position, 20)
2070 << "\n"
2071 " 2: "
2072 << string2.substr(position, 20) << "\n";
henrike@webrtc.org28e20752013-07-10 00:45:362073}
2074
henrike@webrtc.org28e20752013-07-10 00:45:362075TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
2076 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 20:22:162077 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:362078 TestMismatch(std::string(kSdpFullString), message);
2079}
2080
2081TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 18:27:412082 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 20:22:162083 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:362084}
2085
2086// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
2087// the case in a DTLS offer.
2088TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
2089 AddFingerprint();
Steve Antona3a92c22017-12-07 18:27:412090 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 18:04:532091 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 20:22:162092 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:362093
2094 std::string sdp_with_fingerprint = kSdpString;
Yves Gerey665174f2018-06-19 13:03:052095 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2096 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:362097
2098 EXPECT_EQ(sdp_with_fingerprint, message);
2099}
2100
2101// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
2102// be the case in a DTLS answer.
2103TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
2104 AddFingerprint();
2105 RemoveCryptos();
Steve Antona3a92c22017-12-07 18:27:412106 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 18:04:532107 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 20:22:162108 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:362109
2110 std::string sdp_with_fingerprint = kSdpString;
2111 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
2112 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
Yves Gerey665174f2018-06-19 13:03:052113 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2114 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:362115
2116 EXPECT_EQ(sdp_with_fingerprint, message);
2117}
2118
2119TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
2120 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 18:27:412121 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 18:04:532122 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 20:22:162123 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:362124 EXPECT_EQ(std::string(kSdpString), message);
2125}
2126
Henrik Boströmf8187e02021-04-26 19:04:262127TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundles) {
2128 ContentGroup group1(cricket::GROUP_TYPE_BUNDLE);
2129 group1.AddContentName(kAudioContentName);
2130 group1.AddContentName(kVideoContentName);
2131 desc_.AddGroup(group1);
2132 ContentGroup group2(cricket::GROUP_TYPE_BUNDLE);
2133 group2.AddContentName(kAudioContentName2);
2134 desc_.AddGroup(group2);
Harald Alvestrand4d7160e2019-04-12 05:01:292135 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:362136 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 20:22:162137 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:362138 std::string sdp_with_bundle = kSdpFullString;
2139 InjectAfter(kSessionTime,
Henrik Boströmf8187e02021-04-26 19:04:262140 "a=group:BUNDLE audio_content_name video_content_name\r\n"
2141 "a=group:BUNDLE audio_content_name_2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:362142 &sdp_with_bundle);
2143 EXPECT_EQ(sdp_with_bundle, message);
2144}
2145
2146TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 23:14:302147 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
Taylor Brandstetteree8c2462020-07-27 22:52:022148 vcd->set_bandwidth(100 * 1000 + 755); // Integer division will drop the 755.
2149 vcd->set_bandwidth_type("AS");
Steve Antonb1c1de12017-12-21 23:14:302150 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
Taylor Brandstetteree8c2462020-07-27 22:52:022151 acd->set_bandwidth(555);
2152 acd->set_bandwidth_type("TIAS");
Harald Alvestrand4d7160e2019-04-12 05:01:292153 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:362154 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 20:22:162155 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:362156 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 13:03:052157 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:362158 &sdp_with_bandwidth);
Taylor Brandstetteree8c2462020-07-27 22:52:022159 InjectAfter("c=IN IP4 74.125.127.126\r\n", "b=TIAS:555\r\n",
2160 &sdp_with_bandwidth);
2161 EXPECT_EQ(sdp_with_bandwidth, message);
2162}
2163
2164// Should default to b=AS if bandwidth_type isn't set.
2165TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithMissingBandwidthType) {
2166 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
2167 vcd->set_bandwidth(100 * 1000);
2168 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2169 jdesc_.session_version()));
2170 std::string message = webrtc::SdpSerialize(jdesc_);
2171 std::string sdp_with_bandwidth = kSdpFullString;
2172 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:362173 &sdp_with_bandwidth);
2174 EXPECT_EQ(sdp_with_bandwidth, message);
2175}
2176
2177TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
2178 std::vector<std::string> transport_options;
2179 transport_options.push_back(kIceOption1);
2180 transport_options.push_back(kIceOption3);
2181 AddIceOptions(kAudioContentName, transport_options);
2182 transport_options.clear();
2183 transport_options.push_back(kIceOption2);
2184 transport_options.push_back(kIceOption3);
2185 AddIceOptions(kVideoContentName, transport_options);
Harald Alvestrand4d7160e2019-04-12 05:01:292186 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:362187 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 20:22:162188 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:362189 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 13:03:052190 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:362191 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 13:03:052192 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:362193 &sdp_with_ice_options);
2194 EXPECT_EQ(sdp_with_ice_options, message);
2195}
2196
2197TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 22:57:102198 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:362199}
2200
2201TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 22:57:102202 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:362203}
2204
2205TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 22:57:102206 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:362207}
2208
2209TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2210 EXPECT_TRUE(TestSerializeRejected(true, false));
2211}
2212
2213TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2214 EXPECT_TRUE(TestSerializeRejected(false, true));
2215}
2216
2217TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2218 EXPECT_TRUE(TestSerializeRejected(true, true));
2219}
2220
henrike@webrtc.org28e20752013-07-10 00:45:362221TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-18 03:48:382222 bool use_sctpmap = true;
2223 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 18:27:412224 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362225
zhihuang38989e52017-03-21 18:04:532226 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 20:22:162227 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:362228
2229 std::string expected_sdp = kSdpString;
2230 expected_sdp.append(kSdpSctpDataChannelString);
2231 EXPECT_EQ(message, expected_sdp);
2232}
2233
Harald Alvestrand5fc28b12019-05-13 11:36:162234void MutateJsepSctpPort(JsepSessionDescription* jdesc,
2235 const SessionDescription& desc,
2236 int port) {
2237 // Take our pre-built session description and change the SCTP port.
2238 std::unique_ptr<cricket::SessionDescription> mutant = desc.Clone();
2239 SctpDataContentDescription* dcdesc =
2240 mutant->GetContentDescriptionByName(kDataContentName)->as_sctp();
2241 dcdesc->set_port(port);
2242 ASSERT_TRUE(
2243 jdesc->Initialize(std::move(mutant), kSessionId, kSessionVersion));
2244}
2245
jiayl@webrtc.org9c16c392014-05-01 18:30:302246TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-18 03:48:382247 bool use_sctpmap = true;
2248 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 18:27:412249 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 18:04:532250 MakeDescriptionWithoutCandidates(&jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:302251
2252 const int kNewPort = 1234;
Harald Alvestrand5fc28b12019-05-13 11:36:162253 MutateJsepSctpPort(&jsep_desc, desc_, kNewPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:302254
Steve Antone831b8c2018-02-01 20:22:162255 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:302256
2257 std::string expected_sdp = kSdpString;
2258 expected_sdp.append(kSdpSctpDataChannelString);
2259
Steve Anton1c9c9fc2019-02-14 23:13:092260 absl::StrReplaceAll(
2261 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kNewPort)}},
2262 &expected_sdp);
jiayl@webrtc.org9c16c392014-05-01 18:30:302263
2264 EXPECT_EQ(expected_sdp, message);
2265}
2266
Johannes Kron0854eb62018-10-10 20:33:202267TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 08:17:392268 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 20:33:202269 TestSerialize(jdesc_);
2270}
2271
2272TEST_F(WebRtcSdpTest, SerializeMediaContentDescriptionWithExtmapAllowMixed) {
2273 cricket::MediaContentDescription* video_desc =
2274 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2275 ASSERT_TRUE(video_desc);
2276 cricket::MediaContentDescription* audio_desc =
2277 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2278 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 08:17:392279 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 20:33:202280 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 08:17:392281 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 20:33:202282 cricket::MediaContentDescription::kMedia);
2283 TestSerialize(jdesc_);
2284}
2285
henrike@webrtc.org28e20752013-07-10 00:45:362286TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 19:31:362287 bool encrypted = false;
2288 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 18:27:412289 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 18:04:532290 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 20:22:162291 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:362292
2293 std::string sdp_with_extmap = kSdpString;
Yves Gerey665174f2018-06-19 13:03:052294 InjectAfter("a=mid:audio_content_name\r\n", kExtmap, &sdp_with_extmap);
2295 InjectAfter("a=mid:video_content_name\r\n", kExtmap, &sdp_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:362296
2297 EXPECT_EQ(sdp_with_extmap, message);
2298}
2299
jbauch5869f502017-06-29 19:31:362300TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2301 bool encrypted = true;
2302 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 18:27:412303 JsepSessionDescription desc_with_extmap(kDummyType);
Yves Gerey665174f2018-06-19 13:03:052304 ASSERT_TRUE(
Harald Alvestrand4d7160e2019-04-12 05:01:292305 desc_with_extmap.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 20:22:162306 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 19:31:362307}
2308
henrike@webrtc.org28e20752013-07-10 00:45:362309TEST_F(WebRtcSdpTest, SerializeCandidates) {
2310 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:102311 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-17 02:37:232312
2313 Candidate candidate_with_ufrag(candidates_.front());
2314 candidate_with_ufrag.set_username("ABC");
2315 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2316 candidate_with_ufrag));
2317 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2318 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 23:07:482319
2320 Candidate candidate_with_network_info(candidates_.front());
2321 candidate_with_network_info.set_network_id(1);
2322 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2323 candidate_with_network_info));
2324 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2325 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2326 candidate_with_network_info.set_network_cost(999);
2327 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2328 candidate_with_network_info));
2329 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2330 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2331 message);
henrike@webrtc.org28e20752013-07-10 00:45:362332}
2333
Zach Steinb336c272018-08-09 08:16:132334TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) {
2335 rtc::SocketAddress address("a.test", 1234);
2336 cricket::Candidate candidate(
2337 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
2338 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
2339 JsepIceCandidate jcandidate(std::string("audio_content_name"), 0, candidate);
2340 std::string message = webrtc::SdpSerializeCandidate(jcandidate);
2341 EXPECT_EQ(std::string(kRawHostnameCandidate), message);
2342}
2343
mallinath@webrtc.orge999bd02014-08-13 06:05:552344TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:072345 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:312346 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2347 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2348 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:202349 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 13:47:292350 std::unique_ptr<IceCandidateInterface> jcandidate(
2351 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:202352
2353 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2354 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2355}
2356
Taylor Brandstetter8206bc02020-04-02 19:36:382357// Test serializing a TCP candidate that came in with a missing tcptype. This
2358// shouldn't happen according to the spec, but our implementation has been
2359// accepting this for quite some time, treating it as a passive candidate.
2360//
2361// So, we should be able to at least convert such candidates to and from SDP.
2362// See: bugs.webrtc.org/11423
2363TEST_F(WebRtcSdpTest, ParseTcpCandidateWithoutTcptype) {
2364 std::string missing_tcptype =
2365 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9999 typ host";
2366 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2367 EXPECT_TRUE(SdpDeserializeCandidate(missing_tcptype, &jcandidate));
2368
2369 EXPECT_EQ(std::string(cricket::TCPTYPE_PASSIVE_STR),
2370 jcandidate.candidate().tcptype());
2371}
2372
2373TEST_F(WebRtcSdpTest, ParseSslTcpCandidate) {
2374 std::string ssltcp =
2375 "candidate:a0+B/1 1 ssltcp 2130706432 192.168.1.5 9999 typ host tcptype "
2376 "passive";
2377 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2378 EXPECT_TRUE(SdpDeserializeCandidate(ssltcp, &jcandidate));
2379
2380 EXPECT_EQ(std::string("ssltcp"), jcandidate.candidate().protocol());
2381}
2382
htaa6b99442016-04-12 17:29:172383TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 09:34:112384 cricket::VideoCodec h264_codec("H264");
2385 h264_codec.SetParam("profile-level-id", "42e01f");
2386 h264_codec.SetParam("level-asymmetry-allowed", "1");
2387 h264_codec.SetParam("packetization-mode", "1");
2388 video_desc_->AddCodec(h264_codec);
2389
Harald Alvestrand4d7160e2019-04-12 05:01:292390 jdesc_.Initialize(desc_.Clone(), kSessionId, kSessionVersion);
htaa6b99442016-04-12 17:29:172391
Steve Antone831b8c2018-02-01 20:22:162392 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 17:29:172393 size_t after_pt = message.find(" H264/90000");
2394 ASSERT_NE(after_pt, std::string::npos);
2395 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2396 ASSERT_NE(before_pt, std::string::npos);
2397 before_pt += strlen("a=rtpmap:");
2398 std::string pt = message.substr(before_pt, after_pt - before_pt);
2399 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2400 std::string to_find = "a=fmtp:" + pt + " ";
2401 size_t fmtp_pos = message.find(to_find);
2402 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
Mirko Bonadei37ec55e2019-01-28 10:43:522403 size_t fmtp_endpos = message.find('\n', fmtp_pos);
htaa6b99442016-04-12 17:29:172404 ASSERT_NE(std::string::npos, fmtp_endpos);
2405 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2406 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2407 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2408 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 18:02:142409 // Check that there are no spaces after semicolons.
2410 // https://bugs.webrtc.org/5793
2411 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 17:29:172412}
2413
henrike@webrtc.org28e20752013-07-10 00:45:362414TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 18:27:412415 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362416 // Deserialize
2417 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2418 // Verify
2419 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2420}
2421
wu@webrtc.orgcecfd182013-10-30 05:18:122422TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 18:27:412423 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:122424 const char kSdpWithoutMline[] =
Yves Gerey665174f2018-06-19 13:03:052425 "v=0\r\n"
2426 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2427 "s=-\r\n"
2428 "t=0 0\r\n"
2429 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
wu@webrtc.orgcecfd182013-10-30 05:18:122430 // Deserialize
2431 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2432 EXPECT_EQ(0u, jdesc.description()->contents().size());
2433}
2434
henrike@webrtc.org28e20752013-07-10 00:45:362435TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 18:27:412436 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362437 std::string sdp_without_carriage_return = kSdpFullString;
2438 Replace("\r\n", "\n", &sdp_without_carriage_return);
2439 // Deserialize
2440 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2441 // Verify
2442 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2443}
2444
2445TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2446 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 18:27:412447 JsepSessionDescription jdesc_no_candidates(kDummyType);
Harald Alvestrand4d7160e2019-04-12 05:01:292448 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Clone(), kSessionId,
Yves Gerey665174f2018-06-19 13:03:052449 kSessionVersion));
Steve Antona3a92c22017-12-07 18:27:412450 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362451 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2452 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2453}
2454
2455TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2456 static const char kSdpNoRtpmapString[] =
2457 "v=0\r\n"
2458 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2459 "s=-\r\n"
2460 "t=0 0\r\n"
2461 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2462 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:412463 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:362464 // The rtpmap line for static payload codec is optional.
2465 "a=rtpmap:18 G729/16000\r\n"
2466 "a=rtpmap:103 ISAC/16000\r\n";
2467
Steve Antona3a92c22017-12-07 18:27:412468 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362469 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2470 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 23:55:302471 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org28e20752013-07-10 00:45:362472 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 17:07:162473 // The codecs in the AudioContentDescription should be in the same order as
2474 // the payload types (<fmt>s) on the m= line.
2475 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2476 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 16:55:482477 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:362478 EXPECT_EQ(ref_codecs, audio->codecs());
2479}
2480
henrike@webrtc.org704bf9e2014-02-27 17:52:042481TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2482 static const char kSdpNoRtpmapString[] =
2483 "v=0\r\n"
2484 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2485 "s=-\r\n"
2486 "t=0 0\r\n"
2487 "m=audio 49232 RTP/AVP 18 103\r\n"
2488 "a=fmtp:18 annexb=yes\r\n"
2489 "a=rtpmap:103 ISAC/16000\r\n";
2490
Steve Antona3a92c22017-12-07 18:27:412491 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:042492 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2493 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 23:55:302494 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:042495
2496 cricket::AudioCodec g729 = audio->codecs()[0];
2497 EXPECT_EQ("G729", g729.name);
2498 EXPECT_EQ(8000, g729.clockrate);
2499 EXPECT_EQ(18, g729.id);
Yves Gerey665174f2018-06-19 13:03:052500 cricket::CodecParameterMap::iterator found = g729.params.find("annexb");
henrike@webrtc.org704bf9e2014-02-27 17:52:042501 ASSERT_TRUE(found != g729.params.end());
2502 EXPECT_EQ(found->second, "yes");
2503
2504 cricket::AudioCodec isac = audio->codecs()[1];
2505 EXPECT_EQ("ISAC", isac.name);
2506 EXPECT_EQ(103, isac.id);
2507 EXPECT_EQ(16000, isac.clockrate);
2508}
2509
henrike@webrtc.org28e20752013-07-10 00:45:362510// Ensure that we can deserialize SDP with a=fingerprint properly.
2511TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2512 // Add a DTLS a=fingerprint attribute to our session description.
2513 AddFingerprint();
Steve Antona3a92c22017-12-07 18:27:412514 JsepSessionDescription new_jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 05:01:292515 ASSERT_TRUE(new_jdesc.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:362516 jdesc_.session_version()));
2517
Steve Antona3a92c22017-12-07 18:27:412518 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362519 std::string sdp_with_fingerprint = kSdpString;
2520 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2521 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2522 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2523 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2524}
2525
2526TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 18:27:412527 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362528 std::string sdp_with_bundle = kSdpFullString;
2529 InjectAfter(kSessionTime,
2530 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2531 &sdp_with_bundle);
2532 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2533 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2534 group.AddContentName(kAudioContentName);
2535 group.AddContentName(kVideoContentName);
2536 desc_.AddGroup(group);
Harald Alvestrand4d7160e2019-04-12 05:01:292537 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:362538 jdesc_.session_version()));
2539 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2540}
2541
2542TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 18:27:412543 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362544 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 13:03:052545 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:362546 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 13:03:052547 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:362548 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 13:03:052549 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 23:14:302550 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:362551 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 23:14:302552 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:362553 acd->set_bandwidth(50 * 1000);
Harald Alvestrand4d7160e2019-04-12 05:01:292554 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:362555 jdesc_.session_version()));
2556 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2557}
2558
Taylor Brandstetteree8c2462020-07-27 22:52:022559TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithTiasBandwidth) {
2560 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
2561 std::string sdp_with_bandwidth = kSdpFullString;
2562 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=TIAS:100000\r\n",
2563 &sdp_with_bandwidth);
2564 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=TIAS:50000\r\n",
2565 &sdp_with_bandwidth);
2566 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2567 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
2568 vcd->set_bandwidth(100 * 1000);
2569 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
2570 acd->set_bandwidth(50 * 1000);
2571 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2572 jdesc_.session_version()));
2573 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2574}
2575
Philipp Hanckefbbfc022020-07-31 06:30:502576TEST_F(WebRtcSdpTest,
2577 DeserializeSessionDescriptionWithUnknownBandwidthModifier) {
2578 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
2579 std::string sdp_with_bandwidth = kSdpFullString;
2580 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
2581 "b=unknown:100000\r\n", &sdp_with_bandwidth);
2582 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
2583 "b=unknown:50000\r\n", &sdp_with_bandwidth);
2584 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2585 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
2586 vcd->set_bandwidth(-1);
2587 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
2588 acd->set_bandwidth(-1);
2589 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2590 jdesc_.session_version()));
2591 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2592}
2593
henrike@webrtc.org28e20752013-07-10 00:45:362594TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 18:27:412595 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362596 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 13:03:052597 InjectAfter(kSessionTime, "a=ice-options:iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:362598 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 13:03:052599 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:362600 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 13:03:052601 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:362602 &sdp_with_ice_options);
2603 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2604 std::vector<std::string> transport_options;
2605 transport_options.push_back(kIceOption3);
2606 transport_options.push_back(kIceOption1);
2607 AddIceOptions(kAudioContentName, transport_options);
2608 transport_options.clear();
2609 transport_options.push_back(kIceOption3);
2610 transport_options.push_back(kIceOption2);
2611 AddIceOptions(kVideoContentName, transport_options);
Harald Alvestrand4d7160e2019-04-12 05:01:292612 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:362613 jdesc_.session_version()));
2614 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2615}
2616
2617TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2618 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 18:27:412619 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362620 std::string sdp_with_ufrag_pwd = kSdpFullString;
2621 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2622 // Add session level ufrag and pwd
2623 InjectAfter(kSessionTime,
Yves Gerey665174f2018-06-19 13:03:052624 "a=ice-pwd:session+level+icepwd\r\n"
2625 "a=ice-ufrag:session+level+iceufrag\r\n",
2626 &sdp_with_ufrag_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:362627 // Add media level ufrag and pwd for audio
Yves Gerey665174f2018-06-19 13:03:052628 InjectAfter(
2629 "a=mid:audio_content_name\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:362630 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2631 &sdp_with_ufrag_pwd);
2632 // Update the candidate ufrag and pwd to the expected ones.
Yves Gerey665174f2018-06-19 13:03:052633 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, "media+level+iceufrag",
2634 "media+level+icepwd"));
2635 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, "session+level+iceufrag",
2636 "session+level+icepwd"));
henrike@webrtc.org28e20752013-07-10 00:45:362637 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2638 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2639}
2640
henrike@webrtc.org28e20752013-07-10 00:45:362641TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 22:57:102642 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:362643}
2644
2645TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 22:57:102646 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:362647}
2648
2649TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 22:57:102650 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:362651}
2652
2653TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2654 EXPECT_TRUE(TestDeserializeRejected(true, false));
2655}
2656
2657TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2658 EXPECT_TRUE(TestDeserializeRejected(false, true));
2659}
2660
2661TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2662 EXPECT_TRUE(TestDeserializeRejected(true, true));
2663}
2664
Artem Titovf0a34f22020-03-16 17:52:042665// Tests that we can still handle the sdp uses mslabel and label instead of
2666// msid for backward compatibility.
2667TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
2668 jdesc_.description()->set_msid_supported(false);
2669 JsepSessionDescription jdesc(kDummyType);
2670 std::string sdp_without_msid = kSdpFullString;
2671 Replace("msid", "xmsid", &sdp_without_msid);
2672 // Deserialize
2673 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2674 // Verify
2675 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2676 EXPECT_FALSE(jdesc.description()->msid_signaling() &
2677 ~cricket::kMsidSignalingSsrcAttribute);
2678}
2679
Johannes Kron0854eb62018-10-10 20:33:202680TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 08:17:392681 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 20:33:202682 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
Johannes Kron0854eb62018-10-10 20:33:202683 // Deserialize
2684 JsepSessionDescription jdesc_deserialized(kDummyType);
Emil Lundmark801c9992021-01-19 12:06:322685 ASSERT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
Johannes Kron0854eb62018-10-10 20:33:202686 // Verify
2687 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2688}
2689
2690TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 08:17:392691 jdesc_.description()->set_extmap_allow_mixed(false);
Johannes Kron0854eb62018-10-10 20:33:202692 std::string sdp_without_extmap_allow_mixed = kSdpFullString;
Emil Lundmark801c9992021-01-19 12:06:322693 Replace(kExtmapAllowMixed, "", &sdp_without_extmap_allow_mixed);
Johannes Kron0854eb62018-10-10 20:33:202694 // Deserialize
2695 JsepSessionDescription jdesc_deserialized(kDummyType);
Emil Lundmark801c9992021-01-19 12:06:322696 ASSERT_TRUE(
Johannes Kron0854eb62018-10-10 20:33:202697 SdpDeserialize(sdp_without_extmap_allow_mixed, &jdesc_deserialized));
2698 // Verify
2699 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2700}
2701
2702TEST_F(WebRtcSdpTest, DeserializeMediaContentDescriptionWithExtmapAllowMixed) {
2703 cricket::MediaContentDescription* video_desc =
2704 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2705 ASSERT_TRUE(video_desc);
2706 cricket::MediaContentDescription* audio_desc =
2707 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2708 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 08:17:392709 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 20:33:202710 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 08:17:392711 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 20:33:202712 cricket::MediaContentDescription::kMedia);
2713
2714 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2715 InjectAfter("a=mid:audio_content_name\r\n", kExtmapAllowMixed,
2716 &sdp_with_extmap_allow_mixed);
2717 InjectAfter("a=mid:video_content_name\r\n", kExtmapAllowMixed,
2718 &sdp_with_extmap_allow_mixed);
2719
2720 // Deserialize
2721 JsepSessionDescription jdesc_deserialized(kDummyType);
2722 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2723 // Verify
2724 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2725}
2726
henrike@webrtc.org28e20752013-07-10 00:45:362727TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2728 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2729
2730 std::string sdp = kSdpOneCandidate;
2731 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2732 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2733 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2734 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 23:07:482735 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:362736
2737 // Candidate line without generation extension.
2738 sdp = kSdpOneCandidate;
2739 Replace(" generation 2", "", &sdp);
2740 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2741 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2742 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2743 Candidate expected = jcandidate_->candidate();
2744 expected.set_generation(0);
2745 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2746
honghaiza0c44ea2016-03-23 23:07:482747 // Candidate with network id and/or cost.
2748 sdp = kSdpOneCandidate;
2749 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2750 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2751 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2752 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2753 expected = jcandidate_->candidate();
2754 expected.set_network_id(2);
2755 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2756 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2757 // Add network cost
2758 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2759 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2760 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2761 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2762
mallinath@webrtc.org2d60c5e2014-08-08 22:29:202763 sdp = kSdpTcpActiveCandidate;
2764 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2765 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:072766 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:312767 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2768 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2769 kCandidateFoundation1);
kwibergd1fe2812016-04-27 13:47:292770 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2771 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
Yves Gerey665174f2018-06-19 13:03:052772 EXPECT_TRUE(
2773 jcandidate.candidate().IsEquivalent(jcandidate_template->candidate()));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:202774 sdp = kSdpTcpPassiveCandidate;
2775 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2776 sdp = kSdpTcpSOCandidate;
2777 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:362778}
2779
2780// This test verifies the deserialization of candidate-attribute
2781// as per RFC 5245. Candiate-attribute will be of the format
2782// candidate:<blah>. This format will be used when candidates
2783// are trickled.
2784TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2785 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2786
2787 std::string candidate_attribute = kRawCandidate;
2788 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2789 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2790 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2791 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2792 EXPECT_EQ(2u, jcandidate.candidate().generation());
2793
2794 // Candidate line without generation extension.
2795 candidate_attribute = kRawCandidate;
2796 Replace(" generation 2", "", &candidate_attribute);
2797 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2798 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2799 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2800 Candidate expected = jcandidate_->candidate();
2801 expected.set_generation(0);
2802 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2803
2804 // Candidate line without candidate:
2805 candidate_attribute = kRawCandidate;
2806 Replace("candidate:", "", &candidate_attribute);
2807 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2808
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:152809 // Candidate line with IPV6 address.
2810 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
Zach Steinb336c272018-08-09 08:16:132811
2812 // Candidate line with hostname address.
2813 EXPECT_TRUE(SdpDeserializeCandidate(kRawHostnameCandidate, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:152814}
2815
2816// This test verifies that the deserialization of an invalid candidate string
2817// fails.
2818TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
Yves Gerey665174f2018-06-19 13:03:052819 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:152820
2821 std::string candidate_attribute = kRawCandidate;
2822 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:362823 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:152824
2825 candidate_attribute = kSdpOneCandidate;
2826 candidate_attribute.replace(0, 1, "x");
2827 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2828
2829 candidate_attribute = kRawCandidate;
2830 candidate_attribute.append("\r\n");
2831 candidate_attribute.append(kRawCandidate);
2832 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2833
2834 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:362835}
2836
henrike@webrtc.org28e20752013-07-10 00:45:362837TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-18 03:48:382838 bool use_sctpmap = true;
2839 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 18:27:412840 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 05:01:292841 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
henrike@webrtc.org28e20752013-07-10 00:45:362842
2843 std::string sdp_with_data = kSdpString;
2844 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 18:27:412845 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362846
Guido Urdanetacecf87f2019-05-31 10:17:382847 // Verify with UDP/DTLS/SCTP (already in kSdpSctpDataChannelString).
lally@webrtc.org36300852015-02-24 20:19:352848 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2849 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2850
Guido Urdanetacecf87f2019-05-31 10:17:382851 // Verify with DTLS/SCTP.
2852 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2853 kDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:352854 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2855 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2856
2857 // Verify with TCP/DTLS/SCTP.
Guido Urdanetacecf87f2019-05-31 10:17:382858 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
Yves Gerey665174f2018-06-19 13:03:052859 kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:362860 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2861 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2862}
2863
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562864TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-18 03:48:382865 bool use_sctpmap = false;
2866 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 18:27:412867 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 05:01:292868 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562869
2870 std::string sdp_with_data = kSdpString;
2871 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 18:27:412872 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562873
lally@webrtc.orgc7848b72015-02-24 20:19:262874 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2875 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2876}
2877
lally69f57602015-10-08 17:15:042878TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-18 03:48:382879 bool use_sctpmap = false;
2880 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 18:27:412881 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 05:01:292882 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
lally69f57602015-10-08 17:15:042883
2884 std::string sdp_with_data = kSdpString;
2885 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 18:27:412886 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 17:15:042887
lally69f57602015-10-08 17:15:042888 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2889 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2890}
2891
Philipp Hanckeefc55b02020-06-26 08:17:052892TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsButWrongMediaType) {
2893 bool use_sctpmap = true;
2894 AddSctpDataChannel(use_sctpmap);
2895 JsepSessionDescription jdesc(kDummyType);
2896 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
2897
2898 std::string sdp = kSdpSessionString;
2899 sdp += kSdpSctpDataChannelString;
2900
2901 const char needle[] = "m=application ";
2902 sdp.replace(sdp.find(needle), strlen(needle), "m=application:bogus ");
2903
2904 JsepSessionDescription jdesc_output(kDummyType);
2905 EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output));
2906
Philipp Hancke4e8c1152020-10-13 10:43:152907 EXPECT_EQ(1u, jdesc_output.description()->contents().size());
2908 EXPECT_TRUE(jdesc_output.description()->contents()[0].rejected);
Philipp Hanckeefc55b02020-06-26 08:17:052909}
2910
Harald Alvestrand48cce4d2019-04-11 08:41:242911// Helper function to set the max-message-size parameter in the
2912// SCTP data codec.
2913void MutateJsepSctpMaxMessageSize(const SessionDescription& desc,
Harald Alvestrand5fc28b12019-05-13 11:36:162914 int new_value,
Harald Alvestrand48cce4d2019-04-11 08:41:242915 JsepSessionDescription* jdesc) {
Harald Alvestrand8da35a62019-05-10 07:31:042916 std::unique_ptr<cricket::SessionDescription> mutant = desc.Clone();
Harald Alvestrand5fc28b12019-05-13 11:36:162917 SctpDataContentDescription* dcdesc =
2918 mutant->GetContentDescriptionByName(kDataContentName)->as_sctp();
2919 dcdesc->set_max_message_size(new_value);
Harald Alvestrand8da35a62019-05-10 07:31:042920 jdesc->Initialize(std::move(mutant), kSessionId, kSessionVersion);
Harald Alvestrand48cce4d2019-04-11 08:41:242921}
2922
2923TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithMaxMessageSize) {
2924 bool use_sctpmap = false;
2925 AddSctpDataChannel(use_sctpmap);
2926 JsepSessionDescription jdesc(kDummyType);
2927 std::string sdp_with_data = kSdpString;
2928
2929 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
2930 sdp_with_data.append("a=max-message-size:12345\r\n");
Harald Alvestrand5fc28b12019-05-13 11:36:162931 MutateJsepSctpMaxMessageSize(desc_, 12345, &jdesc);
Harald Alvestrand48cce4d2019-04-11 08:41:242932 JsepSessionDescription jdesc_output(kDummyType);
2933
Harald Alvestrand48cce4d2019-04-11 08:41:242934 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2935 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2936}
2937
Harald Alvestrandfbb45bd2019-05-15 06:07:472938TEST_F(WebRtcSdpTest, SerializeSdpWithSctpDataChannelWithMaxMessageSize) {
2939 bool use_sctpmap = false;
2940 AddSctpDataChannel(use_sctpmap);
2941 JsepSessionDescription jdesc(kDummyType);
2942 MutateJsepSctpMaxMessageSize(desc_, 12345, &jdesc);
2943 std::string message = webrtc::SdpSerialize(jdesc);
2944 EXPECT_NE(std::string::npos,
2945 message.find("\r\na=max-message-size:12345\r\n"));
2946 JsepSessionDescription jdesc_output(kDummyType);
2947 EXPECT_TRUE(SdpDeserialize(message, &jdesc_output));
2948 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2949}
2950
2951TEST_F(WebRtcSdpTest,
2952 SerializeSdpWithSctpDataChannelWithDefaultMaxMessageSize) {
2953 // https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-26#section-6
2954 // The default max message size is 64K.
2955 bool use_sctpmap = false;
2956 AddSctpDataChannel(use_sctpmap);
2957 JsepSessionDescription jdesc(kDummyType);
2958 MutateJsepSctpMaxMessageSize(desc_, 65536, &jdesc);
2959 std::string message = webrtc::SdpSerialize(jdesc);
2960 EXPECT_EQ(std::string::npos, message.find("\r\na=max-message-size:"));
2961 JsepSessionDescription jdesc_output(kDummyType);
2962 EXPECT_TRUE(SdpDeserialize(message, &jdesc_output));
2963 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2964}
2965
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562966// Test to check the behaviour if sctp-port is specified
2967// on the m= line and in a=sctp-port.
2968TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-18 03:48:382969 bool use_sctpmap = true;
2970 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 18:27:412971 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 05:01:292972 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562973
2974 std::string sdp_with_data = kSdpString;
2975 // Append m= attributes
2976 sdp_with_data.append(kSdpSctpDataChannelString);
2977 // Append a=sctp-port attribute
2978 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 18:27:412979 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562980
2981 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2982}
2983
Harald Alvestrand5fc28b12019-05-13 11:36:162984// Test behavior if a=rtpmap occurs in an SCTP section.
2985TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpmapAttribute) {
2986 std::string sdp_with_data = kSdpString;
2987 // Append m= attributes
2988 sdp_with_data.append(kSdpSctpDataChannelString);
2989 // Append a=rtpmap attribute
2990 sdp_with_data.append("a=rtpmap:111 opus/48000/2\r\n");
2991 JsepSessionDescription jdesc_output(kDummyType);
2992 // Correct behavior is to ignore the extra attribute.
2993 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2994}
2995
2996TEST_F(WebRtcSdpTest, DeserializeSdpWithStrangeApplicationProtocolNames) {
Harald Alvestrand7af57c62021-04-16 11:12:142997 static const char* bad_strings[] = {
2998 "DTLS/SCTPRTP/", "obviously-bogus", "UDP/TL/RTSP/SAVPF",
2999 "UDP/TL/RTSP/S", "DTLS/SCTP/RTP/FOO", "obviously-bogus/RTP/"};
Harald Alvestrand5fc28b12019-05-13 11:36:163000 for (auto proto : bad_strings) {
3001 std::string sdp_with_data = kSdpString;
3002 sdp_with_data.append("m=application 9 ");
3003 sdp_with_data.append(proto);
3004 sdp_with_data.append(" 47\r\n");
3005 JsepSessionDescription jdesc_output(kDummyType);
3006 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output))
3007 << "Parsing should have failed on " << proto;
3008 }
Harald Alvestrand5fc28b12019-05-13 11:36:163009}
3010
henrike@webrtc.org571df2d2014-02-19 23:04:263011// For crbug/344475.
3012TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
3013 std::string sdp_with_data = kSdpString;
3014 sdp_with_data.append(kSdpSctpDataChannelString);
3015 // Remove the "\n" at the end.
3016 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 18:27:413017 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:263018
3019 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
3020 // No crash is a pass.
3021}
3022
zstein4b2e0822017-02-18 03:48:383023TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
3024 bool use_sctpmap = true;
3025 AddSctpDataChannel(use_sctpmap);
3026
3027 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 18:27:413028 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 11:36:163029 MutateJsepSctpPort(&jdesc, desc_, kUnusualSctpPort);
wu@webrtc.org78187522013-10-07 23:32:023030
jiayl@webrtc.org9c16c392014-05-01 18:30:303031 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:023032 std::string sdp_with_data = kSdpString;
3033 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Anton1c9c9fc2019-02-14 23:13:093034 absl::StrReplaceAll(
3035 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}},
3036 &sdp_with_data);
Steve Antona3a92c22017-12-07 18:27:413037 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:023038
3039 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3040 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-18 03:48:383041}
3042
3043TEST_F(WebRtcSdpTest,
3044 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
3045 bool use_sctpmap = false;
3046 AddSctpDataChannel(use_sctpmap);
3047
Steve Antona3a92c22017-12-07 18:27:413048 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 11:36:163049 MutateJsepSctpPort(&jdesc, desc_, kUnusualSctpPort);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:563050
3051 // We need to test the deserialized JsepSessionDescription from
3052 // kSdpSctpDataChannelStringWithSctpPort for
3053 // draft-ietf-mmusic-sctp-sdp-07
3054 // a=sctp-port
zstein4b2e0822017-02-18 03:48:383055 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:563056 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Anton1c9c9fc2019-02-14 23:13:093057 absl::StrReplaceAll(
3058 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}},
3059 &sdp_with_data);
Steve Antona3a92c22017-12-07 18:27:413060 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:563061
3062 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3063 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:023064}
3065
Peter Thatcherc0c3a862015-06-24 22:31:253066TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-18 03:48:383067 bool use_sctpmap = true;
3068 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 18:27:413069 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 11:36:163070 SctpDataContentDescription* dcd = GetFirstSctpDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 22:31:253071 dcd->set_bandwidth(100 * 1000);
Harald Alvestrand4d7160e2019-04-12 05:01:293072 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
Peter Thatcherc0c3a862015-06-24 22:31:253073
3074 std::string sdp_with_bandwidth = kSdpString;
3075 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
Yves Gerey665174f2018-06-19 13:03:053076 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
Peter Thatcherc0c3a862015-06-24 22:31:253077 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 18:27:413078 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 22:31:253079
3080 // SCTP has congestion control, so we shouldn't limit the bandwidth
3081 // as we do for RTP.
3082 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:163083 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
3084}
3085
Yves Gerey665174f2018-06-19 13:03:053086class WebRtcSdpExtmapTest : public WebRtcSdpTest,
Mirko Bonadei6a489f22019-04-09 13:11:123087 public ::testing::WithParamInterface<bool> {};
jbauch5869f502017-06-29 19:31:363088
3089TEST_P(WebRtcSdpExtmapTest,
Yves Gerey665174f2018-06-19 13:03:053090 DeserializeSessionDescriptionWithSessionLevelExtmap) {
jbauch5869f502017-06-29 19:31:363091 bool encrypted = GetParam();
3092 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:363093}
3094
Yves Gerey665174f2018-06-19 13:03:053095TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
jbauch5869f502017-06-29 19:31:363096 bool encrypted = GetParam();
3097 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:363098}
3099
Yves Gerey665174f2018-06-19 13:03:053100TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithInvalidExtmap) {
jbauch5869f502017-06-29 19:31:363101 bool encrypted = GetParam();
3102 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:363103}
3104
Mirko Bonadeic84f6612019-01-31 11:20:573105INSTANTIATE_TEST_SUITE_P(Encrypted,
3106 WebRtcSdpExtmapTest,
3107 ::testing::Values(false, true));
jbauch5869f502017-06-29 19:31:363108
sergeyu@chromium.org5bc25c42013-12-05 00:24:063109TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 18:27:413110 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:063111 std::string sdp = kSdpFullString;
3112 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
3113 // Deserialize
3114 SdpParseError error;
3115 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
Artem Titovf0a34f22020-03-16 17:52:043116 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:063117 EXPECT_EQ(lastline, error.line);
3118 EXPECT_EQ("Invalid SDP line.", error.description);
3119}
3120
henrike@webrtc.org28e20752013-07-10 00:45:363121TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
3122 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
3123 std::string new_sdp = kSdpOneCandidate;
3124 Replace("udp", "unsupported_transport", &new_sdp);
3125 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3126 new_sdp = kSdpOneCandidate;
3127 Replace("udp", "uDP", &new_sdp);
3128 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3129 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3130 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3131 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
3132}
3133
honghaiza54a0802015-12-17 02:37:233134TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:363135 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-17 02:37:233136 EXPECT_TRUE(
3137 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:363138 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3139 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3140 Candidate ref_candidate = jcandidate_->candidate();
3141 ref_candidate.set_username("user_rtp");
3142 ref_candidate.set_password("password_rtp");
3143 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
3144}
3145
henrike@webrtc.org704bf9e2014-02-27 17:52:043146TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 18:27:413147 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:043148
3149 // Deserialize
3150 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
3151
3152 // Verify
3153 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 23:55:303154 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:043155 EXPECT_TRUE(audio->conference_mode());
3156
3157 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 23:55:303158 cricket::GetFirstVideoContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:043159 EXPECT_TRUE(video->conference_mode());
3160}
3161
deadbeefd45aea82017-09-16 08:24:293162TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 18:27:413163 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 08:24:293164
3165 // We tested deserialization already above, so just test that if we serialize
3166 // and deserialize the flag doesn't disappear.
3167 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 20:22:163168 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 08:24:293169 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
3170
3171 // Verify.
3172 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 23:55:303173 cricket::GetFirstAudioContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 08:24:293174 EXPECT_TRUE(audio->conference_mode());
3175
3176 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 23:55:303177 cricket::GetFirstVideoContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 08:24:293178 EXPECT_TRUE(video->conference_mode());
3179}
3180
Sebastian Jansson97321b62019-07-24 12:01:183181TEST_F(WebRtcSdpTest, SerializeAndDeserializeRemoteNetEstimate) {
3182 {
3183 // By default remote estimates are disabled.
3184 JsepSessionDescription dst(kDummyType);
3185 SdpDeserialize(webrtc::SdpSerialize(jdesc_), &dst);
3186 EXPECT_FALSE(cricket::GetFirstVideoContentDescription(dst.description())
3187 ->remote_estimate());
3188 }
3189 {
3190 // When remote estimate is enabled, the setting is propagated via SDP.
3191 cricket::GetFirstVideoContentDescription(jdesc_.description())
3192 ->set_remote_estimate(true);
3193 JsepSessionDescription dst(kDummyType);
3194 SdpDeserialize(webrtc::SdpSerialize(jdesc_), &dst);
3195 EXPECT_TRUE(cricket::GetFirstVideoContentDescription(dst.description())
3196 ->remote_estimate());
3197 }
3198}
3199
henrike@webrtc.org28e20752013-07-10 00:45:363200TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
3201 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:513202 const char kSdpEmptyType[] = " =candidate";
3203 const char kSdpEqualAsPlus[] = "a+candidate";
3204 const char kSdpSpaceAfterEqual[] = "a= candidate";
3205 const char kSdpUpperType[] = "A=candidate";
3206 const char kSdpEmptyLine[] = "";
3207 const char kSdpMissingValue[] = "a=";
3208
Yves Gerey665174f2018-06-19 13:03:053209 const char kSdpBrokenFingerprint[] =
3210 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:363211 "4AAD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB";
Yves Gerey665174f2018-06-19 13:03:053212 const char kSdpExtraField[] =
3213 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:363214 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB XXX";
Yves Gerey665174f2018-06-19 13:03:053215 const char kSdpMissingSpace[] =
3216 "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:363217 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB";
henrika@webrtc.orgaebb1ad2014-01-14 10:00:583218 // MD5 is not allowed in fingerprints.
Yves Gerey665174f2018-06-19 13:03:053219 const char kSdpMd5[] =
3220 "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:583221 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:363222
3223 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:093224 ExpectParseFailure("v=", kSdpDestroyer);
3225 ExpectParseFailure("o=", kSdpDestroyer);
3226 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:363227 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:093228 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:363229
3230 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:093231 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
3232 ExpectParseFailure("m=video", kSdpDestroyer);
Philipp Hanckeefc55b02020-06-26 08:17:053233 ExpectParseFailure("m=", "c=IN IP4 74.125.224.39");
henrike@webrtc.org28e20752013-07-10 00:45:363234
3235 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:513236 ExpectParseFailure("a=candidate", kSdpEmptyType);
3237 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
3238 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
3239 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:363240
3241 // Bogus fingerprint replacing a=sendrev. We selected this attribute
3242 // because it's orthogonal to what we are replacing and hence
3243 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:513244 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
3245 ExpectParseFailure("a=sendrecv", kSdpExtraField);
3246 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
3247 ExpectParseFailure("a=sendrecv", kSdpMd5);
3248
3249 // Empty Line
3250 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
3251 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:093252}
3253
3254TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
3255 // ssrc
3256 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-17 01:54:103257 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:093258 // crypto
3259 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
3260 // rtpmap
3261 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
3262 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
3263 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
3264 // candidate
3265 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
3266 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
3267 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
3268 ExpectParseFailure("rport 2346", "rport badvalue");
3269 ExpectParseFailure("rport 2346 generation 2",
3270 "rport 2346 generation badvalue");
3271 // m line
3272 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
3273 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
3274
3275 // bandwidth
3276 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
Yves Gerey665174f2018-06-19 13:03:053277 "b=AS:badvalue\r\n", "b=AS:badvalue");
Philipp Hanckefbbfc022020-07-31 06:30:503278 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", "b=AS\r\n",
3279 "b=AS");
3280 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", "b=AS:\r\n",
3281 "b=AS:");
3282 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3283 "b=AS:12:34\r\n", "b=AS:12:34");
3284
wu@webrtc.org5e760e72014-04-02 23:19:093285 // rtcp-fb
3286 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3287 "a=rtcp-fb:badvalue nack\r\n",
3288 "a=rtcp-fb:badvalue nack");
3289 // extmap
3290 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3291 "a=extmap:badvalue http://example.com\r\n",
3292 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:363293}
3294
3295TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 18:27:413296 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:363297
3298 const char kSdpWithReorderedPlTypesString[] =
3299 "v=0\r\n"
3300 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3301 "s=-\r\n"
3302 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:223303 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
Yves Gerey665174f2018-06-19 13:03:053304 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
3305 // in the map.
henrike@webrtc.org28e20752013-07-10 00:45:363306 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:413307 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:363308
3309 // Deserialize
3310 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
3311
henrike@webrtc.org28e20752013-07-10 00:45:363312 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 23:14:303313 GetFirstAudioContentDescription(jdesc_output.description());
3314 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:363315 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:413316 EXPECT_EQ("ISAC", acd->codecs()[0].name);
3317 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:363318 EXPECT_EQ(104, acd->codecs()[0].id);
3319}
3320
3321TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 18:27:413322 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:363323 CodecParams params;
3324 params.max_ptime = 40;
3325 params.ptime = 30;
3326 params.min_ptime = 10;
3327 params.sprop_stereo = 1;
3328 params.stereo = 1;
3329 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:593330 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:363331 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 20:22:163332 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:363333}
3334
3335TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
3336 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 18:27:413337 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:363338 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 20:22:163339 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:363340}
3341
3342TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
3343 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 18:27:413344 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:363345 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 20:22:163346 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:363347}
3348
3349TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 18:27:413350 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:363351
3352 const char kSdpWithFmtpString[] =
3353 "v=0\r\n"
3354 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3355 "s=-\r\n"
3356 "t=0 0\r\n"
3357 "m=video 3457 RTP/SAVPF 120\r\n"
3358 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 16:21:233359 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3360
3361 // Deserialize
3362 SdpParseError error;
Donald Curtis144d0182015-05-15 20:14:243363 EXPECT_TRUE(
3364 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 16:21:233365
Donald Curtis0e07f922015-05-15 16:21:233366 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 23:14:303367 GetFirstVideoContentDescription(jdesc_output.description());
3368 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 16:21:233369 ASSERT_FALSE(vcd->codecs().empty());
3370 cricket::VideoCodec vp8 = vcd->codecs()[0];
3371 EXPECT_EQ("VP8", vp8.name);
3372 EXPECT_EQ(120, vp8.id);
3373 cricket::CodecParameterMap::iterator found =
3374 vp8.params.find("x-google-min-bitrate");
3375 ASSERT_TRUE(found != vp8.params.end());
3376 EXPECT_EQ(found->second, "10");
3377 found = vp8.params.find("x-google-max-quantization");
3378 ASSERT_TRUE(found != vp8.params.end());
3379 EXPECT_EQ(found->second, "40");
3380}
3381
johan2d8d23e2016-06-03 08:22:423382TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 18:27:413383 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 08:22:423384
3385 const char kSdpWithFmtpString[] =
3386 "v=0\r\n"
3387 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3388 "s=-\r\n"
3389 "t=0 0\r\n"
3390 "m=video 49170 RTP/AVP 98\r\n"
3391 "a=rtpmap:98 H264/90000\r\n"
3392 "a=fmtp:98 profile-level-id=42A01E; "
3393 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3394
3395 // Deserialize.
3396 SdpParseError error;
3397 EXPECT_TRUE(
3398 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3399
johan2d8d23e2016-06-03 08:22:423400 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 23:14:303401 GetFirstVideoContentDescription(jdesc_output.description());
3402 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 08:22:423403 ASSERT_FALSE(vcd->codecs().empty());
3404 cricket::VideoCodec h264 = vcd->codecs()[0];
3405 EXPECT_EQ("H264", h264.name);
3406 EXPECT_EQ(98, h264.id);
3407 cricket::CodecParameterMap::const_iterator found =
3408 h264.params.find("profile-level-id");
3409 ASSERT_TRUE(found != h264.params.end());
3410 EXPECT_EQ(found->second, "42A01E");
3411 found = h264.params.find("sprop-parameter-sets");
3412 ASSERT_TRUE(found != h264.params.end());
3413 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3414}
3415
Donald Curtis0e07f922015-05-15 16:21:233416TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 18:27:413417 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 16:21:233418
3419 const char kSdpWithFmtpString[] =
3420 "v=0\r\n"
3421 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3422 "s=-\r\n"
3423 "t=0 0\r\n"
3424 "m=video 3457 RTP/SAVPF 120\r\n"
3425 "a=rtpmap:120 VP8/90000\r\n"
3426 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:363427
3428 // Deserialize
3429 SdpParseError error;
Yves Gerey665174f2018-06-19 13:03:053430 EXPECT_TRUE(
3431 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:363432
henrike@webrtc.org28e20752013-07-10 00:45:363433 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 23:14:303434 GetFirstVideoContentDescription(jdesc_output.description());
3435 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:363436 ASSERT_FALSE(vcd->codecs().empty());
3437 cricket::VideoCodec vp8 = vcd->codecs()[0];
3438 EXPECT_EQ("VP8", vp8.name);
3439 EXPECT_EQ(120, vp8.id);
3440 cricket::CodecParameterMap::iterator found =
3441 vp8.params.find("x-google-min-bitrate");
3442 ASSERT_TRUE(found != vp8.params.end());
3443 EXPECT_EQ(found->second, "10");
3444 found = vp8.params.find("x-google-max-quantization");
3445 ASSERT_TRUE(found != vp8.params.end());
3446 EXPECT_EQ(found->second, "40");
3447}
3448
Mirta Dvornicic479a3c02019-06-04 13:38:503449TEST_F(WebRtcSdpTest, DeserializePacketizationAttributeWithIllegalValue) {
3450 JsepSessionDescription jdesc_output(kDummyType);
3451
3452 const char kSdpWithPacketizationString[] =
3453 "v=0\r\n"
3454 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3455 "s=-\r\n"
3456 "t=0 0\r\n"
3457 "m=audio 9 RTP/SAVPF 111\r\n"
3458 "a=rtpmap:111 opus/48000/2\r\n"
3459 "a=packetization:111 unknownpacketizationattributeforaudio\r\n"
3460 "m=video 3457 RTP/SAVPF 120 121 122\r\n"
3461 "a=rtpmap:120 VP8/90000\r\n"
3462 "a=packetization:120 raw\r\n"
3463 "a=rtpmap:121 VP9/90000\r\n"
3464 "a=rtpmap:122 H264/90000\r\n"
3465 "a=packetization:122 unknownpacketizationattributevalue\r\n";
3466
3467 SdpParseError error;
3468 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithPacketizationString, &jdesc_output,
3469 &error));
3470
3471 AudioContentDescription* acd =
3472 GetFirstAudioContentDescription(jdesc_output.description());
3473 ASSERT_TRUE(acd);
3474 ASSERT_THAT(acd->codecs(), testing::SizeIs(1));
3475 cricket::AudioCodec opus = acd->codecs()[0];
3476 EXPECT_EQ(opus.name, "opus");
3477 EXPECT_EQ(opus.id, 111);
3478
3479 const VideoContentDescription* vcd =
3480 GetFirstVideoContentDescription(jdesc_output.description());
3481 ASSERT_TRUE(vcd);
3482 ASSERT_THAT(vcd->codecs(), testing::SizeIs(3));
3483 cricket::VideoCodec vp8 = vcd->codecs()[0];
3484 EXPECT_EQ(vp8.name, "VP8");
3485 EXPECT_EQ(vp8.id, 120);
3486 EXPECT_EQ(vp8.packetization, "raw");
3487 cricket::VideoCodec vp9 = vcd->codecs()[1];
3488 EXPECT_EQ(vp9.name, "VP9");
3489 EXPECT_EQ(vp9.id, 121);
3490 EXPECT_EQ(vp9.packetization, absl::nullopt);
3491 cricket::VideoCodec h264 = vcd->codecs()[2];
3492 EXPECT_EQ(h264.name, "H264");
3493 EXPECT_EQ(h264.id, 122);
3494 EXPECT_EQ(h264.packetization, absl::nullopt);
3495}
3496
ossuaa4b0772017-01-30 15:41:183497TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 23:14:303498 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 15:41:183499
3500 cricket::AudioCodecs codecs = acd->codecs();
3501 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3502 acd->set_codecs(codecs);
3503
Harald Alvestrand4d7160e2019-04-12 05:01:293504 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 15:41:183505 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 20:22:163506 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 15:41:183507 std::string sdp_with_fmtp = kSdpFullString;
3508 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3509 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3510 &sdp_with_fmtp);
3511 EXPECT_EQ(sdp_with_fmtp, message);
3512}
3513
3514TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 23:14:303515 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 15:41:183516
3517 cricket::AudioCodecs codecs = acd->codecs();
3518 codecs[0].params["stereo"] = "1";
3519 acd->set_codecs(codecs);
3520
Harald Alvestrand4d7160e2019-04-12 05:01:293521 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 15:41:183522 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 20:22:163523 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 15:41:183524 std::string sdp_with_fmtp = kSdpFullString;
Yves Gerey665174f2018-06-19 13:03:053525 InjectAfter("a=rtpmap:111 opus/48000/2\r\n", "a=fmtp:111 stereo=1\r\n",
ossuaa4b0772017-01-30 15:41:183526 &sdp_with_fmtp);
3527 EXPECT_EQ(sdp_with_fmtp, message);
3528}
3529
3530TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 23:14:303531 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 15:41:183532
3533 cricket::AudioCodecs codecs = acd->codecs();
3534 codecs[0].params["ptime"] = "20";
3535 codecs[0].params["maxptime"] = "120";
3536 acd->set_codecs(codecs);
3537
Harald Alvestrand4d7160e2019-04-12 05:01:293538 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 15:41:183539 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 20:22:163540 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 15:41:183541 std::string sdp_with_fmtp = kSdpFullString;
3542 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3543 "a=maxptime:120\r\n" // No comma here. String merging!
3544 "a=ptime:20\r\n",
3545 &sdp_with_fmtp);
3546 EXPECT_EQ(sdp_with_fmtp, message);
3547}
3548
Philipp Hanckef2a4ec12020-07-01 19:07:323549TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithTelephoneEvent) {
3550 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
3551
3552 cricket::AudioCodecs codecs = acd->codecs();
3553 cricket::AudioCodec dtmf(105, "telephone-event", 8000, 0, 1);
3554 dtmf.params[""] = "0-15";
3555 codecs.push_back(dtmf);
3556 acd->set_codecs(codecs);
3557
3558 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
3559 jdesc_.session_version()));
3560 std::string message = webrtc::SdpSerialize(jdesc_);
3561 std::string sdp_with_fmtp = kSdpFullString;
3562 InjectAfter("m=audio 2345 RTP/SAVPF 111 103 104", " 105", &sdp_with_fmtp);
3563 InjectAfter(
3564 "a=rtpmap:104 ISAC/32000\r\n",
3565 "a=rtpmap:105 telephone-event/8000\r\n" // No comma here. String merging!
3566 "a=fmtp:105 0-15\r\n",
3567 &sdp_with_fmtp);
3568 EXPECT_EQ(sdp_with_fmtp, message);
3569}
3570
henrike@webrtc.org28e20752013-07-10 00:45:363571TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 23:14:303572 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:363573
3574 cricket::VideoCodecs codecs = vcd->codecs();
3575 codecs[0].params["x-google-min-bitrate"] = "10";
3576 vcd->set_codecs(codecs);
3577
Harald Alvestrand4d7160e2019-04-12 05:01:293578 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:363579 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 20:22:163580 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:363581 std::string sdp_with_fmtp = kSdpFullString;
3582 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
Yves Gerey665174f2018-06-19 13:03:053583 "a=fmtp:120 x-google-min-bitrate=10\r\n", &sdp_with_fmtp);
henrike@webrtc.org28e20752013-07-10 00:45:363584 EXPECT_EQ(sdp_with_fmtp, message);
3585}
3586
Mirta Dvornicic479a3c02019-06-04 13:38:503587TEST_F(WebRtcSdpTest, SerializeVideoPacketizationAttribute) {
3588 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
3589
3590 cricket::VideoCodecs codecs = vcd->codecs();
3591 codecs[0].packetization = "raw";
3592 vcd->set_codecs(codecs);
3593
3594 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
3595 jdesc_.session_version()));
3596 std::string message = webrtc::SdpSerialize(jdesc_);
3597 std::string sdp_with_packetization = kSdpFullString;
3598 InjectAfter("a=rtpmap:120 VP8/90000\r\n", "a=packetization:120 raw\r\n",
3599 &sdp_with_packetization);
3600 EXPECT_EQ(sdp_with_packetization, message);
3601}
3602
Taylor Brandstetter2f65ec52018-05-24 18:37:283603TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) {
3604 // Deserialize the baseline description, making sure it's ICE full.
Steve Antona3a92c22017-12-07 18:27:413605 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:363606 std::string sdp_with_icelite = kSdpFullString;
3607 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3608 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3609 const cricket::TransportInfo* tinfo1 =
3610 desc->GetTransportInfoByName("audio_content_name");
3611 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3612 const cricket::TransportInfo* tinfo2 =
3613 desc->GetTransportInfoByName("video_content_name");
3614 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 18:37:283615
3616 // Add "a=ice-lite" and deserialize, making sure it's ICE lite.
Yves Gerey665174f2018-06-19 13:03:053617 InjectAfter(kSessionTime, "a=ice-lite\r\n", &sdp_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:363618 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3619 desc = jdesc_with_icelite.description();
3620 const cricket::TransportInfo* atinfo =
3621 desc->GetTransportInfoByName("audio_content_name");
3622 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3623 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 13:03:053624 desc->GetTransportInfoByName("video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:363625 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 18:37:283626
3627 // Now that we know deserialization works, we can use TestSerialize to test
3628 // serialization.
3629 TestSerialize(jdesc_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:363630}
3631
3632// Verifies that the candidates in the input SDP are parsed and serialized
3633// correctly in the output SDP.
3634TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3635 std::string sdp_with_data = kSdpString;
3636 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 18:27:413637 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:363638
3639 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 20:22:163640 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:363641}
sergeyu@chromium.org0be6aa02013-08-23 23:21:253642
3643TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3644 AddFingerprint();
3645 TransportInfo audio_transport_info =
3646 *(desc_.GetTransportInfoByName(kAudioContentName));
3647 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3648 audio_transport_info.description.connection_role);
3649 audio_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 13:03:053650 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:253651
3652 TransportInfo video_transport_info =
3653 *(desc_.GetTransportInfoByName(kVideoContentName));
3654 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3655 video_transport_info.description.connection_role);
3656 video_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 13:03:053657 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:253658
3659 desc_.RemoveTransportInfoByName(kAudioContentName);
3660 desc_.RemoveTransportInfoByName(kVideoContentName);
3661
3662 desc_.AddTransportInfo(audio_transport_info);
3663 desc_.AddTransportInfo(video_transport_info);
3664
Harald Alvestrand4d7160e2019-04-12 05:01:293665 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
sergeyu@chromium.org0be6aa02013-08-23 23:21:253666 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 20:22:163667 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:253668 std::string sdp_with_dtlssetup = kSdpFullString;
3669
3670 // Fingerprint attribute is necessary to add DTLS setup attribute.
Yves Gerey665174f2018-06-19 13:03:053671 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_dtlssetup);
3672 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:253673 // Now adding |setup| attribute.
Yves Gerey665174f2018-06-19 13:03:053674 InjectAfter(kFingerprint, "a=setup:active\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:253675 EXPECT_EQ(sdp_with_dtlssetup, message);
3676}
3677
3678TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
Steve Antona3a92c22017-12-07 18:27:413679 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:253680 std::string sdp_with_dtlssetup = kSdpFullString;
Yves Gerey665174f2018-06-19 13:03:053681 InjectAfter(kSessionTime, "a=setup:actpass\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:253682 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3683 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3684 const cricket::TransportInfo* atinfo =
3685 desc->GetTransportInfoByName("audio_content_name");
3686 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3687 atinfo->description.connection_role);
3688 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 13:03:053689 desc->GetTransportInfoByName("video_content_name");
sergeyu@chromium.org0be6aa02013-08-23 23:21:253690 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3691 vtinfo->description.connection_role);
3692}
jiayl@webrtc.orge7d47a12014-08-05 19:19:053693
3694// Verifies that the order of the serialized m-lines follows the order of the
3695// ContentInfo in SessionDescription, and vise versa for deserialization.
3696TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 18:27:413697 JsepSessionDescription jdesc(kDummyType);
Yves Gerey665174f2018-06-19 13:03:053698 const std::string media_content_sdps[3] = {kSdpAudioString, kSdpVideoString,
3699 kSdpSctpDataChannelString};
3700 const cricket::MediaType media_types[3] = {cricket::MEDIA_TYPE_AUDIO,
3701 cricket::MEDIA_TYPE_VIDEO,
3702 cricket::MEDIA_TYPE_DATA};
jiayl@webrtc.orge7d47a12014-08-05 19:19:053703
3704 // Verifies all 6 permutations.
3705 for (size_t i = 0; i < 6; ++i) {
3706 size_t media_content_in_sdp[3];
3707 // The index of the first media content.
3708 media_content_in_sdp[0] = i / 2;
3709 // The index of the second media content.
3710 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3711 // The index of the third media content.
3712 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3713
3714 std::string sdp_string = kSdpSessionString;
3715 for (size_t i = 0; i < 3; ++i)
3716 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3717
3718 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3719 cricket::SessionDescription* desc = jdesc.description();
3720 EXPECT_EQ(3u, desc->contents().size());
3721
3722 for (size_t i = 0; i < 3; ++i) {
3723 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 23:14:303724 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:053725 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3726 }
3727
Steve Antone831b8c2018-02-01 20:22:163728 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:053729 EXPECT_EQ(sdp_string, serialized_sdp);
3730 }
3731}
deadbeef9d3584c2016-02-17 01:54:103732
deadbeef25ed4352016-12-13 02:37:363733TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3734 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 18:27:413735 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 21:53:473736 ASSERT_TRUE(
deadbeef25ed4352016-12-13 02:37:363737 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3738 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3739}
3740
deadbeef12771a12017-01-03 21:53:473741// The semantics of "a=bundle-only" are only defined when it's used in
3742// combination with a 0 port on the m= line. We should ignore it if used with a
3743// nonzero port.
3744TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3745 // Make the base bundle-only description but unset the bundle-only flag.
3746 MakeBundleOnlyDescription();
3747 jdesc_.description()->contents()[1].bundle_only = false;
3748
3749 std::string modified_sdp = kBundleOnlySdpFullString;
3750 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 18:27:413751 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 21:53:473752 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3753 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-13 02:37:363754}
3755
3756TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3757 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 20:22:163758 TestSerialize(jdesc_);
deadbeef25ed4352016-12-13 02:37:363759}
3760
deadbeef9d3584c2016-02-17 01:54:103761TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3762 MakePlanBDescription();
3763
Steve Antona3a92c22017-12-07 18:27:413764 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-17 01:54:103765 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3766
3767 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3768}
3769
3770TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3771 MakePlanBDescription();
Steve Antone831b8c2018-02-01 20:22:163772 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-17 01:54:103773}
3774
3775TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3776 MakeUnifiedPlanDescription();
3777
Steve Antona3a92c22017-12-07 18:27:413778 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-17 01:54:103779 EXPECT_TRUE(
3780 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3781
3782 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3783}
3784
3785TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3786 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 20:22:163787 TestSerialize(jdesc_);
3788}
3789
Seth Hampson5b4f0752018-04-02 23:31:363790// This tests deserializing a Unified Plan SDP that is compatible with both
Seth Hampson7fa6ee62018-10-17 17:25:283791// Unified Plan and Plan B style SDP, meaning that it contains both "a=ssrc
3792// msid" lines and "a=msid " lines. It tests the case for audio/video tracks
Seth Hampson5b4f0752018-04-02 23:31:363793// with no stream ids and multiple stream ids. For parsing this, the Unified
3794// Plan a=msid lines should take priority, because the Plan B style a=ssrc msid
3795// lines do not support multiple stream ids and no stream ids.
Seth Hampson7fa6ee62018-10-17 17:25:283796TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionSpecialMsid) {
3797 // Create both msid lines for Plan B and Unified Plan support.
3798 MakeUnifiedPlanDescriptionMultipleStreamIds(
3799 cricket::kMsidSignalingMediaSection |
3800 cricket::kMsidSignalingSsrcAttribute);
Seth Hampson5b4f0752018-04-02 23:31:363801
3802 JsepSessionDescription deserialized_description(kDummyType);
3803 EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid,
3804 &deserialized_description));
3805
3806 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
Henrik Boström5b147782018-12-04 10:25:053807 EXPECT_EQ(cricket::kMsidSignalingMediaSection |
3808 cricket::kMsidSignalingSsrcAttribute,
3809 deserialized_description.description()->msid_signaling());
Seth Hampson5b4f0752018-04-02 23:31:363810}
3811
Seth Hampson7fa6ee62018-10-17 17:25:283812// Tests the serialization of a Unified Plan SDP that is compatible for both
3813// Unified Plan and Plan B style SDPs, meaning that it contains both "a=ssrc
3814// msid" lines and "a=msid " lines. It tests the case for no stream ids and
3815// multiple stream ids.
3816TEST_F(WebRtcSdpTest, SerializeSessionDescriptionSpecialMsid) {
3817 // Create both msid lines for Plan B and Unified Plan support.
3818 MakeUnifiedPlanDescriptionMultipleStreamIds(
3819 cricket::kMsidSignalingMediaSection |
3820 cricket::kMsidSignalingSsrcAttribute);
3821 std::string serialized_sdp = webrtc::SdpSerialize(jdesc_);
3822 // We explicitly test that the serialized SDP string is equal to the hard
3823 // coded SDP string. This is necessary, because in the parser "a=msid" lines
3824 // take priority over "a=ssrc msid" lines. This means if we just used
3825 // TestSerialize(), it could serialize an SDP that omits "a=ssrc msid" lines,
3826 // and still pass, because the deserialized version would be the same.
3827 EXPECT_EQ(kUnifiedPlanSdpFullStringWithSpecialMsid, serialized_sdp);
3828}
3829
3830// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3831// that signal stream IDs) is deserialized appropriately. It tests the case for
3832// no stream ids and multiple stream ids.
3833TEST_F(WebRtcSdpTest, UnifiedPlanDeserializeSessionDescriptionSpecialMsid) {
3834 // Only create a=msid lines for strictly Unified Plan stream ID support.
3835 MakeUnifiedPlanDescriptionMultipleStreamIds(
3836 cricket::kMsidSignalingMediaSection);
3837
3838 JsepSessionDescription deserialized_description(kDummyType);
3839 std::string unified_plan_sdp_string =
3840 kUnifiedPlanSdpFullStringWithSpecialMsid;
3841 RemoveSsrcMsidLinesFromSdpString(&unified_plan_sdp_string);
3842 EXPECT_TRUE(
3843 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3844
3845 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3846}
3847
3848// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3849// that signal stream IDs) is serialized appropriately. It tests the case for no
3850// stream ids and multiple stream ids.
3851TEST_F(WebRtcSdpTest, UnifiedPlanSerializeSessionDescriptionSpecialMsid) {
3852 // Only create a=msid lines for strictly Unified Plan stream ID support.
3853 MakeUnifiedPlanDescriptionMultipleStreamIds(
3854 cricket::kMsidSignalingMediaSection);
3855
Seth Hampson5b4f0752018-04-02 23:31:363856 TestSerialize(jdesc_);
3857}
3858
Seth Hampson5897a6e2018-04-03 18:16:333859// This tests that a Unified Plan SDP with no a=ssrc lines is
3860// serialized/deserialized appropriately. In this case the
3861// MediaContentDescription will contain a StreamParams object that doesn't have
3862// any SSRCs. Vice versa, this will be created upon deserializing an SDP with no
3863// SSRC lines.
3864TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3865 MakeUnifiedPlanDescription();
3866 RemoveSsrcSignalingFromStreamParams();
3867 std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString;
3868 RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string);
3869
3870 JsepSessionDescription deserialized_description(kDummyType);
3871 EXPECT_TRUE(
3872 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3873 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3874}
3875
3876TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3877 MakeUnifiedPlanDescription();
3878 RemoveSsrcSignalingFromStreamParams();
3879
3880 TestSerialize(jdesc_);
3881}
3882
Steve Antone831b8c2018-02-01 20:22:163883TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
3884 JsepSessionDescription jsep_desc(kDummyType);
3885 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
3886 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3887}
3888
3889TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
3890 JsepSessionDescription jsep_desc(kDummyType);
3891 std::string sdp = kSdpSessionString;
3892 sdp += kSdpSctpDataChannelString;
3893 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3894 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3895}
3896
3897TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
3898 JsepSessionDescription jsep_desc(kDummyType);
3899 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
3900 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
3901 jsep_desc.description()->msid_signaling());
3902}
3903
3904TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
3905 JsepSessionDescription jsep_desc(kDummyType);
3906 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
3907 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
3908 jsep_desc.description()->msid_signaling());
3909}
3910
3911const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
3912const char kSsrcAttributeMsidLine[] =
3913 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
3914
3915TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
3916 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
3917 std::string sdp = webrtc::SdpSerialize(jdesc_);
3918
3919 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3920 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3921}
3922
3923TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
3924 jdesc_.description()->set_msid_signaling(
3925 cricket::kMsidSignalingSsrcAttribute);
3926 std::string sdp = webrtc::SdpSerialize(jdesc_);
3927
3928 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
3929 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3930}
3931
3932TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
3933 jdesc_.description()->set_msid_signaling(
3934 cricket::kMsidSignalingMediaSection |
3935 cricket::kMsidSignalingSsrcAttribute);
3936 std::string sdp = webrtc::SdpSerialize(jdesc_);
3937
3938 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3939 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-17 01:54:103940}
deadbeef7e146cb2016-09-28 17:04:343941
deadbeefb2362572016-12-14 00:37:063942// Regression test for integer overflow bug:
3943// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3944TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-14 00:37:063945 // Bandwidth attribute is the max signed 32-bit int, which will get
3946 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 20:43:583947 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-14 00:37:063948 "v=0\r\n"
3949 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3950 "s=-\r\n"
3951 "t=0 0\r\n"
3952 "m=video 3457 RTP/SAVPF 120\r\n"
3953 "b=AS:2147483647\r\n"
3954 "foo=fail\r\n";
3955
3956 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3957}
deadbeef7bcdb692017-01-20 20:43:583958
deadbeefbc88c6b2017-08-02 18:26:343959// Similar to the above, except that negative values are illegal, not just
3960// error-prone as large values are.
3961// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3962TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3963 static const char kSdpWithNegativeBandwidth[] =
3964 "v=0\r\n"
3965 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3966 "s=-\r\n"
3967 "t=0 0\r\n"
3968 "m=video 3457 RTP/SAVPF 120\r\n"
3969 "b=AS:-1000\r\n";
3970
3971 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3972}
3973
deadbeef3e8016e2017-08-04 00:49:303974// An exception to the above rule: a value of -1 for b=AS should just be
3975// ignored, resulting in "kAutoBandwidth" in the deserialized object.
3976// Applications historically may be using "b=AS:-1" to mean "no bandwidth
3977// limit", but this is now what ommitting the attribute entirely will do, so
3978// ignoring it will have the intended effect.
3979TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
3980 static const char kSdpWithBandwidthOfNegativeOne[] =
3981 "v=0\r\n"
3982 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3983 "s=-\r\n"
3984 "t=0 0\r\n"
3985 "m=video 3457 RTP/SAVPF 120\r\n"
3986 "b=AS:-1\r\n";
3987
Steve Antona3a92c22017-12-07 18:27:413988 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-04 00:49:303989 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-04 00:49:303990 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 23:14:303991 GetFirstVideoContentDescription(jdesc_output.description());
3992 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-04 00:49:303993 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
3994}
3995
deadbeef7bcdb692017-01-20 20:43:583996// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3997// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3998// Regression test for:
3999// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
4000TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
4001 // Important piece is "ufrag foo pwd bar".
4002 static const char kSdpWithIceCredentialsInCandidateString[] =
4003 "v=0\r\n"
4004 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4005 "s=-\r\n"
4006 "t=0 0\r\n"
4007 "m=audio 9 RTP/SAVPF 111\r\n"
4008 "c=IN IP4 0.0.0.0\r\n"
4009 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4010 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4011 "a=rtpmap:111 opus/48000/2\r\n"
4012 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
4013 "generation 2 ufrag foo pwd bar\r\n";
4014
Steve Antona3a92c22017-12-07 18:27:414015 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 20:43:584016 EXPECT_TRUE(
4017 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
4018 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
4019 ASSERT_NE(nullptr, candidates);
Mirko Bonadeie12c1fe2018-07-03 10:53:234020 ASSERT_EQ(1U, candidates->count());
deadbeef7bcdb692017-01-20 20:43:584021 cricket::Candidate c = candidates->at(0)->candidate();
4022 EXPECT_EQ("ufrag_voice", c.username());
4023 EXPECT_EQ("pwd_voice", c.password());
4024}
deadbeef90f1e1e2017-02-10 20:35:054025
Johannes Kron211856b2018-09-06 10:12:284026// Test that attribute lines "a=ice-ufrag-something"/"a=ice-pwd-something" are
4027// ignored, and only the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
4028// Regression test for:
4029// https://bugs.chromium.org/p/webrtc/issues/detail?id=9712
4030TEST_F(WebRtcSdpTest, AttributeWithPartialMatchingNameIsIgnored) {
4031 static const char kSdpWithFooIceCredentials[] =
4032 "v=0\r\n"
4033 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4034 "s=-\r\n"
4035 "t=0 0\r\n"
4036 "m=audio 9 RTP/SAVPF 111\r\n"
4037 "c=IN IP4 0.0.0.0\r\n"
4038 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4039 "a=ice-ufrag-something:foo\r\na=ice-pwd-something:bar\r\n"
4040 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4041 "a=rtpmap:111 opus/48000/2\r\n"
4042 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
4043 "generation 2\r\n";
4044
4045 JsepSessionDescription jdesc_output(kDummyType);
4046 EXPECT_TRUE(SdpDeserialize(kSdpWithFooIceCredentials, &jdesc_output));
4047 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
4048 ASSERT_NE(nullptr, candidates);
4049 ASSERT_EQ(1U, candidates->count());
4050 cricket::Candidate c = candidates->at(0)->candidate();
4051 EXPECT_EQ("ufrag_voice", c.username());
4052 EXPECT_EQ("pwd_voice", c.password());
4053}
4054
deadbeef90f1e1e2017-02-10 20:35:054055// Test that SDP with an invalid port number in "a=candidate" lines is
4056// rejected, without crashing.
4057// Regression test for:
4058// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
4059TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
4060 static const char kSdpWithInvalidCandidatePort[] =
4061 "v=0\r\n"
4062 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4063 "s=-\r\n"
4064 "t=0 0\r\n"
4065 "m=audio 9 RTP/SAVPF 111\r\n"
4066 "c=IN IP4 0.0.0.0\r\n"
4067 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4068 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4069 "a=rtpmap:111 opus/48000/2\r\n"
4070 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
4071 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
4072
Steve Antona3a92c22017-12-07 18:27:414073 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 20:35:054074 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
4075}
deadbeefa4549d62017-02-11 01:26:224076
4077// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
4078// Regression test for:
4079// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
4080TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
4081 static const char kSdpWithMissingTrackId[] =
4082 "v=0\r\n"
4083 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4084 "s=-\r\n"
4085 "t=0 0\r\n"
4086 "m=audio 9 RTP/SAVPF 111\r\n"
4087 "c=IN IP4 0.0.0.0\r\n"
4088 "a=rtpmap:111 opus/48000/2\r\n"
4089 "a=msid:stream_id \r\n";
4090
Steve Antona3a92c22017-12-07 18:27:414091 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-11 01:26:224092 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
4093}
4094
4095TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
4096 static const char kSdpWithMissingStreamId[] =
4097 "v=0\r\n"
4098 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4099 "s=-\r\n"
4100 "t=0 0\r\n"
4101 "m=audio 9 RTP/SAVPF 111\r\n"
4102 "c=IN IP4 0.0.0.0\r\n"
4103 "a=rtpmap:111 opus/48000/2\r\n"
4104 "a=msid: track_id\r\n";
4105
Steve Antona3a92c22017-12-07 18:27:414106 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-11 01:26:224107 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
4108}
zhihuang38989e52017-03-21 18:04:534109
4110// Tests that if both session-level address and media-level address exist, use
4111// the media-level address.
4112TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 18:27:414113 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 18:04:534114
4115 // Sesssion-level address.
4116 std::string sdp = kSdpFullString;
4117 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
4118 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4119
4120 const auto& content1 = jsep_desc.description()->contents()[0];
4121 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 23:14:304122 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 18:04:534123 const auto& content2 = jsep_desc.description()->contents()[1];
4124 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 23:14:304125 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 18:04:534126}
4127
4128// Tests that the session-level connection address will be used if the media
4129// level-addresses are not specified.
4130TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 18:27:414131 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 18:04:534132
4133 // Sesssion-level address.
4134 std::string sdp = kSdpString;
4135 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
4136 // Remove the media level addresses.
4137 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
4138 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
4139 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4140
4141 const auto& content1 = jsep_desc.description()->contents()[0];
4142 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 23:14:304143 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 18:04:534144 const auto& content2 = jsep_desc.description()->contents()[1];
4145 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 23:14:304146 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 18:04:534147}
4148
4149TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 18:27:414150 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 18:04:534151
4152 std::string sdp = kSdpString;
4153 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4154 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
4155 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
4156 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
4157 &sdp);
4158 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
4159 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
4160 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
4161 &sdp);
4162 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4163 const auto& content1 = jsep_desc.description()->contents()[0];
4164 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 23:14:304165 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 18:04:534166 const auto& content2 = jsep_desc.description()->contents()[1];
4167 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 23:14:304168 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 18:04:534169}
4170
Qingsi Wang56991422019-02-08 20:53:064171// Test that a c= line that contains a hostname connection address can be
4172// parsed.
4173TEST_F(WebRtcSdpTest, ParseConnectionDataWithHostnameConnectionAddress) {
4174 JsepSessionDescription jsep_desc(kDummyType);
4175 std::string sdp = kSdpString;
4176 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4177
4178 sdp = kSdpString;
4179 Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp);
4180 Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp);
4181 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4182
4183 ASSERT_NE(nullptr, jsep_desc.description());
4184 const auto& content1 = jsep_desc.description()->contents()[0];
4185 EXPECT_EQ("example.local:9",
4186 content1.media_description()->connection_address().ToString());
4187 const auto& content2 = jsep_desc.description()->contents()[1];
4188 EXPECT_EQ("example.local:9",
4189 content2.media_description()->connection_address().ToString());
4190}
4191
4192// Test that the invalid or unsupported connection data cannot be parsed.
zhihuang38989e52017-03-21 18:04:534193TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 18:27:414194 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 18:04:534195 std::string sdp = kSdpString;
4196 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4197
4198 // Unsupported multicast IPv4 address.
4199 sdp = kSdpFullString;
4200 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
4201 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4202
4203 // Unsupported multicast IPv6 address.
4204 sdp = kSdpFullString;
4205 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
4206 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4207
4208 // Mismatched address type.
4209 sdp = kSdpFullString;
4210 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
4211 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4212
4213 sdp = kSdpFullString;
4214 Replace("c=IN IP4 74.125.224.39\r\n",
4215 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
4216 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4217}
4218
4219TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 18:27:414220 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 18:04:534221 MakeDescriptionWithoutCandidates(&expected_jsep);
4222 // Serialization.
Steve Antone831b8c2018-02-01 20:22:164223 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 18:04:534224 // Deserialization.
Steve Antona3a92c22017-12-07 18:27:414225 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 18:04:534226 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 23:14:304227 auto audio_desc = jdesc.description()
4228 ->GetContentByName(kAudioContentName)
4229 ->media_description();
4230 auto video_desc = jdesc.description()
4231 ->GetContentByName(kVideoContentName)
4232 ->media_description();
zhihuang38989e52017-03-21 18:04:534233 EXPECT_EQ(audio_desc_->connection_address().ToString(),
4234 audio_desc->connection_address().ToString());
4235 EXPECT_EQ(video_desc_->connection_address().ToString(),
4236 video_desc->connection_address().ToString());
4237}
Taylor Brandstetter93a7b242018-04-16 17:45:244238
4239// RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be
4240// used (i.e., a single space as the session name)." So we should accept that.
4241TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) {
4242 JsepSessionDescription jsep_desc(kDummyType);
4243 std::string sdp = kSdpString;
4244 Replace("s=-\r\n", "s= \r\n", &sdp);
4245 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4246}
Amit Hilbucha2012042018-12-03 19:35:054247
4248// Simulcast malformed input test for invalid format.
4249TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_EmptyAttribute) {
Artem Titovf0a34f22020-03-16 17:52:044250 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
4251 "a=simulcast:\r\n", "a=simulcast:");
Amit Hilbucha2012042018-12-03 19:35:054252}
4253
4254// Tests that duplicate simulcast entries in the SDP triggers a parse failure.
4255TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_DuplicateAttribute) {
Artem Titovf0a34f22020-03-16 17:52:044256 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
4257 "a=simulcast:send 1\r\na=simulcast:recv 2\r\n",
4258 "a=simulcast:");
Amit Hilbucha2012042018-12-03 19:35:054259}
4260
4261// Validates that deserialization uses the a=simulcast: attribute
4262TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttribute) {
Amit Hilbuchc57d5732018-12-11 23:30:114263 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4264 sdp += "a=rid:1 send\r\n";
4265 sdp += "a=rid:2 send\r\n";
4266 sdp += "a=rid:3 send\r\n";
4267 sdp += "a=rid:4 recv\r\n";
4268 sdp += "a=rid:5 recv\r\n";
4269 sdp += "a=rid:6 recv\r\n";
Amit Hilbucha2012042018-12-03 19:35:054270 sdp += "a=simulcast:send 1,2;3 recv 4;5;6\r\n";
4271 JsepSessionDescription output(kDummyType);
4272 SdpParseError error;
4273 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4274 const cricket::ContentInfos& contents = output.description()->contents();
4275 const cricket::MediaContentDescription* media =
4276 contents.back().media_description();
4277 EXPECT_TRUE(media->HasSimulcast());
4278 EXPECT_EQ(2ul, media->simulcast_description().send_layers().size());
4279 EXPECT_EQ(3ul, media->simulcast_description().receive_layers().size());
Amit Hilbuchc57d5732018-12-11 23:30:114280 EXPECT_FALSE(media->streams().empty());
4281 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4282 CompareRidDescriptionIds(rids, {"1", "2", "3"});
Amit Hilbuchc57d5732018-12-11 23:30:114283}
4284
4285// Validates that deserialization removes rids that do not appear in SDP
4286TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttributeRemovesUnknownRids) {
4287 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4288 sdp += "a=rid:1 send\r\n";
4289 sdp += "a=rid:3 send\r\n";
4290 sdp += "a=rid:4 recv\r\n";
4291 sdp += "a=simulcast:send 1,2;3 recv 4;5,6\r\n";
4292 JsepSessionDescription output(kDummyType);
4293 SdpParseError error;
4294 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4295 const cricket::ContentInfos& contents = output.description()->contents();
4296 const cricket::MediaContentDescription* media =
4297 contents.back().media_description();
4298 EXPECT_TRUE(media->HasSimulcast());
4299 const SimulcastDescription& simulcast = media->simulcast_description();
4300 EXPECT_EQ(2ul, simulcast.send_layers().size());
4301 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4302
4303 std::vector<SimulcastLayer> all_send_layers =
4304 simulcast.send_layers().GetAllLayers();
4305 EXPECT_EQ(2ul, all_send_layers.size());
Steve Anton64b626b2019-01-29 01:25:264306 EXPECT_EQ(0,
4307 absl::c_count_if(all_send_layers, [](const SimulcastLayer& layer) {
4308 return layer.rid == "2";
4309 }));
Amit Hilbuchc57d5732018-12-11 23:30:114310
4311 std::vector<SimulcastLayer> all_receive_layers =
4312 simulcast.receive_layers().GetAllLayers();
4313 ASSERT_EQ(1ul, all_receive_layers.size());
4314 EXPECT_EQ("4", all_receive_layers[0].rid);
4315
4316 EXPECT_FALSE(media->streams().empty());
4317 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4318 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 23:30:114319}
4320
4321// Validates that Simulcast removes rids that appear in both send and receive.
4322TEST_F(WebRtcSdpTest,
4323 TestDeserializeSimulcastAttributeRemovesDuplicateSendReceive) {
4324 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4325 sdp += "a=rid:1 send\r\n";
4326 sdp += "a=rid:2 send\r\n";
4327 sdp += "a=rid:3 send\r\n";
4328 sdp += "a=rid:4 recv\r\n";
4329 sdp += "a=simulcast:send 1;2;3 recv 2;4\r\n";
4330 JsepSessionDescription output(kDummyType);
4331 SdpParseError error;
4332 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4333 const cricket::ContentInfos& contents = output.description()->contents();
4334 const cricket::MediaContentDescription* media =
4335 contents.back().media_description();
4336 EXPECT_TRUE(media->HasSimulcast());
4337 const SimulcastDescription& simulcast = media->simulcast_description();
4338 EXPECT_EQ(2ul, simulcast.send_layers().size());
4339 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4340 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4341 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4342
4343 EXPECT_FALSE(media->streams().empty());
4344 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4345 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 23:30:114346}
4347
4348// Ignores empty rid line.
4349TEST_F(WebRtcSdpTest, TestDeserializeIgnoresEmptyRidLines) {
4350 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4351 sdp += "a=rid:1 send\r\n";
4352 sdp += "a=rid:2 send\r\n";
4353 sdp += "a=rid\r\n"; // Should ignore this line.
4354 sdp += "a=rid:\r\n"; // Should ignore this line.
4355 sdp += "a=simulcast:send 1;2\r\n";
4356 JsepSessionDescription output(kDummyType);
4357 SdpParseError error;
4358 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4359 const cricket::ContentInfos& contents = output.description()->contents();
4360 const cricket::MediaContentDescription* media =
4361 contents.back().media_description();
4362 EXPECT_TRUE(media->HasSimulcast());
4363 const SimulcastDescription& simulcast = media->simulcast_description();
4364 EXPECT_TRUE(simulcast.receive_layers().empty());
4365 EXPECT_EQ(2ul, simulcast.send_layers().size());
4366 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4367
4368 EXPECT_FALSE(media->streams().empty());
4369 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4370 CompareRidDescriptionIds(rids, {"1", "2"});
Amit Hilbuchc57d5732018-12-11 23:30:114371}
4372
4373// Ignores malformed rid lines.
4374TEST_F(WebRtcSdpTest, TestDeserializeIgnoresMalformedRidLines) {
4375 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4376 sdp += "a=rid:1 send pt=\r\n"; // Should ignore this line.
4377 sdp += "a=rid:2 receive\r\n"; // Should ignore this line.
4378 sdp += "a=rid:3 max-width=720;pt=120\r\n"; // Should ignore this line.
4379 sdp += "a=rid:4\r\n"; // Should ignore this line.
4380 sdp += "a=rid:5 send\r\n";
4381 sdp += "a=simulcast:send 1,2,3;4,5\r\n";
4382 JsepSessionDescription output(kDummyType);
4383 SdpParseError error;
4384 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4385 const cricket::ContentInfos& contents = output.description()->contents();
4386 const cricket::MediaContentDescription* media =
4387 contents.back().media_description();
4388 EXPECT_TRUE(media->HasSimulcast());
4389 const SimulcastDescription& simulcast = media->simulcast_description();
4390 EXPECT_TRUE(simulcast.receive_layers().empty());
4391 EXPECT_EQ(1ul, simulcast.send_layers().size());
4392 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4393
4394 EXPECT_FALSE(media->streams().empty());
4395 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4396 CompareRidDescriptionIds(rids, {"5"});
Amit Hilbuchc57d5732018-12-11 23:30:114397}
4398
4399// Removes RIDs that specify a different format than the m= section.
4400TEST_F(WebRtcSdpTest, TestDeserializeRemovesRidsWithInvalidCodec) {
4401 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4402 sdp += "a=rid:1 send pt=121,120\r\n"; // Should remove 121 and keep RID.
4403 sdp += "a=rid:2 send pt=121\r\n"; // Should remove RID altogether.
4404 sdp += "a=simulcast:send 1;2\r\n";
4405 JsepSessionDescription output(kDummyType);
4406 SdpParseError error;
4407 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4408 const cricket::ContentInfos& contents = output.description()->contents();
4409 const cricket::MediaContentDescription* media =
4410 contents.back().media_description();
4411 EXPECT_TRUE(media->HasSimulcast());
4412 const SimulcastDescription& simulcast = media->simulcast_description();
4413 EXPECT_TRUE(simulcast.receive_layers().empty());
4414 EXPECT_EQ(1ul, simulcast.send_layers().size());
4415 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4416 EXPECT_EQ("1", simulcast.send_layers()[0][0].rid);
4417 EXPECT_EQ(1ul, media->streams().size());
4418 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4419 EXPECT_EQ(1ul, rids.size());
4420 EXPECT_EQ("1", rids[0].rid);
4421 EXPECT_EQ(1ul, rids[0].payload_types.size());
4422 EXPECT_EQ(120, rids[0].payload_types[0]);
Amit Hilbuchc57d5732018-12-11 23:30:114423}
4424
4425// Ignores duplicate rid lines
4426TEST_F(WebRtcSdpTest, TestDeserializeIgnoresDuplicateRidLines) {
4427 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4428 sdp += "a=rid:1 send\r\n";
4429 sdp += "a=rid:2 send\r\n";
4430 sdp += "a=rid:2 send\r\n";
4431 sdp += "a=rid:3 send\r\n";
4432 sdp += "a=rid:4 recv\r\n";
4433 sdp += "a=simulcast:send 1,2;3 recv 4\r\n";
4434 JsepSessionDescription output(kDummyType);
4435 SdpParseError error;
4436 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4437 const cricket::ContentInfos& contents = output.description()->contents();
4438 const cricket::MediaContentDescription* media =
4439 contents.back().media_description();
4440 EXPECT_TRUE(media->HasSimulcast());
4441 const SimulcastDescription& simulcast = media->simulcast_description();
4442 EXPECT_EQ(2ul, simulcast.send_layers().size());
4443 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4444 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4445 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4446
4447 EXPECT_FALSE(media->streams().empty());
4448 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4449 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbucha2012042018-12-03 19:35:054450}
4451
Florent Castellic4421972019-07-02 18:27:424452TEST_F(WebRtcSdpTest, TestDeserializeRidSendDirection) {
4453 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4454 sdp += "a=rid:1 recv\r\n";
4455 sdp += "a=rid:2 recv\r\n";
4456 sdp += "a=simulcast:send 1;2\r\n";
4457 JsepSessionDescription output(kDummyType);
4458 SdpParseError error;
4459 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4460 const cricket::ContentInfos& contents = output.description()->contents();
4461 const cricket::MediaContentDescription* media =
4462 contents.back().media_description();
4463 EXPECT_FALSE(media->HasSimulcast());
4464}
4465
4466TEST_F(WebRtcSdpTest, TestDeserializeRidRecvDirection) {
4467 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4468 sdp += "a=rid:1 send\r\n";
4469 sdp += "a=rid:2 send\r\n";
4470 sdp += "a=simulcast:recv 1;2\r\n";
4471 JsepSessionDescription output(kDummyType);
4472 SdpParseError error;
4473 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4474 const cricket::ContentInfos& contents = output.description()->contents();
4475 const cricket::MediaContentDescription* media =
4476 contents.back().media_description();
4477 EXPECT_FALSE(media->HasSimulcast());
4478}
4479
4480TEST_F(WebRtcSdpTest, TestDeserializeIgnoresWrongRidDirectionLines) {
4481 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4482 sdp += "a=rid:1 send\r\n";
4483 sdp += "a=rid:2 send\r\n";
4484 sdp += "a=rid:3 send\r\n";
4485 sdp += "a=rid:4 recv\r\n";
4486 sdp += "a=rid:5 recv\r\n";
4487 sdp += "a=rid:6 recv\r\n";
4488 sdp += "a=simulcast:send 1;5;3 recv 4;2;6\r\n";
4489 JsepSessionDescription output(kDummyType);
4490 SdpParseError error;
4491 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4492 const cricket::ContentInfos& contents = output.description()->contents();
4493 const cricket::MediaContentDescription* media =
4494 contents.back().media_description();
4495 EXPECT_TRUE(media->HasSimulcast());
4496 const SimulcastDescription& simulcast = media->simulcast_description();
4497 EXPECT_EQ(2ul, simulcast.send_layers().size());
4498 EXPECT_EQ(2ul, simulcast.receive_layers().size());
4499 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4500 EXPECT_EQ(2ul, simulcast.receive_layers().GetAllLayers().size());
4501
4502 EXPECT_FALSE(media->streams().empty());
4503 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4504 CompareRidDescriptionIds(rids, {"1", "3"});
4505}
4506
Amit Hilbucha2012042018-12-03 19:35:054507// Simulcast serialization integration test.
4508// This test will serialize and deserialize the description and compare.
4509// More detailed tests for parsing simulcast can be found in
4510// unit tests for SdpSerializer.
4511TEST_F(WebRtcSdpTest, SerializeSimulcast_ComplexSerialization) {
Amit Hilbuchc57d5732018-12-11 23:30:114512 MakeUnifiedPlanDescription(/* use_ssrcs = */ false);
Amit Hilbucha2012042018-12-03 19:35:054513 auto description = jdesc_.description();
4514 auto media = description->GetContentDescriptionByName(kVideoContentName3);
Amit Hilbuchc57d5732018-12-11 23:30:114515 ASSERT_EQ(media->streams().size(), 1ul);
4516 StreamParams& send_stream = media->mutable_streams()[0];
4517 std::vector<RidDescription> send_rids;
4518 send_rids.push_back(RidDescription("1", RidDirection::kSend));
4519 send_rids.push_back(RidDescription("2", RidDirection::kSend));
4520 send_rids.push_back(RidDescription("3", RidDirection::kSend));
4521 send_rids.push_back(RidDescription("4", RidDirection::kSend));
4522 send_stream.set_rids(send_rids);
Florent Castellib60141b2019-07-03 10:47:544523 std::vector<RidDescription> receive_rids;
4524 receive_rids.push_back(RidDescription("5", RidDirection::kReceive));
4525 receive_rids.push_back(RidDescription("6", RidDirection::kReceive));
4526 receive_rids.push_back(RidDescription("7", RidDirection::kReceive));
4527 media->set_receive_rids(receive_rids);
Amit Hilbuchc57d5732018-12-11 23:30:114528
Amit Hilbucha2012042018-12-03 19:35:054529 SimulcastDescription& simulcast = media->simulcast_description();
4530 simulcast.send_layers().AddLayerWithAlternatives(
4531 {SimulcastLayer("2", false), SimulcastLayer("1", true)});
4532 simulcast.send_layers().AddLayerWithAlternatives(
4533 {SimulcastLayer("4", false), SimulcastLayer("3", false)});
Florent Castellib60141b2019-07-03 10:47:544534 simulcast.receive_layers().AddLayer({SimulcastLayer("5", false)});
4535 simulcast.receive_layers().AddLayer({SimulcastLayer("6", false)});
4536 simulcast.receive_layers().AddLayer({SimulcastLayer("7", false)});
Amit Hilbucha2012042018-12-03 19:35:054537
Amit Hilbucha2012042018-12-03 19:35:054538 TestSerialize(jdesc_);
4539}
Steve Anton06817cd2018-12-18 23:55:304540
4541// Test that the content name is empty if the media section does not have an
4542// a=mid line.
4543TEST_F(WebRtcSdpTest, ParseNoMid) {
4544 std::string sdp = kSdpString;
4545 Replace("a=mid:audio_content_name\r\n", "", &sdp);
4546 Replace("a=mid:video_content_name\r\n", "", &sdp);
4547
4548 JsepSessionDescription output(kDummyType);
4549 SdpParseError error;
4550 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4551
4552 EXPECT_THAT(output.description()->contents(),
4553 ElementsAre(Field("name", &cricket::ContentInfo::name, ""),
4554 Field("name", &cricket::ContentInfo::name, "")));
4555}
Piotr (Peter) Slatala13e570f2019-02-27 19:34:264556
Guido Urdanetacecf87f2019-05-31 10:17:384557TEST_F(WebRtcSdpTest, SerializeWithDefaultSctpProtocol) {
4558 AddSctpDataChannel(false); // Don't use sctpmap
4559 JsepSessionDescription jsep_desc(kDummyType);
4560 MakeDescriptionWithoutCandidates(&jsep_desc);
4561 std::string message = webrtc::SdpSerialize(jsep_desc);
4562 EXPECT_NE(std::string::npos,
4563 message.find(cricket::kMediaProtocolUdpDtlsSctp));
4564}
4565
4566TEST_F(WebRtcSdpTest, DeserializeWithAllSctpProtocols) {
4567 AddSctpDataChannel(false);
4568 std::string protocols[] = {cricket::kMediaProtocolDtlsSctp,
4569 cricket::kMediaProtocolUdpDtlsSctp,
4570 cricket::kMediaProtocolTcpDtlsSctp};
4571 for (const auto& protocol : protocols) {
4572 sctp_desc_->set_protocol(protocol);
4573 JsepSessionDescription jsep_desc(kDummyType);
4574 MakeDescriptionWithoutCandidates(&jsep_desc);
4575 std::string message = webrtc::SdpSerialize(jsep_desc);
4576 EXPECT_NE(std::string::npos, message.find(protocol));
4577 JsepSessionDescription jsep_output(kDummyType);
4578 SdpParseError error;
4579 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jsep_output, &error));
4580 }
4581}
Taylor Brandstetter4256df02020-02-18 22:05:074582
4583// According to https://tools.ietf.org/html/rfc5576#section-6.1, the CNAME
4584// attribute is mandatory, but we relax that restriction.
4585TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCname) {
4586 std::string sdp_without_cname = kSdpFullString;
4587 Replace("a=ssrc:1 cname:stream_1_cname\r\n", "", &sdp_without_cname);
4588 JsepSessionDescription new_jdesc(kDummyType);
4589 EXPECT_TRUE(SdpDeserialize(sdp_without_cname, &new_jdesc));
4590
4591 audio_desc_->mutable_streams()[0].cname = "";
4592 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
4593 jdesc_.session_version()));
4594 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
4595}
Philipp Hanckeefc55b02020-06-26 08:17:054596
4597TEST_F(WebRtcSdpTest, DeserializeSdpWithUnsupportedMediaType) {
Philipp Hanckeefc55b02020-06-26 08:17:054598 std::string sdp = kSdpSessionString;
4599 sdp +=
4600 "m=bogus 9 RTP/SAVPF 0 8\r\n"
Philipp Hancke4e8c1152020-10-13 10:43:154601 "c=IN IP4 0.0.0.0\r\n"
4602 "a=mid:bogusmid\r\n";
Philipp Hanckeefc55b02020-06-26 08:17:054603 sdp +=
4604 "m=audio/something 9 RTP/SAVPF 0 8\r\n"
Philipp Hancke4e8c1152020-10-13 10:43:154605 "c=IN IP4 0.0.0.0\r\n"
4606 "a=mid:somethingmid\r\n";
Philipp Hanckeefc55b02020-06-26 08:17:054607
4608 JsepSessionDescription jdesc_output(kDummyType);
4609 EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output));
4610
Philipp Hancke4e8c1152020-10-13 10:43:154611 ASSERT_EQ(2u, jdesc_output.description()->contents().size());
4612 ASSERT_NE(nullptr, jdesc_output.description()
4613 ->contents()[0]
4614 .media_description()
4615 ->as_unsupported());
4616 ASSERT_NE(nullptr, jdesc_output.description()
4617 ->contents()[1]
4618 .media_description()
4619 ->as_unsupported());
4620
4621 EXPECT_TRUE(jdesc_output.description()->contents()[0].rejected);
4622 EXPECT_TRUE(jdesc_output.description()->contents()[1].rejected);
4623
4624 EXPECT_EQ(jdesc_output.description()->contents()[0].name, "bogusmid");
4625 EXPECT_EQ(jdesc_output.description()->contents()[1].name, "somethingmid");
Philipp Hanckeefc55b02020-06-26 08:17:054626}
Philipp Hanckeb70c9532021-01-13 09:40:064627
4628TEST_F(WebRtcSdpTest, MediaTypeProtocolMismatch) {
4629 std::string sdp =
4630 "v=0\r\n"
4631 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4632 "s=-\r\n"
4633 "t=0 0\r\n";
4634
4635 ExpectParseFailure(std::string(sdp + "m=audio 9 UDP/DTLS/SCTP 120\r\n"),
4636 "m=audio");
4637 ExpectParseFailure(std::string(sdp + "m=video 9 UDP/DTLS/SCTP 120\r\n"),
4638 "m=video");
4639 ExpectParseFailure(std::string(sdp + "m=video 9 SOMETHING 120\r\n"),
4640 "m=video");
4641 ExpectParseFailure(std::string(sdp + "m=application 9 SOMETHING 120\r\n"),
4642 "m=application");
4643}
Philipp Hanckecd467b52021-01-29 08:29:474644
4645// Regression test for:
4646// https://bugs.chromium.org/p/chromium/issues/detail?id=1171965
4647TEST_F(WebRtcSdpTest, SctpPortInUnsupportedContent) {
4648 std::string sdp =
4649 "v=0\r\n"
4650 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4651 "s=-\r\n"
4652 "t=0 0\r\n"
4653 "m=o 1 DTLS/SCTP 5000\r\n"
4654 "a=sctp-port\r\n";
4655
4656 JsepSessionDescription jdesc_output(kDummyType);
4657 EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output));
4658}
Harald Alvestrand99bcf602021-03-03 07:44:394659
4660TEST_F(WebRtcSdpTest, IllegalMidCharacterValue) {
4661 std::string sdp = kSdpString;
4662 // [ is an illegal token value.
4663 Replace("a=mid:", "a=mid:[]", &sdp);
4664 ExpectParseFailure(std::string(sdp), "a=mid:[]");
4665}