blob: 86e137ee1a4a77cb143c1d98d44e6b4d38e168d4 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2011 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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:36 +00009 */
10
Yves Gerey3e707812018-11-28 16:47:49 +010011#include <stdio.h>
12#include <string.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020013
Yves Gerey3e707812018-11-28 16:47:49 +010014#include <cstdint>
15#include <map>
kwibergd1fe2812016-04-27 06:47:29 -070016#include <memory>
Harald Alvestrandc24a2182022-02-23 13:44:59 +000017#include <sstream>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000018#include <string>
Yves Gerey3e707812018-11-28 16:47:49 +010019#include <utility>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000020#include <vector>
21
Steve Anton64b626b2019-01-28 17:25:26 -080022#include "absl/algorithm/container.h"
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -080023#include "absl/memory/memory.h"
Steve Anton1c9c9fc2019-02-14 15:13:09 -080024#include "absl/strings/str_replace.h"
Harald Alvestrandc24a2182022-02-23 13:44:59 +000025#include "absl/strings/string_view.h"
26#include "absl/types/optional.h"
Yves Gerey3e707812018-11-28 16:47:49 +010027#include "api/array_view.h"
Harald Alvestrand0d018412021-11-04 13:52:31 +000028#include "api/crypto_params.h"
Steve Anton10542f22019-01-11 09:11:00 -080029#include "api/jsep_session_description.h"
30#include "api/media_types.h"
31#include "api/rtp_parameters.h"
Harald Alvestrandc24a2182022-02-23 13:44:59 +000032#include "api/rtp_transceiver_direction.h"
Yves Gerey3e707812018-11-28 16:47:49 +010033#include "media/base/codec.h"
Steve Anton10542f22019-01-11 09:11:00 -080034#include "media/base/media_constants.h"
Harald Alvestrandc24a2182022-02-23 13:44:59 +000035#include "media/base/rid_description.h"
Steve Anton10542f22019-01-11 09:11:00 -080036#include "media/base/stream_params.h"
37#include "p2p/base/p2p_constants.h"
Yves Gerey665174f2018-06-19 15:03:05 +020038#include "p2p/base/port.h"
Steve Anton10542f22019-01-11 09:11:00 -080039#include "p2p/base/transport_description.h"
40#include "p2p/base/transport_info.h"
Harald Alvestrandc24a2182022-02-23 13:44:59 +000041#include "pc/media_protocol_names.h"
Steve Anton10542f22019-01-11 09:11:00 -080042#include "pc/media_session.h"
43#include "pc/session_description.h"
Harald Alvestrandc24a2182022-02-23 13:44:59 +000044#include "pc/simulcast_description.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020045#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 09:11:00 -080046#include "rtc_base/message_digest.h"
47#include "rtc_base/socket_address.h"
48#include "rtc_base/ssl_fingerprint.h"
49#include "rtc_base/string_encode.h"
Steve Anton06817cd2018-12-18 15:55:30 -080050#include "test/gmock.h"
Yves Gerey3e707812018-11-28 16:47:49 +010051#include "test/gtest.h"
Patrik Höglund563934e2017-09-15 09:04:28 +020052
ossu7bb87ee2017-01-23 04:56:25 -080053#ifdef WEBRTC_ANDROID
Steve Anton10542f22019-01-11 09:11:00 -080054#include "pc/test/android_test_initializer.h"
ossu7bb87ee2017-01-23 04:56:25 -080055#endif
Steve Anton10542f22019-01-11 09:11:00 -080056#include "pc/webrtc_sdp.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057
58using cricket::AudioCodec;
59using cricket::AudioContentDescription;
60using cricket::Candidate;
Steve Anton06817cd2018-12-18 15:55:30 -080061using cricket::ContentGroup;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062using cricket::ContentInfo;
Harald Alvestrand0d018412021-11-04 13:52:31 +000063using cricket::CryptoParams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
65using cricket::ICE_CANDIDATE_COMPONENT_RTP;
66using cricket::kFecSsrcGroupSemantics;
67using cricket::LOCAL_PORT_TYPE;
Steve Anton5adfafd2017-12-20 16:34:00 -080068using cricket::MediaProtocolType;
Steve Anton06817cd2018-12-18 15:55:30 -080069using cricket::RELAY_PORT_TYPE;
Amit Hilbuchc57d5732018-12-11 15:30:11 -080070using cricket::RidDescription;
71using cricket::RidDirection;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020072using cricket::SctpDataContentDescription;
Steve Anton06817cd2018-12-18 15:55:30 -080073using cricket::SessionDescription;
Amit Hilbucha2012042018-12-03 11:35:05 -080074using cricket::SimulcastDescription;
75using cricket::SimulcastLayer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076using cricket::StreamParams;
77using cricket::STUN_PORT_TYPE;
78using cricket::TransportDescription;
79using cricket::TransportInfo;
80using cricket::VideoCodec;
81using cricket::VideoContentDescription;
Steve Anton06817cd2018-12-18 15:55:30 -080082using ::testing::ElementsAre;
83using ::testing::Field;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084using webrtc::IceCandidateCollection;
85using webrtc::IceCandidateInterface;
86using webrtc::JsepIceCandidate;
87using webrtc::JsepSessionDescription;
isheriff6f8d6862016-05-26 11:24:55 -070088using webrtc::RtpExtension;
Steve Anton4e70a722017-11-28 14:57:10 -080089using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090using webrtc::SdpParseError;
Steve Antona3a92c22017-12-07 10:27:41 -080091using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092using webrtc::SessionDescriptionInterface;
93
94typedef std::vector<AudioCodec> AudioCodecs;
95typedef std::vector<Candidate> Candidates;
96
Peter Boström0c4e06b2015-10-07 12:23:21 +020097static const uint32_t kDefaultSctpPort = 5000;
zstein4b2e0822017-02-17 19:48:38 -080098static const uint16_t kUnusualSctpPort = 9556;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200100static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 15:17:14 -0800101static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 15:17:14 -0800103static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000104static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200105static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000106static const char kCandidateFoundation1[] = "a0+B/1";
107static const char kCandidateFoundation2[] = "a0+B/2";
108static const char kCandidateFoundation3[] = "a0+B/3";
109static const char kCandidateFoundation4[] = "a0+B/4";
110static const char kAttributeCryptoVoice[] =
111 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
112 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
113 "dummy_session_params\r\n";
114static const char kAttributeCryptoVideo[] =
115 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
116 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
Yves Gerey665174f2018-06-19 15:03:05 +0200117static const char kFingerprint[] =
118 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000119 "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 22:33:20 +0200120static const char kExtmapAllowMixed[] = "a=extmap-allow-mixed\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121static const int kExtmapId = 1;
122static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
123static const char kExtmap[] =
124 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
125static const char kExtmapWithDirectionAndAttribute[] =
126 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
jbauch5869f502017-06-29 12:31:36 -0700127static const char kExtmapWithDirectionAndAttributeEncrypted[] =
128 "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt "
129 "http://example.com/082005/ext.htm#ttime a1 a2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000130
Peter Boström0c4e06b2015-10-07 12:23:21 +0200131static const uint8_t kIdentityDigest[] = {
132 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
133 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000134
lally@webrtc.org34807282015-02-24 20:19:39 +0000135static const char kDtlsSctp[] = "DTLS/SCTP";
136static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
137static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +0000138
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000139struct CodecParams {
140 int max_ptime;
141 int ptime;
142 int min_ptime;
143 int sprop_stereo;
144 int stereo;
145 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000146 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000147};
148
Harald Alvestrand0d018412021-11-04 13:52:31 +0000149// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
150// instead of "a=crypto", and have an explicit test for adding "a=crypto".
151// Currently it's the other way around.
deadbeef9d3584c2016-02-16 17:54:10 -0800152
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000153// Reference sdp string
154static const char kSdpFullString[] =
155 "v=0\r\n"
156 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
157 "s=-\r\n"
158 "t=0 0\r\n"
Emil Lundmark801c9992021-01-19 13:06:32 +0100159 "a=extmap-allow-mixed\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800160 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000161 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
162 "c=IN IP4 74.125.127.126\r\n"
163 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
164 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
165 "generation 2\r\n"
166 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
167 "generation 2\r\n"
168 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
169 "generation 2\r\n"
170 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
171 "generation 2\r\n"
172 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
173 "raddr 192.168.1.5 rport 2346 "
174 "generation 2\r\n"
175 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
176 "raddr 192.168.1.5 rport 2348 "
177 "generation 2\r\n"
178 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
179 "a=mid:audio_content_name\r\n"
180 "a=sendrecv\r\n"
181 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800182 "a=rtcp-rsize\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000183 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
184 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
185 "dummy_session_params\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000186 "a=rtpmap:111 opus/48000/2\r\n"
187 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000188 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000189 "a=ssrc:1 cname:stream_1_cname\r\n"
190 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000191 "m=video 3457 RTP/SAVPF 120\r\n"
192 "c=IN IP4 74.125.224.39\r\n"
193 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
194 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
195 "generation 2\r\n"
196 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
197 "generation 2\r\n"
198 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
199 "generation 2\r\n"
200 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
201 "generation 2\r\n"
202 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
203 "generation 2\r\n"
204 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
205 "generation 2\r\n"
206 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
207 "a=mid:video_content_name\r\n"
208 "a=sendrecv\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000209 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
210 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800212 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213 "a=ssrc:2 cname:stream_1_cname\r\n"
214 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000215 "a=ssrc:3 cname:stream_1_cname\r\n"
Harald Alvestrand88b8dec2022-04-07 09:54:51 +0000216 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000217
218// SDP reference string without the candidates.
219static const char kSdpString[] =
220 "v=0\r\n"
221 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
222 "s=-\r\n"
223 "t=0 0\r\n"
Emil Lundmark801c9992021-01-19 13:06:32 +0100224 "a=extmap-allow-mixed\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800225 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000226 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000227 "c=IN IP4 0.0.0.0\r\n"
228 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000229 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
230 "a=mid:audio_content_name\r\n"
231 "a=sendrecv\r\n"
232 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800233 "a=rtcp-rsize\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000234 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
235 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
236 "dummy_session_params\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000237 "a=rtpmap:111 opus/48000/2\r\n"
238 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000239 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000240 "a=ssrc:1 cname:stream_1_cname\r\n"
241 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000242 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000243 "c=IN IP4 0.0.0.0\r\n"
244 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000245 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
246 "a=mid:video_content_name\r\n"
247 "a=sendrecv\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000248 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
249 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000250 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800251 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000252 "a=ssrc:2 cname:stream_1_cname\r\n"
253 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000254 "a=ssrc:3 cname:stream_1_cname\r\n"
Harald Alvestrand88b8dec2022-04-07 09:54:51 +0000255 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000256
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200257// draft-ietf-mmusic-sctp-sdp-03
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000258static const char kSdpSctpDataChannelString[] =
Guido Urdanetacecf87f2019-05-31 10:17:38 +0000259 "m=application 9 UDP/DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000260 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000261 "a=ice-ufrag:ufrag_data\r\n"
262 "a=ice-pwd:pwd_data\r\n"
263 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000264 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000265
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000266// draft-ietf-mmusic-sctp-sdp-12
Harald Alvestrand48cce4d2019-04-11 10:41:24 +0200267// Note - this is invalid per draft-ietf-mmusic-sctp-sdp-26,
268// since the separator after "sctp-port" needs to be a colon.
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000269static const char kSdpSctpDataChannelStringWithSctpPort[] =
Guido Urdanetacecf87f2019-05-31 10:17:38 +0000270 "m=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\n"
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000271 "a=sctp-port 5000\r\n"
272 "c=IN IP4 0.0.0.0\r\n"
273 "a=ice-ufrag:ufrag_data\r\n"
274 "a=ice-pwd:pwd_data\r\n"
275 "a=mid:data_content_name\r\n";
276
Harald Alvestrand48cce4d2019-04-11 10:41:24 +0200277// draft-ietf-mmusic-sctp-sdp-26
lally69f57602015-10-08 10:15:04 -0700278static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
Guido Urdanetacecf87f2019-05-31 10:17:38 +0000279 "m=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\n"
lally69f57602015-10-08 10:15:04 -0700280 "a=sctp-port:5000\r\n"
281 "c=IN IP4 0.0.0.0\r\n"
282 "a=ice-ufrag:ufrag_data\r\n"
283 "a=ice-pwd:pwd_data\r\n"
284 "a=mid:data_content_name\r\n";
285
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000286static const char kSdpSctpDataChannelWithCandidatesString[] =
Guido Urdanetacecf87f2019-05-31 10:17:38 +0000287 "m=application 2345 UDP/DTLS/SCTP 5000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000288 "c=IN IP4 74.125.127.126\r\n"
289 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
290 "generation 2\r\n"
291 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
292 "generation 2\r\n"
293 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
294 "raddr 192.168.1.5 rport 2346 "
295 "generation 2\r\n"
296 "a=ice-ufrag:ufrag_data\r\n"
297 "a=ice-pwd:pwd_data\r\n"
298 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000299 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000300
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000301static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000302 "v=0\r\n"
303 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
304 "s=-\r\n"
305 "t=0 0\r\n"
306 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000307 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000308 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000309 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000310 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000311 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000312 "a=x-google-flag:conference\r\n";
313
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000314static const char kSdpSessionString[] =
315 "v=0\r\n"
316 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
317 "s=-\r\n"
318 "t=0 0\r\n"
319 "a=msid-semantic: WMS local_stream\r\n";
320
321static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000322 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000323 "c=IN IP4 0.0.0.0\r\n"
324 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000325 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
326 "a=mid:audio_content_name\r\n"
327 "a=sendrecv\r\n"
328 "a=rtpmap:111 opus/48000/2\r\n"
329 "a=ssrc:1 cname:stream_1_cname\r\n"
Harald Alvestrand88b8dec2022-04-07 09:54:51 +0000330 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n";
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000331
332static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000333 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000334 "c=IN IP4 0.0.0.0\r\n"
335 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000336 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
337 "a=mid:video_content_name\r\n"
338 "a=sendrecv\r\n"
339 "a=rtpmap:120 VP8/90000\r\n"
340 "a=ssrc:2 cname:stream_1_cname\r\n"
Harald Alvestrand88b8dec2022-04-07 09:54:51 +0000341 "a=ssrc:2 msid:local_stream video_track_id_1\r\n";
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000342
deadbeef25ed4352016-12-12 18:37:36 -0800343// Reference sdp string using bundle-only.
344static const char kBundleOnlySdpFullString[] =
345 "v=0\r\n"
346 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
347 "s=-\r\n"
348 "t=0 0\r\n"
Emil Lundmark801c9992021-01-19 13:06:32 +0100349 "a=extmap-allow-mixed\r\n"
deadbeef25ed4352016-12-12 18:37:36 -0800350 "a=group:BUNDLE audio_content_name video_content_name\r\n"
351 "a=msid-semantic: WMS local_stream_1\r\n"
352 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
353 "c=IN IP4 74.125.127.126\r\n"
354 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
355 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
356 "generation 2\r\n"
357 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
358 "generation 2\r\n"
359 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
360 "generation 2\r\n"
361 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
362 "generation 2\r\n"
363 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
364 "raddr 192.168.1.5 rport 2346 "
365 "generation 2\r\n"
366 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
367 "raddr 192.168.1.5 rport 2348 "
368 "generation 2\r\n"
369 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
370 "a=mid:audio_content_name\r\n"
371 "a=sendrecv\r\n"
372 "a=rtcp-mux\r\n"
373 "a=rtcp-rsize\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000374 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
375 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
376 "dummy_session_params\r\n"
deadbeef25ed4352016-12-12 18:37:36 -0800377 "a=rtpmap:111 opus/48000/2\r\n"
378 "a=rtpmap:103 ISAC/16000\r\n"
379 "a=rtpmap:104 ISAC/32000\r\n"
380 "a=ssrc:1 cname:stream_1_cname\r\n"
381 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
deadbeef25ed4352016-12-12 18:37:36 -0800382 "m=video 0 RTP/SAVPF 120\r\n"
383 "c=IN IP4 0.0.0.0\r\n"
384 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
385 "a=bundle-only\r\n"
386 "a=mid:video_content_name\r\n"
387 "a=sendrecv\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000388 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
389 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
deadbeef25ed4352016-12-12 18:37:36 -0800390 "a=rtpmap:120 VP8/90000\r\n"
391 "a=ssrc-group:FEC 2 3\r\n"
392 "a=ssrc:2 cname:stream_1_cname\r\n"
393 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
deadbeef25ed4352016-12-12 18:37:36 -0800394 "a=ssrc:3 cname:stream_1_cname\r\n"
Harald Alvestrand88b8dec2022-04-07 09:54:51 +0000395 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n";
deadbeef25ed4352016-12-12 18:37:36 -0800396
deadbeef9d3584c2016-02-16 17:54:10 -0800397// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
398// tracks.
399static const char kPlanBSdpFullString[] =
400 "v=0\r\n"
401 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
402 "s=-\r\n"
403 "t=0 0\r\n"
Emil Lundmark801c9992021-01-19 13:06:32 +0100404 "a=extmap-allow-mixed\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800405 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
406 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
407 "c=IN IP4 74.125.127.126\r\n"
408 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
409 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
410 "generation 2\r\n"
411 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
412 "generation 2\r\n"
413 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
414 "generation 2\r\n"
415 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
416 "generation 2\r\n"
417 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
418 "raddr 192.168.1.5 rport 2346 "
419 "generation 2\r\n"
420 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
421 "raddr 192.168.1.5 rport 2348 "
422 "generation 2\r\n"
423 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
424 "a=mid:audio_content_name\r\n"
425 "a=sendrecv\r\n"
426 "a=rtcp-mux\r\n"
427 "a=rtcp-rsize\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000428 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
429 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
430 "dummy_session_params\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800431 "a=rtpmap:111 opus/48000/2\r\n"
432 "a=rtpmap:103 ISAC/16000\r\n"
433 "a=rtpmap:104 ISAC/32000\r\n"
434 "a=ssrc:1 cname:stream_1_cname\r\n"
435 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800436 "a=ssrc:4 cname:stream_2_cname\r\n"
437 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800438 "m=video 3457 RTP/SAVPF 120\r\n"
439 "c=IN IP4 74.125.224.39\r\n"
440 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
441 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
442 "generation 2\r\n"
443 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
444 "generation 2\r\n"
445 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
446 "generation 2\r\n"
447 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
448 "generation 2\r\n"
449 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
450 "generation 2\r\n"
451 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
452 "generation 2\r\n"
453 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
454 "a=mid:video_content_name\r\n"
455 "a=sendrecv\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000456 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
457 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800458 "a=rtpmap:120 VP8/90000\r\n"
459 "a=ssrc-group:FEC 2 3\r\n"
460 "a=ssrc:2 cname:stream_1_cname\r\n"
461 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800462 "a=ssrc:3 cname:stream_1_cname\r\n"
463 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800464 "a=ssrc:5 cname:stream_2_cname\r\n"
465 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800466 "a=ssrc:6 cname:stream_2_cname\r\n"
Harald Alvestrand88b8dec2022-04-07 09:54:51 +0000467 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n";
deadbeef9d3584c2016-02-16 17:54:10 -0800468
469// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
470// tracks.
471static const char kUnifiedPlanSdpFullString[] =
472 "v=0\r\n"
473 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
474 "s=-\r\n"
475 "t=0 0\r\n"
Emil Lundmark801c9992021-01-19 13:06:32 +0100476 "a=extmap-allow-mixed\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800477 "a=msid-semantic: WMS local_stream_1\r\n"
478 // Audio track 1, stream 1 (with candidates).
479 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
480 "c=IN IP4 74.125.127.126\r\n"
481 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
482 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
483 "generation 2\r\n"
484 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
485 "generation 2\r\n"
486 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
487 "generation 2\r\n"
488 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
489 "generation 2\r\n"
490 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
491 "raddr 192.168.1.5 rport 2346 "
492 "generation 2\r\n"
493 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
494 "raddr 192.168.1.5 rport 2348 "
495 "generation 2\r\n"
496 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
497 "a=mid:audio_content_name\r\n"
498 "a=msid:local_stream_1 audio_track_id_1\r\n"
499 "a=sendrecv\r\n"
500 "a=rtcp-mux\r\n"
501 "a=rtcp-rsize\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000502 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
503 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
504 "dummy_session_params\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800505 "a=rtpmap:111 opus/48000/2\r\n"
506 "a=rtpmap:103 ISAC/16000\r\n"
507 "a=rtpmap:104 ISAC/32000\r\n"
508 "a=ssrc:1 cname:stream_1_cname\r\n"
509 // Video track 1, stream 1 (with candidates).
510 "m=video 3457 RTP/SAVPF 120\r\n"
511 "c=IN IP4 74.125.224.39\r\n"
512 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
513 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
514 "generation 2\r\n"
515 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
516 "generation 2\r\n"
517 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
518 "generation 2\r\n"
519 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
520 "generation 2\r\n"
521 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
522 "generation 2\r\n"
523 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
524 "generation 2\r\n"
525 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
526 "a=mid:video_content_name\r\n"
527 "a=msid:local_stream_1 video_track_id_1\r\n"
528 "a=sendrecv\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000529 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
530 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800531 "a=rtpmap:120 VP8/90000\r\n"
532 "a=ssrc-group:FEC 2 3\r\n"
533 "a=ssrc:2 cname:stream_1_cname\r\n"
534 "a=ssrc:3 cname:stream_1_cname\r\n"
535 // Audio track 2, stream 2.
536 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
537 "c=IN IP4 0.0.0.0\r\n"
538 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
539 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
540 "a=mid:audio_content_name_2\r\n"
541 "a=msid:local_stream_2 audio_track_id_2\r\n"
542 "a=sendrecv\r\n"
543 "a=rtcp-mux\r\n"
544 "a=rtcp-rsize\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000545 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
546 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
547 "dummy_session_params\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800548 "a=rtpmap:111 opus/48000/2\r\n"
549 "a=rtpmap:103 ISAC/16000\r\n"
550 "a=rtpmap:104 ISAC/32000\r\n"
551 "a=ssrc:4 cname:stream_2_cname\r\n"
552 // Video track 2, stream 2.
553 "m=video 9 RTP/SAVPF 120\r\n"
554 "c=IN IP4 0.0.0.0\r\n"
555 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
556 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
557 "a=mid:video_content_name_2\r\n"
558 "a=msid:local_stream_2 video_track_id_2\r\n"
559 "a=sendrecv\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000560 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
561 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800562 "a=rtpmap:120 VP8/90000\r\n"
563 "a=ssrc:5 cname:stream_2_cname\r\n"
564 // Video track 3, stream 2.
565 "m=video 9 RTP/SAVPF 120\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_video_3\r\na=ice-pwd:pwd_video_3\r\n"
569 "a=mid:video_content_name_3\r\n"
570 "a=msid:local_stream_2 video_track_id_3\r\n"
571 "a=sendrecv\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000572 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
573 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800574 "a=rtpmap:120 VP8/90000\r\n"
575 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000576
Seth Hampson5b4f0752018-04-02 16:31:36 -0700577// Unified Plan SDP reference string:
578// - audio track 1 has 1 a=msid lines
579// - audio track 2 has 2 a=msid lines
580// - audio track 3 has 1 a=msid line with the special "-" marker signifying that
581// there are 0 media stream ids.
582// This Unified Plan SDP represents a SDP that signals the msid using both
583// a=msid and a=ssrc msid semantics.
584static const char kUnifiedPlanSdpFullStringWithSpecialMsid[] =
585 "v=0\r\n"
586 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
587 "s=-\r\n"
588 "t=0 0\r\n"
Emil Lundmark801c9992021-01-19 13:06:32 +0100589 "a=extmap-allow-mixed\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700590 "a=msid-semantic: WMS local_stream_1\r\n"
591 // Audio track 1, with 1 stream id.
592 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
593 "c=IN IP4 74.125.127.126\r\n"
594 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
595 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
596 "generation 2\r\n"
597 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
598 "generation 2\r\n"
599 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
600 "generation 2\r\n"
601 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
602 "generation 2\r\n"
603 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
604 "raddr 192.168.1.5 rport 2346 "
605 "generation 2\r\n"
606 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
607 "raddr 192.168.1.5 rport 2348 "
608 "generation 2\r\n"
609 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
610 "a=mid:audio_content_name\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700611 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700612 "a=msid:local_stream_1 audio_track_id_1\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700613 "a=rtcp-mux\r\n"
614 "a=rtcp-rsize\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000615 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
616 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
617 "dummy_session_params\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700618 "a=rtpmap:111 opus/48000/2\r\n"
619 "a=rtpmap:103 ISAC/16000\r\n"
620 "a=rtpmap:104 ISAC/32000\r\n"
621 "a=ssrc:1 cname:stream_1_cname\r\n"
622 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700623 // Audio track 2, with two stream ids.
624 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
625 "c=IN IP4 0.0.0.0\r\n"
626 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
627 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
628 "a=mid:audio_content_name_2\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700629 "a=sendrecv\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700630 "a=msid:local_stream_1 audio_track_id_2\r\n"
631 "a=msid:local_stream_2 audio_track_id_2\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700632 "a=rtcp-mux\r\n"
633 "a=rtcp-rsize\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000634 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
635 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
636 "dummy_session_params\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700637 "a=rtpmap:111 opus/48000/2\r\n"
638 "a=rtpmap:103 ISAC/16000\r\n"
639 "a=rtpmap:104 ISAC/32000\r\n"
640 "a=ssrc:4 cname:stream_1_cname\r\n"
641 // The support for Plan B msid signaling only includes the
642 // first media stream id "local_stream_1."
643 "a=ssrc:4 msid:local_stream_1 audio_track_id_2\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700644 // Audio track 3, with no stream ids.
645 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
646 "c=IN IP4 0.0.0.0\r\n"
647 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
648 "a=ice-ufrag:ufrag_voice_3\r\na=ice-pwd:pwd_voice_3\r\n"
649 "a=mid:audio_content_name_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700650 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700651 "a=msid:- audio_track_id_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700652 "a=rtcp-mux\r\n"
653 "a=rtcp-rsize\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000654 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
655 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
656 "dummy_session_params\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700657 "a=rtpmap:111 opus/48000/2\r\n"
658 "a=rtpmap:103 ISAC/16000\r\n"
659 "a=rtpmap:104 ISAC/32000\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700660 "a=ssrc:7 cname:stream_2_cname\r\n"
Harald Alvestrand88b8dec2022-04-07 09:54:51 +0000661 "a=ssrc:7 msid:- audio_track_id_3\r\n";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700662
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800663// SDP string for unified plan without SSRCs
664static const char kUnifiedPlanSdpFullStringNoSsrc[] =
665 "v=0\r\n"
666 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
667 "s=-\r\n"
668 "t=0 0\r\n"
669 "a=msid-semantic: WMS local_stream_1\r\n"
670 // Audio track 1, stream 1 (with candidates).
671 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
672 "c=IN IP4 74.125.127.126\r\n"
673 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
674 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
675 "generation 2\r\n"
676 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
677 "generation 2\r\n"
678 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
679 "generation 2\r\n"
680 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
681 "generation 2\r\n"
682 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
683 "raddr 192.168.1.5 rport 2346 "
684 "generation 2\r\n"
685 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
686 "raddr 192.168.1.5 rport 2348 "
687 "generation 2\r\n"
688 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
689 "a=mid:audio_content_name\r\n"
690 "a=msid:local_stream_1 audio_track_id_1\r\n"
691 "a=sendrecv\r\n"
692 "a=rtcp-mux\r\n"
693 "a=rtcp-rsize\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000694 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
695 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
696 "dummy_session_params\r\n"
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800697 "a=rtpmap:111 opus/48000/2\r\n"
698 "a=rtpmap:103 ISAC/16000\r\n"
699 "a=rtpmap:104 ISAC/32000\r\n"
700 // Video track 1, stream 1 (with candidates).
701 "m=video 3457 RTP/SAVPF 120\r\n"
702 "c=IN IP4 74.125.224.39\r\n"
703 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
704 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
705 "generation 2\r\n"
706 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
707 "generation 2\r\n"
708 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
709 "generation 2\r\n"
710 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
711 "generation 2\r\n"
712 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
713 "generation 2\r\n"
714 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
715 "generation 2\r\n"
716 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
717 "a=mid:video_content_name\r\n"
718 "a=msid:local_stream_1 video_track_id_1\r\n"
719 "a=sendrecv\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000720 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
721 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800722 "a=rtpmap:120 VP8/90000\r\n"
723 // Audio track 2, stream 2.
724 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
725 "c=IN IP4 0.0.0.0\r\n"
726 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
727 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
728 "a=mid:audio_content_name_2\r\n"
729 "a=msid:local_stream_2 audio_track_id_2\r\n"
730 "a=sendrecv\r\n"
731 "a=rtcp-mux\r\n"
732 "a=rtcp-rsize\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000733 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
734 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
735 "dummy_session_params\r\n"
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800736 "a=rtpmap:111 opus/48000/2\r\n"
737 "a=rtpmap:103 ISAC/16000\r\n"
738 "a=rtpmap:104 ISAC/32000\r\n"
739 // Video track 2, stream 2.
740 "m=video 9 RTP/SAVPF 120\r\n"
741 "c=IN IP4 0.0.0.0\r\n"
742 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
743 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
744 "a=mid:video_content_name_2\r\n"
745 "a=msid:local_stream_2 video_track_id_2\r\n"
746 "a=sendrecv\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000747 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
748 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800749 "a=rtpmap:120 VP8/90000\r\n"
750 // Video track 3, stream 2.
751 "m=video 9 RTP/SAVPF 120\r\n"
752 "c=IN IP4 0.0.0.0\r\n"
753 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
754 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
755 "a=mid:video_content_name_3\r\n"
756 "a=msid:local_stream_2 video_track_id_3\r\n"
757 "a=sendrecv\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000758 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
759 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800760 "a=rtpmap:120 VP8/90000\r\n";
761
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000762// One candidate reference string as per W3c spec.
763// candidate:<blah> not a=candidate:<blah>CRLF
764static const char kRawCandidate[] =
765 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
766// One candidate reference string.
767static const char kSdpOneCandidate[] =
768 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
769 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000770
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000771static const char kSdpTcpActiveCandidate[] =
772 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
773 "tcptype active generation 2";
774static const char kSdpTcpPassiveCandidate[] =
775 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
776 "tcptype passive generation 2";
777static const char kSdpTcpSOCandidate[] =
778 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
779 "tcptype so generation 2";
780static const char kSdpTcpInvalidCandidate[] =
781 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
782 "tcptype invalid generation 2";
783
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000784// One candidate reference string with IPV6 address.
785static const char kRawIPV6Candidate[] =
786 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 12:04:36 -0700787 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788
789// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800790static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000791 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800792 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000793
Zach Steinb336c272018-08-09 01:16:13 -0700794static const char kRawHostnameCandidate[] =
795 "candidate:a0+B/1 1 udp 2130706432 a.test 1234 typ host generation 2";
796
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000797// Session id and version
798static const char kSessionId[] = "18446744069414584320";
799static const char kSessionVersion[] = "18446462598732840960";
800
deadbeef9d3584c2016-02-16 17:54:10 -0800801// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802static const char kIceOption1[] = "iceoption1";
803static const char kIceOption2[] = "iceoption2";
804static const char kIceOption3[] = "iceoption3";
805
deadbeef9d3584c2016-02-16 17:54:10 -0800806// ICE ufrags/passwords.
807static const char kUfragVoice[] = "ufrag_voice";
808static const char kPwdVoice[] = "pwd_voice";
809static const char kUfragVideo[] = "ufrag_video";
810static const char kPwdVideo[] = "pwd_video";
811static const char kUfragData[] = "ufrag_data";
812static const char kPwdData[] = "pwd_data";
813
814// Extra ufrags/passwords for extra unified plan m= sections.
815static const char kUfragVoice2[] = "ufrag_voice_2";
816static const char kPwdVoice2[] = "pwd_voice_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700817static const char kUfragVoice3[] = "ufrag_voice_3";
818static const char kPwdVoice3[] = "pwd_voice_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800819static const char kUfragVideo2[] = "ufrag_video_2";
820static const char kPwdVideo2[] = "pwd_video_2";
821static const char kUfragVideo3[] = "ufrag_video_3";
822static const char kPwdVideo3[] = "pwd_video_3";
823
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000824// Content name
825static const char kAudioContentName[] = "audio_content_name";
826static const char kVideoContentName[] = "video_content_name";
827static const char kDataContentName[] = "data_content_name";
828
deadbeef9d3584c2016-02-16 17:54:10 -0800829// Extra content names for extra unified plan m= sections.
830static const char kAudioContentName2[] = "audio_content_name_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700831static const char kAudioContentName3[] = "audio_content_name_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800832static const char kVideoContentName2[] = "video_content_name_2";
833static const char kVideoContentName3[] = "video_content_name_3";
834
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000835// MediaStream 1
Seth Hampson845e8782018-03-02 11:34:10 -0800836static const char kStreamId1[] = "local_stream_1";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000837static const char kStream1Cname[] = "stream_1_cname";
838static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200839static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800841static const uint32_t kVideoTrack1Ssrc1 = 2;
842static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000843
844// MediaStream 2
Seth Hampson845e8782018-03-02 11:34:10 -0800845static const char kStreamId2[] = "local_stream_2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000846static const char kStream2Cname[] = "stream_2_cname";
847static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200848static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800849static const char kVideoTrackId2[] = "video_track_id_2";
850static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000851static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800852static const uint32_t kVideoTrack3Ssrc = 6;
Seth Hampson5b4f0752018-04-02 16:31:36 -0700853static const char kAudioTrackId3[] = "audio_track_id_3";
854static const uint32_t kAudioTrack3Ssrc = 7;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000855
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000856// Candidate
857static const char kDummyMid[] = "dummy_mid";
858static const int kDummyIndex = 123;
859
860// Misc
Steve Antona3a92c22017-12-07 10:27:41 -0800861static SdpType kDummyType = SdpType::kOffer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000862
863// Helper functions
864
865static bool SdpDeserialize(const std::string& message,
866 JsepSessionDescription* jdesc) {
867 return webrtc::SdpDeserialize(message, jdesc, NULL);
868}
869
870static bool SdpDeserializeCandidate(const std::string& message,
871 JsepIceCandidate* candidate) {
872 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
873}
874
Artem Titov880fa812021-07-30 22:30:23 +0200875// Add some extra `newlines` to the `message` after `line`.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876static void InjectAfter(const std::string& line,
877 const std::string& newlines,
878 std::string* message) {
Steve Anton1c9c9fc2019-02-14 15:13:09 -0800879 absl::StrReplaceAll({{line, line + newlines}}, message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000880}
881
882static void Replace(const std::string& line,
883 const std::string& newlines,
884 std::string* message) {
Steve Anton1c9c9fc2019-02-14 15:13:09 -0800885 absl::StrReplaceAll({{line, newlines}}, message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000886}
887
Artem Titov880fa812021-07-30 22:30:23 +0200888// Expect a parse failure on the line containing `bad_part` when attempting to
889// parse `bad_sdp`.
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000890static void ExpectParseFailure(const std::string& bad_sdp,
891 const std::string& bad_part) {
Steve Antona3a92c22017-12-07 10:27:41 -0800892 JsepSessionDescription desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000893 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000894 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
Harald Alvestrand99bcf602021-03-03 07:44:39 +0000895 ASSERT_FALSE(ret);
896 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()))
897 << "Did not find " << bad_part << " in " << error.line;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000898}
899
Artem Titov880fa812021-07-30 22:30:23 +0200900// Expect fail to parse kSdpFullString if replace `good_part` with `bad_part`.
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000901static void ExpectParseFailure(const char* good_part, const char* bad_part) {
902 std::string bad_sdp = kSdpFullString;
903 Replace(good_part, bad_part, &bad_sdp);
904 ExpectParseFailure(bad_sdp, bad_part);
905}
906
Artem Titov880fa812021-07-30 22:30:23 +0200907// Expect fail to parse kSdpFullString if add `newlines` after `injectpoint`.
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000908static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
909 const std::string& newlines,
910 const std::string& bad_part) {
911 std::string bad_sdp = kSdpFullString;
912 InjectAfter(injectpoint, newlines, &bad_sdp);
913 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000914}
915
Steve Anton4e70a722017-11-28 14:57:10 -0800916static void ReplaceDirection(RtpTransceiverDirection direction,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000917 std::string* message) {
918 std::string new_direction;
919 switch (direction) {
Steve Anton4e70a722017-11-28 14:57:10 -0800920 case RtpTransceiverDirection::kInactive:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000921 new_direction = "a=inactive";
922 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800923 case RtpTransceiverDirection::kSendOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000924 new_direction = "a=sendonly";
925 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800926 case RtpTransceiverDirection::kRecvOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000927 new_direction = "a=recvonly";
928 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800929 case RtpTransceiverDirection::kSendRecv:
Markus Handell45c104b2020-03-11 10:51:13 +0100930 new_direction = "a=sendrecv";
931 break;
932 case RtpTransceiverDirection::kStopped:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933 default:
Artem Titovd3251962021-11-15 16:57:07 +0100934 RTC_DCHECK_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000935 new_direction = "a=sendrecv";
936 break;
937 }
938 Replace("a=sendrecv", new_direction, message);
939}
940
Yves Gerey665174f2018-06-19 15:03:05 +0200941static void ReplaceRejected(bool audio_rejected,
942 bool video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000943 std::string* message) {
944 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800945 Replace("m=audio 9", "m=audio 0", message);
946 Replace(kAttributeIceUfragVoice, "", message);
947 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000948 }
949 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800950 Replace("m=video 9", "m=video 0", message);
951 Replace(kAttributeIceUfragVideo, "", message);
952 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000953 }
954}
955
956// WebRtcSdpTest
957
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200958class WebRtcSdpTest : public ::testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000959 public:
Steve Antona3a92c22017-12-07 10:27:41 -0800960 WebRtcSdpTest() : jdesc_(kDummyType) {
phoglund37ebcf02016-01-08 05:04:57 -0800961#ifdef WEBRTC_ANDROID
962 webrtc::InitializeAndroidObjects();
963#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000964 // AudioContentDescription
965 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -0800966 StreamParams audio_stream;
967 audio_stream.id = kAudioTrackId1;
968 audio_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -0800969 audio_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -0800970 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
971 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 11:04:53 -0700972 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
973 audio_desc_->set_connection_address(audio_addr);
Harald Alvestrand1716d392019-06-03 20:35:45 +0200974 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
975 absl::WrapUnique(audio_desc_));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000976
977 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -0800978 video_desc_ = CreateVideoContentDescription();
979 StreamParams video_stream;
980 video_stream.id = kVideoTrackId1;
981 video_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -0800982 video_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -0800983 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
984 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
985 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
986 video_stream.ssrc_groups.push_back(ssrc_group);
987 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 11:04:53 -0700988 rtc::SocketAddress video_addr("74.125.224.39", 3457);
989 video_desc_->set_connection_address(video_addr);
Harald Alvestrand1716d392019-06-03 20:35:45 +0200990 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp,
991 absl::WrapUnique(video_desc_));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000992
993 // TransportInfo
Steve Anton06817cd2018-12-18 15:55:30 -0800994 desc_.AddTransportInfo(TransportInfo(
995 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice)));
996 desc_.AddTransportInfo(TransportInfo(
997 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000998
999 // v4 host
1000 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001001 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001002 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001003 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1004 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001005 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001006 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001007 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1008 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001009 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001010 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001011 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1012 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001013 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001014 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001015 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1016 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001017
1018 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001019 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001020 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1021 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001022 cricket::LOCAL_PORT_TYPE,
1023 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001024 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001025 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1026 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001027 cricket::LOCAL_PORT_TYPE,
1028 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001029 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001030 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1031 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001032 cricket::LOCAL_PORT_TYPE,
1033 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001034 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001035 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1036 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001037 cricket::LOCAL_PORT_TYPE,
1038 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001039
1040 // stun
1041 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001042 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
1043 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001044 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1045 address_stun, kCandidatePriority, "", "",
1046 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001047 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001048 candidate9.set_related_address(rel_address_stun);
1049
1050 address_stun.SetPort(port_stun++);
1051 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001052 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1053 address_stun, kCandidatePriority, "", "",
1054 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001055 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001056 candidate10.set_related_address(rel_address_stun);
1057
1058 // relay
1059 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001060 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001061 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1062 address_relay, kCandidatePriority, "", "",
1063 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001064 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001065 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001066 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1067 address_relay, kCandidatePriority, "", "",
1068 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001069 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001070
1071 // voice
1072 candidates_.push_back(candidate1);
1073 candidates_.push_back(candidate2);
1074 candidates_.push_back(candidate5);
1075 candidates_.push_back(candidate6);
1076 candidates_.push_back(candidate9);
1077 candidates_.push_back(candidate10);
1078
1079 // video
1080 candidates_.push_back(candidate3);
1081 candidates_.push_back(candidate4);
1082 candidates_.push_back(candidate7);
1083 candidates_.push_back(candidate8);
1084 candidates_.push_back(candidate11);
1085 candidates_.push_back(candidate12);
1086
Yves Gerey665174f2018-06-19 15:03:05 +02001087 jcandidate_.reset(
1088 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001089
1090 // Set up JsepSessionDescription.
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001091 jdesc_.Initialize(desc_.Clone(), kSessionId, kSessionVersion);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001092 std::string mline_id;
1093 int mline_index = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001094 for (size_t i = 0; i < candidates_.size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001095 // In this test, the audio m line index will be 0, and the video m line
1096 // will be 1.
1097 bool is_video = (i > 5);
1098 mline_id = is_video ? "video_content_name" : "audio_content_name";
1099 mline_index = is_video ? 1 : 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001100 JsepIceCandidate jice(mline_id, mline_index, candidates_.at(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001101 jdesc_.AddCandidate(&jice);
1102 }
1103 }
1104
Seth Hampson5b4f0752018-04-02 16:31:36 -07001105 void RemoveVideoCandidates() {
deadbeef25ed4352016-12-12 18:37:36 -08001106 const IceCandidateCollection* video_candidates_collection =
1107 jdesc_.candidates(1);
1108 ASSERT_NE(nullptr, video_candidates_collection);
1109 std::vector<cricket::Candidate> video_candidates;
1110 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1111 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1112 c.set_transport_name("video_content_name");
1113 video_candidates.push_back(c);
1114 }
1115 jdesc_.RemoveCandidates(video_candidates);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001116 }
1117
1118 // Turns the existing reference description into a description using
1119 // a=bundle-only. This means no transport attributes and a 0 port value on
1120 // the m= sections not associated with the BUNDLE-tag.
1121 void MakeBundleOnlyDescription() {
1122 RemoveVideoCandidates();
deadbeef25ed4352016-12-12 18:37:36 -08001123
1124 // And the rest of the transport attributes.
1125 desc_.transport_infos()[1].description.ice_ufrag.clear();
1126 desc_.transport_infos()[1].description.ice_pwd.clear();
1127 desc_.transport_infos()[1].description.connection_role =
1128 cricket::CONNECTIONROLE_NONE;
1129
1130 // Set bundle-only flag.
1131 desc_.contents()[1].bundle_only = true;
1132
1133 // Add BUNDLE group.
1134 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1135 group.AddContentName(kAudioContentName);
1136 group.AddContentName(kVideoContentName);
1137 desc_.AddGroup(group);
1138
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001139 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef25ed4352016-12-12 18:37:36 -08001140 jdesc_.session_version()));
1141 }
1142
deadbeef9d3584c2016-02-16 17:54:10 -08001143 // Turns the existing reference description into a plan B description,
1144 // with 2 audio tracks and 3 video tracks.
1145 void MakePlanBDescription() {
Harald Alvestrandb97d2fe2020-02-28 11:54:40 +01001146 audio_desc_ = new AudioContentDescription(*audio_desc_);
1147 video_desc_ = new VideoContentDescription(*video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001148
1149 StreamParams audio_track_2;
1150 audio_track_2.id = kAudioTrackId2;
1151 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001152 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001153 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1154 audio_desc_->AddStream(audio_track_2);
1155
1156 StreamParams video_track_2;
1157 video_track_2.id = kVideoTrackId2;
1158 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001159 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001160 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1161 video_desc_->AddStream(video_track_2);
1162
1163 StreamParams video_track_3;
1164 video_track_3.id = kVideoTrackId3;
1165 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001166 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001167 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1168 video_desc_->AddStream(video_track_3);
1169
1170 desc_.RemoveContentByName(kAudioContentName);
1171 desc_.RemoveContentByName(kVideoContentName);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001172 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1173 absl::WrapUnique(audio_desc_));
1174 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp,
1175 absl::WrapUnique(video_desc_));
deadbeef9d3584c2016-02-16 17:54:10 -08001176
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001177 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef9d3584c2016-02-16 17:54:10 -08001178 jdesc_.session_version()));
1179 }
1180
1181 // Turns the existing reference description into a unified plan description,
1182 // with 2 audio tracks and 3 video tracks.
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001183 void MakeUnifiedPlanDescription(bool use_ssrcs = true) {
deadbeef9d3584c2016-02-16 17:54:10 -08001184 // Audio track 2.
1185 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1186 StreamParams audio_track_2;
1187 audio_track_2.id = kAudioTrackId2;
Seth Hampson845e8782018-03-02 11:34:10 -08001188 audio_track_2.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001189 if (use_ssrcs) {
1190 audio_track_2.cname = kStream2Cname;
1191 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1192 }
deadbeef9d3584c2016-02-16 17:54:10 -08001193 audio_desc_2->AddStream(audio_track_2);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001194 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp,
1195 absl::WrapUnique(audio_desc_2));
Steve Anton06817cd2018-12-18 15:55:30 -08001196 desc_.AddTransportInfo(TransportInfo(
1197 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2)));
deadbeef9d3584c2016-02-16 17:54:10 -08001198 // Video track 2, in stream 2.
1199 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1200 StreamParams video_track_2;
1201 video_track_2.id = kVideoTrackId2;
Seth Hampson845e8782018-03-02 11:34:10 -08001202 video_track_2.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001203 if (use_ssrcs) {
1204 video_track_2.cname = kStream2Cname;
1205 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1206 }
deadbeef9d3584c2016-02-16 17:54:10 -08001207 video_desc_2->AddStream(video_track_2);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001208 desc_.AddContent(kVideoContentName2, MediaProtocolType::kRtp,
1209 absl::WrapUnique(video_desc_2));
Steve Anton06817cd2018-12-18 15:55:30 -08001210 desc_.AddTransportInfo(TransportInfo(
1211 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2)));
deadbeef9d3584c2016-02-16 17:54:10 -08001212
1213 // Video track 3, in stream 2.
1214 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1215 StreamParams video_track_3;
1216 video_track_3.id = kVideoTrackId3;
Seth Hampson845e8782018-03-02 11:34:10 -08001217 video_track_3.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001218 if (use_ssrcs) {
1219 video_track_3.cname = kStream2Cname;
1220 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1221 }
deadbeef9d3584c2016-02-16 17:54:10 -08001222 video_desc_3->AddStream(video_track_3);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001223 desc_.AddContent(kVideoContentName3, MediaProtocolType::kRtp,
1224 absl::WrapUnique(video_desc_3));
Steve Anton06817cd2018-12-18 15:55:30 -08001225 desc_.AddTransportInfo(TransportInfo(
1226 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3)));
Steve Antone831b8c2018-02-01 12:22:16 -08001227 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
deadbeef9d3584c2016-02-16 17:54:10 -08001228
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001229 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef9d3584c2016-02-16 17:54:10 -08001230 jdesc_.session_version()));
1231 }
1232
1233 // Creates an audio content description with no streams, and some default
1234 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001235 AudioContentDescription* CreateAudioContentDescription() {
1236 AudioContentDescription* audio = new AudioContentDescription();
1237 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -08001238 audio->set_rtcp_reduced_size(true);
Harald Alvestrand0d018412021-11-04 13:52:31 +00001239 audio->AddCrypto(CryptoParams(
1240 1, "AES_CM_128_HMAC_SHA1_32",
1241 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1242 "dummy_session_params"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001243 audio->set_protocol(cricket::kMediaProtocolSavpf);
Philipp Hanckef2a4ec12020-07-01 21:07:32 +02001244 audio->AddCodec(AudioCodec(111, "opus", 48000, 0, 2));
ossue1405ad2017-01-23 08:55:48 -08001245 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1246 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001247 return audio;
1248 }
1249
Seth Hampson5b4f0752018-04-02 16:31:36 -07001250 // Turns the existing reference description into a unified plan description,
1251 // with 3 audio MediaContentDescriptions with special StreamParams that
1252 // contain 0 or multiple stream ids: - audio track 1 has 1 media stream id -
1253 // audio track 2 has 2 media stream ids - audio track 3 has 0 media stream ids
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001254 void MakeUnifiedPlanDescriptionMultipleStreamIds(const int msid_signaling) {
Seth Hampson5b4f0752018-04-02 16:31:36 -07001255 desc_.RemoveContentByName(kVideoContentName);
1256 desc_.RemoveTransportInfoByName(kVideoContentName);
1257 RemoveVideoCandidates();
1258
1259 // Audio track 2 has 2 media stream ids.
1260 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1261 StreamParams audio_track_2;
1262 audio_track_2.id = kAudioTrackId2;
1263 audio_track_2.cname = kStream1Cname;
1264 audio_track_2.set_stream_ids({kStreamId1, kStreamId2});
1265 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1266 audio_desc_2->AddStream(audio_track_2);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001267 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp,
1268 absl::WrapUnique(audio_desc_2));
Steve Anton06817cd2018-12-18 15:55:30 -08001269 desc_.AddTransportInfo(TransportInfo(
1270 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2)));
Seth Hampson5b4f0752018-04-02 16:31:36 -07001271
1272 // Audio track 3 has no stream ids.
1273 AudioContentDescription* audio_desc_3 = CreateAudioContentDescription();
1274 StreamParams audio_track_3;
1275 audio_track_3.id = kAudioTrackId3;
1276 audio_track_3.cname = kStream2Cname;
1277 audio_track_3.set_stream_ids({});
1278 audio_track_3.ssrcs.push_back(kAudioTrack3Ssrc);
1279 audio_desc_3->AddStream(audio_track_3);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001280 desc_.AddContent(kAudioContentName3, MediaProtocolType::kRtp,
1281 absl::WrapUnique(audio_desc_3));
Steve Anton06817cd2018-12-18 15:55:30 -08001282 desc_.AddTransportInfo(TransportInfo(
1283 kAudioContentName3, TransportDescription(kUfragVoice3, kPwdVoice3)));
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001284 desc_.set_msid_signaling(msid_signaling);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001285 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
Seth Hampson5b4f0752018-04-02 16:31:36 -07001286 jdesc_.session_version()));
1287 }
1288
Seth Hampson5897a6e2018-04-03 11:16:33 -07001289 // Turns the existing reference description into a unified plan description
1290 // with one audio MediaContentDescription that contains one StreamParams with
1291 // 0 ssrcs.
1292 void MakeUnifiedPlanDescriptionNoSsrcSignaling() {
1293 desc_.RemoveContentByName(kVideoContentName);
1294 desc_.RemoveContentByName(kAudioContentName);
1295 desc_.RemoveTransportInfoByName(kVideoContentName);
1296 RemoveVideoCandidates();
1297
1298 AudioContentDescription* audio_desc = CreateAudioContentDescription();
1299 StreamParams audio_track;
1300 audio_track.id = kAudioTrackId1;
1301 audio_track.set_stream_ids({kStreamId1});
1302 audio_desc->AddStream(audio_track);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001303 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1304 absl::WrapUnique(audio_desc));
Seth Hampson5897a6e2018-04-03 11:16:33 -07001305
1306 // Enable signaling a=msid lines.
1307 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001308 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
Seth Hampson5897a6e2018-04-03 11:16:33 -07001309 jdesc_.session_version()));
1310 }
1311
deadbeef9d3584c2016-02-16 17:54:10 -08001312 // Creates a video content description with no streams, and some default
1313 // configuration.
1314 VideoContentDescription* CreateVideoContentDescription() {
1315 VideoContentDescription* video = new VideoContentDescription();
Harald Alvestrand0d018412021-11-04 13:52:31 +00001316 video->AddCrypto(CryptoParams(
1317 1, "AES_CM_128_HMAC_SHA1_80",
1318 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
deadbeef9d3584c2016-02-16 17:54:10 -08001319 video->set_protocol(cricket::kMediaProtocolSavpf);
1320 video->AddCodec(
perkj26752742016-10-24 01:21:16 -07001321 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-16 17:54:10 -08001322 return video;
1323 }
1324
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001325 template <class MCD>
Yves Gerey665174f2018-06-19 15:03:05 +02001326 void CompareMediaContentDescription(const MCD* cd1, const MCD* cd2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001327 // type
Harald Alvestrand1716d392019-06-03 20:35:45 +02001328 EXPECT_EQ(cd1->type(), cd2->type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001329
1330 // content direction
1331 EXPECT_EQ(cd1->direction(), cd2->direction());
1332
1333 // rtcp_mux
1334 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1335
deadbeef13871492015-12-09 12:37:51 -08001336 // rtcp_reduced_size
1337 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1338
Harald Alvestrand0d018412021-11-04 13:52:31 +00001339 // cryptos
1340 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1341 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1342 ADD_FAILURE();
1343 return;
1344 }
1345 for (size_t i = 0; i < cd1->cryptos().size(); ++i) {
1346 const CryptoParams c1 = cd1->cryptos().at(i);
1347 const CryptoParams c2 = cd2->cryptos().at(i);
1348 EXPECT_TRUE(c1.Matches(c2));
1349 EXPECT_EQ(c1.key_params, c2.key_params);
1350 EXPECT_EQ(c1.session_params, c2.session_params);
1351 }
1352
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001353 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001354 // Use an equivalence class here, for old and new versions of the
1355 // protocol description.
Yves Gerey665174f2018-06-19 15:03:05 +02001356 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp ||
1357 cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1358 cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
lally@webrtc.org36300852015-02-24 20:19:35 +00001359 const bool cd2_is_also_dtls_sctp =
Yves Gerey665174f2018-06-19 15:03:05 +02001360 cd2->protocol() == cricket::kMediaProtocolDtlsSctp ||
1361 cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1362 cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
lally@webrtc.org36300852015-02-24 20:19:35 +00001363 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001364 } else {
1365 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1366 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001367
1368 // codecs
1369 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1370
1371 // bandwidth
1372 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1373
1374 // streams
1375 EXPECT_EQ(cd1->streams(), cd2->streams());
1376
Johannes Kron0854eb62018-10-10 22:33:20 +02001377 // extmap-allow-mixed
Johannes Kron9581bc42018-10-23 10:17:39 +02001378 EXPECT_EQ(cd1->extmap_allow_mixed_enum(), cd2->extmap_allow_mixed_enum());
Johannes Kron0854eb62018-10-10 22:33:20 +02001379
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001380 // extmap
1381 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1382 cd2->rtp_header_extensions().size());
Yves Gerey665174f2018-06-19 15:03:05 +02001383 for (size_t i = 0; i < cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 11:24:55 -07001384 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1385 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001386 EXPECT_EQ(ext1.uri, ext2.uri);
1387 EXPECT_EQ(ext1.id, ext2.id);
jbauch5869f502017-06-29 12:31:36 -07001388 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001389 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001390 }
1391
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001392 void CompareRidDescriptionIds(const std::vector<RidDescription>& rids,
1393 const std::vector<std::string>& ids) {
1394 // Order of elements does not matter, only equivalence of sets.
1395 EXPECT_EQ(rids.size(), ids.size());
1396 for (const std::string& id : ids) {
Steve Anton64b626b2019-01-28 17:25:26 -08001397 EXPECT_EQ(1l, absl::c_count_if(rids, [id](const RidDescription& rid) {
1398 return rid.rid == id;
1399 }));
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001400 }
1401 }
1402
Amit Hilbucha2012042018-12-03 11:35:05 -08001403 void CompareSimulcastDescription(const SimulcastDescription& simulcast1,
1404 const SimulcastDescription& simulcast2) {
1405 EXPECT_EQ(simulcast1.send_layers().size(), simulcast2.send_layers().size());
1406 EXPECT_EQ(simulcast1.receive_layers().size(),
1407 simulcast2.receive_layers().size());
1408 }
1409
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001410 void CompareSctpDataContentDescription(
1411 const SctpDataContentDescription* dcd1,
1412 const SctpDataContentDescription* dcd2) {
Harald Alvestrand26bf7c42019-04-23 05:20:17 +00001413 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001414 EXPECT_EQ(dcd1->port(), dcd2->port());
1415 EXPECT_EQ(dcd1->max_message_size(), dcd2->max_message_size());
Harald Alvestrand26bf7c42019-04-23 05:20:17 +00001416 }
1417
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001418 void CompareSessionDescription(const SessionDescription& desc1,
1419 const SessionDescription& desc2) {
1420 // Compare content descriptions.
1421 if (desc1.contents().size() != desc2.contents().size()) {
1422 ADD_FAILURE();
1423 return;
1424 }
Yves Gerey665174f2018-06-19 15:03:05 +02001425 for (size_t i = 0; i < desc1.contents().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001426 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1427 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-12 18:37:36 -08001428 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001429 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-12 18:37:36 -08001430 EXPECT_EQ(c1.type, c2.type);
1431 EXPECT_EQ(c1.rejected, c2.rejected);
1432 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001433
1434 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1435 if (IsAudioContent(&c1)) {
1436 const AudioContentDescription* acd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001437 c1.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001438 const AudioContentDescription* acd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001439 c2.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001440 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1441 }
1442
1443 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1444 if (IsVideoContent(&c1)) {
1445 const VideoContentDescription* vcd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001446 c1.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001447 const VideoContentDescription* vcd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001448 c2.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001449 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1450 }
1451
1452 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001453 if (c1.media_description()->as_sctp()) {
1454 ASSERT_TRUE(c2.media_description()->as_sctp());
1455 const SctpDataContentDescription* scd1 =
1456 c1.media_description()->as_sctp();
1457 const SctpDataContentDescription* scd2 =
1458 c2.media_description()->as_sctp();
1459 CompareSctpDataContentDescription(scd1, scd2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001460 }
Amit Hilbucha2012042018-12-03 11:35:05 -08001461
1462 CompareSimulcastDescription(
1463 c1.media_description()->simulcast_description(),
1464 c2.media_description()->simulcast_description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001465 }
1466
1467 // group
1468 const cricket::ContentGroups groups1 = desc1.groups();
1469 const cricket::ContentGroups groups2 = desc2.groups();
1470 EXPECT_EQ(groups1.size(), groups1.size());
1471 if (groups1.size() != groups2.size()) {
1472 ADD_FAILURE();
1473 return;
1474 }
1475 for (size_t i = 0; i < groups1.size(); ++i) {
1476 const cricket::ContentGroup group1 = groups1.at(i);
1477 const cricket::ContentGroup group2 = groups2.at(i);
1478 EXPECT_EQ(group1.semantics(), group2.semantics());
1479 const cricket::ContentNames names1 = group1.content_names();
1480 const cricket::ContentNames names2 = group2.content_names();
1481 EXPECT_EQ(names1.size(), names2.size());
1482 if (names1.size() != names2.size()) {
1483 ADD_FAILURE();
1484 return;
1485 }
1486 cricket::ContentNames::const_iterator iter1 = names1.begin();
1487 cricket::ContentNames::const_iterator iter2 = names2.begin();
1488 while (iter1 != names1.end()) {
1489 EXPECT_EQ(*iter1++, *iter2++);
1490 }
1491 }
1492
1493 // transport info
1494 const cricket::TransportInfos transports1 = desc1.transport_infos();
1495 const cricket::TransportInfos transports2 = desc2.transport_infos();
1496 EXPECT_EQ(transports1.size(), transports2.size());
1497 if (transports1.size() != transports2.size()) {
1498 ADD_FAILURE();
1499 return;
1500 }
1501 for (size_t i = 0; i < transports1.size(); ++i) {
1502 const cricket::TransportInfo transport1 = transports1.at(i);
1503 const cricket::TransportInfo transport2 = transports2.at(i);
1504 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001505 EXPECT_EQ(transport1.description.ice_ufrag,
1506 transport2.description.ice_ufrag);
Yves Gerey665174f2018-06-19 15:03:05 +02001507 EXPECT_EQ(transport1.description.ice_pwd, transport2.description.ice_pwd);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07001508 EXPECT_EQ(transport1.description.ice_mode,
1509 transport2.description.ice_mode);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001510 if (transport1.description.identity_fingerprint) {
1511 EXPECT_EQ(*transport1.description.identity_fingerprint,
1512 *transport2.description.identity_fingerprint);
1513 } else {
1514 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1515 transport2.description.identity_fingerprint.get());
1516 }
1517 EXPECT_EQ(transport1.description.transport_options,
1518 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001519 }
deadbeefc80741f2015-10-22 13:14:45 -07001520
1521 // global attributes
1522 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
Johannes Kron9581bc42018-10-23 10:17:39 +02001523 EXPECT_EQ(desc1.extmap_allow_mixed(), desc2.extmap_allow_mixed());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001524 }
1525
Yves Gerey665174f2018-06-19 15:03:05 +02001526 bool CompareSessionDescription(const JsepSessionDescription& desc1,
1527 const JsepSessionDescription& desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001528 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1529 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1530 CompareSessionDescription(*desc1.description(), *desc2.description());
1531 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1532 return false;
1533 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1534 const IceCandidateCollection* cc1 = desc1.candidates(i);
1535 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-12 18:37:36 -08001536 if (cc1->count() != cc2->count()) {
1537 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001538 return false;
deadbeef25ed4352016-12-12 18:37:36 -08001539 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001540 for (size_t j = 0; j < cc1->count(); ++j) {
1541 const IceCandidateInterface* c1 = cc1->at(j);
1542 const IceCandidateInterface* c2 = cc2->at(j);
1543 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1544 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1545 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1546 }
1547 }
1548 return true;
1549 }
1550
Artem Titov880fa812021-07-30 22:30:23 +02001551 // Disable the ice-ufrag and ice-pwd in given `sdp` message by replacing
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001552 // them with invalid keywords so that the parser will just ignore them.
1553 bool RemoveCandidateUfragPwd(std::string* sdp) {
Steve Anton1c9c9fc2019-02-14 15:13:09 -08001554 absl::StrReplaceAll(
1555 {{"a=ice-ufrag", "a=xice-ufrag"}, {"a=ice-pwd", "a=xice-pwd"}}, sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001556 return true;
1557 }
1558
Artem Titov880fa812021-07-30 22:30:23 +02001559 // Update the candidates in `jdesc` to use the given `ufrag` and `pwd`.
Yves Gerey665174f2018-06-19 15:03:05 +02001560 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc,
1561 int mline_index,
1562 const std::string& ufrag,
1563 const std::string& pwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001564 std::string content_name;
1565 if (mline_index == 0) {
1566 content_name = kAudioContentName;
1567 } else if (mline_index == 1) {
1568 content_name = kVideoContentName;
1569 } else {
Artem Titovd3251962021-11-15 16:57:07 +01001570 RTC_DCHECK_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001571 }
Yves Gerey665174f2018-06-19 15:03:05 +02001572 TransportInfo transport_info(content_name,
1573 TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001574 SessionDescription* desc =
1575 const_cast<SessionDescription*>(jdesc->description());
1576 desc->RemoveTransportInfoByName(content_name);
Steve Anton06817cd2018-12-18 15:55:30 -08001577 desc->AddTransportInfo(transport_info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001578 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1579 const IceCandidateCollection* cc = jdesc_.candidates(i);
1580 for (size_t j = 0; j < cc->count(); ++j) {
1581 if (cc->at(j)->sdp_mline_index() == mline_index) {
Yves Gerey665174f2018-06-19 15:03:05 +02001582 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(ufrag);
1583 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001584 }
1585 }
1586 }
1587 return true;
1588 }
1589
1590 void AddIceOptions(const std::string& content_name,
1591 const std::vector<std::string>& transport_options) {
1592 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1593 cricket::TransportInfo transport_info =
1594 *(desc_.GetTransportInfoByName(content_name));
1595 desc_.RemoveTransportInfoByName(content_name);
1596 transport_info.description.transport_options = transport_options;
1597 desc_.AddTransportInfo(transport_info);
1598 }
1599
deadbeef3f7219b2015-12-28 15:17:14 -08001600 void SetIceUfragPwd(const std::string& content_name,
1601 const std::string& ice_ufrag,
1602 const std::string& ice_pwd) {
1603 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1604 cricket::TransportInfo transport_info =
1605 *(desc_.GetTransportInfoByName(content_name));
1606 desc_.RemoveTransportInfoByName(content_name);
1607 transport_info.description.ice_ufrag = ice_ufrag;
1608 transport_info.description.ice_pwd = ice_pwd;
1609 desc_.AddTransportInfo(transport_info);
1610 }
1611
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001612 void AddFingerprint() {
1613 desc_.RemoveTransportInfoByName(kAudioContentName);
1614 desc_.RemoveTransportInfoByName(kVideoContentName);
Steve Anton4905edb2018-10-15 19:27:44 -07001615 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, kIdentityDigest);
Steve Anton06817cd2018-12-18 15:55:30 -08001616 desc_.AddTransportInfo(TransportInfo(
deadbeef46eed762016-01-28 13:24:37 -08001617 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001618 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1619 cricket::ICEMODE_FULL,
Steve Anton06817cd2018-12-18 15:55:30 -08001620 cricket::CONNECTIONROLE_NONE, &fingerprint)));
1621 desc_.AddTransportInfo(TransportInfo(
deadbeef46eed762016-01-28 13:24:37 -08001622 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001623 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1624 cricket::ICEMODE_FULL,
Steve Anton06817cd2018-12-18 15:55:30 -08001625 cricket::CONNECTIONROLE_NONE, &fingerprint)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001626 }
1627
jbauch5869f502017-06-29 12:31:36 -07001628 void AddExtmap(bool encrypted) {
Harald Alvestrandb97d2fe2020-02-28 11:54:40 +01001629 audio_desc_ = new AudioContentDescription(*audio_desc_);
1630 video_desc_ = new VideoContentDescription(*video_desc_);
jbauch5869f502017-06-29 12:31:36 -07001631 audio_desc_->AddRtpHeaderExtension(
1632 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1633 video_desc_->AddRtpHeaderExtension(
1634 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001635 desc_.RemoveContentByName(kAudioContentName);
1636 desc_.RemoveContentByName(kVideoContentName);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001637 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1638 absl::WrapUnique(audio_desc_));
1639 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp,
1640 absl::WrapUnique(video_desc_));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001641 }
1642
Harald Alvestrand0d018412021-11-04 13:52:31 +00001643 void RemoveCryptos() {
1644 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1645 video_desc_->set_cryptos(std::vector<CryptoParams>());
1646 }
1647
Seth Hampson5897a6e2018-04-03 11:16:33 -07001648 // Removes everything in StreamParams from the session description that is
1649 // used for a=ssrc lines.
1650 void RemoveSsrcSignalingFromStreamParams() {
Harald Alvestrand1716d392019-06-03 20:35:45 +02001651 for (cricket::ContentInfo& content_info :
1652 jdesc_.description()->contents()) {
Seth Hampson5897a6e2018-04-03 11:16:33 -07001653 // With Unified Plan there should be one StreamParams per m= section.
1654 StreamParams& stream =
1655 content_info.media_description()->mutable_streams()[0];
1656 stream.ssrcs.clear();
1657 stream.ssrc_groups.clear();
1658 stream.cname.clear();
1659 }
1660 }
1661
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001662 // Removes all a=ssrc lines from the SDP string, except for the
1663 // "a=ssrc:... cname:..." lines.
1664 void RemoveSsrcMsidLinesFromSdpString(std::string* sdp_string) {
1665 const char kAttributeSsrc[] = "a=ssrc";
1666 const char kAttributeCname[] = "cname";
1667 size_t ssrc_line_pos = sdp_string->find(kAttributeSsrc);
1668 while (ssrc_line_pos != std::string::npos) {
1669 size_t beg_line_pos = sdp_string->rfind('\n', ssrc_line_pos);
1670 size_t end_line_pos = sdp_string->find('\n', ssrc_line_pos);
1671 size_t cname_pos = sdp_string->find(kAttributeCname, ssrc_line_pos);
1672 if (cname_pos == std::string::npos || cname_pos > end_line_pos) {
1673 // Only erase a=ssrc lines that don't contain "cname".
1674 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1675 ssrc_line_pos = sdp_string->find(kAttributeSsrc, beg_line_pos);
1676 } else {
1677 // Skip the "a=ssrc:... cname" line and find the next "a=ssrc" line.
1678 ssrc_line_pos = sdp_string->find(kAttributeSsrc, end_line_pos);
1679 }
1680 }
1681 }
1682
Seth Hampson5897a6e2018-04-03 11:16:33 -07001683 // Removes all a=ssrc lines from the SDP string.
1684 void RemoveSsrcLinesFromSdpString(std::string* sdp_string) {
1685 const char kAttributeSsrc[] = "a=ssrc";
1686 while (sdp_string->find(kAttributeSsrc) != std::string::npos) {
1687 size_t pos_ssrc_attribute = sdp_string->find(kAttributeSsrc);
1688 size_t beg_line_pos = sdp_string->rfind('\n', pos_ssrc_attribute);
1689 size_t end_line_pos = sdp_string->find('\n', pos_ssrc_attribute);
1690 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1691 }
1692 }
1693
Steve Anton4e70a722017-11-28 14:57:10 -08001694 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001695 audio_desc_->set_direction(direction);
1696 video_desc_->set_direction(direction);
1697 std::string new_sdp = kSdpFullString;
1698 ReplaceDirection(direction, &new_sdp);
1699
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001700 if (!jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001701 jdesc_.session_version())) {
1702 return false;
1703 }
Steve Antone831b8c2018-02-01 12:22:16 -08001704 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001705 EXPECT_EQ(new_sdp, message);
1706 return true;
1707 }
1708
1709 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
Harald Alvestrandb97d2fe2020-02-28 11:54:40 +01001710 audio_desc_ = new AudioContentDescription(*audio_desc_);
1711 video_desc_ = new VideoContentDescription(*video_desc_);
zhihuang38989e52017-03-21 11:04:53 -07001712
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001713 desc_.RemoveContentByName(kAudioContentName);
1714 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001715 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001716 absl::WrapUnique(audio_desc_));
Steve Anton5adfafd2017-12-20 16:34:00 -08001717 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001718 absl::WrapUnique(video_desc_));
deadbeef9d3584c2016-02-16 17:54:10 -08001719 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1720 audio_rejected ? "" : kPwdVoice);
1721 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1722 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001723
1724 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001725 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1726
Steve Antona3a92c22017-12-07 10:27:41 -08001727 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001728 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001729 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001730 EXPECT_EQ(new_sdp, message);
1731 return true;
1732 }
1733
zstein4b2e0822017-02-17 19:48:38 -08001734 void AddSctpDataChannel(bool use_sctpmap) {
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001735 std::unique_ptr<SctpDataContentDescription> data(
1736 new SctpDataContentDescription());
1737 sctp_desc_ = data.get();
1738 sctp_desc_->set_use_sctpmap(use_sctpmap);
Guido Urdanetacecf87f2019-05-31 10:17:38 +00001739 sctp_desc_->set_protocol(cricket::kMediaProtocolUdpDtlsSctp);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001740 sctp_desc_->set_port(kDefaultSctpPort);
Steve Anton5adfafd2017-12-20 16:34:00 -08001741 desc_.AddContent(kDataContentName, MediaProtocolType::kSctp,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001742 std::move(data));
Steve Anton06817cd2018-12-18 15:55:30 -08001743 desc_.AddTransportInfo(TransportInfo(
1744 kDataContentName, TransportDescription(kUfragData, kPwdData)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001745 }
1746
Steve Anton4e70a722017-11-28 14:57:10 -08001747 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001748 std::string new_sdp = kSdpFullString;
1749 ReplaceDirection(direction, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001750 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001751
1752 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1753
1754 audio_desc_->set_direction(direction);
1755 video_desc_->set_direction(direction);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001756 if (!jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001757 jdesc_.session_version())) {
1758 return false;
1759 }
1760 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1761 return true;
1762 }
1763
1764 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001765 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001766 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001767 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001768 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001769
Harald Alvestrandb97d2fe2020-02-28 11:54:40 +01001770 audio_desc_ = new AudioContentDescription(*audio_desc_);
1771 video_desc_ = new VideoContentDescription(*video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001772 desc_.RemoveContentByName(kAudioContentName);
1773 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001774 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001775 absl::WrapUnique(audio_desc_));
Steve Anton5adfafd2017-12-20 16:34:00 -08001776 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001777 absl::WrapUnique(video_desc_));
deadbeef9d3584c2016-02-16 17:54:10 -08001778 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1779 audio_rejected ? "" : kPwdVoice);
1780 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1781 video_rejected ? "" : kPwdVideo);
Steve Antona3a92c22017-12-07 10:27:41 -08001782 JsepSessionDescription jdesc_no_candidates(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001783 if (!jdesc_no_candidates.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef3f7219b2015-12-28 15:17:14 -08001784 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001785 return false;
1786 }
deadbeef3f7219b2015-12-28 15:17:14 -08001787 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001788 return true;
1789 }
1790
Yves Gerey665174f2018-06-19 15:03:05 +02001791 void TestDeserializeExtmap(bool session_level,
1792 bool media_level,
1793 bool encrypted) {
jbauch5869f502017-06-29 12:31:36 -07001794 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08001795 JsepSessionDescription new_jdesc(SdpType::kOffer);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001796 ASSERT_TRUE(new_jdesc.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001797 jdesc_.session_version()));
Steve Antona3a92c22017-12-07 10:27:41 -08001798 JsepSessionDescription jdesc_with_extmap(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001799 std::string sdp_with_extmap = kSdpString;
1800 if (session_level) {
jbauch5869f502017-06-29 12:31:36 -07001801 InjectAfter(kSessionTime,
1802 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1803 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001804 &sdp_with_extmap);
1805 }
1806 if (media_level) {
jbauch5869f502017-06-29 12:31:36 -07001807 InjectAfter(kAttributeIcePwdVoice,
1808 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1809 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001810 &sdp_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07001811 InjectAfter(kAttributeIcePwdVideo,
1812 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1813 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001814 &sdp_with_extmap);
1815 }
1816 // The extmap can't be present at the same time in both session level and
1817 // media level.
1818 if (session_level && media_level) {
1819 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02001820 EXPECT_FALSE(
1821 webrtc::SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001822 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1823 } else {
1824 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1825 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1826 }
1827 }
1828
1829 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
Yves Gerey665174f2018-06-19 15:03:05 +02001830 const std::string& name,
1831 int expected_value) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001832 cricket::CodecParameterMap::const_iterator found = params.find(name);
1833 ASSERT_TRUE(found != params.end());
Jonas Olsson6b1985d2018-07-05 11:59:48 +02001834 EXPECT_EQ(found->second, rtc::ToString(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001835 }
1836
1837 void TestDeserializeCodecParams(const CodecParams& params,
1838 JsepSessionDescription* jdesc_output) {
1839 std::string sdp =
1840 "v=0\r\n"
1841 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1842 "s=-\r\n"
1843 "t=0 0\r\n"
1844 // Include semantics for WebRTC Media Streams since it is supported by
1845 // this parser, and will be added to the SDP when serializing a session
1846 // description.
1847 "a=msid-semantic: WMS\r\n"
1848 // Pl type 111 preferred.
Philipp Hanckef2a4ec12020-07-01 21:07:32 +02001849 "m=audio 9 RTP/SAVPF 111 104 103 105\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001850 // Pltype 111 listed before 103 and 104 in the map.
1851 "a=rtpmap:111 opus/48000/2\r\n"
1852 // Pltype 103 listed before 104.
1853 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001854 "a=rtpmap:104 ISAC/32000\r\n"
Philipp Hanckef2a4ec12020-07-01 21:07:32 +02001855 "a=rtpmap:105 telephone-event/8000\r\n"
1856 "a=fmtp:105 0-15,66,70\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001857 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001858 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001859 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001860 << "; sprop-stereo=" << params.sprop_stereo
1861 << "; useinbandfec=" << params.useinband
Jonas Olssonb2b20312020-01-14 12:11:31 +01001862 << "; maxaveragebitrate=" << params.maxaveragebitrate
1863 << "\r\n"
1864 "a=ptime:"
1865 << params.ptime
1866 << "\r\n"
1867 "a=maxptime:"
1868 << params.max_ptime << "\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001869 sdp += os.str();
1870
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001871 os.clear();
1872 os.str("");
1873 // Pl type 100 preferred.
Philipp Hanckeb7bc2432021-03-11 15:28:00 +01001874 os << "m=video 9 RTP/SAVPF 99 95 96\r\n"
1875 "a=rtpmap:96 VP9/90000\r\n" // out-of-order wrt the m= line.
Jonas Olssonb2b20312020-01-14 12:11:31 +01001876 "a=rtpmap:99 VP8/90000\r\n"
1877 "a=rtpmap:95 RTX/90000\r\n"
1878 "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001879 sdp += os.str();
1880
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001881 // Deserialize
1882 SdpParseError error;
1883 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1884
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001885 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001886 GetFirstAudioContentDescription(jdesc_output->description());
1887 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001888 ASSERT_FALSE(acd->codecs().empty());
1889 cricket::AudioCodec opus = acd->codecs()[0];
1890 EXPECT_EQ("opus", opus.name);
1891 EXPECT_EQ(111, opus.id);
1892 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1893 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1894 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1895 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001896 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1897 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001898 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1899 cricket::AudioCodec codec = acd->codecs()[i];
1900 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1901 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001902 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001903
Philipp Hanckef2a4ec12020-07-01 21:07:32 +02001904 cricket::AudioCodec dtmf = acd->codecs()[3];
1905 EXPECT_EQ("telephone-event", dtmf.name);
1906 EXPECT_EQ(105, dtmf.id);
1907 EXPECT_EQ(3u,
1908 dtmf.params.size()); // ptime and max_ptime count as parameters.
1909 EXPECT_EQ(dtmf.params.begin()->first, "");
1910 EXPECT_EQ(dtmf.params.begin()->second, "0-15,66,70");
1911
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001912 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001913 GetFirstVideoContentDescription(jdesc_output->description());
1914 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001915 ASSERT_FALSE(vcd->codecs().empty());
1916 cricket::VideoCodec vp8 = vcd->codecs()[0];
1917 EXPECT_EQ("VP8", vp8.name);
1918 EXPECT_EQ(99, vp8.id);
1919 cricket::VideoCodec rtx = vcd->codecs()[1];
1920 EXPECT_EQ("RTX", rtx.name);
1921 EXPECT_EQ(95, rtx.id);
1922 VerifyCodecParameter(rtx.params, "apt", vp8.id);
Philipp Hanckeb7bc2432021-03-11 15:28:00 +01001923 // VP9 is listed last in the m= line so should come after VP8 and RTX.
1924 cricket::VideoCodec vp9 = vcd->codecs()[2];
1925 EXPECT_EQ("VP9", vp9.name);
1926 EXPECT_EQ(96, vp9.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001927 }
1928
1929 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1930 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001931 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001932 "v=0\r\n"
1933 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1934 "s=-\r\n"
1935 "t=0 0\r\n"
1936 // Include semantics for WebRTC Media Streams since it is supported by
1937 // this parser, and will be added to the SDP when serializing a session
1938 // description.
1939 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001940 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001941 "a=rtpmap:111 opus/48000/2\r\n";
1942 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001943 "m=video 3457 RTP/SAVPF 101\r\n"
1944 "a=rtpmap:101 VP8/90000\r\n"
Elad Alonfadb1812019-05-24 13:40:02 +02001945 "a=rtcp-fb:101 goog-lntf\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001946 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001947 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001948 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001949 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001950 os << sdp_session_and_audio;
Yves Gerey665174f2018-06-19 15:03:05 +02001951 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001952 os << sdp_video;
Yves Gerey665174f2018-06-19 15:03:05 +02001953 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001954 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001955 // Deserialize
1956 SdpParseError error;
1957 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001958 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001959 GetFirstAudioContentDescription(jdesc_output->description());
1960 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001961 ASSERT_FALSE(acd->codecs().empty());
1962 cricket::AudioCodec opus = acd->codecs()[0];
1963 EXPECT_EQ(111, opus.id);
Yves Gerey665174f2018-06-19 15:03:05 +02001964 EXPECT_TRUE(opus.HasFeedbackParam(cricket::FeedbackParam(
1965 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001966
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001967 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001968 GetFirstVideoContentDescription(jdesc_output->description());
1969 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001970 ASSERT_FALSE(vcd->codecs().empty());
1971 cricket::VideoCodec vp8 = vcd->codecs()[0];
1972 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1973 vp8.name.c_str());
1974 EXPECT_EQ(101, vp8.id);
Yves Gerey665174f2018-06-19 15:03:05 +02001975 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
Elad Alonfadb1812019-05-24 13:40:02 +02001976 cricket::kRtcpFbParamLntf, cricket::kParamValueEmpty)));
1977 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
Yves Gerey665174f2018-06-19 15:03:05 +02001978 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
1979 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1980 cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli)));
1981 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1982 cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty)));
1983 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1984 cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001985 }
1986
1987 // Two SDP messages can mean the same thing but be different strings, e.g.
1988 // some of the lines can be serialized in different order.
1989 // However, a deserialized description can be compared field by field and has
1990 // no order. If deserializer has already been tested, serializing then
1991 // deserializing and comparing JsepSessionDescription will test
1992 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 12:22:16 -08001993 void TestSerialize(const JsepSessionDescription& jdesc) {
1994 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 10:27:41 -08001995 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001996 SdpParseError error;
1997 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1998 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1999 }
2000
zhihuang38989e52017-03-21 11:04:53 -07002001 // Calling 'Initialize' with a copy of the inner SessionDescription will
2002 // create a copy of the JsepSessionDescription without candidates. The
2003 // 'connection address' field, previously set from the candidates, must also
2004 // be reset.
2005 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
2006 rtc::SocketAddress audio_addr("0.0.0.0", 9);
2007 rtc::SocketAddress video_addr("0.0.0.0", 9);
2008 audio_desc_->set_connection_address(audio_addr);
2009 video_desc_->set_connection_address(video_addr);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002010 ASSERT_TRUE(jdesc->Initialize(desc_.Clone(), kSessionId, kSessionVersion));
zhihuang38989e52017-03-21 11:04:53 -07002011 }
2012
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002013 protected:
2014 SessionDescription desc_;
2015 AudioContentDescription* audio_desc_;
2016 VideoContentDescription* video_desc_;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002017 SctpDataContentDescription* sctp_desc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002018 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07002019 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002020 JsepSessionDescription jdesc_;
2021};
2022
2023void TestMismatch(const std::string& string1, const std::string& string2) {
2024 int position = 0;
2025 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
2026 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002027 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002028 break;
2029 }
2030 }
2031 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
2032 << " character\n"
Jonas Olssonb2b20312020-01-14 12:11:31 +01002033 " 1: "
2034 << string1.substr(position, 20)
2035 << "\n"
2036 " 2: "
2037 << string2.substr(position, 20) << "\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002038}
2039
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002040TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
2041 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 12:22:16 -08002042 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002043 TestMismatch(std::string(kSdpFullString), message);
2044}
2045
2046TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 10:27:41 -08002047 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 12:22:16 -08002048 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002049}
2050
Harald Alvestrand0d018412021-11-04 13:52:31 +00002051// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002052// the case in a DTLS offer.
2053TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
2054 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002055 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002056 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08002057 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002058
2059 std::string sdp_with_fingerprint = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002060 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2061 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002062
2063 EXPECT_EQ(sdp_with_fingerprint, message);
2064}
2065
2066// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
2067// be the case in a DTLS answer.
2068TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
2069 AddFingerprint();
Harald Alvestrand0d018412021-11-04 13:52:31 +00002070 RemoveCryptos();
Steve Antona3a92c22017-12-07 10:27:41 -08002071 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002072 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08002073 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002074
2075 std::string sdp_with_fingerprint = kSdpString;
2076 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
2077 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
Yves Gerey665174f2018-06-19 15:03:05 +02002078 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2079 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002080
2081 EXPECT_EQ(sdp_with_fingerprint, message);
2082}
2083
2084TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
2085 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002086 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002087 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08002088 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002089 EXPECT_EQ(std::string(kSdpString), message);
2090}
2091
Henrik Boströmf8187e02021-04-26 21:04:26 +02002092TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundles) {
2093 ContentGroup group1(cricket::GROUP_TYPE_BUNDLE);
2094 group1.AddContentName(kAudioContentName);
2095 group1.AddContentName(kVideoContentName);
2096 desc_.AddGroup(group1);
2097 ContentGroup group2(cricket::GROUP_TYPE_BUNDLE);
2098 group2.AddContentName(kAudioContentName2);
2099 desc_.AddGroup(group2);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002100 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002101 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002102 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002103 std::string sdp_with_bundle = kSdpFullString;
2104 InjectAfter(kSessionTime,
Henrik Boströmf8187e02021-04-26 21:04:26 +02002105 "a=group:BUNDLE audio_content_name video_content_name\r\n"
2106 "a=group:BUNDLE audio_content_name_2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002107 &sdp_with_bundle);
2108 EXPECT_EQ(sdp_with_bundle, message);
2109}
2110
2111TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 15:14:30 -08002112 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
Taylor Brandstetteree8c2462020-07-27 15:52:02 -07002113 vcd->set_bandwidth(100 * 1000 + 755); // Integer division will drop the 755.
2114 vcd->set_bandwidth_type("AS");
Steve Antonb1c1de12017-12-21 15:14:30 -08002115 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
Taylor Brandstetteree8c2462020-07-27 15:52:02 -07002116 acd->set_bandwidth(555);
2117 acd->set_bandwidth_type("TIAS");
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002118 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002119 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002120 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002121 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002122 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002123 &sdp_with_bandwidth);
Taylor Brandstetteree8c2462020-07-27 15:52:02 -07002124 InjectAfter("c=IN IP4 74.125.127.126\r\n", "b=TIAS:555\r\n",
2125 &sdp_with_bandwidth);
2126 EXPECT_EQ(sdp_with_bandwidth, message);
2127}
2128
2129// Should default to b=AS if bandwidth_type isn't set.
2130TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithMissingBandwidthType) {
2131 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
2132 vcd->set_bandwidth(100 * 1000);
2133 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2134 jdesc_.session_version()));
2135 std::string message = webrtc::SdpSerialize(jdesc_);
2136 std::string sdp_with_bandwidth = kSdpFullString;
2137 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002138 &sdp_with_bandwidth);
2139 EXPECT_EQ(sdp_with_bandwidth, message);
2140}
2141
2142TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
2143 std::vector<std::string> transport_options;
2144 transport_options.push_back(kIceOption1);
2145 transport_options.push_back(kIceOption3);
2146 AddIceOptions(kAudioContentName, transport_options);
2147 transport_options.clear();
2148 transport_options.push_back(kIceOption2);
2149 transport_options.push_back(kIceOption3);
2150 AddIceOptions(kVideoContentName, transport_options);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002151 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002152 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002153 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002154 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002155 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002156 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002157 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002158 &sdp_with_ice_options);
2159 EXPECT_EQ(sdp_with_ice_options, message);
2160}
2161
2162TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002163 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002164}
2165
2166TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002167 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002168}
2169
2170TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002171 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002172}
2173
2174TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2175 EXPECT_TRUE(TestSerializeRejected(true, false));
2176}
2177
2178TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2179 EXPECT_TRUE(TestSerializeRejected(false, true));
2180}
2181
2182TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2183 EXPECT_TRUE(TestSerializeRejected(true, true));
2184}
2185
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002186TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08002187 bool use_sctpmap = true;
2188 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002189 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002190
zhihuang38989e52017-03-21 11:04:53 -07002191 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002192 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002193
2194 std::string expected_sdp = kSdpString;
2195 expected_sdp.append(kSdpSctpDataChannelString);
2196 EXPECT_EQ(message, expected_sdp);
2197}
2198
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002199void MutateJsepSctpPort(JsepSessionDescription* jdesc,
2200 const SessionDescription& desc,
2201 int port) {
2202 // Take our pre-built session description and change the SCTP port.
2203 std::unique_ptr<cricket::SessionDescription> mutant = desc.Clone();
2204 SctpDataContentDescription* dcdesc =
2205 mutant->GetContentDescriptionByName(kDataContentName)->as_sctp();
2206 dcdesc->set_port(port);
2207 ASSERT_TRUE(
2208 jdesc->Initialize(std::move(mutant), kSessionId, kSessionVersion));
2209}
2210
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002211TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08002212 bool use_sctpmap = true;
2213 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002214 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002215 MakeDescriptionWithoutCandidates(&jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002216
2217 const int kNewPort = 1234;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002218 MutateJsepSctpPort(&jsep_desc, desc_, kNewPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002219
Steve Antone831b8c2018-02-01 12:22:16 -08002220 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002221
2222 std::string expected_sdp = kSdpString;
2223 expected_sdp.append(kSdpSctpDataChannelString);
2224
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002225 absl::StrReplaceAll(
2226 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kNewPort)}},
2227 &expected_sdp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002228
2229 EXPECT_EQ(expected_sdp, message);
2230}
2231
Johannes Kron0854eb62018-10-10 22:33:20 +02002232TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002233 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002234 TestSerialize(jdesc_);
2235}
2236
2237TEST_F(WebRtcSdpTest, SerializeMediaContentDescriptionWithExtmapAllowMixed) {
2238 cricket::MediaContentDescription* video_desc =
2239 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2240 ASSERT_TRUE(video_desc);
2241 cricket::MediaContentDescription* audio_desc =
2242 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2243 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002244 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002245 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002246 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002247 cricket::MediaContentDescription::kMedia);
2248 TestSerialize(jdesc_);
2249}
2250
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002251TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002252 bool encrypted = false;
2253 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002254 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002255 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 12:22:16 -08002256 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002257
2258 std::string sdp_with_extmap = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002259 InjectAfter("a=mid:audio_content_name\r\n", kExtmap, &sdp_with_extmap);
2260 InjectAfter("a=mid:video_content_name\r\n", kExtmap, &sdp_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002261
2262 EXPECT_EQ(sdp_with_extmap, message);
2263}
2264
jbauch5869f502017-06-29 12:31:36 -07002265TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2266 bool encrypted = true;
2267 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002268 JsepSessionDescription desc_with_extmap(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002269 ASSERT_TRUE(
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002270 desc_with_extmap.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 12:22:16 -08002271 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07002272}
2273
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002274TEST_F(WebRtcSdpTest, SerializeCandidates) {
2275 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002276 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002277
2278 Candidate candidate_with_ufrag(candidates_.front());
2279 candidate_with_ufrag.set_username("ABC");
2280 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2281 candidate_with_ufrag));
2282 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2283 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002284
2285 Candidate candidate_with_network_info(candidates_.front());
2286 candidate_with_network_info.set_network_id(1);
2287 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2288 candidate_with_network_info));
2289 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2290 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2291 candidate_with_network_info.set_network_cost(999);
2292 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2293 candidate_with_network_info));
2294 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2295 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2296 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002297}
2298
Zach Steinb336c272018-08-09 01:16:13 -07002299TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) {
2300 rtc::SocketAddress address("a.test", 1234);
2301 cricket::Candidate candidate(
2302 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
2303 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
2304 JsepIceCandidate jcandidate(std::string("audio_content_name"), 0, candidate);
2305 std::string message = webrtc::SdpSerializeCandidate(jcandidate);
2306 EXPECT_EQ(std::string(kRawHostnameCandidate), message);
2307}
2308
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002309TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002310 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002311 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2312 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2313 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002314 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002315 std::unique_ptr<IceCandidateInterface> jcandidate(
2316 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002317
2318 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2319 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2320}
2321
Taylor Brandstetter8206bc02020-04-02 12:36:38 -07002322// Test serializing a TCP candidate that came in with a missing tcptype. This
2323// shouldn't happen according to the spec, but our implementation has been
2324// accepting this for quite some time, treating it as a passive candidate.
2325//
2326// So, we should be able to at least convert such candidates to and from SDP.
2327// See: bugs.webrtc.org/11423
2328TEST_F(WebRtcSdpTest, ParseTcpCandidateWithoutTcptype) {
2329 std::string missing_tcptype =
2330 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9999 typ host";
2331 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2332 EXPECT_TRUE(SdpDeserializeCandidate(missing_tcptype, &jcandidate));
2333
2334 EXPECT_EQ(std::string(cricket::TCPTYPE_PASSIVE_STR),
2335 jcandidate.candidate().tcptype());
2336}
2337
2338TEST_F(WebRtcSdpTest, ParseSslTcpCandidate) {
2339 std::string ssltcp =
2340 "candidate:a0+B/1 1 ssltcp 2130706432 192.168.1.5 9999 typ host tcptype "
2341 "passive";
2342 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2343 EXPECT_TRUE(SdpDeserializeCandidate(ssltcp, &jcandidate));
2344
2345 EXPECT_EQ(std::string("ssltcp"), jcandidate.candidate().protocol());
2346}
2347
htaa6b99442016-04-12 10:29:17 -07002348TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002349 cricket::VideoCodec h264_codec("H264");
2350 h264_codec.SetParam("profile-level-id", "42e01f");
2351 h264_codec.SetParam("level-asymmetry-allowed", "1");
2352 h264_codec.SetParam("packetization-mode", "1");
2353 video_desc_->AddCodec(h264_codec);
2354
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002355 jdesc_.Initialize(desc_.Clone(), kSessionId, kSessionVersion);
htaa6b99442016-04-12 10:29:17 -07002356
Steve Antone831b8c2018-02-01 12:22:16 -08002357 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 10:29:17 -07002358 size_t after_pt = message.find(" H264/90000");
2359 ASSERT_NE(after_pt, std::string::npos);
2360 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2361 ASSERT_NE(before_pt, std::string::npos);
2362 before_pt += strlen("a=rtpmap:");
2363 std::string pt = message.substr(before_pt, after_pt - before_pt);
Artem Titov880fa812021-07-30 22:30:23 +02002364 // TODO(hta): Check if payload type `pt` occurs in the m=video line.
htaa6b99442016-04-12 10:29:17 -07002365 std::string to_find = "a=fmtp:" + pt + " ";
2366 size_t fmtp_pos = message.find(to_find);
2367 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
Mirko Bonadei37ec55e2019-01-28 11:43:52 +01002368 size_t fmtp_endpos = message.find('\n', fmtp_pos);
htaa6b99442016-04-12 10:29:17 -07002369 ASSERT_NE(std::string::npos, fmtp_endpos);
2370 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2371 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2372 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2373 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002374 // Check that there are no spaces after semicolons.
2375 // https://bugs.webrtc.org/5793
2376 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002377}
2378
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002379TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 10:27:41 -08002380 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002381 // Deserialize
2382 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2383 // Verify
2384 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2385}
2386
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002387TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 10:27:41 -08002388 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002389 const char kSdpWithoutMline[] =
Yves Gerey665174f2018-06-19 15:03:05 +02002390 "v=0\r\n"
2391 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2392 "s=-\r\n"
2393 "t=0 0\r\n"
2394 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002395 // Deserialize
2396 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2397 EXPECT_EQ(0u, jdesc.description()->contents().size());
2398}
2399
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002400TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 10:27:41 -08002401 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002402 std::string sdp_without_carriage_return = kSdpFullString;
2403 Replace("\r\n", "\n", &sdp_without_carriage_return);
2404 // Deserialize
2405 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2406 // Verify
2407 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2408}
2409
2410TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2411 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002412 JsepSessionDescription jdesc_no_candidates(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002413 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Clone(), kSessionId,
Yves Gerey665174f2018-06-19 15:03:05 +02002414 kSessionVersion));
Steve Antona3a92c22017-12-07 10:27:41 -08002415 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002416 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2417 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2418}
2419
2420TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2421 static const char kSdpNoRtpmapString[] =
2422 "v=0\r\n"
2423 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2424 "s=-\r\n"
2425 "t=0 0\r\n"
2426 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2427 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002428 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002429 // The rtpmap line for static payload codec is optional.
Henrik Boström874517b2022-05-31 12:22:41 +00002430 "a=rtpmap:18 G729/16000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002431 "a=rtpmap:103 ISAC/16000\r\n";
2432
Steve Antona3a92c22017-12-07 10:27:41 -08002433 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002434 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2435 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08002436 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002437 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002438 // The codecs in the AudioContentDescription should be in the same order as
2439 // the payload types (<fmt>s) on the m= line.
2440 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
Henrik Boström874517b2022-05-31 12:22:41 +00002441 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002442 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002443 EXPECT_EQ(ref_codecs, audio->codecs());
2444}
2445
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002446TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2447 static const char kSdpNoRtpmapString[] =
2448 "v=0\r\n"
2449 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2450 "s=-\r\n"
2451 "t=0 0\r\n"
2452 "m=audio 49232 RTP/AVP 18 103\r\n"
2453 "a=fmtp:18 annexb=yes\r\n"
2454 "a=rtpmap:103 ISAC/16000\r\n";
2455
Steve Antona3a92c22017-12-07 10:27:41 -08002456 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002457 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2458 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08002459 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002460
2461 cricket::AudioCodec g729 = audio->codecs()[0];
2462 EXPECT_EQ("G729", g729.name);
2463 EXPECT_EQ(8000, g729.clockrate);
2464 EXPECT_EQ(18, g729.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002465 cricket::CodecParameterMap::iterator found = g729.params.find("annexb");
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002466 ASSERT_TRUE(found != g729.params.end());
2467 EXPECT_EQ(found->second, "yes");
2468
2469 cricket::AudioCodec isac = audio->codecs()[1];
2470 EXPECT_EQ("ISAC", isac.name);
2471 EXPECT_EQ(103, isac.id);
2472 EXPECT_EQ(16000, isac.clockrate);
2473}
2474
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002475// Ensure that we can deserialize SDP with a=fingerprint properly.
2476TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2477 // Add a DTLS a=fingerprint attribute to our session description.
2478 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002479 JsepSessionDescription new_jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002480 ASSERT_TRUE(new_jdesc.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002481 jdesc_.session_version()));
2482
Steve Antona3a92c22017-12-07 10:27:41 -08002483 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002484 std::string sdp_with_fingerprint = kSdpString;
2485 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2486 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2487 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2488 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2489}
2490
2491TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 10:27:41 -08002492 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002493 std::string sdp_with_bundle = kSdpFullString;
2494 InjectAfter(kSessionTime,
2495 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2496 &sdp_with_bundle);
2497 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2498 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2499 group.AddContentName(kAudioContentName);
2500 group.AddContentName(kVideoContentName);
2501 desc_.AddGroup(group);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002502 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002503 jdesc_.session_version()));
2504 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2505}
2506
2507TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002508 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002509 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002510 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002511 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002512 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002513 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002514 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 15:14:30 -08002515 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002516 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002517 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002518 acd->set_bandwidth(50 * 1000);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002519 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002520 jdesc_.session_version()));
2521 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2522}
2523
Taylor Brandstetteree8c2462020-07-27 15:52:02 -07002524TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithTiasBandwidth) {
2525 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
2526 std::string sdp_with_bandwidth = kSdpFullString;
2527 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=TIAS:100000\r\n",
2528 &sdp_with_bandwidth);
2529 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=TIAS:50000\r\n",
2530 &sdp_with_bandwidth);
2531 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2532 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
2533 vcd->set_bandwidth(100 * 1000);
2534 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
2535 acd->set_bandwidth(50 * 1000);
2536 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2537 jdesc_.session_version()));
2538 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2539}
2540
Philipp Hanckefbbfc022020-07-31 08:30:50 +02002541TEST_F(WebRtcSdpTest,
2542 DeserializeSessionDescriptionWithUnknownBandwidthModifier) {
2543 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
2544 std::string sdp_with_bandwidth = kSdpFullString;
2545 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
2546 "b=unknown:100000\r\n", &sdp_with_bandwidth);
2547 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
2548 "b=unknown:50000\r\n", &sdp_with_bandwidth);
2549 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2550 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
2551 vcd->set_bandwidth(-1);
2552 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
2553 acd->set_bandwidth(-1);
2554 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2555 jdesc_.session_version()));
2556 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2557}
2558
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002559TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 10:27:41 -08002560 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002561 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002562 InjectAfter(kSessionTime, "a=ice-options:iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002563 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002564 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002565 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002566 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002567 &sdp_with_ice_options);
2568 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2569 std::vector<std::string> transport_options;
2570 transport_options.push_back(kIceOption3);
2571 transport_options.push_back(kIceOption1);
2572 AddIceOptions(kAudioContentName, transport_options);
2573 transport_options.clear();
2574 transport_options.push_back(kIceOption3);
2575 transport_options.push_back(kIceOption2);
2576 AddIceOptions(kVideoContentName, transport_options);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002577 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002578 jdesc_.session_version()));
2579 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2580}
2581
2582TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2583 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 10:27:41 -08002584 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002585 std::string sdp_with_ufrag_pwd = kSdpFullString;
2586 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2587 // Add session level ufrag and pwd
2588 InjectAfter(kSessionTime,
Yves Gerey665174f2018-06-19 15:03:05 +02002589 "a=ice-pwd:session+level+icepwd\r\n"
2590 "a=ice-ufrag:session+level+iceufrag\r\n",
2591 &sdp_with_ufrag_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002592 // Add media level ufrag and pwd for audio
Yves Gerey665174f2018-06-19 15:03:05 +02002593 InjectAfter(
2594 "a=mid:audio_content_name\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002595 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2596 &sdp_with_ufrag_pwd);
2597 // Update the candidate ufrag and pwd to the expected ones.
Yves Gerey665174f2018-06-19 15:03:05 +02002598 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, "media+level+iceufrag",
2599 "media+level+icepwd"));
2600 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, "session+level+iceufrag",
2601 "session+level+icepwd"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002602 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2603 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2604}
2605
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002606TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002607 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002608}
2609
2610TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002611 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002612}
2613
2614TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002615 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002616}
2617
2618TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2619 EXPECT_TRUE(TestDeserializeRejected(true, false));
2620}
2621
2622TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2623 EXPECT_TRUE(TestDeserializeRejected(false, true));
2624}
2625
2626TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2627 EXPECT_TRUE(TestDeserializeRejected(true, true));
2628}
2629
Johannes Kron0854eb62018-10-10 22:33:20 +02002630TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002631 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002632 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
Johannes Kron0854eb62018-10-10 22:33:20 +02002633 // Deserialize
2634 JsepSessionDescription jdesc_deserialized(kDummyType);
Emil Lundmark801c9992021-01-19 13:06:32 +01002635 ASSERT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
Johannes Kron0854eb62018-10-10 22:33:20 +02002636 // Verify
2637 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2638}
2639
2640TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002641 jdesc_.description()->set_extmap_allow_mixed(false);
Johannes Kron0854eb62018-10-10 22:33:20 +02002642 std::string sdp_without_extmap_allow_mixed = kSdpFullString;
Emil Lundmark801c9992021-01-19 13:06:32 +01002643 Replace(kExtmapAllowMixed, "", &sdp_without_extmap_allow_mixed);
Johannes Kron0854eb62018-10-10 22:33:20 +02002644 // Deserialize
2645 JsepSessionDescription jdesc_deserialized(kDummyType);
Emil Lundmark801c9992021-01-19 13:06:32 +01002646 ASSERT_TRUE(
Johannes Kron0854eb62018-10-10 22:33:20 +02002647 SdpDeserialize(sdp_without_extmap_allow_mixed, &jdesc_deserialized));
2648 // Verify
2649 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2650}
2651
2652TEST_F(WebRtcSdpTest, DeserializeMediaContentDescriptionWithExtmapAllowMixed) {
2653 cricket::MediaContentDescription* video_desc =
2654 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2655 ASSERT_TRUE(video_desc);
2656 cricket::MediaContentDescription* audio_desc =
2657 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2658 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002659 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002660 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002661 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002662 cricket::MediaContentDescription::kMedia);
2663
2664 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2665 InjectAfter("a=mid:audio_content_name\r\n", kExtmapAllowMixed,
2666 &sdp_with_extmap_allow_mixed);
2667 InjectAfter("a=mid:video_content_name\r\n", kExtmapAllowMixed,
2668 &sdp_with_extmap_allow_mixed);
2669
2670 // Deserialize
2671 JsepSessionDescription jdesc_deserialized(kDummyType);
2672 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2673 // Verify
2674 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2675}
2676
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002677TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2678 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2679
2680 std::string sdp = kSdpOneCandidate;
2681 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2682 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2683 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2684 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002685 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002686
2687 // Candidate line without generation extension.
2688 sdp = kSdpOneCandidate;
2689 Replace(" generation 2", "", &sdp);
2690 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2691 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2692 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2693 Candidate expected = jcandidate_->candidate();
2694 expected.set_generation(0);
2695 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2696
honghaiza0c44ea2016-03-23 16:07:48 -07002697 // Candidate with network id and/or cost.
2698 sdp = kSdpOneCandidate;
2699 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2700 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2701 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2702 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2703 expected = jcandidate_->candidate();
2704 expected.set_network_id(2);
2705 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2706 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2707 // Add network cost
2708 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2709 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2710 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2711 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2712
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002713 sdp = kSdpTcpActiveCandidate;
2714 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2715 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002716 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002717 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2718 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2719 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002720 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2721 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
Yves Gerey665174f2018-06-19 15:03:05 +02002722 EXPECT_TRUE(
2723 jcandidate.candidate().IsEquivalent(jcandidate_template->candidate()));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002724 sdp = kSdpTcpPassiveCandidate;
2725 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2726 sdp = kSdpTcpSOCandidate;
2727 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002728}
2729
2730// This test verifies the deserialization of candidate-attribute
David Sanders60c588d2022-03-19 01:43:10 -07002731// as per RFC 5245. Candidate-attribute will be of the format
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002732// candidate:<blah>. This format will be used when candidates
2733// are trickled.
2734TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2735 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2736
2737 std::string candidate_attribute = kRawCandidate;
2738 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2739 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2740 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2741 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2742 EXPECT_EQ(2u, jcandidate.candidate().generation());
2743
2744 // Candidate line without generation extension.
2745 candidate_attribute = kRawCandidate;
2746 Replace(" generation 2", "", &candidate_attribute);
2747 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2748 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2749 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2750 Candidate expected = jcandidate_->candidate();
2751 expected.set_generation(0);
2752 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2753
2754 // Candidate line without candidate:
2755 candidate_attribute = kRawCandidate;
2756 Replace("candidate:", "", &candidate_attribute);
2757 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2758
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002759 // Candidate line with IPV6 address.
2760 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
Zach Steinb336c272018-08-09 01:16:13 -07002761
2762 // Candidate line with hostname address.
2763 EXPECT_TRUE(SdpDeserializeCandidate(kRawHostnameCandidate, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002764}
2765
2766// This test verifies that the deserialization of an invalid candidate string
2767// fails.
2768TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
Yves Gerey665174f2018-06-19 15:03:05 +02002769 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002770
2771 std::string candidate_attribute = kRawCandidate;
2772 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002773 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002774
2775 candidate_attribute = kSdpOneCandidate;
2776 candidate_attribute.replace(0, 1, "x");
2777 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2778
2779 candidate_attribute = kRawCandidate;
2780 candidate_attribute.append("\r\n");
2781 candidate_attribute.append(kRawCandidate);
2782 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2783
2784 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002785}
2786
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002787TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002788 bool use_sctpmap = true;
2789 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002790 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002791 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002792
2793 std::string sdp_with_data = kSdpString;
2794 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002795 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002796
Guido Urdanetacecf87f2019-05-31 10:17:38 +00002797 // Verify with UDP/DTLS/SCTP (already in kSdpSctpDataChannelString).
lally@webrtc.org36300852015-02-24 20:19:35 +00002798 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2799 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2800
Guido Urdanetacecf87f2019-05-31 10:17:38 +00002801 // Verify with DTLS/SCTP.
2802 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2803 kDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002804 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2805 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2806
2807 // Verify with TCP/DTLS/SCTP.
Guido Urdanetacecf87f2019-05-31 10:17:38 +00002808 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
Yves Gerey665174f2018-06-19 15:03:05 +02002809 kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002810 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2811 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2812}
2813
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002814TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002815 bool use_sctpmap = false;
2816 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002817 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002818 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002819
2820 std::string sdp_with_data = kSdpString;
2821 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002822 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002823
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002824 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2825 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2826}
2827
lally69f57602015-10-08 10:15:04 -07002828TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002829 bool use_sctpmap = false;
2830 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002831 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002832 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
lally69f57602015-10-08 10:15:04 -07002833
2834 std::string sdp_with_data = kSdpString;
2835 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002836 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 10:15:04 -07002837
lally69f57602015-10-08 10:15:04 -07002838 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2839 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2840}
2841
Philipp Hanckeefc55b02020-06-26 10:17:05 +02002842TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsButWrongMediaType) {
2843 bool use_sctpmap = true;
2844 AddSctpDataChannel(use_sctpmap);
2845 JsepSessionDescription jdesc(kDummyType);
2846 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
2847
2848 std::string sdp = kSdpSessionString;
2849 sdp += kSdpSctpDataChannelString;
2850
2851 const char needle[] = "m=application ";
2852 sdp.replace(sdp.find(needle), strlen(needle), "m=application:bogus ");
2853
2854 JsepSessionDescription jdesc_output(kDummyType);
2855 EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output));
2856
Philipp Hancke4e8c1152020-10-13 12:43:15 +02002857 EXPECT_EQ(1u, jdesc_output.description()->contents().size());
2858 EXPECT_TRUE(jdesc_output.description()->contents()[0].rejected);
Philipp Hanckeefc55b02020-06-26 10:17:05 +02002859}
2860
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002861// Helper function to set the max-message-size parameter in the
2862// SCTP data codec.
2863void MutateJsepSctpMaxMessageSize(const SessionDescription& desc,
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002864 int new_value,
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002865 JsepSessionDescription* jdesc) {
Harald Alvestrand8da35a62019-05-10 09:31:04 +02002866 std::unique_ptr<cricket::SessionDescription> mutant = desc.Clone();
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002867 SctpDataContentDescription* dcdesc =
2868 mutant->GetContentDescriptionByName(kDataContentName)->as_sctp();
2869 dcdesc->set_max_message_size(new_value);
Harald Alvestrand8da35a62019-05-10 09:31:04 +02002870 jdesc->Initialize(std::move(mutant), kSessionId, kSessionVersion);
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002871}
2872
2873TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithMaxMessageSize) {
2874 bool use_sctpmap = false;
2875 AddSctpDataChannel(use_sctpmap);
2876 JsepSessionDescription jdesc(kDummyType);
2877 std::string sdp_with_data = kSdpString;
2878
2879 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
2880 sdp_with_data.append("a=max-message-size:12345\r\n");
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002881 MutateJsepSctpMaxMessageSize(desc_, 12345, &jdesc);
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002882 JsepSessionDescription jdesc_output(kDummyType);
2883
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002884 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2885 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2886}
2887
Harald Alvestrandfbb45bd2019-05-15 08:07:47 +02002888TEST_F(WebRtcSdpTest, SerializeSdpWithSctpDataChannelWithMaxMessageSize) {
2889 bool use_sctpmap = false;
2890 AddSctpDataChannel(use_sctpmap);
2891 JsepSessionDescription jdesc(kDummyType);
2892 MutateJsepSctpMaxMessageSize(desc_, 12345, &jdesc);
2893 std::string message = webrtc::SdpSerialize(jdesc);
2894 EXPECT_NE(std::string::npos,
2895 message.find("\r\na=max-message-size:12345\r\n"));
2896 JsepSessionDescription jdesc_output(kDummyType);
2897 EXPECT_TRUE(SdpDeserialize(message, &jdesc_output));
2898 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2899}
2900
2901TEST_F(WebRtcSdpTest,
2902 SerializeSdpWithSctpDataChannelWithDefaultMaxMessageSize) {
2903 // https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-26#section-6
2904 // The default max message size is 64K.
2905 bool use_sctpmap = false;
2906 AddSctpDataChannel(use_sctpmap);
2907 JsepSessionDescription jdesc(kDummyType);
2908 MutateJsepSctpMaxMessageSize(desc_, 65536, &jdesc);
2909 std::string message = webrtc::SdpSerialize(jdesc);
2910 EXPECT_EQ(std::string::npos, message.find("\r\na=max-message-size:"));
2911 JsepSessionDescription jdesc_output(kDummyType);
2912 EXPECT_TRUE(SdpDeserialize(message, &jdesc_output));
2913 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2914}
2915
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002916// Test to check the behaviour if sctp-port is specified
2917// on the m= line and in a=sctp-port.
2918TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002919 bool use_sctpmap = true;
2920 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002921 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002922 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002923
2924 std::string sdp_with_data = kSdpString;
2925 // Append m= attributes
2926 sdp_with_data.append(kSdpSctpDataChannelString);
2927 // Append a=sctp-port attribute
2928 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 10:27:41 -08002929 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002930
2931 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2932}
2933
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002934// Test behavior if a=rtpmap occurs in an SCTP section.
2935TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpmapAttribute) {
2936 std::string sdp_with_data = kSdpString;
2937 // Append m= attributes
2938 sdp_with_data.append(kSdpSctpDataChannelString);
2939 // Append a=rtpmap attribute
2940 sdp_with_data.append("a=rtpmap:111 opus/48000/2\r\n");
2941 JsepSessionDescription jdesc_output(kDummyType);
2942 // Correct behavior is to ignore the extra attribute.
2943 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2944}
2945
2946TEST_F(WebRtcSdpTest, DeserializeSdpWithStrangeApplicationProtocolNames) {
Harald Alvestrand7af57c62021-04-16 11:12:14 +00002947 static const char* bad_strings[] = {
2948 "DTLS/SCTPRTP/", "obviously-bogus", "UDP/TL/RTSP/SAVPF",
2949 "UDP/TL/RTSP/S", "DTLS/SCTP/RTP/FOO", "obviously-bogus/RTP/"};
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002950 for (auto proto : bad_strings) {
2951 std::string sdp_with_data = kSdpString;
2952 sdp_with_data.append("m=application 9 ");
2953 sdp_with_data.append(proto);
2954 sdp_with_data.append(" 47\r\n");
2955 JsepSessionDescription jdesc_output(kDummyType);
2956 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output))
2957 << "Parsing should have failed on " << proto;
2958 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002959}
2960
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002961// For crbug/344475.
2962TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2963 std::string sdp_with_data = kSdpString;
2964 sdp_with_data.append(kSdpSctpDataChannelString);
2965 // Remove the "\n" at the end.
2966 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 10:27:41 -08002967 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002968
2969 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2970 // No crash is a pass.
2971}
2972
zstein4b2e0822017-02-17 19:48:38 -08002973TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
2974 bool use_sctpmap = true;
2975 AddSctpDataChannel(use_sctpmap);
2976
2977 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 10:27:41 -08002978 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002979 MutateJsepSctpPort(&jdesc, desc_, kUnusualSctpPort);
wu@webrtc.org78187522013-10-07 23:32:02 +00002980
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002981 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002982 std::string sdp_with_data = kSdpString;
2983 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002984 absl::StrReplaceAll(
2985 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}},
2986 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002987 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:02 +00002988
2989 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2990 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08002991}
2992
2993TEST_F(WebRtcSdpTest,
2994 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
2995 bool use_sctpmap = false;
2996 AddSctpDataChannel(use_sctpmap);
2997
Steve Antona3a92c22017-12-07 10:27:41 -08002998 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002999 MutateJsepSctpPort(&jdesc, desc_, kUnusualSctpPort);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003000
3001 // We need to test the deserialized JsepSessionDescription from
3002 // kSdpSctpDataChannelStringWithSctpPort for
3003 // draft-ietf-mmusic-sctp-sdp-07
3004 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08003005 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003006 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Anton1c9c9fc2019-02-14 15:13:09 -08003007 absl::StrReplaceAll(
3008 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}},
3009 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08003010 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003011
3012 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3013 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00003014}
3015
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003016TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08003017 bool use_sctpmap = true;
3018 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08003019 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003020 SctpDataContentDescription* dcd = GetFirstSctpDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003021 dcd->set_bandwidth(100 * 1000);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003022 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003023
3024 std::string sdp_with_bandwidth = kSdpString;
3025 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02003026 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003027 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08003028 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003029
3030 // SCTP has congestion control, so we shouldn't limit the bandwidth
3031 // as we do for RTP.
3032 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003033 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
3034}
3035
Yves Gerey665174f2018-06-19 15:03:05 +02003036class WebRtcSdpExtmapTest : public WebRtcSdpTest,
Mirko Bonadei6a489f22019-04-09 15:11:12 +02003037 public ::testing::WithParamInterface<bool> {};
jbauch5869f502017-06-29 12:31:36 -07003038
3039TEST_P(WebRtcSdpExtmapTest,
Yves Gerey665174f2018-06-19 15:03:05 +02003040 DeserializeSessionDescriptionWithSessionLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003041 bool encrypted = GetParam();
3042 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003043}
3044
Yves Gerey665174f2018-06-19 15:03:05 +02003045TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003046 bool encrypted = GetParam();
3047 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003048}
3049
Yves Gerey665174f2018-06-19 15:03:05 +02003050TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithInvalidExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003051 bool encrypted = GetParam();
3052 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003053}
3054
Mirko Bonadeic84f6612019-01-31 12:20:57 +01003055INSTANTIATE_TEST_SUITE_P(Encrypted,
3056 WebRtcSdpExtmapTest,
3057 ::testing::Values(false, true));
jbauch5869f502017-06-29 12:31:36 -07003058
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003059TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 10:27:41 -08003060 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003061 std::string sdp = kSdpFullString;
3062 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
3063 // Deserialize
3064 SdpParseError error;
3065 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
Harald Alvestrand88b8dec2022-04-07 09:54:51 +00003066 const std::string lastline = "a=ssrc:3 msid:local_stream_1 video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003067 EXPECT_EQ(lastline, error.line);
3068 EXPECT_EQ("Invalid SDP line.", error.description);
3069}
3070
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003071TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
3072 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
3073 std::string new_sdp = kSdpOneCandidate;
3074 Replace("udp", "unsupported_transport", &new_sdp);
3075 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3076 new_sdp = kSdpOneCandidate;
3077 Replace("udp", "uDP", &new_sdp);
3078 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3079 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3080 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3081 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
3082}
3083
honghaiza54a0802015-12-16 18:37:23 -08003084TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003085 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08003086 EXPECT_TRUE(
3087 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003088 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3089 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3090 Candidate ref_candidate = jcandidate_->candidate();
3091 ref_candidate.set_username("user_rtp");
3092 ref_candidate.set_password("password_rtp");
3093 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
3094}
3095
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003096TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08003097 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003098
3099 // Deserialize
3100 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
3101
3102 // Verify
3103 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08003104 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003105 EXPECT_TRUE(audio->conference_mode());
3106
3107 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 15:55:30 -08003108 cricket::GetFirstVideoContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003109 EXPECT_TRUE(video->conference_mode());
3110}
3111
deadbeefd45aea82017-09-16 01:24:29 -07003112TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08003113 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 01:24:29 -07003114
3115 // We tested deserialization already above, so just test that if we serialize
3116 // and deserialize the flag doesn't disappear.
3117 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 12:22:16 -08003118 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 01:24:29 -07003119 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
3120
3121 // Verify.
3122 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08003123 cricket::GetFirstAudioContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 01:24:29 -07003124 EXPECT_TRUE(audio->conference_mode());
3125
3126 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 15:55:30 -08003127 cricket::GetFirstVideoContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 01:24:29 -07003128 EXPECT_TRUE(video->conference_mode());
3129}
3130
Sebastian Jansson97321b62019-07-24 14:01:18 +02003131TEST_F(WebRtcSdpTest, SerializeAndDeserializeRemoteNetEstimate) {
3132 {
3133 // By default remote estimates are disabled.
3134 JsepSessionDescription dst(kDummyType);
3135 SdpDeserialize(webrtc::SdpSerialize(jdesc_), &dst);
3136 EXPECT_FALSE(cricket::GetFirstVideoContentDescription(dst.description())
3137 ->remote_estimate());
3138 }
3139 {
3140 // When remote estimate is enabled, the setting is propagated via SDP.
3141 cricket::GetFirstVideoContentDescription(jdesc_.description())
3142 ->set_remote_estimate(true);
3143 JsepSessionDescription dst(kDummyType);
3144 SdpDeserialize(webrtc::SdpSerialize(jdesc_), &dst);
3145 EXPECT_TRUE(cricket::GetFirstVideoContentDescription(dst.description())
3146 ->remote_estimate());
3147 }
3148}
3149
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003150TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
3151 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003152 const char kSdpEmptyType[] = " =candidate";
3153 const char kSdpEqualAsPlus[] = "a+candidate";
3154 const char kSdpSpaceAfterEqual[] = "a= candidate";
3155 const char kSdpUpperType[] = "A=candidate";
3156 const char kSdpEmptyLine[] = "";
3157 const char kSdpMissingValue[] = "a=";
3158
Yves Gerey665174f2018-06-19 15:03:05 +02003159 const char kSdpBrokenFingerprint[] =
3160 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003161 "4AAD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB";
Yves Gerey665174f2018-06-19 15:03:05 +02003162 const char kSdpExtraField[] =
3163 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003164 "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 15:03:05 +02003165 const char kSdpMissingSpace[] =
3166 "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003167 "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:58 +00003168 // MD5 is not allowed in fingerprints.
Yves Gerey665174f2018-06-19 15:03:05 +02003169 const char kSdpMd5[] =
3170 "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003171 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003172
3173 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003174 ExpectParseFailure("v=", kSdpDestroyer);
3175 ExpectParseFailure("o=", kSdpDestroyer);
3176 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003177 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003178 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003179
3180 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003181 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
3182 ExpectParseFailure("m=video", kSdpDestroyer);
Philipp Hanckeefc55b02020-06-26 10:17:05 +02003183 ExpectParseFailure("m=", "c=IN IP4 74.125.224.39");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003184
3185 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003186 ExpectParseFailure("a=candidate", kSdpEmptyType);
3187 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
3188 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
3189 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003190
3191 // Bogus fingerprint replacing a=sendrev. We selected this attribute
3192 // because it's orthogonal to what we are replacing and hence
3193 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003194 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
3195 ExpectParseFailure("a=sendrecv", kSdpExtraField);
3196 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
3197 ExpectParseFailure("a=sendrecv", kSdpMd5);
3198
3199 // Empty Line
3200 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
3201 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003202}
3203
3204TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
3205 // ssrc
3206 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08003207 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
Harald Alvestrand0d018412021-11-04 13:52:31 +00003208 // crypto
3209 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003210 // rtpmap
3211 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
3212 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
3213 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
3214 // candidate
3215 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
3216 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
3217 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
3218 ExpectParseFailure("rport 2346", "rport badvalue");
3219 ExpectParseFailure("rport 2346 generation 2",
3220 "rport 2346 generation badvalue");
3221 // m line
3222 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
3223 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
3224
3225 // bandwidth
3226 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003227 "b=AS:badvalue\r\n", "b=AS:badvalue");
Philipp Hanckefbbfc022020-07-31 08:30:50 +02003228 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", "b=AS\r\n",
3229 "b=AS");
3230 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", "b=AS:\r\n",
3231 "b=AS:");
3232 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3233 "b=AS:12:34\r\n", "b=AS:12:34");
3234
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003235 // rtcp-fb
3236 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3237 "a=rtcp-fb:badvalue nack\r\n",
3238 "a=rtcp-fb:badvalue nack");
3239 // extmap
3240 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3241 "a=extmap:badvalue http://example.com\r\n",
3242 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003243}
3244
3245TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 10:27:41 -08003246 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003247
3248 const char kSdpWithReorderedPlTypesString[] =
3249 "v=0\r\n"
3250 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3251 "s=-\r\n"
3252 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00003253 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
Yves Gerey665174f2018-06-19 15:03:05 +02003254 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
3255 // in the map.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003256 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003257 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003258
3259 // Deserialize
3260 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
3261
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003262 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003263 GetFirstAudioContentDescription(jdesc_output.description());
3264 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003265 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003266 EXPECT_EQ("ISAC", acd->codecs()[0].name);
3267 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003268 EXPECT_EQ(104, acd->codecs()[0].id);
3269}
3270
3271TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 10:27:41 -08003272 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003273 CodecParams params;
3274 params.max_ptime = 40;
3275 params.ptime = 30;
3276 params.min_ptime = 10;
3277 params.sprop_stereo = 1;
3278 params.stereo = 1;
3279 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003280 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003281 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 12:22:16 -08003282 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003283}
3284
3285TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
3286 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 10:27:41 -08003287 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003288 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003289 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003290}
3291
3292TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
3293 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 10:27:41 -08003294 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003295 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003296 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003297}
3298
3299TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 10:27:41 -08003300 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003301
3302 const char kSdpWithFmtpString[] =
3303 "v=0\r\n"
3304 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3305 "s=-\r\n"
3306 "t=0 0\r\n"
3307 "m=video 3457 RTP/SAVPF 120\r\n"
3308 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07003309 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3310
3311 // Deserialize
3312 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07003313 EXPECT_TRUE(
3314 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07003315
Donald Curtis0e07f922015-05-15 09:21:23 -07003316 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003317 GetFirstVideoContentDescription(jdesc_output.description());
3318 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 09:21:23 -07003319 ASSERT_FALSE(vcd->codecs().empty());
3320 cricket::VideoCodec vp8 = vcd->codecs()[0];
3321 EXPECT_EQ("VP8", vp8.name);
3322 EXPECT_EQ(120, vp8.id);
3323 cricket::CodecParameterMap::iterator found =
3324 vp8.params.find("x-google-min-bitrate");
3325 ASSERT_TRUE(found != vp8.params.end());
3326 EXPECT_EQ(found->second, "10");
3327 found = vp8.params.find("x-google-max-quantization");
3328 ASSERT_TRUE(found != vp8.params.end());
3329 EXPECT_EQ(found->second, "40");
3330}
3331
johan2d8d23e2016-06-03 01:22:42 -07003332TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 10:27:41 -08003333 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 01:22:42 -07003334
3335 const char kSdpWithFmtpString[] =
3336 "v=0\r\n"
3337 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3338 "s=-\r\n"
3339 "t=0 0\r\n"
3340 "m=video 49170 RTP/AVP 98\r\n"
3341 "a=rtpmap:98 H264/90000\r\n"
3342 "a=fmtp:98 profile-level-id=42A01E; "
3343 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3344
3345 // Deserialize.
3346 SdpParseError error;
3347 EXPECT_TRUE(
3348 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3349
johan2d8d23e2016-06-03 01:22:42 -07003350 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003351 GetFirstVideoContentDescription(jdesc_output.description());
3352 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 01:22:42 -07003353 ASSERT_FALSE(vcd->codecs().empty());
3354 cricket::VideoCodec h264 = vcd->codecs()[0];
3355 EXPECT_EQ("H264", h264.name);
3356 EXPECT_EQ(98, h264.id);
3357 cricket::CodecParameterMap::const_iterator found =
3358 h264.params.find("profile-level-id");
3359 ASSERT_TRUE(found != h264.params.end());
3360 EXPECT_EQ(found->second, "42A01E");
3361 found = h264.params.find("sprop-parameter-sets");
3362 ASSERT_TRUE(found != h264.params.end());
3363 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3364}
3365
Donald Curtis0e07f922015-05-15 09:21:23 -07003366TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 10:27:41 -08003367 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 09:21:23 -07003368
3369 const char kSdpWithFmtpString[] =
3370 "v=0\r\n"
3371 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3372 "s=-\r\n"
3373 "t=0 0\r\n"
3374 "m=video 3457 RTP/SAVPF 120\r\n"
3375 "a=rtpmap:120 VP8/90000\r\n"
3376 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003377
3378 // Deserialize
3379 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02003380 EXPECT_TRUE(
3381 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003382
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003383 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003384 GetFirstVideoContentDescription(jdesc_output.description());
3385 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003386 ASSERT_FALSE(vcd->codecs().empty());
3387 cricket::VideoCodec vp8 = vcd->codecs()[0];
3388 EXPECT_EQ("VP8", vp8.name);
3389 EXPECT_EQ(120, vp8.id);
3390 cricket::CodecParameterMap::iterator found =
3391 vp8.params.find("x-google-min-bitrate");
3392 ASSERT_TRUE(found != vp8.params.end());
3393 EXPECT_EQ(found->second, "10");
3394 found = vp8.params.find("x-google-max-quantization");
3395 ASSERT_TRUE(found != vp8.params.end());
3396 EXPECT_EQ(found->second, "40");
3397}
3398
Mirta Dvornicic479a3c02019-06-04 15:38:50 +02003399TEST_F(WebRtcSdpTest, DeserializePacketizationAttributeWithIllegalValue) {
3400 JsepSessionDescription jdesc_output(kDummyType);
3401
3402 const char kSdpWithPacketizationString[] =
3403 "v=0\r\n"
3404 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3405 "s=-\r\n"
3406 "t=0 0\r\n"
3407 "m=audio 9 RTP/SAVPF 111\r\n"
3408 "a=rtpmap:111 opus/48000/2\r\n"
3409 "a=packetization:111 unknownpacketizationattributeforaudio\r\n"
3410 "m=video 3457 RTP/SAVPF 120 121 122\r\n"
3411 "a=rtpmap:120 VP8/90000\r\n"
3412 "a=packetization:120 raw\r\n"
3413 "a=rtpmap:121 VP9/90000\r\n"
3414 "a=rtpmap:122 H264/90000\r\n"
3415 "a=packetization:122 unknownpacketizationattributevalue\r\n";
3416
3417 SdpParseError error;
3418 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithPacketizationString, &jdesc_output,
3419 &error));
3420
3421 AudioContentDescription* acd =
3422 GetFirstAudioContentDescription(jdesc_output.description());
3423 ASSERT_TRUE(acd);
3424 ASSERT_THAT(acd->codecs(), testing::SizeIs(1));
3425 cricket::AudioCodec opus = acd->codecs()[0];
3426 EXPECT_EQ(opus.name, "opus");
3427 EXPECT_EQ(opus.id, 111);
3428
3429 const VideoContentDescription* vcd =
3430 GetFirstVideoContentDescription(jdesc_output.description());
3431 ASSERT_TRUE(vcd);
3432 ASSERT_THAT(vcd->codecs(), testing::SizeIs(3));
3433 cricket::VideoCodec vp8 = vcd->codecs()[0];
3434 EXPECT_EQ(vp8.name, "VP8");
3435 EXPECT_EQ(vp8.id, 120);
3436 EXPECT_EQ(vp8.packetization, "raw");
3437 cricket::VideoCodec vp9 = vcd->codecs()[1];
3438 EXPECT_EQ(vp9.name, "VP9");
3439 EXPECT_EQ(vp9.id, 121);
3440 EXPECT_EQ(vp9.packetization, absl::nullopt);
3441 cricket::VideoCodec h264 = vcd->codecs()[2];
3442 EXPECT_EQ(h264.name, "H264");
3443 EXPECT_EQ(h264.id, 122);
3444 EXPECT_EQ(h264.packetization, absl::nullopt);
3445}
3446
ossuaa4b0772017-01-30 07:41:18 -08003447TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003448 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003449
3450 cricket::AudioCodecs codecs = acd->codecs();
3451 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3452 acd->set_codecs(codecs);
3453
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003454 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003455 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003456 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003457 std::string sdp_with_fmtp = kSdpFullString;
3458 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3459 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3460 &sdp_with_fmtp);
3461 EXPECT_EQ(sdp_with_fmtp, message);
3462}
3463
3464TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003465 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003466
3467 cricket::AudioCodecs codecs = acd->codecs();
3468 codecs[0].params["stereo"] = "1";
3469 acd->set_codecs(codecs);
3470
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003471 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003472 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003473 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003474 std::string sdp_with_fmtp = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003475 InjectAfter("a=rtpmap:111 opus/48000/2\r\n", "a=fmtp:111 stereo=1\r\n",
ossuaa4b0772017-01-30 07:41:18 -08003476 &sdp_with_fmtp);
3477 EXPECT_EQ(sdp_with_fmtp, message);
3478}
3479
3480TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003481 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003482
3483 cricket::AudioCodecs codecs = acd->codecs();
3484 codecs[0].params["ptime"] = "20";
3485 codecs[0].params["maxptime"] = "120";
3486 acd->set_codecs(codecs);
3487
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003488 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003489 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003490 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003491 std::string sdp_with_fmtp = kSdpFullString;
3492 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3493 "a=maxptime:120\r\n" // No comma here. String merging!
3494 "a=ptime:20\r\n",
3495 &sdp_with_fmtp);
3496 EXPECT_EQ(sdp_with_fmtp, message);
3497}
3498
Philipp Hanckef2a4ec12020-07-01 21:07:32 +02003499TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithTelephoneEvent) {
3500 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
3501
3502 cricket::AudioCodecs codecs = acd->codecs();
3503 cricket::AudioCodec dtmf(105, "telephone-event", 8000, 0, 1);
3504 dtmf.params[""] = "0-15";
3505 codecs.push_back(dtmf);
3506 acd->set_codecs(codecs);
3507
3508 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
3509 jdesc_.session_version()));
3510 std::string message = webrtc::SdpSerialize(jdesc_);
3511 std::string sdp_with_fmtp = kSdpFullString;
3512 InjectAfter("m=audio 2345 RTP/SAVPF 111 103 104", " 105", &sdp_with_fmtp);
3513 InjectAfter(
3514 "a=rtpmap:104 ISAC/32000\r\n",
3515 "a=rtpmap:105 telephone-event/8000\r\n" // No comma here. String merging!
3516 "a=fmtp:105 0-15\r\n",
3517 &sdp_with_fmtp);
3518 EXPECT_EQ(sdp_with_fmtp, message);
3519}
3520
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003521TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003522 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003523
3524 cricket::VideoCodecs codecs = vcd->codecs();
3525 codecs[0].params["x-google-min-bitrate"] = "10";
3526 vcd->set_codecs(codecs);
3527
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003528 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003529 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003530 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003531 std::string sdp_with_fmtp = kSdpFullString;
3532 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003533 "a=fmtp:120 x-google-min-bitrate=10\r\n", &sdp_with_fmtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003534 EXPECT_EQ(sdp_with_fmtp, message);
3535}
3536
Mirta Dvornicic479a3c02019-06-04 15:38:50 +02003537TEST_F(WebRtcSdpTest, SerializeVideoPacketizationAttribute) {
3538 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
3539
3540 cricket::VideoCodecs codecs = vcd->codecs();
3541 codecs[0].packetization = "raw";
3542 vcd->set_codecs(codecs);
3543
3544 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
3545 jdesc_.session_version()));
3546 std::string message = webrtc::SdpSerialize(jdesc_);
3547 std::string sdp_with_packetization = kSdpFullString;
3548 InjectAfter("a=rtpmap:120 VP8/90000\r\n", "a=packetization:120 raw\r\n",
3549 &sdp_with_packetization);
3550 EXPECT_EQ(sdp_with_packetization, message);
3551}
3552
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003553TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) {
3554 // Deserialize the baseline description, making sure it's ICE full.
Steve Antona3a92c22017-12-07 10:27:41 -08003555 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003556 std::string sdp_with_icelite = kSdpFullString;
3557 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3558 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3559 const cricket::TransportInfo* tinfo1 =
3560 desc->GetTransportInfoByName("audio_content_name");
3561 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3562 const cricket::TransportInfo* tinfo2 =
3563 desc->GetTransportInfoByName("video_content_name");
3564 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003565
3566 // Add "a=ice-lite" and deserialize, making sure it's ICE lite.
Yves Gerey665174f2018-06-19 15:03:05 +02003567 InjectAfter(kSessionTime, "a=ice-lite\r\n", &sdp_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003568 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3569 desc = jdesc_with_icelite.description();
3570 const cricket::TransportInfo* atinfo =
3571 desc->GetTransportInfoByName("audio_content_name");
3572 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3573 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003574 desc->GetTransportInfoByName("video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003575 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003576
3577 // Now that we know deserialization works, we can use TestSerialize to test
3578 // serialization.
3579 TestSerialize(jdesc_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003580}
3581
3582// Verifies that the candidates in the input SDP are parsed and serialized
3583// correctly in the output SDP.
3584TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3585 std::string sdp_with_data = kSdpString;
3586 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 10:27:41 -08003587 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003588
3589 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 12:22:16 -08003590 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003591}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003592
3593TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3594 AddFingerprint();
3595 TransportInfo audio_transport_info =
3596 *(desc_.GetTransportInfoByName(kAudioContentName));
3597 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3598 audio_transport_info.description.connection_role);
3599 audio_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003600 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003601
3602 TransportInfo video_transport_info =
3603 *(desc_.GetTransportInfoByName(kVideoContentName));
3604 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3605 video_transport_info.description.connection_role);
3606 video_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003607 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003608
3609 desc_.RemoveTransportInfoByName(kAudioContentName);
3610 desc_.RemoveTransportInfoByName(kVideoContentName);
3611
3612 desc_.AddTransportInfo(audio_transport_info);
3613 desc_.AddTransportInfo(video_transport_info);
3614
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003615 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003616 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003617 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003618 std::string sdp_with_dtlssetup = kSdpFullString;
3619
3620 // Fingerprint attribute is necessary to add DTLS setup attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003621 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_dtlssetup);
3622 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_dtlssetup);
Artem Titov880fa812021-07-30 22:30:23 +02003623 // Now adding `setup` attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003624 InjectAfter(kFingerprint, "a=setup:active\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003625 EXPECT_EQ(sdp_with_dtlssetup, message);
3626}
3627
Harald Alvestrandefece422021-08-19 09:12:51 +00003628TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttributeActpass) {
Steve Antona3a92c22017-12-07 10:27:41 -08003629 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003630 std::string sdp_with_dtlssetup = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003631 InjectAfter(kSessionTime, "a=setup:actpass\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003632 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3633 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3634 const cricket::TransportInfo* atinfo =
3635 desc->GetTransportInfoByName("audio_content_name");
3636 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3637 atinfo->description.connection_role);
3638 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003639 desc->GetTransportInfoByName("video_content_name");
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003640 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3641 vtinfo->description.connection_role);
3642}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003643
Harald Alvestrandefece422021-08-19 09:12:51 +00003644TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttributeActive) {
3645 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
3646 std::string sdp_with_dtlssetup = kSdpFullString;
3647 InjectAfter(kSessionTime, "a=setup:active\r\n", &sdp_with_dtlssetup);
3648 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3649 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3650 const cricket::TransportInfo* atinfo =
3651 desc->GetTransportInfoByName("audio_content_name");
3652 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
3653 atinfo->description.connection_role);
3654 const cricket::TransportInfo* vtinfo =
3655 desc->GetTransportInfoByName("video_content_name");
3656 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
3657 vtinfo->description.connection_role);
3658}
3659TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttributePassive) {
3660 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
3661 std::string sdp_with_dtlssetup = kSdpFullString;
3662 InjectAfter(kSessionTime, "a=setup:passive\r\n", &sdp_with_dtlssetup);
3663 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3664 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3665 const cricket::TransportInfo* atinfo =
3666 desc->GetTransportInfoByName("audio_content_name");
3667 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
3668 atinfo->description.connection_role);
3669 const cricket::TransportInfo* vtinfo =
3670 desc->GetTransportInfoByName("video_content_name");
3671 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
3672 vtinfo->description.connection_role);
3673}
3674
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003675// Verifies that the order of the serialized m-lines follows the order of the
3676// ContentInfo in SessionDescription, and vise versa for deserialization.
3677TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 10:27:41 -08003678 JsepSessionDescription jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02003679 const std::string media_content_sdps[3] = {kSdpAudioString, kSdpVideoString,
3680 kSdpSctpDataChannelString};
3681 const cricket::MediaType media_types[3] = {cricket::MEDIA_TYPE_AUDIO,
3682 cricket::MEDIA_TYPE_VIDEO,
3683 cricket::MEDIA_TYPE_DATA};
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003684
3685 // Verifies all 6 permutations.
3686 for (size_t i = 0; i < 6; ++i) {
3687 size_t media_content_in_sdp[3];
3688 // The index of the first media content.
3689 media_content_in_sdp[0] = i / 2;
3690 // The index of the second media content.
3691 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3692 // The index of the third media content.
3693 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3694
3695 std::string sdp_string = kSdpSessionString;
3696 for (size_t i = 0; i < 3; ++i)
3697 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3698
3699 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3700 cricket::SessionDescription* desc = jdesc.description();
3701 EXPECT_EQ(3u, desc->contents().size());
3702
3703 for (size_t i = 0; i < 3; ++i) {
3704 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 15:14:30 -08003705 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003706 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3707 }
3708
Steve Antone831b8c2018-02-01 12:22:16 -08003709 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003710 EXPECT_EQ(sdp_string, serialized_sdp);
3711 }
3712}
deadbeef9d3584c2016-02-16 17:54:10 -08003713
deadbeef25ed4352016-12-12 18:37:36 -08003714TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3715 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 10:27:41 -08003716 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003717 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003718 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3719 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3720}
3721
deadbeef12771a12017-01-03 13:53:47 -08003722// The semantics of "a=bundle-only" are only defined when it's used in
3723// combination with a 0 port on the m= line. We should ignore it if used with a
3724// nonzero port.
3725TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3726 // Make the base bundle-only description but unset the bundle-only flag.
3727 MakeBundleOnlyDescription();
3728 jdesc_.description()->contents()[1].bundle_only = false;
3729
3730 std::string modified_sdp = kBundleOnlySdpFullString;
3731 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08003732 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003733 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3734 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003735}
3736
3737TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3738 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003739 TestSerialize(jdesc_);
deadbeef25ed4352016-12-12 18:37:36 -08003740}
3741
deadbeef9d3584c2016-02-16 17:54:10 -08003742TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3743 MakePlanBDescription();
3744
Steve Antona3a92c22017-12-07 10:27:41 -08003745 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003746 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3747
3748 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3749}
3750
3751TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3752 MakePlanBDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003753 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-16 17:54:10 -08003754}
3755
3756TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3757 MakeUnifiedPlanDescription();
3758
Steve Antona3a92c22017-12-07 10:27:41 -08003759 JsepSessionDescription deserialized_description(kDummyType);
Harald Alvestrand0d018412021-11-04 13:52:31 +00003760 EXPECT_TRUE(
deadbeef9d3584c2016-02-16 17:54:10 -08003761 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3762
3763 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3764}
3765
3766TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3767 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003768 TestSerialize(jdesc_);
3769}
3770
Seth Hampson5b4f0752018-04-02 16:31:36 -07003771// This tests deserializing a Unified Plan SDP that is compatible with both
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003772// Unified Plan and Plan B style SDP, meaning that it contains both "a=ssrc
3773// msid" lines and "a=msid " lines. It tests the case for audio/video tracks
Seth Hampson5b4f0752018-04-02 16:31:36 -07003774// with no stream ids and multiple stream ids. For parsing this, the Unified
3775// Plan a=msid lines should take priority, because the Plan B style a=ssrc msid
3776// lines do not support multiple stream ids and no stream ids.
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003777TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionSpecialMsid) {
3778 // Create both msid lines for Plan B and Unified Plan support.
3779 MakeUnifiedPlanDescriptionMultipleStreamIds(
3780 cricket::kMsidSignalingMediaSection |
3781 cricket::kMsidSignalingSsrcAttribute);
Seth Hampson5b4f0752018-04-02 16:31:36 -07003782
3783 JsepSessionDescription deserialized_description(kDummyType);
3784 EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid,
3785 &deserialized_description));
3786
3787 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
Henrik Boström5b147782018-12-04 11:25:05 +01003788 EXPECT_EQ(cricket::kMsidSignalingMediaSection |
3789 cricket::kMsidSignalingSsrcAttribute,
3790 deserialized_description.description()->msid_signaling());
Seth Hampson5b4f0752018-04-02 16:31:36 -07003791}
3792
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003793// Tests the serialization of a Unified Plan SDP that is compatible for both
3794// Unified Plan and Plan B style SDPs, meaning that it contains both "a=ssrc
3795// msid" lines and "a=msid " lines. It tests the case for no stream ids and
3796// multiple stream ids.
3797TEST_F(WebRtcSdpTest, SerializeSessionDescriptionSpecialMsid) {
3798 // Create both msid lines for Plan B and Unified Plan support.
3799 MakeUnifiedPlanDescriptionMultipleStreamIds(
3800 cricket::kMsidSignalingMediaSection |
3801 cricket::kMsidSignalingSsrcAttribute);
3802 std::string serialized_sdp = webrtc::SdpSerialize(jdesc_);
3803 // We explicitly test that the serialized SDP string is equal to the hard
3804 // coded SDP string. This is necessary, because in the parser "a=msid" lines
3805 // take priority over "a=ssrc msid" lines. This means if we just used
3806 // TestSerialize(), it could serialize an SDP that omits "a=ssrc msid" lines,
3807 // and still pass, because the deserialized version would be the same.
3808 EXPECT_EQ(kUnifiedPlanSdpFullStringWithSpecialMsid, serialized_sdp);
3809}
3810
3811// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3812// that signal stream IDs) is deserialized appropriately. It tests the case for
3813// no stream ids and multiple stream ids.
3814TEST_F(WebRtcSdpTest, UnifiedPlanDeserializeSessionDescriptionSpecialMsid) {
3815 // Only create a=msid lines for strictly Unified Plan stream ID support.
3816 MakeUnifiedPlanDescriptionMultipleStreamIds(
3817 cricket::kMsidSignalingMediaSection);
3818
3819 JsepSessionDescription deserialized_description(kDummyType);
3820 std::string unified_plan_sdp_string =
3821 kUnifiedPlanSdpFullStringWithSpecialMsid;
3822 RemoveSsrcMsidLinesFromSdpString(&unified_plan_sdp_string);
3823 EXPECT_TRUE(
3824 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3825
3826 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3827}
3828
3829// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3830// that signal stream IDs) is serialized appropriately. It tests the case for no
3831// stream ids and multiple stream ids.
3832TEST_F(WebRtcSdpTest, UnifiedPlanSerializeSessionDescriptionSpecialMsid) {
3833 // Only create a=msid lines for strictly Unified Plan stream ID support.
3834 MakeUnifiedPlanDescriptionMultipleStreamIds(
3835 cricket::kMsidSignalingMediaSection);
3836
Seth Hampson5b4f0752018-04-02 16:31:36 -07003837 TestSerialize(jdesc_);
3838}
3839
Seth Hampson5897a6e2018-04-03 11:16:33 -07003840// This tests that a Unified Plan SDP with no a=ssrc lines is
3841// serialized/deserialized appropriately. In this case the
3842// MediaContentDescription will contain a StreamParams object that doesn't have
3843// any SSRCs. Vice versa, this will be created upon deserializing an SDP with no
3844// SSRC lines.
3845TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3846 MakeUnifiedPlanDescription();
3847 RemoveSsrcSignalingFromStreamParams();
3848 std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString;
3849 RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string);
3850
3851 JsepSessionDescription deserialized_description(kDummyType);
3852 EXPECT_TRUE(
3853 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3854 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3855}
3856
3857TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3858 MakeUnifiedPlanDescription();
3859 RemoveSsrcSignalingFromStreamParams();
3860
3861 TestSerialize(jdesc_);
3862}
3863
Steve Antone831b8c2018-02-01 12:22:16 -08003864TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
3865 JsepSessionDescription jsep_desc(kDummyType);
3866 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
3867 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3868}
3869
3870TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
3871 JsepSessionDescription jsep_desc(kDummyType);
3872 std::string sdp = kSdpSessionString;
3873 sdp += kSdpSctpDataChannelString;
3874 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3875 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3876}
3877
3878TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
3879 JsepSessionDescription jsep_desc(kDummyType);
3880 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
3881 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
3882 jsep_desc.description()->msid_signaling());
3883}
3884
3885TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
3886 JsepSessionDescription jsep_desc(kDummyType);
3887 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
3888 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
3889 jsep_desc.description()->msid_signaling());
3890}
3891
3892const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
3893const char kSsrcAttributeMsidLine[] =
3894 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
3895
3896TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
3897 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
3898 std::string sdp = webrtc::SdpSerialize(jdesc_);
3899
3900 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3901 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3902}
3903
3904TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
3905 jdesc_.description()->set_msid_signaling(
3906 cricket::kMsidSignalingSsrcAttribute);
3907 std::string sdp = webrtc::SdpSerialize(jdesc_);
3908
3909 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
3910 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3911}
3912
3913TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
3914 jdesc_.description()->set_msid_signaling(
3915 cricket::kMsidSignalingMediaSection |
3916 cricket::kMsidSignalingSsrcAttribute);
3917 std::string sdp = webrtc::SdpSerialize(jdesc_);
3918
3919 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3920 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-16 17:54:10 -08003921}
deadbeef7e146cb2016-09-28 10:04:34 -07003922
deadbeefb2362572016-12-13 16:37:06 -08003923// Regression test for integer overflow bug:
3924// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3925TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003926 // Bandwidth attribute is the max signed 32-bit int, which will get
3927 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003928 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003929 "v=0\r\n"
3930 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3931 "s=-\r\n"
3932 "t=0 0\r\n"
3933 "m=video 3457 RTP/SAVPF 120\r\n"
3934 "b=AS:2147483647\r\n"
3935 "foo=fail\r\n";
3936
3937 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3938}
deadbeef7bcdb692017-01-20 12:43:58 -08003939
deadbeefbc88c6b2017-08-02 11:26:34 -07003940// Similar to the above, except that negative values are illegal, not just
3941// error-prone as large values are.
3942// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3943TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3944 static const char kSdpWithNegativeBandwidth[] =
3945 "v=0\r\n"
3946 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3947 "s=-\r\n"
3948 "t=0 0\r\n"
3949 "m=video 3457 RTP/SAVPF 120\r\n"
3950 "b=AS:-1000\r\n";
3951
3952 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3953}
3954
deadbeef3e8016e2017-08-03 17:49:30 -07003955// An exception to the above rule: a value of -1 for b=AS should just be
3956// ignored, resulting in "kAutoBandwidth" in the deserialized object.
3957// Applications historically may be using "b=AS:-1" to mean "no bandwidth
3958// limit", but this is now what ommitting the attribute entirely will do, so
3959// ignoring it will have the intended effect.
3960TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
3961 static const char kSdpWithBandwidthOfNegativeOne[] =
3962 "v=0\r\n"
3963 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3964 "s=-\r\n"
3965 "t=0 0\r\n"
3966 "m=video 3457 RTP/SAVPF 120\r\n"
3967 "b=AS:-1\r\n";
3968
Steve Antona3a92c22017-12-07 10:27:41 -08003969 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-03 17:49:30 -07003970 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-03 17:49:30 -07003971 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003972 GetFirstVideoContentDescription(jdesc_output.description());
3973 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-03 17:49:30 -07003974 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
3975}
3976
deadbeef7bcdb692017-01-20 12:43:58 -08003977// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3978// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3979// Regression test for:
3980// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3981TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3982 // Important piece is "ufrag foo pwd bar".
3983 static const char kSdpWithIceCredentialsInCandidateString[] =
3984 "v=0\r\n"
3985 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3986 "s=-\r\n"
3987 "t=0 0\r\n"
3988 "m=audio 9 RTP/SAVPF 111\r\n"
3989 "c=IN IP4 0.0.0.0\r\n"
3990 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3991 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3992 "a=rtpmap:111 opus/48000/2\r\n"
3993 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3994 "generation 2 ufrag foo pwd bar\r\n";
3995
Steve Antona3a92c22017-12-07 10:27:41 -08003996 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 12:43:58 -08003997 EXPECT_TRUE(
3998 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
3999 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
4000 ASSERT_NE(nullptr, candidates);
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02004001 ASSERT_EQ(1U, candidates->count());
deadbeef7bcdb692017-01-20 12:43:58 -08004002 cricket::Candidate c = candidates->at(0)->candidate();
4003 EXPECT_EQ("ufrag_voice", c.username());
4004 EXPECT_EQ("pwd_voice", c.password());
4005}
deadbeef90f1e1e2017-02-10 12:35:05 -08004006
Johannes Kron211856b2018-09-06 12:12:28 +02004007// Test that attribute lines "a=ice-ufrag-something"/"a=ice-pwd-something" are
4008// ignored, and only the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
4009// Regression test for:
4010// https://bugs.chromium.org/p/webrtc/issues/detail?id=9712
4011TEST_F(WebRtcSdpTest, AttributeWithPartialMatchingNameIsIgnored) {
4012 static const char kSdpWithFooIceCredentials[] =
4013 "v=0\r\n"
4014 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4015 "s=-\r\n"
4016 "t=0 0\r\n"
4017 "m=audio 9 RTP/SAVPF 111\r\n"
4018 "c=IN IP4 0.0.0.0\r\n"
4019 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4020 "a=ice-ufrag-something:foo\r\na=ice-pwd-something:bar\r\n"
4021 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4022 "a=rtpmap:111 opus/48000/2\r\n"
4023 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
4024 "generation 2\r\n";
4025
4026 JsepSessionDescription jdesc_output(kDummyType);
4027 EXPECT_TRUE(SdpDeserialize(kSdpWithFooIceCredentials, &jdesc_output));
4028 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
4029 ASSERT_NE(nullptr, candidates);
4030 ASSERT_EQ(1U, candidates->count());
4031 cricket::Candidate c = candidates->at(0)->candidate();
4032 EXPECT_EQ("ufrag_voice", c.username());
4033 EXPECT_EQ("pwd_voice", c.password());
4034}
4035
deadbeef90f1e1e2017-02-10 12:35:05 -08004036// Test that SDP with an invalid port number in "a=candidate" lines is
4037// rejected, without crashing.
4038// Regression test for:
4039// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
4040TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
4041 static const char kSdpWithInvalidCandidatePort[] =
4042 "v=0\r\n"
4043 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4044 "s=-\r\n"
4045 "t=0 0\r\n"
4046 "m=audio 9 RTP/SAVPF 111\r\n"
4047 "c=IN IP4 0.0.0.0\r\n"
4048 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4049 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4050 "a=rtpmap:111 opus/48000/2\r\n"
4051 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
4052 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
4053
Steve Antona3a92c22017-12-07 10:27:41 -08004054 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 12:35:05 -08004055 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
4056}
deadbeefa4549d62017-02-10 17:26:22 -08004057
4058// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
4059// Regression test for:
4060// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
4061TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
4062 static const char kSdpWithMissingTrackId[] =
4063 "v=0\r\n"
4064 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4065 "s=-\r\n"
4066 "t=0 0\r\n"
4067 "m=audio 9 RTP/SAVPF 111\r\n"
4068 "c=IN IP4 0.0.0.0\r\n"
4069 "a=rtpmap:111 opus/48000/2\r\n"
4070 "a=msid:stream_id \r\n";
4071
Steve Antona3a92c22017-12-07 10:27:41 -08004072 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08004073 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
4074}
4075
4076TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
4077 static const char kSdpWithMissingStreamId[] =
4078 "v=0\r\n"
4079 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4080 "s=-\r\n"
4081 "t=0 0\r\n"
4082 "m=audio 9 RTP/SAVPF 111\r\n"
4083 "c=IN IP4 0.0.0.0\r\n"
4084 "a=rtpmap:111 opus/48000/2\r\n"
4085 "a=msid: track_id\r\n";
4086
Steve Antona3a92c22017-12-07 10:27:41 -08004087 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08004088 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
4089}
zhihuang38989e52017-03-21 11:04:53 -07004090
4091// Tests that if both session-level address and media-level address exist, use
4092// the media-level address.
4093TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 10:27:41 -08004094 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004095
4096 // Sesssion-level address.
4097 std::string sdp = kSdpFullString;
4098 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
4099 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4100
4101 const auto& content1 = jsep_desc.description()->contents()[0];
4102 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 15:14:30 -08004103 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004104 const auto& content2 = jsep_desc.description()->contents()[1];
4105 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 15:14:30 -08004106 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004107}
4108
4109// Tests that the session-level connection address will be used if the media
4110// level-addresses are not specified.
4111TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 10:27:41 -08004112 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004113
4114 // Sesssion-level address.
4115 std::string sdp = kSdpString;
4116 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
4117 // Remove the media level addresses.
4118 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
4119 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
4120 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4121
4122 const auto& content1 = jsep_desc.description()->contents()[0];
4123 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004124 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004125 const auto& content2 = jsep_desc.description()->contents()[1];
4126 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004127 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004128}
4129
4130TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 10:27:41 -08004131 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004132
4133 std::string sdp = kSdpString;
4134 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4135 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
4136 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
4137 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
4138 &sdp);
4139 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
4140 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
4141 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
4142 &sdp);
4143 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4144 const auto& content1 = jsep_desc.description()->contents()[0];
4145 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004146 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004147 const auto& content2 = jsep_desc.description()->contents()[1];
4148 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004149 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004150}
4151
Qingsi Wang56991422019-02-08 12:53:06 -08004152// Test that a c= line that contains a hostname connection address can be
4153// parsed.
4154TEST_F(WebRtcSdpTest, ParseConnectionDataWithHostnameConnectionAddress) {
4155 JsepSessionDescription jsep_desc(kDummyType);
4156 std::string sdp = kSdpString;
4157 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4158
4159 sdp = kSdpString;
4160 Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp);
4161 Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp);
4162 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4163
4164 ASSERT_NE(nullptr, jsep_desc.description());
4165 const auto& content1 = jsep_desc.description()->contents()[0];
4166 EXPECT_EQ("example.local:9",
4167 content1.media_description()->connection_address().ToString());
4168 const auto& content2 = jsep_desc.description()->contents()[1];
4169 EXPECT_EQ("example.local:9",
4170 content2.media_description()->connection_address().ToString());
4171}
4172
4173// Test that the invalid or unsupported connection data cannot be parsed.
zhihuang38989e52017-03-21 11:04:53 -07004174TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 10:27:41 -08004175 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004176 std::string sdp = kSdpString;
4177 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4178
4179 // Unsupported multicast IPv4 address.
4180 sdp = kSdpFullString;
4181 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
4182 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4183
4184 // Unsupported multicast IPv6 address.
4185 sdp = kSdpFullString;
4186 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
4187 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4188
4189 // Mismatched address type.
4190 sdp = kSdpFullString;
4191 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
4192 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4193
4194 sdp = kSdpFullString;
4195 Replace("c=IN IP4 74.125.224.39\r\n",
4196 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
4197 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4198}
4199
4200TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 10:27:41 -08004201 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004202 MakeDescriptionWithoutCandidates(&expected_jsep);
4203 // Serialization.
Steve Antone831b8c2018-02-01 12:22:16 -08004204 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 11:04:53 -07004205 // Deserialization.
Steve Antona3a92c22017-12-07 10:27:41 -08004206 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004207 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 15:14:30 -08004208 auto audio_desc = jdesc.description()
4209 ->GetContentByName(kAudioContentName)
4210 ->media_description();
4211 auto video_desc = jdesc.description()
4212 ->GetContentByName(kVideoContentName)
4213 ->media_description();
zhihuang38989e52017-03-21 11:04:53 -07004214 EXPECT_EQ(audio_desc_->connection_address().ToString(),
4215 audio_desc->connection_address().ToString());
4216 EXPECT_EQ(video_desc_->connection_address().ToString(),
4217 video_desc->connection_address().ToString());
4218}
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07004219
4220// RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be
4221// used (i.e., a single space as the session name)." So we should accept that.
4222TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) {
4223 JsepSessionDescription jsep_desc(kDummyType);
4224 std::string sdp = kSdpString;
4225 Replace("s=-\r\n", "s= \r\n", &sdp);
4226 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4227}
Amit Hilbucha2012042018-12-03 11:35:05 -08004228
4229// Simulcast malformed input test for invalid format.
4230TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_EmptyAttribute) {
Harald Alvestrand88b8dec2022-04-07 09:54:51 +00004231 ExpectParseFailureWithNewLines(
4232 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n", "a=simulcast:\r\n",
4233 "a=simulcast:");
Amit Hilbucha2012042018-12-03 11:35:05 -08004234}
4235
4236// Tests that duplicate simulcast entries in the SDP triggers a parse failure.
4237TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_DuplicateAttribute) {
Harald Alvestrand88b8dec2022-04-07 09:54:51 +00004238 ExpectParseFailureWithNewLines(
4239 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n",
4240 "a=simulcast:send 1\r\na=simulcast:recv 2\r\n", "a=simulcast:");
Amit Hilbucha2012042018-12-03 11:35:05 -08004241}
4242
4243// Validates that deserialization uses the a=simulcast: attribute
4244TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttribute) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004245 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4246 sdp += "a=rid:1 send\r\n";
4247 sdp += "a=rid:2 send\r\n";
4248 sdp += "a=rid:3 send\r\n";
4249 sdp += "a=rid:4 recv\r\n";
4250 sdp += "a=rid:5 recv\r\n";
4251 sdp += "a=rid:6 recv\r\n";
Amit Hilbucha2012042018-12-03 11:35:05 -08004252 sdp += "a=simulcast:send 1,2;3 recv 4;5;6\r\n";
4253 JsepSessionDescription output(kDummyType);
4254 SdpParseError error;
4255 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4256 const cricket::ContentInfos& contents = output.description()->contents();
4257 const cricket::MediaContentDescription* media =
4258 contents.back().media_description();
4259 EXPECT_TRUE(media->HasSimulcast());
4260 EXPECT_EQ(2ul, media->simulcast_description().send_layers().size());
4261 EXPECT_EQ(3ul, media->simulcast_description().receive_layers().size());
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004262 EXPECT_FALSE(media->streams().empty());
4263 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4264 CompareRidDescriptionIds(rids, {"1", "2", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004265}
4266
4267// Validates that deserialization removes rids that do not appear in SDP
4268TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttributeRemovesUnknownRids) {
4269 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4270 sdp += "a=rid:1 send\r\n";
4271 sdp += "a=rid:3 send\r\n";
4272 sdp += "a=rid:4 recv\r\n";
4273 sdp += "a=simulcast:send 1,2;3 recv 4;5,6\r\n";
4274 JsepSessionDescription output(kDummyType);
4275 SdpParseError error;
4276 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4277 const cricket::ContentInfos& contents = output.description()->contents();
4278 const cricket::MediaContentDescription* media =
4279 contents.back().media_description();
4280 EXPECT_TRUE(media->HasSimulcast());
4281 const SimulcastDescription& simulcast = media->simulcast_description();
4282 EXPECT_EQ(2ul, simulcast.send_layers().size());
4283 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4284
4285 std::vector<SimulcastLayer> all_send_layers =
4286 simulcast.send_layers().GetAllLayers();
4287 EXPECT_EQ(2ul, all_send_layers.size());
Steve Anton64b626b2019-01-28 17:25:26 -08004288 EXPECT_EQ(0,
4289 absl::c_count_if(all_send_layers, [](const SimulcastLayer& layer) {
4290 return layer.rid == "2";
4291 }));
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004292
4293 std::vector<SimulcastLayer> all_receive_layers =
4294 simulcast.receive_layers().GetAllLayers();
4295 ASSERT_EQ(1ul, all_receive_layers.size());
4296 EXPECT_EQ("4", all_receive_layers[0].rid);
4297
4298 EXPECT_FALSE(media->streams().empty());
4299 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4300 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004301}
4302
4303// Validates that Simulcast removes rids that appear in both send and receive.
4304TEST_F(WebRtcSdpTest,
4305 TestDeserializeSimulcastAttributeRemovesDuplicateSendReceive) {
4306 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4307 sdp += "a=rid:1 send\r\n";
4308 sdp += "a=rid:2 send\r\n";
4309 sdp += "a=rid:3 send\r\n";
4310 sdp += "a=rid:4 recv\r\n";
4311 sdp += "a=simulcast:send 1;2;3 recv 2;4\r\n";
4312 JsepSessionDescription output(kDummyType);
4313 SdpParseError error;
4314 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4315 const cricket::ContentInfos& contents = output.description()->contents();
4316 const cricket::MediaContentDescription* media =
4317 contents.back().media_description();
4318 EXPECT_TRUE(media->HasSimulcast());
4319 const SimulcastDescription& simulcast = media->simulcast_description();
4320 EXPECT_EQ(2ul, simulcast.send_layers().size());
4321 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4322 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4323 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4324
4325 EXPECT_FALSE(media->streams().empty());
4326 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4327 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004328}
4329
4330// Ignores empty rid line.
4331TEST_F(WebRtcSdpTest, TestDeserializeIgnoresEmptyRidLines) {
4332 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4333 sdp += "a=rid:1 send\r\n";
4334 sdp += "a=rid:2 send\r\n";
4335 sdp += "a=rid\r\n"; // Should ignore this line.
4336 sdp += "a=rid:\r\n"; // Should ignore this line.
4337 sdp += "a=simulcast:send 1;2\r\n";
4338 JsepSessionDescription output(kDummyType);
4339 SdpParseError error;
4340 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4341 const cricket::ContentInfos& contents = output.description()->contents();
4342 const cricket::MediaContentDescription* media =
4343 contents.back().media_description();
4344 EXPECT_TRUE(media->HasSimulcast());
4345 const SimulcastDescription& simulcast = media->simulcast_description();
4346 EXPECT_TRUE(simulcast.receive_layers().empty());
4347 EXPECT_EQ(2ul, simulcast.send_layers().size());
4348 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4349
4350 EXPECT_FALSE(media->streams().empty());
4351 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4352 CompareRidDescriptionIds(rids, {"1", "2"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004353}
4354
4355// Ignores malformed rid lines.
4356TEST_F(WebRtcSdpTest, TestDeserializeIgnoresMalformedRidLines) {
4357 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4358 sdp += "a=rid:1 send pt=\r\n"; // Should ignore this line.
4359 sdp += "a=rid:2 receive\r\n"; // Should ignore this line.
4360 sdp += "a=rid:3 max-width=720;pt=120\r\n"; // Should ignore this line.
4361 sdp += "a=rid:4\r\n"; // Should ignore this line.
4362 sdp += "a=rid:5 send\r\n";
4363 sdp += "a=simulcast:send 1,2,3;4,5\r\n";
4364 JsepSessionDescription output(kDummyType);
4365 SdpParseError error;
4366 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4367 const cricket::ContentInfos& contents = output.description()->contents();
4368 const cricket::MediaContentDescription* media =
4369 contents.back().media_description();
4370 EXPECT_TRUE(media->HasSimulcast());
4371 const SimulcastDescription& simulcast = media->simulcast_description();
4372 EXPECT_TRUE(simulcast.receive_layers().empty());
4373 EXPECT_EQ(1ul, simulcast.send_layers().size());
4374 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4375
4376 EXPECT_FALSE(media->streams().empty());
4377 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4378 CompareRidDescriptionIds(rids, {"5"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004379}
4380
4381// Removes RIDs that specify a different format than the m= section.
4382TEST_F(WebRtcSdpTest, TestDeserializeRemovesRidsWithInvalidCodec) {
4383 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4384 sdp += "a=rid:1 send pt=121,120\r\n"; // Should remove 121 and keep RID.
4385 sdp += "a=rid:2 send pt=121\r\n"; // Should remove RID altogether.
4386 sdp += "a=simulcast:send 1;2\r\n";
4387 JsepSessionDescription output(kDummyType);
4388 SdpParseError error;
4389 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4390 const cricket::ContentInfos& contents = output.description()->contents();
4391 const cricket::MediaContentDescription* media =
4392 contents.back().media_description();
4393 EXPECT_TRUE(media->HasSimulcast());
4394 const SimulcastDescription& simulcast = media->simulcast_description();
4395 EXPECT_TRUE(simulcast.receive_layers().empty());
4396 EXPECT_EQ(1ul, simulcast.send_layers().size());
4397 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4398 EXPECT_EQ("1", simulcast.send_layers()[0][0].rid);
4399 EXPECT_EQ(1ul, media->streams().size());
4400 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4401 EXPECT_EQ(1ul, rids.size());
4402 EXPECT_EQ("1", rids[0].rid);
4403 EXPECT_EQ(1ul, rids[0].payload_types.size());
4404 EXPECT_EQ(120, rids[0].payload_types[0]);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004405}
4406
4407// Ignores duplicate rid lines
4408TEST_F(WebRtcSdpTest, TestDeserializeIgnoresDuplicateRidLines) {
4409 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4410 sdp += "a=rid:1 send\r\n";
4411 sdp += "a=rid:2 send\r\n";
4412 sdp += "a=rid:2 send\r\n";
4413 sdp += "a=rid:3 send\r\n";
4414 sdp += "a=rid:4 recv\r\n";
4415 sdp += "a=simulcast:send 1,2;3 recv 4\r\n";
4416 JsepSessionDescription output(kDummyType);
4417 SdpParseError error;
4418 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4419 const cricket::ContentInfos& contents = output.description()->contents();
4420 const cricket::MediaContentDescription* media =
4421 contents.back().media_description();
4422 EXPECT_TRUE(media->HasSimulcast());
4423 const SimulcastDescription& simulcast = media->simulcast_description();
4424 EXPECT_EQ(2ul, simulcast.send_layers().size());
4425 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4426 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4427 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4428
4429 EXPECT_FALSE(media->streams().empty());
4430 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4431 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbucha2012042018-12-03 11:35:05 -08004432}
4433
Florent Castellic4421972019-07-02 20:27:42 +02004434TEST_F(WebRtcSdpTest, TestDeserializeRidSendDirection) {
4435 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4436 sdp += "a=rid:1 recv\r\n";
4437 sdp += "a=rid:2 recv\r\n";
4438 sdp += "a=simulcast:send 1;2\r\n";
4439 JsepSessionDescription output(kDummyType);
4440 SdpParseError error;
4441 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4442 const cricket::ContentInfos& contents = output.description()->contents();
4443 const cricket::MediaContentDescription* media =
4444 contents.back().media_description();
4445 EXPECT_FALSE(media->HasSimulcast());
4446}
4447
4448TEST_F(WebRtcSdpTest, TestDeserializeRidRecvDirection) {
4449 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4450 sdp += "a=rid:1 send\r\n";
4451 sdp += "a=rid:2 send\r\n";
4452 sdp += "a=simulcast:recv 1;2\r\n";
4453 JsepSessionDescription output(kDummyType);
4454 SdpParseError error;
4455 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4456 const cricket::ContentInfos& contents = output.description()->contents();
4457 const cricket::MediaContentDescription* media =
4458 contents.back().media_description();
4459 EXPECT_FALSE(media->HasSimulcast());
4460}
4461
4462TEST_F(WebRtcSdpTest, TestDeserializeIgnoresWrongRidDirectionLines) {
4463 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4464 sdp += "a=rid:1 send\r\n";
4465 sdp += "a=rid:2 send\r\n";
4466 sdp += "a=rid:3 send\r\n";
4467 sdp += "a=rid:4 recv\r\n";
4468 sdp += "a=rid:5 recv\r\n";
4469 sdp += "a=rid:6 recv\r\n";
4470 sdp += "a=simulcast:send 1;5;3 recv 4;2;6\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_TRUE(media->HasSimulcast());
4478 const SimulcastDescription& simulcast = media->simulcast_description();
4479 EXPECT_EQ(2ul, simulcast.send_layers().size());
4480 EXPECT_EQ(2ul, simulcast.receive_layers().size());
4481 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4482 EXPECT_EQ(2ul, simulcast.receive_layers().GetAllLayers().size());
4483
4484 EXPECT_FALSE(media->streams().empty());
4485 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4486 CompareRidDescriptionIds(rids, {"1", "3"});
4487}
4488
Amit Hilbucha2012042018-12-03 11:35:05 -08004489// Simulcast serialization integration test.
4490// This test will serialize and deserialize the description and compare.
4491// More detailed tests for parsing simulcast can be found in
4492// unit tests for SdpSerializer.
4493TEST_F(WebRtcSdpTest, SerializeSimulcast_ComplexSerialization) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004494 MakeUnifiedPlanDescription(/* use_ssrcs = */ false);
Amit Hilbucha2012042018-12-03 11:35:05 -08004495 auto description = jdesc_.description();
4496 auto media = description->GetContentDescriptionByName(kVideoContentName3);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004497 ASSERT_EQ(media->streams().size(), 1ul);
4498 StreamParams& send_stream = media->mutable_streams()[0];
4499 std::vector<RidDescription> send_rids;
4500 send_rids.push_back(RidDescription("1", RidDirection::kSend));
4501 send_rids.push_back(RidDescription("2", RidDirection::kSend));
4502 send_rids.push_back(RidDescription("3", RidDirection::kSend));
4503 send_rids.push_back(RidDescription("4", RidDirection::kSend));
4504 send_stream.set_rids(send_rids);
Florent Castellib60141b2019-07-03 12:47:54 +02004505 std::vector<RidDescription> receive_rids;
4506 receive_rids.push_back(RidDescription("5", RidDirection::kReceive));
4507 receive_rids.push_back(RidDescription("6", RidDirection::kReceive));
4508 receive_rids.push_back(RidDescription("7", RidDirection::kReceive));
4509 media->set_receive_rids(receive_rids);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004510
Amit Hilbucha2012042018-12-03 11:35:05 -08004511 SimulcastDescription& simulcast = media->simulcast_description();
4512 simulcast.send_layers().AddLayerWithAlternatives(
4513 {SimulcastLayer("2", false), SimulcastLayer("1", true)});
4514 simulcast.send_layers().AddLayerWithAlternatives(
4515 {SimulcastLayer("4", false), SimulcastLayer("3", false)});
Florent Castellib60141b2019-07-03 12:47:54 +02004516 simulcast.receive_layers().AddLayer({SimulcastLayer("5", false)});
4517 simulcast.receive_layers().AddLayer({SimulcastLayer("6", false)});
4518 simulcast.receive_layers().AddLayer({SimulcastLayer("7", false)});
Amit Hilbucha2012042018-12-03 11:35:05 -08004519
Amit Hilbucha2012042018-12-03 11:35:05 -08004520 TestSerialize(jdesc_);
4521}
Steve Anton06817cd2018-12-18 15:55:30 -08004522
4523// Test that the content name is empty if the media section does not have an
4524// a=mid line.
4525TEST_F(WebRtcSdpTest, ParseNoMid) {
4526 std::string sdp = kSdpString;
4527 Replace("a=mid:audio_content_name\r\n", "", &sdp);
4528 Replace("a=mid:video_content_name\r\n", "", &sdp);
4529
4530 JsepSessionDescription output(kDummyType);
4531 SdpParseError error;
4532 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4533
4534 EXPECT_THAT(output.description()->contents(),
4535 ElementsAre(Field("name", &cricket::ContentInfo::name, ""),
4536 Field("name", &cricket::ContentInfo::name, "")));
4537}
Piotr (Peter) Slatala13e570f2019-02-27 11:34:26 -08004538
Guido Urdanetacecf87f2019-05-31 10:17:38 +00004539TEST_F(WebRtcSdpTest, SerializeWithDefaultSctpProtocol) {
4540 AddSctpDataChannel(false); // Don't use sctpmap
4541 JsepSessionDescription jsep_desc(kDummyType);
4542 MakeDescriptionWithoutCandidates(&jsep_desc);
4543 std::string message = webrtc::SdpSerialize(jsep_desc);
4544 EXPECT_NE(std::string::npos,
4545 message.find(cricket::kMediaProtocolUdpDtlsSctp));
4546}
4547
4548TEST_F(WebRtcSdpTest, DeserializeWithAllSctpProtocols) {
4549 AddSctpDataChannel(false);
4550 std::string protocols[] = {cricket::kMediaProtocolDtlsSctp,
4551 cricket::kMediaProtocolUdpDtlsSctp,
4552 cricket::kMediaProtocolTcpDtlsSctp};
4553 for (const auto& protocol : protocols) {
4554 sctp_desc_->set_protocol(protocol);
4555 JsepSessionDescription jsep_desc(kDummyType);
4556 MakeDescriptionWithoutCandidates(&jsep_desc);
4557 std::string message = webrtc::SdpSerialize(jsep_desc);
4558 EXPECT_NE(std::string::npos, message.find(protocol));
4559 JsepSessionDescription jsep_output(kDummyType);
4560 SdpParseError error;
4561 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jsep_output, &error));
4562 }
4563}
Taylor Brandstetter4256df02020-02-18 14:05:07 -08004564
4565// According to https://tools.ietf.org/html/rfc5576#section-6.1, the CNAME
4566// attribute is mandatory, but we relax that restriction.
4567TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCname) {
4568 std::string sdp_without_cname = kSdpFullString;
4569 Replace("a=ssrc:1 cname:stream_1_cname\r\n", "", &sdp_without_cname);
4570 JsepSessionDescription new_jdesc(kDummyType);
4571 EXPECT_TRUE(SdpDeserialize(sdp_without_cname, &new_jdesc));
4572
4573 audio_desc_->mutable_streams()[0].cname = "";
4574 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
4575 jdesc_.session_version()));
4576 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
4577}
Philipp Hanckeefc55b02020-06-26 10:17:05 +02004578
4579TEST_F(WebRtcSdpTest, DeserializeSdpWithUnsupportedMediaType) {
Philipp Hanckeefc55b02020-06-26 10:17:05 +02004580 std::string sdp = kSdpSessionString;
4581 sdp +=
4582 "m=bogus 9 RTP/SAVPF 0 8\r\n"
Philipp Hancke4e8c1152020-10-13 12:43:15 +02004583 "c=IN IP4 0.0.0.0\r\n"
4584 "a=mid:bogusmid\r\n";
Philipp Hanckeefc55b02020-06-26 10:17:05 +02004585 sdp +=
4586 "m=audio/something 9 RTP/SAVPF 0 8\r\n"
Philipp Hancke4e8c1152020-10-13 12:43:15 +02004587 "c=IN IP4 0.0.0.0\r\n"
4588 "a=mid:somethingmid\r\n";
Philipp Hanckeefc55b02020-06-26 10:17:05 +02004589
4590 JsepSessionDescription jdesc_output(kDummyType);
4591 EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output));
4592
Philipp Hancke4e8c1152020-10-13 12:43:15 +02004593 ASSERT_EQ(2u, jdesc_output.description()->contents().size());
4594 ASSERT_NE(nullptr, jdesc_output.description()
4595 ->contents()[0]
4596 .media_description()
4597 ->as_unsupported());
4598 ASSERT_NE(nullptr, jdesc_output.description()
4599 ->contents()[1]
4600 .media_description()
4601 ->as_unsupported());
4602
4603 EXPECT_TRUE(jdesc_output.description()->contents()[0].rejected);
4604 EXPECT_TRUE(jdesc_output.description()->contents()[1].rejected);
4605
4606 EXPECT_EQ(jdesc_output.description()->contents()[0].name, "bogusmid");
4607 EXPECT_EQ(jdesc_output.description()->contents()[1].name, "somethingmid");
Philipp Hanckeefc55b02020-06-26 10:17:05 +02004608}
Philipp Hanckeb70c9532021-01-13 10:40:06 +01004609
4610TEST_F(WebRtcSdpTest, MediaTypeProtocolMismatch) {
4611 std::string sdp =
4612 "v=0\r\n"
4613 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4614 "s=-\r\n"
4615 "t=0 0\r\n";
4616
4617 ExpectParseFailure(std::string(sdp + "m=audio 9 UDP/DTLS/SCTP 120\r\n"),
4618 "m=audio");
4619 ExpectParseFailure(std::string(sdp + "m=video 9 UDP/DTLS/SCTP 120\r\n"),
4620 "m=video");
4621 ExpectParseFailure(std::string(sdp + "m=video 9 SOMETHING 120\r\n"),
4622 "m=video");
4623 ExpectParseFailure(std::string(sdp + "m=application 9 SOMETHING 120\r\n"),
4624 "m=application");
4625}
Philipp Hanckecd467b52021-01-29 09:29:47 +01004626
4627// Regression test for:
4628// https://bugs.chromium.org/p/chromium/issues/detail?id=1171965
4629TEST_F(WebRtcSdpTest, SctpPortInUnsupportedContent) {
4630 std::string sdp =
4631 "v=0\r\n"
4632 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4633 "s=-\r\n"
4634 "t=0 0\r\n"
4635 "m=o 1 DTLS/SCTP 5000\r\n"
4636 "a=sctp-port\r\n";
4637
4638 JsepSessionDescription jdesc_output(kDummyType);
4639 EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output));
4640}
Harald Alvestrand99bcf602021-03-03 07:44:39 +00004641
4642TEST_F(WebRtcSdpTest, IllegalMidCharacterValue) {
4643 std::string sdp = kSdpString;
4644 // [ is an illegal token value.
4645 Replace("a=mid:", "a=mid:[]", &sdp);
4646 ExpectParseFailure(std::string(sdp), "a=mid:[]");
4647}
Philipp Hancked58ac5a2021-11-25 08:57:54 +01004648
4649TEST_F(WebRtcSdpTest, MaxChannels) {
4650 std::string sdp =
4651 "v=0\r\n"
4652 "o=- 11 22 IN IP4 127.0.0.1\r\n"
4653 "s=-\r\n"
4654 "t=0 0\r\n"
4655 "m=audio 49232 RTP/AVP 108\r\n"
4656 "a=rtpmap:108 ISAC/16000/512\r\n";
4657
4658 ExpectParseFailure(sdp, "a=rtpmap:108 ISAC/16000/512");
4659}
Harald Alvestrand88b8dec2022-04-07 09:54:51 +00004660
4661// This tests parsing of SDP with unknown ssrc-specific attributes.
4662TEST_F(WebRtcSdpTest, ParseIgnoreUnknownSsrcSpecificAttribute) {
4663 std::string sdp = kSdpString;
4664 sdp += "a=ssrc:1 mslabel:something\r\n";
4665
4666 JsepSessionDescription output(kDummyType);
4667 SdpParseError error;
4668 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4669}