blob: 034e04e94a4f68086508425bf878c8197748eae7 [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
Harald Alvestrand4d7160e2019-04-12 07:01:29 +020014#include <algorithm>
Yves Gerey3e707812018-11-28 16:47:49 +010015#include <cstdint>
16#include <map>
kwibergd1fe2812016-04-27 06:47:29 -070017#include <memory>
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"
Yves Gerey3e707812018-11-28 16:47:49 +010025#include "api/array_view.h"
Steve Anton10542f22019-01-11 09:11:00 -080026#include "api/crypto_params.h"
27#include "api/jsep_session_description.h"
28#include "api/media_types.h"
29#include "api/rtp_parameters.h"
30#include "api/rtp_transceiver_interface.h"
Yves Gerey3e707812018-11-28 16:47:49 +010031#include "media/base/codec.h"
Steve Anton10542f22019-01-11 09:11:00 -080032#include "media/base/media_constants.h"
33#include "media/base/stream_params.h"
34#include "p2p/base/p2p_constants.h"
Yves Gerey665174f2018-06-19 15:03:05 +020035#include "p2p/base/port.h"
Steve Anton10542f22019-01-11 09:11:00 -080036#include "p2p/base/transport_description.h"
37#include "p2p/base/transport_info.h"
38#include "pc/media_session.h"
39#include "pc/session_description.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020040#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 09:11:00 -080041#include "rtc_base/message_digest.h"
42#include "rtc_base/socket_address.h"
43#include "rtc_base/ssl_fingerprint.h"
44#include "rtc_base/string_encode.h"
Steve Anton06817cd2018-12-18 15:55:30 -080045#include "test/gmock.h"
Yves Gerey3e707812018-11-28 16:47:49 +010046#include "test/gtest.h"
Patrik Höglund563934e2017-09-15 09:04:28 +020047
ossu7bb87ee2017-01-23 04:56:25 -080048#ifdef WEBRTC_ANDROID
Steve Anton10542f22019-01-11 09:11:00 -080049#include "pc/test/android_test_initializer.h"
ossu7bb87ee2017-01-23 04:56:25 -080050#endif
Steve Anton10542f22019-01-11 09:11:00 -080051#include "pc/webrtc_sdp.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000052
53using cricket::AudioCodec;
54using cricket::AudioContentDescription;
55using cricket::Candidate;
Steve Anton06817cd2018-12-18 15:55:30 -080056using cricket::ContentGroup;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057using cricket::ContentInfo;
58using cricket::CryptoParams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059using cricket::DataCodec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
61using cricket::ICE_CANDIDATE_COMPONENT_RTP;
62using cricket::kFecSsrcGroupSemantics;
63using cricket::LOCAL_PORT_TYPE;
Steve Anton5adfafd2017-12-20 16:34:00 -080064using cricket::MediaProtocolType;
Steve Anton06817cd2018-12-18 15:55:30 -080065using cricket::RELAY_PORT_TYPE;
Amit Hilbuchc57d5732018-12-11 15:30:11 -080066using cricket::RidDescription;
67using cricket::RidDirection;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020068using cricket::RtpDataContentDescription;
69using cricket::SctpDataContentDescription;
Steve Anton06817cd2018-12-18 15:55:30 -080070using cricket::SessionDescription;
Amit Hilbucha2012042018-12-03 11:35:05 -080071using cricket::SimulcastDescription;
72using cricket::SimulcastLayer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073using cricket::StreamParams;
74using cricket::STUN_PORT_TYPE;
75using cricket::TransportDescription;
76using cricket::TransportInfo;
77using cricket::VideoCodec;
78using cricket::VideoContentDescription;
Steve Anton06817cd2018-12-18 15:55:30 -080079using ::testing::ElementsAre;
80using ::testing::Field;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000081using webrtc::IceCandidateCollection;
82using webrtc::IceCandidateInterface;
83using webrtc::JsepIceCandidate;
84using webrtc::JsepSessionDescription;
isheriff6f8d6862016-05-26 11:24:55 -070085using webrtc::RtpExtension;
Steve Anton4e70a722017-11-28 14:57:10 -080086using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087using webrtc::SdpParseError;
Steve Antona3a92c22017-12-07 10:27:41 -080088using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000089using webrtc::SessionDescriptionInterface;
90
91typedef std::vector<AudioCodec> AudioCodecs;
92typedef std::vector<Candidate> Candidates;
93
Peter Boström0c4e06b2015-10-07 12:23:21 +020094static const uint32_t kDefaultSctpPort = 5000;
zstein4b2e0822017-02-17 19:48:38 -080095static const uint16_t kUnusualSctpPort = 9556;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000096static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020097static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 15:17:14 -080098static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 15:17:14 -0800100static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000101static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200102static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103static const char kCandidateFoundation1[] = "a0+B/1";
104static const char kCandidateFoundation2[] = "a0+B/2";
105static const char kCandidateFoundation3[] = "a0+B/3";
106static const char kCandidateFoundation4[] = "a0+B/4";
107static const char kAttributeCryptoVoice[] =
108 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
109 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
110 "dummy_session_params\r\n";
111static const char kAttributeCryptoVideo[] =
112 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
113 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
Yves Gerey665174f2018-06-19 15:03:05 +0200114static const char kFingerprint[] =
115 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116 "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 +0200117static const char kExtmapAllowMixed[] = "a=extmap-allow-mixed\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000118static const int kExtmapId = 1;
119static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
120static const char kExtmap[] =
121 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
122static const char kExtmapWithDirectionAndAttribute[] =
123 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
jbauch5869f502017-06-29 12:31:36 -0700124static const char kExtmapWithDirectionAndAttributeEncrypted[] =
125 "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt "
126 "http://example.com/082005/ext.htm#ttime a1 a2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000127
Peter Boström0c4e06b2015-10-07 12:23:21 +0200128static const uint8_t kIdentityDigest[] = {
129 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
130 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000131
lally@webrtc.org34807282015-02-24 20:19:39 +0000132static const char kDtlsSctp[] = "DTLS/SCTP";
133static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
134static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +0000135
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000136struct CodecParams {
137 int max_ptime;
138 int ptime;
139 int min_ptime;
140 int sprop_stereo;
141 int stereo;
142 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000143 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000144};
145
deadbeef9d3584c2016-02-16 17:54:10 -0800146// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
147// instead of "a=crypto", and have an explicit test for adding "a=crypto".
148// Currently it's the other way around.
149
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000150// Reference sdp string
151static const char kSdpFullString[] =
152 "v=0\r\n"
153 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
154 "s=-\r\n"
155 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800156 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000157 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
158 "c=IN IP4 74.125.127.126\r\n"
159 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
160 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
161 "generation 2\r\n"
162 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
163 "generation 2\r\n"
164 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
165 "generation 2\r\n"
166 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
167 "generation 2\r\n"
168 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
169 "raddr 192.168.1.5 rport 2346 "
170 "generation 2\r\n"
171 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
172 "raddr 192.168.1.5 rport 2348 "
173 "generation 2\r\n"
174 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
175 "a=mid:audio_content_name\r\n"
176 "a=sendrecv\r\n"
177 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800178 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000179 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
180 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
181 "dummy_session_params\r\n"
182 "a=rtpmap:111 opus/48000/2\r\n"
183 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000184 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185 "a=ssrc:1 cname:stream_1_cname\r\n"
186 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187 "m=video 3457 RTP/SAVPF 120\r\n"
188 "c=IN IP4 74.125.224.39\r\n"
189 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
190 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
191 "generation 2\r\n"
192 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
193 "generation 2\r\n"
194 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
195 "generation 2\r\n"
196 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
197 "generation 2\r\n"
198 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
199 "generation 2\r\n"
200 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
201 "generation 2\r\n"
202 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
203 "a=mid:video_content_name\r\n"
204 "a=sendrecv\r\n"
205 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
206 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
207 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800208 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000209 "a=ssrc:2 cname:stream_1_cname\r\n"
210 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 "a=ssrc:3 cname:stream_1_cname\r\n"
Philipp Hanckee3f257c2020-02-19 16:25:52 +0100212 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213
214// SDP reference string without the candidates.
215static const char kSdpString[] =
216 "v=0\r\n"
217 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
218 "s=-\r\n"
219 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800220 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000221 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000222 "c=IN IP4 0.0.0.0\r\n"
223 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000224 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
225 "a=mid:audio_content_name\r\n"
226 "a=sendrecv\r\n"
227 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800228 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000229 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
230 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
231 "dummy_session_params\r\n"
232 "a=rtpmap:111 opus/48000/2\r\n"
233 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000234 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000235 "a=ssrc:1 cname:stream_1_cname\r\n"
236 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000237 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000238 "c=IN IP4 0.0.0.0\r\n"
239 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000240 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
241 "a=mid:video_content_name\r\n"
242 "a=sendrecv\r\n"
243 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
244 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
245 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800246 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000247 "a=ssrc:2 cname:stream_1_cname\r\n"
248 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000249 "a=ssrc:3 cname:stream_1_cname\r\n"
Philipp Hanckee3f257c2020-02-19 16:25:52 +0100250 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000251
252static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000253 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000254 "c=IN IP4 0.0.0.0\r\n"
255 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000256 "a=ice-ufrag:ufrag_data\r\n"
257 "a=ice-pwd:pwd_data\r\n"
258 "a=mid:data_content_name\r\n"
259 "a=sendrecv\r\n"
260 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
261 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
262 "a=rtpmap:101 google-data/90000\r\n"
263 "a=ssrc:10 cname:data_channel_cname\r\n"
Philipp Hanckee3f257c2020-02-19 16:25:52 +0100264 "a=ssrc:10 msid:data_channel data_channeld0\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000265
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200266// draft-ietf-mmusic-sctp-sdp-03
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000267static const char kSdpSctpDataChannelString[] =
Guido Urdanetacecf87f2019-05-31 10:17:38 +0000268 "m=application 9 UDP/DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000269 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000270 "a=ice-ufrag:ufrag_data\r\n"
271 "a=ice-pwd:pwd_data\r\n"
272 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000273 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000274
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000275// draft-ietf-mmusic-sctp-sdp-12
Harald Alvestrand48cce4d2019-04-11 10:41:24 +0200276// Note - this is invalid per draft-ietf-mmusic-sctp-sdp-26,
277// since the separator after "sctp-port" needs to be a colon.
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000278static const char kSdpSctpDataChannelStringWithSctpPort[] =
Guido Urdanetacecf87f2019-05-31 10:17:38 +0000279 "m=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\n"
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000280 "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
Harald Alvestrand48cce4d2019-04-11 10:41:24 +0200286// draft-ietf-mmusic-sctp-sdp-26
lally69f57602015-10-08 10:15:04 -0700287static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
Guido Urdanetacecf87f2019-05-31 10:17:38 +0000288 "m=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\n"
lally69f57602015-10-08 10:15:04 -0700289 "a=sctp-port:5000\r\n"
290 "c=IN IP4 0.0.0.0\r\n"
291 "a=ice-ufrag:ufrag_data\r\n"
292 "a=ice-pwd:pwd_data\r\n"
293 "a=mid:data_content_name\r\n";
294
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000295static const char kSdpSctpDataChannelWithCandidatesString[] =
Guido Urdanetacecf87f2019-05-31 10:17:38 +0000296 "m=application 2345 UDP/DTLS/SCTP 5000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000297 "c=IN IP4 74.125.127.126\r\n"
298 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
299 "generation 2\r\n"
300 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
301 "generation 2\r\n"
302 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
303 "raddr 192.168.1.5 rport 2346 "
304 "generation 2\r\n"
305 "a=ice-ufrag:ufrag_data\r\n"
306 "a=ice-pwd:pwd_data\r\n"
307 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000308 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000309
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000310static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000311 "v=0\r\n"
312 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
313 "s=-\r\n"
314 "t=0 0\r\n"
315 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000316 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000317 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000318 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000319 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000320 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000321 "a=x-google-flag:conference\r\n";
322
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000323static const char kSdpSessionString[] =
324 "v=0\r\n"
325 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
326 "s=-\r\n"
327 "t=0 0\r\n"
328 "a=msid-semantic: WMS local_stream\r\n";
329
330static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000331 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000332 "c=IN IP4 0.0.0.0\r\n"
333 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000334 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
335 "a=mid:audio_content_name\r\n"
336 "a=sendrecv\r\n"
337 "a=rtpmap:111 opus/48000/2\r\n"
338 "a=ssrc:1 cname:stream_1_cname\r\n"
Philipp Hanckee3f257c2020-02-19 16:25:52 +0100339 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n";
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000340
341static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000342 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000343 "c=IN IP4 0.0.0.0\r\n"
344 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000345 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
346 "a=mid:video_content_name\r\n"
347 "a=sendrecv\r\n"
348 "a=rtpmap:120 VP8/90000\r\n"
349 "a=ssrc:2 cname:stream_1_cname\r\n"
Philipp Hanckee3f257c2020-02-19 16:25:52 +0100350 "a=ssrc:2 msid:local_stream video_track_id_1\r\n";
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000351
deadbeef25ed4352016-12-12 18:37:36 -0800352// Reference sdp string using bundle-only.
353static const char kBundleOnlySdpFullString[] =
354 "v=0\r\n"
355 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
356 "s=-\r\n"
357 "t=0 0\r\n"
358 "a=group:BUNDLE audio_content_name video_content_name\r\n"
359 "a=msid-semantic: WMS local_stream_1\r\n"
360 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
361 "c=IN IP4 74.125.127.126\r\n"
362 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
363 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
364 "generation 2\r\n"
365 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
366 "generation 2\r\n"
367 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
368 "generation 2\r\n"
369 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
370 "generation 2\r\n"
371 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
372 "raddr 192.168.1.5 rport 2346 "
373 "generation 2\r\n"
374 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
375 "raddr 192.168.1.5 rport 2348 "
376 "generation 2\r\n"
377 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
378 "a=mid:audio_content_name\r\n"
379 "a=sendrecv\r\n"
380 "a=rtcp-mux\r\n"
381 "a=rtcp-rsize\r\n"
382 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
383 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
384 "dummy_session_params\r\n"
385 "a=rtpmap:111 opus/48000/2\r\n"
386 "a=rtpmap:103 ISAC/16000\r\n"
387 "a=rtpmap:104 ISAC/32000\r\n"
388 "a=ssrc:1 cname:stream_1_cname\r\n"
389 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
deadbeef25ed4352016-12-12 18:37:36 -0800390 "m=video 0 RTP/SAVPF 120\r\n"
391 "c=IN IP4 0.0.0.0\r\n"
392 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
393 "a=bundle-only\r\n"
394 "a=mid:video_content_name\r\n"
395 "a=sendrecv\r\n"
396 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
397 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
398 "a=rtpmap:120 VP8/90000\r\n"
399 "a=ssrc-group:FEC 2 3\r\n"
400 "a=ssrc:2 cname:stream_1_cname\r\n"
401 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
deadbeef25ed4352016-12-12 18:37:36 -0800402 "a=ssrc:3 cname:stream_1_cname\r\n"
Philipp Hanckee3f257c2020-02-19 16:25:52 +0100403 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n";
deadbeef25ed4352016-12-12 18:37:36 -0800404
deadbeef9d3584c2016-02-16 17:54:10 -0800405// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
406// tracks.
407static const char kPlanBSdpFullString[] =
408 "v=0\r\n"
409 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
410 "s=-\r\n"
411 "t=0 0\r\n"
412 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
413 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
414 "c=IN IP4 74.125.127.126\r\n"
415 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
416 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
417 "generation 2\r\n"
418 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
419 "generation 2\r\n"
420 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
421 "generation 2\r\n"
422 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
423 "generation 2\r\n"
424 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
425 "raddr 192.168.1.5 rport 2346 "
426 "generation 2\r\n"
427 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
428 "raddr 192.168.1.5 rport 2348 "
429 "generation 2\r\n"
430 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
431 "a=mid:audio_content_name\r\n"
432 "a=sendrecv\r\n"
433 "a=rtcp-mux\r\n"
434 "a=rtcp-rsize\r\n"
435 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
436 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
437 "dummy_session_params\r\n"
438 "a=rtpmap:111 opus/48000/2\r\n"
439 "a=rtpmap:103 ISAC/16000\r\n"
440 "a=rtpmap:104 ISAC/32000\r\n"
441 "a=ssrc:1 cname:stream_1_cname\r\n"
442 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800443 "a=ssrc:4 cname:stream_2_cname\r\n"
444 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800445 "m=video 3457 RTP/SAVPF 120\r\n"
446 "c=IN IP4 74.125.224.39\r\n"
447 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
448 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
449 "generation 2\r\n"
450 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
451 "generation 2\r\n"
452 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
453 "generation 2\r\n"
454 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
455 "generation 2\r\n"
456 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
457 "generation 2\r\n"
458 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
459 "generation 2\r\n"
460 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
461 "a=mid:video_content_name\r\n"
462 "a=sendrecv\r\n"
463 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
464 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
465 "a=rtpmap:120 VP8/90000\r\n"
466 "a=ssrc-group:FEC 2 3\r\n"
467 "a=ssrc:2 cname:stream_1_cname\r\n"
468 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800469 "a=ssrc:3 cname:stream_1_cname\r\n"
470 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800471 "a=ssrc:5 cname:stream_2_cname\r\n"
472 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800473 "a=ssrc:6 cname:stream_2_cname\r\n"
Philipp Hanckee3f257c2020-02-19 16:25:52 +0100474 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n";
deadbeef9d3584c2016-02-16 17:54:10 -0800475
476// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
477// tracks.
478static const char kUnifiedPlanSdpFullString[] =
479 "v=0\r\n"
480 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
481 "s=-\r\n"
482 "t=0 0\r\n"
483 "a=msid-semantic: WMS local_stream_1\r\n"
484 // Audio track 1, stream 1 (with candidates).
485 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
486 "c=IN IP4 74.125.127.126\r\n"
487 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
488 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
489 "generation 2\r\n"
490 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
491 "generation 2\r\n"
492 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
493 "generation 2\r\n"
494 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
495 "generation 2\r\n"
496 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
497 "raddr 192.168.1.5 rport 2346 "
498 "generation 2\r\n"
499 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
500 "raddr 192.168.1.5 rport 2348 "
501 "generation 2\r\n"
502 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
503 "a=mid:audio_content_name\r\n"
504 "a=msid:local_stream_1 audio_track_id_1\r\n"
505 "a=sendrecv\r\n"
506 "a=rtcp-mux\r\n"
507 "a=rtcp-rsize\r\n"
508 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
509 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
510 "dummy_session_params\r\n"
511 "a=rtpmap:111 opus/48000/2\r\n"
512 "a=rtpmap:103 ISAC/16000\r\n"
513 "a=rtpmap:104 ISAC/32000\r\n"
514 "a=ssrc:1 cname:stream_1_cname\r\n"
515 // Video track 1, stream 1 (with candidates).
516 "m=video 3457 RTP/SAVPF 120\r\n"
517 "c=IN IP4 74.125.224.39\r\n"
518 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
519 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
520 "generation 2\r\n"
521 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
522 "generation 2\r\n"
523 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
524 "generation 2\r\n"
525 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
526 "generation 2\r\n"
527 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
528 "generation 2\r\n"
529 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
530 "generation 2\r\n"
531 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
532 "a=mid:video_content_name\r\n"
533 "a=msid:local_stream_1 video_track_id_1\r\n"
534 "a=sendrecv\r\n"
535 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
536 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
537 "a=rtpmap:120 VP8/90000\r\n"
538 "a=ssrc-group:FEC 2 3\r\n"
539 "a=ssrc:2 cname:stream_1_cname\r\n"
540 "a=ssrc:3 cname:stream_1_cname\r\n"
541 // Audio track 2, stream 2.
542 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
543 "c=IN IP4 0.0.0.0\r\n"
544 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
545 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
546 "a=mid:audio_content_name_2\r\n"
547 "a=msid:local_stream_2 audio_track_id_2\r\n"
548 "a=sendrecv\r\n"
549 "a=rtcp-mux\r\n"
550 "a=rtcp-rsize\r\n"
551 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
552 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
553 "dummy_session_params\r\n"
554 "a=rtpmap:111 opus/48000/2\r\n"
555 "a=rtpmap:103 ISAC/16000\r\n"
556 "a=rtpmap:104 ISAC/32000\r\n"
557 "a=ssrc:4 cname:stream_2_cname\r\n"
558 // Video track 2, stream 2.
559 "m=video 9 RTP/SAVPF 120\r\n"
560 "c=IN IP4 0.0.0.0\r\n"
561 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
562 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
563 "a=mid:video_content_name_2\r\n"
564 "a=msid:local_stream_2 video_track_id_2\r\n"
565 "a=sendrecv\r\n"
566 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
567 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
568 "a=rtpmap:120 VP8/90000\r\n"
569 "a=ssrc:5 cname:stream_2_cname\r\n"
570 // Video track 3, stream 2.
571 "m=video 9 RTP/SAVPF 120\r\n"
572 "c=IN IP4 0.0.0.0\r\n"
573 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
574 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
575 "a=mid:video_content_name_3\r\n"
576 "a=msid:local_stream_2 video_track_id_3\r\n"
577 "a=sendrecv\r\n"
578 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
579 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
580 "a=rtpmap:120 VP8/90000\r\n"
581 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000582
Seth Hampson5b4f0752018-04-02 16:31:36 -0700583// Unified Plan SDP reference string:
584// - audio track 1 has 1 a=msid lines
585// - audio track 2 has 2 a=msid lines
586// - audio track 3 has 1 a=msid line with the special "-" marker signifying that
587// there are 0 media stream ids.
588// This Unified Plan SDP represents a SDP that signals the msid using both
589// a=msid and a=ssrc msid semantics.
590static const char kUnifiedPlanSdpFullStringWithSpecialMsid[] =
591 "v=0\r\n"
592 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
593 "s=-\r\n"
594 "t=0 0\r\n"
595 "a=msid-semantic: WMS local_stream_1\r\n"
596 // Audio track 1, with 1 stream id.
597 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
598 "c=IN IP4 74.125.127.126\r\n"
599 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
600 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
601 "generation 2\r\n"
602 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
603 "generation 2\r\n"
604 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
605 "generation 2\r\n"
606 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
607 "generation 2\r\n"
608 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
609 "raddr 192.168.1.5 rport 2346 "
610 "generation 2\r\n"
611 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
612 "raddr 192.168.1.5 rport 2348 "
613 "generation 2\r\n"
614 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
615 "a=mid:audio_content_name\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700616 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700617 "a=msid:local_stream_1 audio_track_id_1\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700618 "a=rtcp-mux\r\n"
619 "a=rtcp-rsize\r\n"
620 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
621 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
622 "dummy_session_params\r\n"
623 "a=rtpmap:111 opus/48000/2\r\n"
624 "a=rtpmap:103 ISAC/16000\r\n"
625 "a=rtpmap:104 ISAC/32000\r\n"
626 "a=ssrc:1 cname:stream_1_cname\r\n"
627 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700628 // Audio track 2, with two stream ids.
629 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
630 "c=IN IP4 0.0.0.0\r\n"
631 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
632 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
633 "a=mid:audio_content_name_2\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700634 "a=sendrecv\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700635 "a=msid:local_stream_1 audio_track_id_2\r\n"
636 "a=msid:local_stream_2 audio_track_id_2\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700637 "a=rtcp-mux\r\n"
638 "a=rtcp-rsize\r\n"
639 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
640 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
641 "dummy_session_params\r\n"
642 "a=rtpmap:111 opus/48000/2\r\n"
643 "a=rtpmap:103 ISAC/16000\r\n"
644 "a=rtpmap:104 ISAC/32000\r\n"
645 "a=ssrc:4 cname:stream_1_cname\r\n"
646 // The support for Plan B msid signaling only includes the
647 // first media stream id "local_stream_1."
648 "a=ssrc:4 msid:local_stream_1 audio_track_id_2\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700649 // Audio track 3, with no stream ids.
650 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
651 "c=IN IP4 0.0.0.0\r\n"
652 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
653 "a=ice-ufrag:ufrag_voice_3\r\na=ice-pwd:pwd_voice_3\r\n"
654 "a=mid:audio_content_name_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700655 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700656 "a=msid:- audio_track_id_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700657 "a=rtcp-mux\r\n"
658 "a=rtcp-rsize\r\n"
659 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
660 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
661 "dummy_session_params\r\n"
662 "a=rtpmap:111 opus/48000/2\r\n"
663 "a=rtpmap:103 ISAC/16000\r\n"
664 "a=rtpmap:104 ISAC/32000\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700665 "a=ssrc:7 cname:stream_2_cname\r\n"
Philipp Hanckee3f257c2020-02-19 16:25:52 +0100666 "a=ssrc:7 msid:- audio_track_id_3\r\n";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700667
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800668// SDP string for unified plan without SSRCs
669static const char kUnifiedPlanSdpFullStringNoSsrc[] =
670 "v=0\r\n"
671 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
672 "s=-\r\n"
673 "t=0 0\r\n"
674 "a=msid-semantic: WMS local_stream_1\r\n"
675 // Audio track 1, stream 1 (with candidates).
676 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
677 "c=IN IP4 74.125.127.126\r\n"
678 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
679 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
680 "generation 2\r\n"
681 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
682 "generation 2\r\n"
683 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
684 "generation 2\r\n"
685 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
686 "generation 2\r\n"
687 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
688 "raddr 192.168.1.5 rport 2346 "
689 "generation 2\r\n"
690 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
691 "raddr 192.168.1.5 rport 2348 "
692 "generation 2\r\n"
693 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
694 "a=mid:audio_content_name\r\n"
695 "a=msid:local_stream_1 audio_track_id_1\r\n"
696 "a=sendrecv\r\n"
697 "a=rtcp-mux\r\n"
698 "a=rtcp-rsize\r\n"
699 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
700 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
701 "dummy_session_params\r\n"
702 "a=rtpmap:111 opus/48000/2\r\n"
703 "a=rtpmap:103 ISAC/16000\r\n"
704 "a=rtpmap:104 ISAC/32000\r\n"
705 // Video track 1, stream 1 (with candidates).
706 "m=video 3457 RTP/SAVPF 120\r\n"
707 "c=IN IP4 74.125.224.39\r\n"
708 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
709 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
710 "generation 2\r\n"
711 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
712 "generation 2\r\n"
713 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
714 "generation 2\r\n"
715 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
716 "generation 2\r\n"
717 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
718 "generation 2\r\n"
719 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
720 "generation 2\r\n"
721 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
722 "a=mid:video_content_name\r\n"
723 "a=msid:local_stream_1 video_track_id_1\r\n"
724 "a=sendrecv\r\n"
725 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
726 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
727 "a=rtpmap:120 VP8/90000\r\n"
728 // Audio track 2, stream 2.
729 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
730 "c=IN IP4 0.0.0.0\r\n"
731 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
732 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
733 "a=mid:audio_content_name_2\r\n"
734 "a=msid:local_stream_2 audio_track_id_2\r\n"
735 "a=sendrecv\r\n"
736 "a=rtcp-mux\r\n"
737 "a=rtcp-rsize\r\n"
738 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
739 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
740 "dummy_session_params\r\n"
741 "a=rtpmap:111 opus/48000/2\r\n"
742 "a=rtpmap:103 ISAC/16000\r\n"
743 "a=rtpmap:104 ISAC/32000\r\n"
744 // Video track 2, stream 2.
745 "m=video 9 RTP/SAVPF 120\r\n"
746 "c=IN IP4 0.0.0.0\r\n"
747 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
748 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
749 "a=mid:video_content_name_2\r\n"
750 "a=msid:local_stream_2 video_track_id_2\r\n"
751 "a=sendrecv\r\n"
752 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
753 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
754 "a=rtpmap:120 VP8/90000\r\n"
755 // Video track 3, stream 2.
756 "m=video 9 RTP/SAVPF 120\r\n"
757 "c=IN IP4 0.0.0.0\r\n"
758 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
759 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
760 "a=mid:video_content_name_3\r\n"
761 "a=msid:local_stream_2 video_track_id_3\r\n"
762 "a=sendrecv\r\n"
763 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
764 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
765 "a=rtpmap:120 VP8/90000\r\n";
766
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000767// One candidate reference string as per W3c spec.
768// candidate:<blah> not a=candidate:<blah>CRLF
769static const char kRawCandidate[] =
770 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
771// One candidate reference string.
772static const char kSdpOneCandidate[] =
773 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
774 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000775
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000776static const char kSdpTcpActiveCandidate[] =
777 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
778 "tcptype active generation 2";
779static const char kSdpTcpPassiveCandidate[] =
780 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
781 "tcptype passive generation 2";
782static const char kSdpTcpSOCandidate[] =
783 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
784 "tcptype so generation 2";
785static const char kSdpTcpInvalidCandidate[] =
786 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
787 "tcptype invalid generation 2";
788
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000789// One candidate reference string with IPV6 address.
790static const char kRawIPV6Candidate[] =
791 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 12:04:36 -0700792 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000793
794// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800795static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000796 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800797 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000798
Zach Steinb336c272018-08-09 01:16:13 -0700799static const char kRawHostnameCandidate[] =
800 "candidate:a0+B/1 1 udp 2130706432 a.test 1234 typ host generation 2";
801
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802// Session id and version
803static const char kSessionId[] = "18446744069414584320";
804static const char kSessionVersion[] = "18446462598732840960";
805
deadbeef9d3584c2016-02-16 17:54:10 -0800806// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000807static const char kIceOption1[] = "iceoption1";
808static const char kIceOption2[] = "iceoption2";
809static const char kIceOption3[] = "iceoption3";
810
deadbeef9d3584c2016-02-16 17:54:10 -0800811// ICE ufrags/passwords.
812static const char kUfragVoice[] = "ufrag_voice";
813static const char kPwdVoice[] = "pwd_voice";
814static const char kUfragVideo[] = "ufrag_video";
815static const char kPwdVideo[] = "pwd_video";
816static const char kUfragData[] = "ufrag_data";
817static const char kPwdData[] = "pwd_data";
818
819// Extra ufrags/passwords for extra unified plan m= sections.
820static const char kUfragVoice2[] = "ufrag_voice_2";
821static const char kPwdVoice2[] = "pwd_voice_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700822static const char kUfragVoice3[] = "ufrag_voice_3";
823static const char kPwdVoice3[] = "pwd_voice_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800824static const char kUfragVideo2[] = "ufrag_video_2";
825static const char kPwdVideo2[] = "pwd_video_2";
826static const char kUfragVideo3[] = "ufrag_video_3";
827static const char kPwdVideo3[] = "pwd_video_3";
828
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000829// Content name
830static const char kAudioContentName[] = "audio_content_name";
831static const char kVideoContentName[] = "video_content_name";
832static const char kDataContentName[] = "data_content_name";
833
deadbeef9d3584c2016-02-16 17:54:10 -0800834// Extra content names for extra unified plan m= sections.
835static const char kAudioContentName2[] = "audio_content_name_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700836static const char kAudioContentName3[] = "audio_content_name_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800837static const char kVideoContentName2[] = "video_content_name_2";
838static const char kVideoContentName3[] = "video_content_name_3";
839
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840// MediaStream 1
Seth Hampson845e8782018-03-02 11:34:10 -0800841static const char kStreamId1[] = "local_stream_1";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842static const char kStream1Cname[] = "stream_1_cname";
843static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200844static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000845static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800846static const uint32_t kVideoTrack1Ssrc1 = 2;
847static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000848
849// MediaStream 2
Seth Hampson845e8782018-03-02 11:34:10 -0800850static const char kStreamId2[] = "local_stream_2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000851static const char kStream2Cname[] = "stream_2_cname";
852static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200853static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800854static const char kVideoTrackId2[] = "video_track_id_2";
855static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000856static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800857static const uint32_t kVideoTrack3Ssrc = 6;
Seth Hampson5b4f0752018-04-02 16:31:36 -0700858static const char kAudioTrackId3[] = "audio_track_id_3";
859static const uint32_t kAudioTrack3Ssrc = 7;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000860
861// DataChannel
862static const char kDataChannelLabel[] = "data_channel";
863static const char kDataChannelMsid[] = "data_channeld0";
864static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200865static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000866
867// Candidate
868static const char kDummyMid[] = "dummy_mid";
869static const int kDummyIndex = 123;
870
871// Misc
Steve Antona3a92c22017-12-07 10:27:41 -0800872static SdpType kDummyType = SdpType::kOffer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000873
874// Helper functions
875
876static bool SdpDeserialize(const std::string& message,
877 JsepSessionDescription* jdesc) {
878 return webrtc::SdpDeserialize(message, jdesc, NULL);
879}
880
881static bool SdpDeserializeCandidate(const std::string& message,
882 JsepIceCandidate* candidate) {
883 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
884}
885
886// Add some extra |newlines| to the |message| after |line|.
887static void InjectAfter(const std::string& line,
888 const std::string& newlines,
889 std::string* message) {
Steve Anton1c9c9fc2019-02-14 15:13:09 -0800890 absl::StrReplaceAll({{line, line + newlines}}, message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000891}
892
893static void Replace(const std::string& line,
894 const std::string& newlines,
895 std::string* message) {
Steve Anton1c9c9fc2019-02-14 15:13:09 -0800896 absl::StrReplaceAll({{line, newlines}}, message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000897}
898
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000899// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
900// message.
901static void ExpectParseFailure(const std::string& bad_sdp,
902 const std::string& bad_part) {
Steve Antona3a92c22017-12-07 10:27:41 -0800903 JsepSessionDescription desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000904 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000905 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000906 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000907 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
908}
909
910// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
911static void ExpectParseFailure(const char* good_part, const char* bad_part) {
912 std::string bad_sdp = kSdpFullString;
913 Replace(good_part, bad_part, &bad_sdp);
914 ExpectParseFailure(bad_sdp, bad_part);
915}
916
917// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
918static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
919 const std::string& newlines,
920 const std::string& bad_part) {
921 std::string bad_sdp = kSdpFullString;
922 InjectAfter(injectpoint, newlines, &bad_sdp);
923 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000924}
925
Steve Anton4e70a722017-11-28 14:57:10 -0800926static void ReplaceDirection(RtpTransceiverDirection direction,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000927 std::string* message) {
928 std::string new_direction;
929 switch (direction) {
Steve Anton4e70a722017-11-28 14:57:10 -0800930 case RtpTransceiverDirection::kInactive:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000931 new_direction = "a=inactive";
932 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800933 case RtpTransceiverDirection::kSendOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000934 new_direction = "a=sendonly";
935 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800936 case RtpTransceiverDirection::kRecvOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000937 new_direction = "a=recvonly";
938 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800939 case RtpTransceiverDirection::kSendRecv:
Markus Handell45c104b2020-03-11 10:51:13 +0100940 new_direction = "a=sendrecv";
941 break;
942 case RtpTransceiverDirection::kStopped:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000943 default:
Markus Handell45c104b2020-03-11 10:51:13 +0100944 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945 new_direction = "a=sendrecv";
946 break;
947 }
948 Replace("a=sendrecv", new_direction, message);
949}
950
Yves Gerey665174f2018-06-19 15:03:05 +0200951static void ReplaceRejected(bool audio_rejected,
952 bool video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000953 std::string* message) {
954 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800955 Replace("m=audio 9", "m=audio 0", message);
956 Replace(kAttributeIceUfragVoice, "", message);
957 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000958 }
959 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800960 Replace("m=video 9", "m=video 0", message);
961 Replace(kAttributeIceUfragVideo, "", message);
962 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000963 }
964}
965
966// WebRtcSdpTest
967
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200968class WebRtcSdpTest : public ::testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969 public:
Steve Antona3a92c22017-12-07 10:27:41 -0800970 WebRtcSdpTest() : jdesc_(kDummyType) {
phoglund37ebcf02016-01-08 05:04:57 -0800971#ifdef WEBRTC_ANDROID
972 webrtc::InitializeAndroidObjects();
973#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000974 // AudioContentDescription
975 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -0800976 StreamParams audio_stream;
977 audio_stream.id = kAudioTrackId1;
978 audio_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -0800979 audio_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -0800980 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
981 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 11:04:53 -0700982 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
983 audio_desc_->set_connection_address(audio_addr);
Harald Alvestrand1716d392019-06-03 20:35:45 +0200984 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
985 absl::WrapUnique(audio_desc_));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000986
987 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -0800988 video_desc_ = CreateVideoContentDescription();
989 StreamParams video_stream;
990 video_stream.id = kVideoTrackId1;
991 video_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -0800992 video_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -0800993 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
994 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
995 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
996 video_stream.ssrc_groups.push_back(ssrc_group);
997 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 11:04:53 -0700998 rtc::SocketAddress video_addr("74.125.224.39", 3457);
999 video_desc_->set_connection_address(video_addr);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001000 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp,
1001 absl::WrapUnique(video_desc_));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001002
1003 // TransportInfo
Steve Anton06817cd2018-12-18 15:55:30 -08001004 desc_.AddTransportInfo(TransportInfo(
1005 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice)));
1006 desc_.AddTransportInfo(TransportInfo(
1007 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001008
1009 // v4 host
1010 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001011 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001012 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001013 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1014 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001015 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001016 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001017 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1018 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001019 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001020 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001021 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1022 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001023 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001024 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001025 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1026 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001027
1028 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001029 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001030 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "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 candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "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 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001040 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1041 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001042 cricket::LOCAL_PORT_TYPE,
1043 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001044 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001045 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1046 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001047 cricket::LOCAL_PORT_TYPE,
1048 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001049
1050 // stun
1051 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001052 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
1053 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001054 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1055 address_stun, kCandidatePriority, "", "",
1056 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001057 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001058 candidate9.set_related_address(rel_address_stun);
1059
1060 address_stun.SetPort(port_stun++);
1061 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001062 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1063 address_stun, kCandidatePriority, "", "",
1064 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001065 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001066 candidate10.set_related_address(rel_address_stun);
1067
1068 // relay
1069 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001070 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001071 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1072 address_relay, kCandidatePriority, "", "",
1073 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001074 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001075 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001076 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1077 address_relay, kCandidatePriority, "", "",
1078 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001079 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001080
1081 // voice
1082 candidates_.push_back(candidate1);
1083 candidates_.push_back(candidate2);
1084 candidates_.push_back(candidate5);
1085 candidates_.push_back(candidate6);
1086 candidates_.push_back(candidate9);
1087 candidates_.push_back(candidate10);
1088
1089 // video
1090 candidates_.push_back(candidate3);
1091 candidates_.push_back(candidate4);
1092 candidates_.push_back(candidate7);
1093 candidates_.push_back(candidate8);
1094 candidates_.push_back(candidate11);
1095 candidates_.push_back(candidate12);
1096
Yves Gerey665174f2018-06-19 15:03:05 +02001097 jcandidate_.reset(
1098 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001099
1100 // Set up JsepSessionDescription.
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001101 jdesc_.Initialize(desc_.Clone(), kSessionId, kSessionVersion);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001102 std::string mline_id;
1103 int mline_index = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001104 for (size_t i = 0; i < candidates_.size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001105 // In this test, the audio m line index will be 0, and the video m line
1106 // will be 1.
1107 bool is_video = (i > 5);
1108 mline_id = is_video ? "video_content_name" : "audio_content_name";
1109 mline_index = is_video ? 1 : 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001110 JsepIceCandidate jice(mline_id, mline_index, candidates_.at(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001111 jdesc_.AddCandidate(&jice);
1112 }
1113 }
1114
Seth Hampson5b4f0752018-04-02 16:31:36 -07001115 void RemoveVideoCandidates() {
deadbeef25ed4352016-12-12 18:37:36 -08001116 const IceCandidateCollection* video_candidates_collection =
1117 jdesc_.candidates(1);
1118 ASSERT_NE(nullptr, video_candidates_collection);
1119 std::vector<cricket::Candidate> video_candidates;
1120 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1121 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1122 c.set_transport_name("video_content_name");
1123 video_candidates.push_back(c);
1124 }
1125 jdesc_.RemoveCandidates(video_candidates);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001126 }
1127
1128 // Turns the existing reference description into a description using
1129 // a=bundle-only. This means no transport attributes and a 0 port value on
1130 // the m= sections not associated with the BUNDLE-tag.
1131 void MakeBundleOnlyDescription() {
1132 RemoveVideoCandidates();
deadbeef25ed4352016-12-12 18:37:36 -08001133
1134 // And the rest of the transport attributes.
1135 desc_.transport_infos()[1].description.ice_ufrag.clear();
1136 desc_.transport_infos()[1].description.ice_pwd.clear();
1137 desc_.transport_infos()[1].description.connection_role =
1138 cricket::CONNECTIONROLE_NONE;
1139
1140 // Set bundle-only flag.
1141 desc_.contents()[1].bundle_only = true;
1142
1143 // Add BUNDLE group.
1144 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1145 group.AddContentName(kAudioContentName);
1146 group.AddContentName(kVideoContentName);
1147 desc_.AddGroup(group);
1148
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001149 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef25ed4352016-12-12 18:37:36 -08001150 jdesc_.session_version()));
1151 }
1152
deadbeef9d3584c2016-02-16 17:54:10 -08001153 // Turns the existing reference description into a plan B description,
1154 // with 2 audio tracks and 3 video tracks.
1155 void MakePlanBDescription() {
Harald Alvestrandb97d2fe2020-02-28 11:54:40 +01001156 audio_desc_ = new AudioContentDescription(*audio_desc_);
1157 video_desc_ = new VideoContentDescription(*video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001158
1159 StreamParams audio_track_2;
1160 audio_track_2.id = kAudioTrackId2;
1161 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001162 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001163 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1164 audio_desc_->AddStream(audio_track_2);
1165
1166 StreamParams video_track_2;
1167 video_track_2.id = kVideoTrackId2;
1168 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001169 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001170 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1171 video_desc_->AddStream(video_track_2);
1172
1173 StreamParams video_track_3;
1174 video_track_3.id = kVideoTrackId3;
1175 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001176 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001177 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1178 video_desc_->AddStream(video_track_3);
1179
1180 desc_.RemoveContentByName(kAudioContentName);
1181 desc_.RemoveContentByName(kVideoContentName);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001182 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1183 absl::WrapUnique(audio_desc_));
1184 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp,
1185 absl::WrapUnique(video_desc_));
deadbeef9d3584c2016-02-16 17:54:10 -08001186
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001187 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef9d3584c2016-02-16 17:54:10 -08001188 jdesc_.session_version()));
1189 }
1190
1191 // Turns the existing reference description into a unified plan description,
1192 // with 2 audio tracks and 3 video tracks.
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001193 void MakeUnifiedPlanDescription(bool use_ssrcs = true) {
deadbeef9d3584c2016-02-16 17:54:10 -08001194 // Audio track 2.
1195 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1196 StreamParams audio_track_2;
1197 audio_track_2.id = kAudioTrackId2;
Seth Hampson845e8782018-03-02 11:34:10 -08001198 audio_track_2.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001199 if (use_ssrcs) {
1200 audio_track_2.cname = kStream2Cname;
1201 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1202 }
deadbeef9d3584c2016-02-16 17:54:10 -08001203 audio_desc_2->AddStream(audio_track_2);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001204 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp,
1205 absl::WrapUnique(audio_desc_2));
Steve Anton06817cd2018-12-18 15:55:30 -08001206 desc_.AddTransportInfo(TransportInfo(
1207 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2)));
deadbeef9d3584c2016-02-16 17:54:10 -08001208 // Video track 2, in stream 2.
1209 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1210 StreamParams video_track_2;
1211 video_track_2.id = kVideoTrackId2;
Seth Hampson845e8782018-03-02 11:34:10 -08001212 video_track_2.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001213 if (use_ssrcs) {
1214 video_track_2.cname = kStream2Cname;
1215 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1216 }
deadbeef9d3584c2016-02-16 17:54:10 -08001217 video_desc_2->AddStream(video_track_2);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001218 desc_.AddContent(kVideoContentName2, MediaProtocolType::kRtp,
1219 absl::WrapUnique(video_desc_2));
Steve Anton06817cd2018-12-18 15:55:30 -08001220 desc_.AddTransportInfo(TransportInfo(
1221 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2)));
deadbeef9d3584c2016-02-16 17:54:10 -08001222
1223 // Video track 3, in stream 2.
1224 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1225 StreamParams video_track_3;
1226 video_track_3.id = kVideoTrackId3;
Seth Hampson845e8782018-03-02 11:34:10 -08001227 video_track_3.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001228 if (use_ssrcs) {
1229 video_track_3.cname = kStream2Cname;
1230 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1231 }
deadbeef9d3584c2016-02-16 17:54:10 -08001232 video_desc_3->AddStream(video_track_3);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001233 desc_.AddContent(kVideoContentName3, MediaProtocolType::kRtp,
1234 absl::WrapUnique(video_desc_3));
Steve Anton06817cd2018-12-18 15:55:30 -08001235 desc_.AddTransportInfo(TransportInfo(
1236 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3)));
Steve Antone831b8c2018-02-01 12:22:16 -08001237 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
deadbeef9d3584c2016-02-16 17:54:10 -08001238
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001239 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef9d3584c2016-02-16 17:54:10 -08001240 jdesc_.session_version()));
1241 }
1242
1243 // Creates an audio content description with no streams, and some default
1244 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001245 AudioContentDescription* CreateAudioContentDescription() {
1246 AudioContentDescription* audio = new AudioContentDescription();
1247 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -08001248 audio->set_rtcp_reduced_size(true);
Yves Gerey665174f2018-06-19 15:03:05 +02001249 audio->AddCrypto(CryptoParams(
1250 1, "AES_CM_128_HMAC_SHA1_32",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001251 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1252 "dummy_session_params"));
1253 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef67cf2c12016-04-13 10:07:16 -07001254 AudioCodec opus(111, "opus", 48000, 0, 2);
deadbeef9d3584c2016-02-16 17:54:10 -08001255 audio->AddCodec(opus);
ossue1405ad2017-01-23 08:55:48 -08001256 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1257 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001258 return audio;
1259 }
1260
Seth Hampson5b4f0752018-04-02 16:31:36 -07001261 // Turns the existing reference description into a unified plan description,
1262 // with 3 audio MediaContentDescriptions with special StreamParams that
1263 // contain 0 or multiple stream ids: - audio track 1 has 1 media stream id -
1264 // audio track 2 has 2 media stream ids - audio track 3 has 0 media stream ids
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001265 void MakeUnifiedPlanDescriptionMultipleStreamIds(const int msid_signaling) {
Seth Hampson5b4f0752018-04-02 16:31:36 -07001266 desc_.RemoveContentByName(kVideoContentName);
1267 desc_.RemoveTransportInfoByName(kVideoContentName);
1268 RemoveVideoCandidates();
1269
1270 // Audio track 2 has 2 media stream ids.
1271 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1272 StreamParams audio_track_2;
1273 audio_track_2.id = kAudioTrackId2;
1274 audio_track_2.cname = kStream1Cname;
1275 audio_track_2.set_stream_ids({kStreamId1, kStreamId2});
1276 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1277 audio_desc_2->AddStream(audio_track_2);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001278 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp,
1279 absl::WrapUnique(audio_desc_2));
Steve Anton06817cd2018-12-18 15:55:30 -08001280 desc_.AddTransportInfo(TransportInfo(
1281 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2)));
Seth Hampson5b4f0752018-04-02 16:31:36 -07001282
1283 // Audio track 3 has no stream ids.
1284 AudioContentDescription* audio_desc_3 = CreateAudioContentDescription();
1285 StreamParams audio_track_3;
1286 audio_track_3.id = kAudioTrackId3;
1287 audio_track_3.cname = kStream2Cname;
1288 audio_track_3.set_stream_ids({});
1289 audio_track_3.ssrcs.push_back(kAudioTrack3Ssrc);
1290 audio_desc_3->AddStream(audio_track_3);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001291 desc_.AddContent(kAudioContentName3, MediaProtocolType::kRtp,
1292 absl::WrapUnique(audio_desc_3));
Steve Anton06817cd2018-12-18 15:55:30 -08001293 desc_.AddTransportInfo(TransportInfo(
1294 kAudioContentName3, TransportDescription(kUfragVoice3, kPwdVoice3)));
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001295 desc_.set_msid_signaling(msid_signaling);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001296 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
Seth Hampson5b4f0752018-04-02 16:31:36 -07001297 jdesc_.session_version()));
1298 }
1299
Seth Hampson5897a6e2018-04-03 11:16:33 -07001300 // Turns the existing reference description into a unified plan description
1301 // with one audio MediaContentDescription that contains one StreamParams with
1302 // 0 ssrcs.
1303 void MakeUnifiedPlanDescriptionNoSsrcSignaling() {
1304 desc_.RemoveContentByName(kVideoContentName);
1305 desc_.RemoveContentByName(kAudioContentName);
1306 desc_.RemoveTransportInfoByName(kVideoContentName);
1307 RemoveVideoCandidates();
1308
1309 AudioContentDescription* audio_desc = CreateAudioContentDescription();
1310 StreamParams audio_track;
1311 audio_track.id = kAudioTrackId1;
1312 audio_track.set_stream_ids({kStreamId1});
1313 audio_desc->AddStream(audio_track);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001314 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1315 absl::WrapUnique(audio_desc));
Seth Hampson5897a6e2018-04-03 11:16:33 -07001316
1317 // Enable signaling a=msid lines.
1318 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001319 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
Seth Hampson5897a6e2018-04-03 11:16:33 -07001320 jdesc_.session_version()));
1321 }
1322
deadbeef9d3584c2016-02-16 17:54:10 -08001323 // Creates a video content description with no streams, and some default
1324 // configuration.
1325 VideoContentDescription* CreateVideoContentDescription() {
1326 VideoContentDescription* video = new VideoContentDescription();
1327 video->AddCrypto(CryptoParams(
1328 1, "AES_CM_128_HMAC_SHA1_80",
1329 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1330 video->set_protocol(cricket::kMediaProtocolSavpf);
1331 video->AddCodec(
perkj26752742016-10-24 01:21:16 -07001332 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-16 17:54:10 -08001333 return video;
1334 }
1335
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001336 template <class MCD>
Yves Gerey665174f2018-06-19 15:03:05 +02001337 void CompareMediaContentDescription(const MCD* cd1, const MCD* cd2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001338 // type
Harald Alvestrand1716d392019-06-03 20:35:45 +02001339 EXPECT_EQ(cd1->type(), cd2->type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001340
1341 // content direction
1342 EXPECT_EQ(cd1->direction(), cd2->direction());
1343
1344 // rtcp_mux
1345 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1346
deadbeef13871492015-12-09 12:37:51 -08001347 // rtcp_reduced_size
1348 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1349
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001350 // cryptos
1351 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1352 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1353 ADD_FAILURE();
1354 return;
1355 }
Yves Gerey665174f2018-06-19 15:03:05 +02001356 for (size_t i = 0; i < cd1->cryptos().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001357 const CryptoParams c1 = cd1->cryptos().at(i);
1358 const CryptoParams c2 = cd2->cryptos().at(i);
1359 EXPECT_TRUE(c1.Matches(c2));
1360 EXPECT_EQ(c1.key_params, c2.key_params);
1361 EXPECT_EQ(c1.session_params, c2.session_params);
1362 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001363
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001364 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001365 // Use an equivalence class here, for old and new versions of the
1366 // protocol description.
Yves Gerey665174f2018-06-19 15:03:05 +02001367 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp ||
1368 cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1369 cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
lally@webrtc.org36300852015-02-24 20:19:35 +00001370 const bool cd2_is_also_dtls_sctp =
Yves Gerey665174f2018-06-19 15:03:05 +02001371 cd2->protocol() == cricket::kMediaProtocolDtlsSctp ||
1372 cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1373 cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
lally@webrtc.org36300852015-02-24 20:19:35 +00001374 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001375 } else {
1376 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1377 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001378
1379 // codecs
1380 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1381
1382 // bandwidth
1383 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1384
1385 // streams
1386 EXPECT_EQ(cd1->streams(), cd2->streams());
1387
Johannes Kron0854eb62018-10-10 22:33:20 +02001388 // extmap-allow-mixed
Johannes Kron9581bc42018-10-23 10:17:39 +02001389 EXPECT_EQ(cd1->extmap_allow_mixed_enum(), cd2->extmap_allow_mixed_enum());
Johannes Kron0854eb62018-10-10 22:33:20 +02001390
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001391 // extmap
1392 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1393 cd2->rtp_header_extensions().size());
Yves Gerey665174f2018-06-19 15:03:05 +02001394 for (size_t i = 0; i < cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 11:24:55 -07001395 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1396 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001397 EXPECT_EQ(ext1.uri, ext2.uri);
1398 EXPECT_EQ(ext1.id, ext2.id);
jbauch5869f502017-06-29 12:31:36 -07001399 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001400 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001401 }
1402
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001403 void CompareRidDescriptionIds(const std::vector<RidDescription>& rids,
1404 const std::vector<std::string>& ids) {
1405 // Order of elements does not matter, only equivalence of sets.
1406 EXPECT_EQ(rids.size(), ids.size());
1407 for (const std::string& id : ids) {
Steve Anton64b626b2019-01-28 17:25:26 -08001408 EXPECT_EQ(1l, absl::c_count_if(rids, [id](const RidDescription& rid) {
1409 return rid.rid == id;
1410 }));
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001411 }
1412 }
1413
Amit Hilbucha2012042018-12-03 11:35:05 -08001414 void CompareSimulcastDescription(const SimulcastDescription& simulcast1,
1415 const SimulcastDescription& simulcast2) {
1416 EXPECT_EQ(simulcast1.send_layers().size(), simulcast2.send_layers().size());
1417 EXPECT_EQ(simulcast1.receive_layers().size(),
1418 simulcast2.receive_layers().size());
1419 }
1420
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001421 void CompareRtpDataContentDescription(const RtpDataContentDescription* dcd1,
1422 const RtpDataContentDescription* dcd2) {
1423 CompareMediaContentDescription<RtpDataContentDescription>(dcd1, dcd2);
1424 }
1425
1426 void CompareSctpDataContentDescription(
1427 const SctpDataContentDescription* dcd1,
1428 const SctpDataContentDescription* dcd2) {
Harald Alvestrand26bf7c42019-04-23 05:20:17 +00001429 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001430 EXPECT_EQ(dcd1->port(), dcd2->port());
1431 EXPECT_EQ(dcd1->max_message_size(), dcd2->max_message_size());
Harald Alvestrand26bf7c42019-04-23 05:20:17 +00001432 }
1433
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001434 void CompareSessionDescription(const SessionDescription& desc1,
1435 const SessionDescription& desc2) {
1436 // Compare content descriptions.
1437 if (desc1.contents().size() != desc2.contents().size()) {
1438 ADD_FAILURE();
1439 return;
1440 }
Yves Gerey665174f2018-06-19 15:03:05 +02001441 for (size_t i = 0; i < desc1.contents().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001442 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1443 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-12 18:37:36 -08001444 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001445 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-12 18:37:36 -08001446 EXPECT_EQ(c1.type, c2.type);
1447 EXPECT_EQ(c1.rejected, c2.rejected);
1448 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001449
1450 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1451 if (IsAudioContent(&c1)) {
1452 const AudioContentDescription* acd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001453 c1.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001454 const AudioContentDescription* acd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001455 c2.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001456 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1457 }
1458
1459 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1460 if (IsVideoContent(&c1)) {
1461 const VideoContentDescription* vcd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001462 c1.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001463 const VideoContentDescription* vcd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001464 c2.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001465 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1466 }
1467
1468 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001469 if (c1.media_description()->as_sctp()) {
1470 ASSERT_TRUE(c2.media_description()->as_sctp());
1471 const SctpDataContentDescription* scd1 =
1472 c1.media_description()->as_sctp();
1473 const SctpDataContentDescription* scd2 =
1474 c2.media_description()->as_sctp();
1475 CompareSctpDataContentDescription(scd1, scd2);
1476 } else {
1477 if (IsDataContent(&c1)) {
1478 const RtpDataContentDescription* dcd1 =
1479 c1.media_description()->as_rtp_data();
1480 const RtpDataContentDescription* dcd2 =
1481 c2.media_description()->as_rtp_data();
1482 CompareRtpDataContentDescription(dcd1, dcd2);
1483 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001484 }
Amit Hilbucha2012042018-12-03 11:35:05 -08001485
1486 CompareSimulcastDescription(
1487 c1.media_description()->simulcast_description(),
1488 c2.media_description()->simulcast_description());
Bjorn A Mellem8e1343a2019-09-30 15:12:47 -07001489 EXPECT_EQ(c1.media_description()->alt_protocol(),
1490 c2.media_description()->alt_protocol());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001491 }
1492
1493 // group
1494 const cricket::ContentGroups groups1 = desc1.groups();
1495 const cricket::ContentGroups groups2 = desc2.groups();
1496 EXPECT_EQ(groups1.size(), groups1.size());
1497 if (groups1.size() != groups2.size()) {
1498 ADD_FAILURE();
1499 return;
1500 }
1501 for (size_t i = 0; i < groups1.size(); ++i) {
1502 const cricket::ContentGroup group1 = groups1.at(i);
1503 const cricket::ContentGroup group2 = groups2.at(i);
1504 EXPECT_EQ(group1.semantics(), group2.semantics());
1505 const cricket::ContentNames names1 = group1.content_names();
1506 const cricket::ContentNames names2 = group2.content_names();
1507 EXPECT_EQ(names1.size(), names2.size());
1508 if (names1.size() != names2.size()) {
1509 ADD_FAILURE();
1510 return;
1511 }
1512 cricket::ContentNames::const_iterator iter1 = names1.begin();
1513 cricket::ContentNames::const_iterator iter2 = names2.begin();
1514 while (iter1 != names1.end()) {
1515 EXPECT_EQ(*iter1++, *iter2++);
1516 }
1517 }
1518
1519 // transport info
1520 const cricket::TransportInfos transports1 = desc1.transport_infos();
1521 const cricket::TransportInfos transports2 = desc2.transport_infos();
1522 EXPECT_EQ(transports1.size(), transports2.size());
1523 if (transports1.size() != transports2.size()) {
1524 ADD_FAILURE();
1525 return;
1526 }
1527 for (size_t i = 0; i < transports1.size(); ++i) {
1528 const cricket::TransportInfo transport1 = transports1.at(i);
1529 const cricket::TransportInfo transport2 = transports2.at(i);
1530 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001531 EXPECT_EQ(transport1.description.ice_ufrag,
1532 transport2.description.ice_ufrag);
Yves Gerey665174f2018-06-19 15:03:05 +02001533 EXPECT_EQ(transport1.description.ice_pwd, transport2.description.ice_pwd);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07001534 EXPECT_EQ(transport1.description.ice_mode,
1535 transport2.description.ice_mode);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001536 if (transport1.description.identity_fingerprint) {
1537 EXPECT_EQ(*transport1.description.identity_fingerprint,
1538 *transport2.description.identity_fingerprint);
1539 } else {
1540 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1541 transport2.description.identity_fingerprint.get());
1542 }
1543 EXPECT_EQ(transport1.description.transport_options,
1544 transport2.description.transport_options);
Bjorn A Mellemc85ebbe2019-06-07 10:28:06 -07001545 EXPECT_EQ(transport1.description.opaque_parameters,
1546 transport2.description.opaque_parameters);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001547 }
deadbeefc80741f2015-10-22 13:14:45 -07001548
1549 // global attributes
1550 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
Johannes Kron9581bc42018-10-23 10:17:39 +02001551 EXPECT_EQ(desc1.extmap_allow_mixed(), desc2.extmap_allow_mixed());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001552 }
1553
Yves Gerey665174f2018-06-19 15:03:05 +02001554 bool CompareSessionDescription(const JsepSessionDescription& desc1,
1555 const JsepSessionDescription& desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001556 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1557 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1558 CompareSessionDescription(*desc1.description(), *desc2.description());
1559 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1560 return false;
1561 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1562 const IceCandidateCollection* cc1 = desc1.candidates(i);
1563 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-12 18:37:36 -08001564 if (cc1->count() != cc2->count()) {
1565 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001566 return false;
deadbeef25ed4352016-12-12 18:37:36 -08001567 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001568 for (size_t j = 0; j < cc1->count(); ++j) {
1569 const IceCandidateInterface* c1 = cc1->at(j);
1570 const IceCandidateInterface* c2 = cc2->at(j);
1571 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1572 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1573 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1574 }
1575 }
1576 return true;
1577 }
1578
1579 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1580 // them with invalid keywords so that the parser will just ignore them.
1581 bool RemoveCandidateUfragPwd(std::string* sdp) {
Steve Anton1c9c9fc2019-02-14 15:13:09 -08001582 absl::StrReplaceAll(
1583 {{"a=ice-ufrag", "a=xice-ufrag"}, {"a=ice-pwd", "a=xice-pwd"}}, sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001584 return true;
1585 }
1586
1587 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
Yves Gerey665174f2018-06-19 15:03:05 +02001588 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc,
1589 int mline_index,
1590 const std::string& ufrag,
1591 const std::string& pwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001592 std::string content_name;
1593 if (mline_index == 0) {
1594 content_name = kAudioContentName;
1595 } else if (mline_index == 1) {
1596 content_name = kVideoContentName;
1597 } else {
nissec80e7412017-01-11 05:56:46 -08001598 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001599 }
Yves Gerey665174f2018-06-19 15:03:05 +02001600 TransportInfo transport_info(content_name,
1601 TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001602 SessionDescription* desc =
1603 const_cast<SessionDescription*>(jdesc->description());
1604 desc->RemoveTransportInfoByName(content_name);
Steve Anton06817cd2018-12-18 15:55:30 -08001605 desc->AddTransportInfo(transport_info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001606 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1607 const IceCandidateCollection* cc = jdesc_.candidates(i);
1608 for (size_t j = 0; j < cc->count(); ++j) {
1609 if (cc->at(j)->sdp_mline_index() == mline_index) {
Yves Gerey665174f2018-06-19 15:03:05 +02001610 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(ufrag);
1611 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001612 }
1613 }
1614 }
1615 return true;
1616 }
1617
1618 void AddIceOptions(const std::string& content_name,
1619 const std::vector<std::string>& transport_options) {
1620 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1621 cricket::TransportInfo transport_info =
1622 *(desc_.GetTransportInfoByName(content_name));
1623 desc_.RemoveTransportInfoByName(content_name);
1624 transport_info.description.transport_options = transport_options;
1625 desc_.AddTransportInfo(transport_info);
1626 }
1627
deadbeef3f7219b2015-12-28 15:17:14 -08001628 void SetIceUfragPwd(const std::string& content_name,
1629 const std::string& ice_ufrag,
1630 const std::string& ice_pwd) {
1631 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1632 cricket::TransportInfo transport_info =
1633 *(desc_.GetTransportInfoByName(content_name));
1634 desc_.RemoveTransportInfoByName(content_name);
1635 transport_info.description.ice_ufrag = ice_ufrag;
1636 transport_info.description.ice_pwd = ice_pwd;
1637 desc_.AddTransportInfo(transport_info);
1638 }
1639
Bjorn A Mellemc85ebbe2019-06-07 10:28:06 -07001640 void AddOpaqueTransportParameters(const std::string& content_name,
1641 cricket::OpaqueTransportParameters params) {
1642 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1643 cricket::TransportInfo info = *(desc_.GetTransportInfoByName(content_name));
1644 desc_.RemoveTransportInfoByName(content_name);
1645 info.description.opaque_parameters = params;
1646 desc_.AddTransportInfo(info);
1647 }
1648
Bjorn A Mellem8e1343a2019-09-30 15:12:47 -07001649 void AddAltProtocol(const std::string& content_name,
1650 const std::string& alt_protocol) {
1651 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1652 cricket::MediaContentDescription* description =
1653 desc_.GetContentDescriptionByName(content_name);
1654 description->set_alt_protocol(alt_protocol);
1655 }
1656
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001657 void AddFingerprint() {
1658 desc_.RemoveTransportInfoByName(kAudioContentName);
1659 desc_.RemoveTransportInfoByName(kVideoContentName);
Steve Anton4905edb2018-10-15 19:27:44 -07001660 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, kIdentityDigest);
Steve Anton06817cd2018-12-18 15:55:30 -08001661 desc_.AddTransportInfo(TransportInfo(
deadbeef46eed762016-01-28 13:24:37 -08001662 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001663 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1664 cricket::ICEMODE_FULL,
Steve Anton06817cd2018-12-18 15:55:30 -08001665 cricket::CONNECTIONROLE_NONE, &fingerprint)));
1666 desc_.AddTransportInfo(TransportInfo(
deadbeef46eed762016-01-28 13:24:37 -08001667 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001668 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1669 cricket::ICEMODE_FULL,
Steve Anton06817cd2018-12-18 15:55:30 -08001670 cricket::CONNECTIONROLE_NONE, &fingerprint)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001671 }
1672
jbauch5869f502017-06-29 12:31:36 -07001673 void AddExtmap(bool encrypted) {
Harald Alvestrandb97d2fe2020-02-28 11:54:40 +01001674 audio_desc_ = new AudioContentDescription(*audio_desc_);
1675 video_desc_ = new VideoContentDescription(*video_desc_);
jbauch5869f502017-06-29 12:31:36 -07001676 audio_desc_->AddRtpHeaderExtension(
1677 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1678 video_desc_->AddRtpHeaderExtension(
1679 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001680 desc_.RemoveContentByName(kAudioContentName);
1681 desc_.RemoveContentByName(kVideoContentName);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001682 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1683 absl::WrapUnique(audio_desc_));
1684 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp,
1685 absl::WrapUnique(video_desc_));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001686 }
1687
1688 void RemoveCryptos() {
1689 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1690 video_desc_->set_cryptos(std::vector<CryptoParams>());
1691 }
1692
Seth Hampson5897a6e2018-04-03 11:16:33 -07001693 // Removes everything in StreamParams from the session description that is
1694 // used for a=ssrc lines.
1695 void RemoveSsrcSignalingFromStreamParams() {
Harald Alvestrand1716d392019-06-03 20:35:45 +02001696 for (cricket::ContentInfo& content_info :
1697 jdesc_.description()->contents()) {
Seth Hampson5897a6e2018-04-03 11:16:33 -07001698 // With Unified Plan there should be one StreamParams per m= section.
1699 StreamParams& stream =
1700 content_info.media_description()->mutable_streams()[0];
1701 stream.ssrcs.clear();
1702 stream.ssrc_groups.clear();
1703 stream.cname.clear();
1704 }
1705 }
1706
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001707 // Removes all a=ssrc lines from the SDP string, except for the
1708 // "a=ssrc:... cname:..." lines.
1709 void RemoveSsrcMsidLinesFromSdpString(std::string* sdp_string) {
1710 const char kAttributeSsrc[] = "a=ssrc";
1711 const char kAttributeCname[] = "cname";
1712 size_t ssrc_line_pos = sdp_string->find(kAttributeSsrc);
1713 while (ssrc_line_pos != std::string::npos) {
1714 size_t beg_line_pos = sdp_string->rfind('\n', ssrc_line_pos);
1715 size_t end_line_pos = sdp_string->find('\n', ssrc_line_pos);
1716 size_t cname_pos = sdp_string->find(kAttributeCname, ssrc_line_pos);
1717 if (cname_pos == std::string::npos || cname_pos > end_line_pos) {
1718 // Only erase a=ssrc lines that don't contain "cname".
1719 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1720 ssrc_line_pos = sdp_string->find(kAttributeSsrc, beg_line_pos);
1721 } else {
1722 // Skip the "a=ssrc:... cname" line and find the next "a=ssrc" line.
1723 ssrc_line_pos = sdp_string->find(kAttributeSsrc, end_line_pos);
1724 }
1725 }
1726 }
1727
Seth Hampson5897a6e2018-04-03 11:16:33 -07001728 // Removes all a=ssrc lines from the SDP string.
1729 void RemoveSsrcLinesFromSdpString(std::string* sdp_string) {
1730 const char kAttributeSsrc[] = "a=ssrc";
1731 while (sdp_string->find(kAttributeSsrc) != std::string::npos) {
1732 size_t pos_ssrc_attribute = sdp_string->find(kAttributeSsrc);
1733 size_t beg_line_pos = sdp_string->rfind('\n', pos_ssrc_attribute);
1734 size_t end_line_pos = sdp_string->find('\n', pos_ssrc_attribute);
1735 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1736 }
1737 }
1738
Steve Anton4e70a722017-11-28 14:57:10 -08001739 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001740 audio_desc_->set_direction(direction);
1741 video_desc_->set_direction(direction);
1742 std::string new_sdp = kSdpFullString;
1743 ReplaceDirection(direction, &new_sdp);
1744
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001745 if (!jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001746 jdesc_.session_version())) {
1747 return false;
1748 }
Steve Antone831b8c2018-02-01 12:22:16 -08001749 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001750 EXPECT_EQ(new_sdp, message);
1751 return true;
1752 }
1753
1754 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
Harald Alvestrandb97d2fe2020-02-28 11:54:40 +01001755 audio_desc_ = new AudioContentDescription(*audio_desc_);
1756 video_desc_ = new VideoContentDescription(*video_desc_);
zhihuang38989e52017-03-21 11:04:53 -07001757
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001758 desc_.RemoveContentByName(kAudioContentName);
1759 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001760 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001761 absl::WrapUnique(audio_desc_));
Steve Anton5adfafd2017-12-20 16:34:00 -08001762 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001763 absl::WrapUnique(video_desc_));
deadbeef9d3584c2016-02-16 17:54:10 -08001764 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1765 audio_rejected ? "" : kPwdVoice);
1766 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1767 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001768
1769 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001770 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1771
Steve Antona3a92c22017-12-07 10:27:41 -08001772 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001773 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001774 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001775 EXPECT_EQ(new_sdp, message);
1776 return true;
1777 }
1778
zstein4b2e0822017-02-17 19:48:38 -08001779 void AddSctpDataChannel(bool use_sctpmap) {
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001780 std::unique_ptr<SctpDataContentDescription> data(
1781 new SctpDataContentDescription());
1782 sctp_desc_ = data.get();
1783 sctp_desc_->set_use_sctpmap(use_sctpmap);
Guido Urdanetacecf87f2019-05-31 10:17:38 +00001784 sctp_desc_->set_protocol(cricket::kMediaProtocolUdpDtlsSctp);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001785 sctp_desc_->set_port(kDefaultSctpPort);
Steve Anton5adfafd2017-12-20 16:34:00 -08001786 desc_.AddContent(kDataContentName, MediaProtocolType::kSctp,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001787 std::move(data));
Steve Anton06817cd2018-12-18 15:55:30 -08001788 desc_.AddTransportInfo(TransportInfo(
1789 kDataContentName, TransportDescription(kUfragData, kPwdData)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001790 }
1791
1792 void AddRtpDataChannel() {
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001793 std::unique_ptr<RtpDataContentDescription> data(
1794 new RtpDataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001795 data_desc_ = data.get();
1796
deadbeef67cf2c12016-04-13 10:07:16 -07001797 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001798 StreamParams data_stream;
1799 data_stream.id = kDataChannelMsid;
1800 data_stream.cname = kDataChannelCname;
Seth Hampson845e8782018-03-02 11:34:10 -08001801 data_stream.set_stream_ids({kDataChannelLabel});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001802 data_stream.ssrcs.push_back(kDataChannelSsrc);
1803 data_desc_->AddStream(data_stream);
Yves Gerey665174f2018-06-19 15:03:05 +02001804 data_desc_->AddCrypto(
1805 CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
1806 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001807 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001808 desc_.AddContent(kDataContentName, MediaProtocolType::kRtp,
1809 std::move(data));
Steve Anton06817cd2018-12-18 15:55:30 -08001810 desc_.AddTransportInfo(TransportInfo(
1811 kDataContentName, TransportDescription(kUfragData, kPwdData)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001812 }
1813
Steve Anton4e70a722017-11-28 14:57:10 -08001814 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001815 std::string new_sdp = kSdpFullString;
1816 ReplaceDirection(direction, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001817 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001818
1819 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1820
1821 audio_desc_->set_direction(direction);
1822 video_desc_->set_direction(direction);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001823 if (!jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001824 jdesc_.session_version())) {
1825 return false;
1826 }
1827 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1828 return true;
1829 }
1830
1831 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001832 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001833 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001834 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001835 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001836
Harald Alvestrandb97d2fe2020-02-28 11:54:40 +01001837 audio_desc_ = new AudioContentDescription(*audio_desc_);
1838 video_desc_ = new VideoContentDescription(*video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001839 desc_.RemoveContentByName(kAudioContentName);
1840 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001841 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001842 absl::WrapUnique(audio_desc_));
Steve Anton5adfafd2017-12-20 16:34:00 -08001843 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001844 absl::WrapUnique(video_desc_));
deadbeef9d3584c2016-02-16 17:54:10 -08001845 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1846 audio_rejected ? "" : kPwdVoice);
1847 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1848 video_rejected ? "" : kPwdVideo);
Steve Antona3a92c22017-12-07 10:27:41 -08001849 JsepSessionDescription jdesc_no_candidates(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001850 if (!jdesc_no_candidates.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef3f7219b2015-12-28 15:17:14 -08001851 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001852 return false;
1853 }
deadbeef3f7219b2015-12-28 15:17:14 -08001854 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001855 return true;
1856 }
1857
Yves Gerey665174f2018-06-19 15:03:05 +02001858 void TestDeserializeExtmap(bool session_level,
1859 bool media_level,
1860 bool encrypted) {
jbauch5869f502017-06-29 12:31:36 -07001861 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08001862 JsepSessionDescription new_jdesc(SdpType::kOffer);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001863 ASSERT_TRUE(new_jdesc.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001864 jdesc_.session_version()));
Steve Antona3a92c22017-12-07 10:27:41 -08001865 JsepSessionDescription jdesc_with_extmap(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001866 std::string sdp_with_extmap = kSdpString;
1867 if (session_level) {
jbauch5869f502017-06-29 12:31:36 -07001868 InjectAfter(kSessionTime,
1869 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1870 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001871 &sdp_with_extmap);
1872 }
1873 if (media_level) {
jbauch5869f502017-06-29 12:31:36 -07001874 InjectAfter(kAttributeIcePwdVoice,
1875 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1876 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001877 &sdp_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07001878 InjectAfter(kAttributeIcePwdVideo,
1879 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1880 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001881 &sdp_with_extmap);
1882 }
1883 // The extmap can't be present at the same time in both session level and
1884 // media level.
1885 if (session_level && media_level) {
1886 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02001887 EXPECT_FALSE(
1888 webrtc::SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001889 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1890 } else {
1891 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1892 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1893 }
1894 }
1895
1896 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
Yves Gerey665174f2018-06-19 15:03:05 +02001897 const std::string& name,
1898 int expected_value) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001899 cricket::CodecParameterMap::const_iterator found = params.find(name);
1900 ASSERT_TRUE(found != params.end());
Jonas Olsson6b1985d2018-07-05 11:59:48 +02001901 EXPECT_EQ(found->second, rtc::ToString(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001902 }
1903
1904 void TestDeserializeCodecParams(const CodecParams& params,
1905 JsepSessionDescription* jdesc_output) {
1906 std::string sdp =
1907 "v=0\r\n"
1908 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1909 "s=-\r\n"
1910 "t=0 0\r\n"
1911 // Include semantics for WebRTC Media Streams since it is supported by
1912 // this parser, and will be added to the SDP when serializing a session
1913 // description.
1914 "a=msid-semantic: WMS\r\n"
1915 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001916 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001917 // Pltype 111 listed before 103 and 104 in the map.
1918 "a=rtpmap:111 opus/48000/2\r\n"
1919 // Pltype 103 listed before 104.
1920 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001921 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001922 "a=fmtp:111 0-15,66,70\r\n"
1923 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001924 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001925 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001926 << "; sprop-stereo=" << params.sprop_stereo
1927 << "; useinbandfec=" << params.useinband
Jonas Olssonb2b20312020-01-14 12:11:31 +01001928 << "; maxaveragebitrate=" << params.maxaveragebitrate
1929 << "\r\n"
1930 "a=ptime:"
1931 << params.ptime
1932 << "\r\n"
1933 "a=maxptime:"
1934 << params.max_ptime << "\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001935 sdp += os.str();
1936
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001937 os.clear();
1938 os.str("");
1939 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001940 os << "m=video 9 RTP/SAVPF 99 95\r\n"
Jonas Olssonb2b20312020-01-14 12:11:31 +01001941 "a=rtpmap:99 VP8/90000\r\n"
1942 "a=rtpmap:95 RTX/90000\r\n"
1943 "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001944 sdp += os.str();
1945
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001946 // Deserialize
1947 SdpParseError error;
1948 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1949
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001950 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001951 GetFirstAudioContentDescription(jdesc_output->description());
1952 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001953 ASSERT_FALSE(acd->codecs().empty());
1954 cricket::AudioCodec opus = acd->codecs()[0];
1955 EXPECT_EQ("opus", opus.name);
1956 EXPECT_EQ(111, opus.id);
1957 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1958 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1959 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1960 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001961 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1962 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001963 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1964 cricket::AudioCodec codec = acd->codecs()[i];
1965 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1966 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001967 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001968
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001969 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001970 GetFirstVideoContentDescription(jdesc_output->description());
1971 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001972 ASSERT_FALSE(vcd->codecs().empty());
1973 cricket::VideoCodec vp8 = vcd->codecs()[0];
1974 EXPECT_EQ("VP8", vp8.name);
1975 EXPECT_EQ(99, vp8.id);
1976 cricket::VideoCodec rtx = vcd->codecs()[1];
1977 EXPECT_EQ("RTX", rtx.name);
1978 EXPECT_EQ(95, rtx.id);
1979 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001980 }
1981
1982 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1983 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001984 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001985 "v=0\r\n"
1986 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1987 "s=-\r\n"
1988 "t=0 0\r\n"
1989 // Include semantics for WebRTC Media Streams since it is supported by
1990 // this parser, and will be added to the SDP when serializing a session
1991 // description.
1992 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001993 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001994 "a=rtpmap:111 opus/48000/2\r\n";
1995 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001996 "m=video 3457 RTP/SAVPF 101\r\n"
1997 "a=rtpmap:101 VP8/90000\r\n"
Elad Alonfadb1812019-05-24 13:40:02 +02001998 "a=rtcp-fb:101 goog-lntf\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001999 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002000 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00002001 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002002 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00002003 os << sdp_session_and_audio;
Yves Gerey665174f2018-06-19 15:03:05 +02002004 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00002005 os << sdp_video;
Yves Gerey665174f2018-06-19 15:03:05 +02002006 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00002007 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002008 // Deserialize
2009 SdpParseError error;
2010 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002011 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08002012 GetFirstAudioContentDescription(jdesc_output->description());
2013 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002014 ASSERT_FALSE(acd->codecs().empty());
2015 cricket::AudioCodec opus = acd->codecs()[0];
2016 EXPECT_EQ(111, opus.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002017 EXPECT_TRUE(opus.HasFeedbackParam(cricket::FeedbackParam(
2018 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002019
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002020 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08002021 GetFirstVideoContentDescription(jdesc_output->description());
2022 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002023 ASSERT_FALSE(vcd->codecs().empty());
2024 cricket::VideoCodec vp8 = vcd->codecs()[0];
2025 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
2026 vp8.name.c_str());
2027 EXPECT_EQ(101, vp8.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002028 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
Elad Alonfadb1812019-05-24 13:40:02 +02002029 cricket::kRtcpFbParamLntf, cricket::kParamValueEmpty)));
2030 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
Yves Gerey665174f2018-06-19 15:03:05 +02002031 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
2032 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2033 cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli)));
2034 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2035 cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty)));
2036 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2037 cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002038 }
2039
2040 // Two SDP messages can mean the same thing but be different strings, e.g.
2041 // some of the lines can be serialized in different order.
2042 // However, a deserialized description can be compared field by field and has
2043 // no order. If deserializer has already been tested, serializing then
2044 // deserializing and comparing JsepSessionDescription will test
2045 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 12:22:16 -08002046 void TestSerialize(const JsepSessionDescription& jdesc) {
2047 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 10:27:41 -08002048 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002049 SdpParseError error;
2050 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
2051 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
2052 }
2053
zhihuang38989e52017-03-21 11:04:53 -07002054 // Calling 'Initialize' with a copy of the inner SessionDescription will
2055 // create a copy of the JsepSessionDescription without candidates. The
2056 // 'connection address' field, previously set from the candidates, must also
2057 // be reset.
2058 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
2059 rtc::SocketAddress audio_addr("0.0.0.0", 9);
2060 rtc::SocketAddress video_addr("0.0.0.0", 9);
2061 audio_desc_->set_connection_address(audio_addr);
2062 video_desc_->set_connection_address(video_addr);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002063 ASSERT_TRUE(jdesc->Initialize(desc_.Clone(), kSessionId, kSessionVersion));
zhihuang38989e52017-03-21 11:04:53 -07002064 }
2065
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002066 protected:
2067 SessionDescription desc_;
2068 AudioContentDescription* audio_desc_;
2069 VideoContentDescription* video_desc_;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002070 RtpDataContentDescription* data_desc_;
2071 SctpDataContentDescription* sctp_desc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002072 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07002073 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002074 JsepSessionDescription jdesc_;
2075};
2076
2077void TestMismatch(const std::string& string1, const std::string& string2) {
2078 int position = 0;
2079 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
2080 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002081 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002082 break;
2083 }
2084 }
2085 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
2086 << " character\n"
Jonas Olssonb2b20312020-01-14 12:11:31 +01002087 " 1: "
2088 << string1.substr(position, 20)
2089 << "\n"
2090 " 2: "
2091 << string2.substr(position, 20) << "\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002092}
2093
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002094TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
2095 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 12:22:16 -08002096 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002097 TestMismatch(std::string(kSdpFullString), message);
2098}
2099
2100TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 10:27:41 -08002101 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 12:22:16 -08002102 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002103}
2104
2105// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
2106// the case in a DTLS offer.
2107TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
2108 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002109 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002110 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08002111 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002112
2113 std::string sdp_with_fingerprint = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002114 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2115 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002116
2117 EXPECT_EQ(sdp_with_fingerprint, message);
2118}
2119
2120// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
2121// be the case in a DTLS answer.
2122TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
2123 AddFingerprint();
2124 RemoveCryptos();
Steve Antona3a92c22017-12-07 10:27:41 -08002125 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002126 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08002127 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002128
2129 std::string sdp_with_fingerprint = kSdpString;
2130 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
2131 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
Yves Gerey665174f2018-06-19 15:03:05 +02002132 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2133 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002134
2135 EXPECT_EQ(sdp_with_fingerprint, message);
2136}
2137
2138TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
2139 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002140 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002141 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08002142 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002143 EXPECT_EQ(std::string(kSdpString), message);
2144}
2145
2146TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
2147 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2148 group.AddContentName(kAudioContentName);
2149 group.AddContentName(kVideoContentName);
2150 desc_.AddGroup(group);
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_bundle = kSdpFullString;
2155 InjectAfter(kSessionTime,
2156 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2157 &sdp_with_bundle);
2158 EXPECT_EQ(sdp_with_bundle, message);
2159}
2160
2161TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 15:14:30 -08002162 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002163 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002164 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002165 acd->set_bandwidth(50 * 1000);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002166 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002167 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002168 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002169 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002170 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002171 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002172 InjectAfter("c=IN IP4 74.125.127.126\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002173 &sdp_with_bandwidth);
2174 EXPECT_EQ(sdp_with_bandwidth, message);
2175}
2176
2177TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
2178 std::vector<std::string> transport_options;
2179 transport_options.push_back(kIceOption1);
2180 transport_options.push_back(kIceOption3);
2181 AddIceOptions(kAudioContentName, transport_options);
2182 transport_options.clear();
2183 transport_options.push_back(kIceOption2);
2184 transport_options.push_back(kIceOption3);
2185 AddIceOptions(kVideoContentName, transport_options);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002186 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002187 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002188 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002189 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002190 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002191 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002192 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002193 &sdp_with_ice_options);
2194 EXPECT_EQ(sdp_with_ice_options, message);
2195}
2196
Bjorn A Mellemc85ebbe2019-06-07 10:28:06 -07002197TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithOpaqueTransportParams) {
2198 cricket::OpaqueTransportParameters params;
2199 params.protocol = "foo";
2200 params.parameters = "test64";
2201 AddOpaqueTransportParameters(kAudioContentName, params);
2202 AddOpaqueTransportParameters(kVideoContentName, params);
2203
2204 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2205 jdesc_.session_version()));
2206 std::string message = webrtc::SdpSerialize(jdesc_);
2207
2208 std::string sdp_with_transport_parameters = kSdpFullString;
2209 InjectAfter(kAttributeIcePwdVoice, "a=x-opaque:foo:dGVzdDY0\r\n",
2210 &sdp_with_transport_parameters);
2211 InjectAfter(kAttributeIcePwdVideo, "a=x-opaque:foo:dGVzdDY0\r\n",
2212 &sdp_with_transport_parameters);
2213 EXPECT_EQ(message, sdp_with_transport_parameters);
2214}
2215
Bjorn A Mellem8e1343a2019-09-30 15:12:47 -07002216TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAltProtocol) {
2217 AddAltProtocol(kAudioContentName, "foo");
2218 AddAltProtocol(kVideoContentName, "bar");
2219
2220 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2221 jdesc_.session_version()));
2222 std::string message = webrtc::SdpSerialize(jdesc_);
2223
2224 std::string sdp_with_alt_protocol = kSdpFullString;
2225 InjectAfter(kAttributeIcePwdVoice, "a=x-alt-protocol:foo\r\n",
2226 &sdp_with_alt_protocol);
2227 InjectAfter(kAttributeIcePwdVideo, "a=x-alt-protocol:bar\r\n",
2228 &sdp_with_alt_protocol);
2229 EXPECT_EQ(message, sdp_with_alt_protocol);
2230}
2231
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002232TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002233 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002234}
2235
2236TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002237 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002238}
2239
2240TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002241 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002242}
2243
2244TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2245 EXPECT_TRUE(TestSerializeRejected(true, false));
2246}
2247
2248TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2249 EXPECT_TRUE(TestSerializeRejected(false, true));
2250}
2251
2252TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2253 EXPECT_TRUE(TestSerializeRejected(true, true));
2254}
2255
2256TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
2257 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002258 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002259
zhihuang38989e52017-03-21 11:04:53 -07002260 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002261 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002262
2263 std::string expected_sdp = kSdpString;
2264 expected_sdp.append(kSdpRtpDataChannelString);
2265 EXPECT_EQ(expected_sdp, message);
2266}
2267
2268TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08002269 bool use_sctpmap = true;
2270 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002271 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002272
zhihuang38989e52017-03-21 11:04:53 -07002273 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002274 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002275
2276 std::string expected_sdp = kSdpString;
2277 expected_sdp.append(kSdpSctpDataChannelString);
2278 EXPECT_EQ(message, expected_sdp);
2279}
2280
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002281void MutateJsepSctpPort(JsepSessionDescription* jdesc,
2282 const SessionDescription& desc,
2283 int port) {
2284 // Take our pre-built session description and change the SCTP port.
2285 std::unique_ptr<cricket::SessionDescription> mutant = desc.Clone();
2286 SctpDataContentDescription* dcdesc =
2287 mutant->GetContentDescriptionByName(kDataContentName)->as_sctp();
2288 dcdesc->set_port(port);
2289 ASSERT_TRUE(
2290 jdesc->Initialize(std::move(mutant), kSessionId, kSessionVersion));
2291}
2292
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002293TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08002294 bool use_sctpmap = true;
2295 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002296 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002297 MakeDescriptionWithoutCandidates(&jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002298
2299 const int kNewPort = 1234;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002300 MutateJsepSctpPort(&jsep_desc, desc_, kNewPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002301
Steve Antone831b8c2018-02-01 12:22:16 -08002302 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002303
2304 std::string expected_sdp = kSdpString;
2305 expected_sdp.append(kSdpSctpDataChannelString);
2306
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002307 absl::StrReplaceAll(
2308 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kNewPort)}},
2309 &expected_sdp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002310
2311 EXPECT_EQ(expected_sdp, message);
2312}
2313
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002314TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002315 JsepSessionDescription jsep_desc(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002316 AddRtpDataChannel();
Yves Gerey665174f2018-06-19 15:03:05 +02002317 data_desc_->set_bandwidth(100 * 1000);
zhihuang38989e52017-03-21 11:04:53 -07002318 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002319 std::string message = webrtc::SdpSerialize(jsep_desc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002320
2321 std::string expected_sdp = kSdpString;
2322 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002323 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00002324 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02002325 "b=AS:100\r\n", &expected_sdp);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002326 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002327}
2328
Johannes Kron0854eb62018-10-10 22:33:20 +02002329TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002330 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002331 TestSerialize(jdesc_);
2332}
2333
2334TEST_F(WebRtcSdpTest, SerializeMediaContentDescriptionWithExtmapAllowMixed) {
2335 cricket::MediaContentDescription* video_desc =
2336 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2337 ASSERT_TRUE(video_desc);
2338 cricket::MediaContentDescription* audio_desc =
2339 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2340 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002341 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002342 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002343 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002344 cricket::MediaContentDescription::kMedia);
2345 TestSerialize(jdesc_);
2346}
2347
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002348TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002349 bool encrypted = false;
2350 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002351 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002352 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 12:22:16 -08002353 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002354
2355 std::string sdp_with_extmap = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002356 InjectAfter("a=mid:audio_content_name\r\n", kExtmap, &sdp_with_extmap);
2357 InjectAfter("a=mid:video_content_name\r\n", kExtmap, &sdp_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002358
2359 EXPECT_EQ(sdp_with_extmap, message);
2360}
2361
jbauch5869f502017-06-29 12:31:36 -07002362TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2363 bool encrypted = true;
2364 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002365 JsepSessionDescription desc_with_extmap(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002366 ASSERT_TRUE(
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002367 desc_with_extmap.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 12:22:16 -08002368 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07002369}
2370
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002371TEST_F(WebRtcSdpTest, SerializeCandidates) {
2372 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002373 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002374
2375 Candidate candidate_with_ufrag(candidates_.front());
2376 candidate_with_ufrag.set_username("ABC");
2377 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2378 candidate_with_ufrag));
2379 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2380 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002381
2382 Candidate candidate_with_network_info(candidates_.front());
2383 candidate_with_network_info.set_network_id(1);
2384 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2385 candidate_with_network_info));
2386 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2387 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2388 candidate_with_network_info.set_network_cost(999);
2389 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2390 candidate_with_network_info));
2391 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2392 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2393 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002394}
2395
Zach Steinb336c272018-08-09 01:16:13 -07002396TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) {
2397 rtc::SocketAddress address("a.test", 1234);
2398 cricket::Candidate candidate(
2399 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
2400 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
2401 JsepIceCandidate jcandidate(std::string("audio_content_name"), 0, candidate);
2402 std::string message = webrtc::SdpSerializeCandidate(jcandidate);
2403 EXPECT_EQ(std::string(kRawHostnameCandidate), message);
2404}
2405
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002406// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2407// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002408TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002409 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002410 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2411 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2412 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002413 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002414 std::unique_ptr<IceCandidateInterface> jcandidate(
2415 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002416
2417 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2418 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2419}
2420
htaa6b99442016-04-12 10:29:17 -07002421TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002422 cricket::VideoCodec h264_codec("H264");
2423 h264_codec.SetParam("profile-level-id", "42e01f");
2424 h264_codec.SetParam("level-asymmetry-allowed", "1");
2425 h264_codec.SetParam("packetization-mode", "1");
2426 video_desc_->AddCodec(h264_codec);
2427
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002428 jdesc_.Initialize(desc_.Clone(), kSessionId, kSessionVersion);
htaa6b99442016-04-12 10:29:17 -07002429
Steve Antone831b8c2018-02-01 12:22:16 -08002430 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 10:29:17 -07002431 size_t after_pt = message.find(" H264/90000");
2432 ASSERT_NE(after_pt, std::string::npos);
2433 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2434 ASSERT_NE(before_pt, std::string::npos);
2435 before_pt += strlen("a=rtpmap:");
2436 std::string pt = message.substr(before_pt, after_pt - before_pt);
2437 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2438 std::string to_find = "a=fmtp:" + pt + " ";
2439 size_t fmtp_pos = message.find(to_find);
2440 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
Mirko Bonadei37ec55e2019-01-28 11:43:52 +01002441 size_t fmtp_endpos = message.find('\n', fmtp_pos);
htaa6b99442016-04-12 10:29:17 -07002442 ASSERT_NE(std::string::npos, fmtp_endpos);
2443 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2444 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2445 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2446 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002447 // Check that there are no spaces after semicolons.
2448 // https://bugs.webrtc.org/5793
2449 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002450}
2451
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002452TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 10:27:41 -08002453 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002454 // Deserialize
2455 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2456 // Verify
2457 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2458}
2459
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002460TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 10:27:41 -08002461 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002462 const char kSdpWithoutMline[] =
Yves Gerey665174f2018-06-19 15:03:05 +02002463 "v=0\r\n"
2464 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2465 "s=-\r\n"
2466 "t=0 0\r\n"
2467 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002468 // Deserialize
2469 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2470 EXPECT_EQ(0u, jdesc.description()->contents().size());
2471}
2472
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002473TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 10:27:41 -08002474 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002475 std::string sdp_without_carriage_return = kSdpFullString;
2476 Replace("\r\n", "\n", &sdp_without_carriage_return);
2477 // Deserialize
2478 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2479 // Verify
2480 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2481}
2482
2483TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2484 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002485 JsepSessionDescription jdesc_no_candidates(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002486 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Clone(), kSessionId,
Yves Gerey665174f2018-06-19 15:03:05 +02002487 kSessionVersion));
Steve Antona3a92c22017-12-07 10:27:41 -08002488 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002489 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2490 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2491}
2492
2493TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2494 static const char kSdpNoRtpmapString[] =
2495 "v=0\r\n"
2496 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2497 "s=-\r\n"
2498 "t=0 0\r\n"
2499 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2500 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002501 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002502 // The rtpmap line for static payload codec is optional.
2503 "a=rtpmap:18 G729/16000\r\n"
2504 "a=rtpmap:103 ISAC/16000\r\n";
2505
Steve Antona3a92c22017-12-07 10:27:41 -08002506 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002507 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2508 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08002509 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002510 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002511 // The codecs in the AudioContentDescription should be in the same order as
2512 // the payload types (<fmt>s) on the m= line.
2513 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2514 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002515 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002516 EXPECT_EQ(ref_codecs, audio->codecs());
2517}
2518
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002519TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2520 static const char kSdpNoRtpmapString[] =
2521 "v=0\r\n"
2522 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2523 "s=-\r\n"
2524 "t=0 0\r\n"
2525 "m=audio 49232 RTP/AVP 18 103\r\n"
2526 "a=fmtp:18 annexb=yes\r\n"
2527 "a=rtpmap:103 ISAC/16000\r\n";
2528
Steve Antona3a92c22017-12-07 10:27:41 -08002529 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002530 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2531 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08002532 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002533
2534 cricket::AudioCodec g729 = audio->codecs()[0];
2535 EXPECT_EQ("G729", g729.name);
2536 EXPECT_EQ(8000, g729.clockrate);
2537 EXPECT_EQ(18, g729.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002538 cricket::CodecParameterMap::iterator found = g729.params.find("annexb");
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002539 ASSERT_TRUE(found != g729.params.end());
2540 EXPECT_EQ(found->second, "yes");
2541
2542 cricket::AudioCodec isac = audio->codecs()[1];
2543 EXPECT_EQ("ISAC", isac.name);
2544 EXPECT_EQ(103, isac.id);
2545 EXPECT_EQ(16000, isac.clockrate);
2546}
2547
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002548// Ensure that we can deserialize SDP with a=fingerprint properly.
2549TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2550 // Add a DTLS a=fingerprint attribute to our session description.
2551 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002552 JsepSessionDescription new_jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002553 ASSERT_TRUE(new_jdesc.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002554 jdesc_.session_version()));
2555
Steve Antona3a92c22017-12-07 10:27:41 -08002556 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002557 std::string sdp_with_fingerprint = kSdpString;
2558 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2559 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2560 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2561 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2562}
2563
2564TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 10:27:41 -08002565 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002566 std::string sdp_with_bundle = kSdpFullString;
2567 InjectAfter(kSessionTime,
2568 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2569 &sdp_with_bundle);
2570 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2571 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2572 group.AddContentName(kAudioContentName);
2573 group.AddContentName(kVideoContentName);
2574 desc_.AddGroup(group);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002575 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002576 jdesc_.session_version()));
2577 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2578}
2579
2580TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002581 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002582 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002583 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002584 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002585 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002586 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002587 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 15:14:30 -08002588 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002589 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002590 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002591 acd->set_bandwidth(50 * 1000);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002592 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002593 jdesc_.session_version()));
2594 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2595}
2596
2597TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 10:27:41 -08002598 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002599 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002600 InjectAfter(kSessionTime, "a=ice-options:iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002601 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002602 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002603 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002604 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002605 &sdp_with_ice_options);
2606 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2607 std::vector<std::string> transport_options;
2608 transport_options.push_back(kIceOption3);
2609 transport_options.push_back(kIceOption1);
2610 AddIceOptions(kAudioContentName, transport_options);
2611 transport_options.clear();
2612 transport_options.push_back(kIceOption3);
2613 transport_options.push_back(kIceOption2);
2614 AddIceOptions(kVideoContentName, transport_options);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002615 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002616 jdesc_.session_version()));
2617 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2618}
2619
Bjorn A Mellemc85ebbe2019-06-07 10:28:06 -07002620TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithOpaqueTransportParams) {
2621 std::string sdp_with_transport_parameters = kSdpFullString;
2622 InjectAfter(kAttributeIcePwdVoice, "a=x-opaque:foo:dGVzdDY0\r\n",
2623 &sdp_with_transport_parameters);
2624 InjectAfter(kAttributeIcePwdVideo, "a=x-opaque:foo:dGVzdDY0\r\n",
2625 &sdp_with_transport_parameters);
2626
2627 JsepSessionDescription jdesc_with_transport_parameters(kDummyType);
2628 EXPECT_TRUE(SdpDeserialize(sdp_with_transport_parameters,
2629 &jdesc_with_transport_parameters));
2630
2631 cricket::OpaqueTransportParameters params;
2632 params.protocol = "foo";
2633 params.parameters = "test64";
2634
2635 AddOpaqueTransportParameters(kAudioContentName, params);
2636 AddOpaqueTransportParameters(kVideoContentName, params);
2637
2638 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2639 jdesc_.session_version()));
2640 EXPECT_TRUE(
2641 CompareSessionDescription(jdesc_, jdesc_with_transport_parameters));
2642}
2643
Bjorn A Mellem8e1343a2019-09-30 15:12:47 -07002644TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithAltProtocol) {
2645 std::string sdp_with_alt_protocol = kSdpFullString;
2646 InjectAfter(kAttributeIcePwdVoice, "a=x-alt-protocol:foo\r\n",
2647 &sdp_with_alt_protocol);
2648 InjectAfter(kAttributeIcePwdVideo, "a=x-alt-protocol:bar\r\n",
2649 &sdp_with_alt_protocol);
2650
2651 JsepSessionDescription jdesc_with_alt_protocol(kDummyType);
2652 EXPECT_TRUE(SdpDeserialize(sdp_with_alt_protocol, &jdesc_with_alt_protocol));
2653
2654 AddAltProtocol(kAudioContentName, "foo");
2655 AddAltProtocol(kVideoContentName, "bar");
2656
2657 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2658 jdesc_.session_version()));
2659 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_alt_protocol));
2660}
2661
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002662TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2663 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 10:27:41 -08002664 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002665 std::string sdp_with_ufrag_pwd = kSdpFullString;
2666 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2667 // Add session level ufrag and pwd
2668 InjectAfter(kSessionTime,
Yves Gerey665174f2018-06-19 15:03:05 +02002669 "a=ice-pwd:session+level+icepwd\r\n"
2670 "a=ice-ufrag:session+level+iceufrag\r\n",
2671 &sdp_with_ufrag_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002672 // Add media level ufrag and pwd for audio
Yves Gerey665174f2018-06-19 15:03:05 +02002673 InjectAfter(
2674 "a=mid:audio_content_name\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002675 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2676 &sdp_with_ufrag_pwd);
2677 // Update the candidate ufrag and pwd to the expected ones.
Yves Gerey665174f2018-06-19 15:03:05 +02002678 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, "media+level+iceufrag",
2679 "media+level+icepwd"));
2680 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, "session+level+iceufrag",
2681 "session+level+icepwd"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002682 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2683 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2684}
2685
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002686TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002687 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002688}
2689
2690TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002691 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002692}
2693
2694TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002695 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002696}
2697
2698TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2699 EXPECT_TRUE(TestDeserializeRejected(true, false));
2700}
2701
2702TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2703 EXPECT_TRUE(TestDeserializeRejected(false, true));
2704}
2705
2706TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2707 EXPECT_TRUE(TestDeserializeRejected(true, true));
2708}
2709
Johannes Kron0854eb62018-10-10 22:33:20 +02002710TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002711 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002712 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2713 InjectAfter("t=0 0\r\n", kExtmapAllowMixed, &sdp_with_extmap_allow_mixed);
2714 // Deserialize
2715 JsepSessionDescription jdesc_deserialized(kDummyType);
2716 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2717 // Verify
2718 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2719}
2720
2721TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002722 jdesc_.description()->set_extmap_allow_mixed(false);
Johannes Kron0854eb62018-10-10 22:33:20 +02002723 std::string sdp_without_extmap_allow_mixed = kSdpFullString;
2724 // Deserialize
2725 JsepSessionDescription jdesc_deserialized(kDummyType);
2726 EXPECT_TRUE(
2727 SdpDeserialize(sdp_without_extmap_allow_mixed, &jdesc_deserialized));
2728 // Verify
2729 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2730}
2731
2732TEST_F(WebRtcSdpTest, DeserializeMediaContentDescriptionWithExtmapAllowMixed) {
2733 cricket::MediaContentDescription* video_desc =
2734 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2735 ASSERT_TRUE(video_desc);
2736 cricket::MediaContentDescription* audio_desc =
2737 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2738 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002739 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002740 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002741 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002742 cricket::MediaContentDescription::kMedia);
2743
2744 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2745 InjectAfter("a=mid:audio_content_name\r\n", kExtmapAllowMixed,
2746 &sdp_with_extmap_allow_mixed);
2747 InjectAfter("a=mid:video_content_name\r\n", kExtmapAllowMixed,
2748 &sdp_with_extmap_allow_mixed);
2749
2750 // Deserialize
2751 JsepSessionDescription jdesc_deserialized(kDummyType);
2752 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2753 // Verify
2754 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2755}
2756
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002757TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2758 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2759
2760 std::string sdp = kSdpOneCandidate;
2761 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2762 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2763 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2764 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002765 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002766
2767 // Candidate line without generation extension.
2768 sdp = kSdpOneCandidate;
2769 Replace(" generation 2", "", &sdp);
2770 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2771 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2772 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2773 Candidate expected = jcandidate_->candidate();
2774 expected.set_generation(0);
2775 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2776
honghaiza0c44ea2016-03-23 16:07:48 -07002777 // Candidate with network id and/or cost.
2778 sdp = kSdpOneCandidate;
2779 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2780 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2781 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2782 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2783 expected = jcandidate_->candidate();
2784 expected.set_network_id(2);
2785 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2786 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2787 // Add network cost
2788 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2789 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2790 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2791 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2792
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002793 sdp = kSdpTcpActiveCandidate;
2794 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2795 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002796 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002797 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2798 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2799 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002800 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2801 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
Yves Gerey665174f2018-06-19 15:03:05 +02002802 EXPECT_TRUE(
2803 jcandidate.candidate().IsEquivalent(jcandidate_template->candidate()));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002804 sdp = kSdpTcpPassiveCandidate;
2805 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2806 sdp = kSdpTcpSOCandidate;
2807 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002808}
2809
2810// This test verifies the deserialization of candidate-attribute
2811// as per RFC 5245. Candiate-attribute will be of the format
2812// candidate:<blah>. This format will be used when candidates
2813// are trickled.
2814TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2815 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2816
2817 std::string candidate_attribute = kRawCandidate;
2818 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2819 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2820 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2821 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2822 EXPECT_EQ(2u, jcandidate.candidate().generation());
2823
2824 // Candidate line without generation extension.
2825 candidate_attribute = kRawCandidate;
2826 Replace(" generation 2", "", &candidate_attribute);
2827 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2828 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2829 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2830 Candidate expected = jcandidate_->candidate();
2831 expected.set_generation(0);
2832 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2833
2834 // Candidate line without candidate:
2835 candidate_attribute = kRawCandidate;
2836 Replace("candidate:", "", &candidate_attribute);
2837 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2838
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002839 // Candidate line with IPV6 address.
2840 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
Zach Steinb336c272018-08-09 01:16:13 -07002841
2842 // Candidate line with hostname address.
2843 EXPECT_TRUE(SdpDeserializeCandidate(kRawHostnameCandidate, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002844}
2845
2846// This test verifies that the deserialization of an invalid candidate string
2847// fails.
2848TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
Yves Gerey665174f2018-06-19 15:03:05 +02002849 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002850
2851 std::string candidate_attribute = kRawCandidate;
2852 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002853 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002854
2855 candidate_attribute = kSdpOneCandidate;
2856 candidate_attribute.replace(0, 1, "x");
2857 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2858
2859 candidate_attribute = kRawCandidate;
2860 candidate_attribute.append("\r\n");
2861 candidate_attribute.append(kRawCandidate);
2862 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2863
2864 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002865}
2866
2867TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2868 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002869 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002870 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002871
2872 std::string sdp_with_data = kSdpString;
2873 sdp_with_data.append(kSdpRtpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002874 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002875
2876 // Deserialize
2877 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2878 // Verify
2879 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2880}
2881
2882TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002883 bool use_sctpmap = true;
2884 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002885 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002886 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002887
2888 std::string sdp_with_data = kSdpString;
2889 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002890 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002891
Guido Urdanetacecf87f2019-05-31 10:17:38 +00002892 // Verify with UDP/DTLS/SCTP (already in kSdpSctpDataChannelString).
lally@webrtc.org36300852015-02-24 20:19:35 +00002893 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2894 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2895
Guido Urdanetacecf87f2019-05-31 10:17:38 +00002896 // Verify with DTLS/SCTP.
2897 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2898 kDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002899 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2900 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2901
2902 // Verify with TCP/DTLS/SCTP.
Guido Urdanetacecf87f2019-05-31 10:17:38 +00002903 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
Yves Gerey665174f2018-06-19 15:03:05 +02002904 kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002905 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2906 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2907}
2908
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002909TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002910 bool use_sctpmap = false;
2911 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002912 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002913 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002914
2915 std::string sdp_with_data = kSdpString;
2916 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002917 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002918
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002919 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2920 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2921}
2922
lally69f57602015-10-08 10:15:04 -07002923TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002924 bool use_sctpmap = false;
2925 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002926 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002927 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
lally69f57602015-10-08 10:15:04 -07002928
2929 std::string sdp_with_data = kSdpString;
2930 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002931 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 10:15:04 -07002932
lally69f57602015-10-08 10:15:04 -07002933 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2934 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2935}
2936
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002937// Helper function to set the max-message-size parameter in the
2938// SCTP data codec.
2939void MutateJsepSctpMaxMessageSize(const SessionDescription& desc,
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002940 int new_value,
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002941 JsepSessionDescription* jdesc) {
Harald Alvestrand8da35a62019-05-10 09:31:04 +02002942 std::unique_ptr<cricket::SessionDescription> mutant = desc.Clone();
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002943 SctpDataContentDescription* dcdesc =
2944 mutant->GetContentDescriptionByName(kDataContentName)->as_sctp();
2945 dcdesc->set_max_message_size(new_value);
Harald Alvestrand8da35a62019-05-10 09:31:04 +02002946 jdesc->Initialize(std::move(mutant), kSessionId, kSessionVersion);
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002947}
2948
2949TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithMaxMessageSize) {
2950 bool use_sctpmap = false;
2951 AddSctpDataChannel(use_sctpmap);
2952 JsepSessionDescription jdesc(kDummyType);
2953 std::string sdp_with_data = kSdpString;
2954
2955 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
2956 sdp_with_data.append("a=max-message-size:12345\r\n");
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002957 MutateJsepSctpMaxMessageSize(desc_, 12345, &jdesc);
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002958 JsepSessionDescription jdesc_output(kDummyType);
2959
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002960 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2961 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2962}
2963
Harald Alvestrandfbb45bd2019-05-15 08:07:47 +02002964TEST_F(WebRtcSdpTest, SerializeSdpWithSctpDataChannelWithMaxMessageSize) {
2965 bool use_sctpmap = false;
2966 AddSctpDataChannel(use_sctpmap);
2967 JsepSessionDescription jdesc(kDummyType);
2968 MutateJsepSctpMaxMessageSize(desc_, 12345, &jdesc);
2969 std::string message = webrtc::SdpSerialize(jdesc);
2970 EXPECT_NE(std::string::npos,
2971 message.find("\r\na=max-message-size:12345\r\n"));
2972 JsepSessionDescription jdesc_output(kDummyType);
2973 EXPECT_TRUE(SdpDeserialize(message, &jdesc_output));
2974 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2975}
2976
2977TEST_F(WebRtcSdpTest,
2978 SerializeSdpWithSctpDataChannelWithDefaultMaxMessageSize) {
2979 // https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-26#section-6
2980 // The default max message size is 64K.
2981 bool use_sctpmap = false;
2982 AddSctpDataChannel(use_sctpmap);
2983 JsepSessionDescription jdesc(kDummyType);
2984 MutateJsepSctpMaxMessageSize(desc_, 65536, &jdesc);
2985 std::string message = webrtc::SdpSerialize(jdesc);
2986 EXPECT_EQ(std::string::npos, message.find("\r\na=max-message-size:"));
2987 JsepSessionDescription jdesc_output(kDummyType);
2988 EXPECT_TRUE(SdpDeserialize(message, &jdesc_output));
2989 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2990}
2991
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002992// Test to check the behaviour if sctp-port is specified
2993// on the m= line and in a=sctp-port.
2994TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002995 bool use_sctpmap = true;
2996 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002997 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002998 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002999
3000 std::string sdp_with_data = kSdpString;
3001 // Append m= attributes
3002 sdp_with_data.append(kSdpSctpDataChannelString);
3003 // Append a=sctp-port attribute
3004 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 10:27:41 -08003005 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003006
3007 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
3008}
3009
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003010// Test behavior if a=rtpmap occurs in an SCTP section.
3011TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpmapAttribute) {
3012 std::string sdp_with_data = kSdpString;
3013 // Append m= attributes
3014 sdp_with_data.append(kSdpSctpDataChannelString);
3015 // Append a=rtpmap attribute
3016 sdp_with_data.append("a=rtpmap:111 opus/48000/2\r\n");
3017 JsepSessionDescription jdesc_output(kDummyType);
3018 // Correct behavior is to ignore the extra attribute.
3019 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3020}
3021
3022TEST_F(WebRtcSdpTest, DeserializeSdpWithStrangeApplicationProtocolNames) {
3023 static const char* bad_strings[] = {"DTLS/SCTPRTP/", "obviously-bogus",
3024 "UDP/TL/RTSP/SAVPF", "UDP/TL/RTSP/S"};
3025 for (auto proto : bad_strings) {
3026 std::string sdp_with_data = kSdpString;
3027 sdp_with_data.append("m=application 9 ");
3028 sdp_with_data.append(proto);
3029 sdp_with_data.append(" 47\r\n");
3030 JsepSessionDescription jdesc_output(kDummyType);
3031 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output))
3032 << "Parsing should have failed on " << proto;
3033 }
3034 // The following strings are strange, but acceptable as RTP.
3035 static const char* weird_strings[] = {"DTLS/SCTP/RTP/FOO",
3036 "obviously-bogus/RTP/"};
3037 for (auto proto : weird_strings) {
3038 std::string sdp_with_data = kSdpString;
3039 sdp_with_data.append("m=application 9 ");
3040 sdp_with_data.append(proto);
3041 sdp_with_data.append(" 47\r\n");
3042 JsepSessionDescription jdesc_output(kDummyType);
3043 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output))
3044 << "Parsing should have succeeded on " << proto;
3045 }
3046}
3047
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00003048// For crbug/344475.
3049TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
3050 std::string sdp_with_data = kSdpString;
3051 sdp_with_data.append(kSdpSctpDataChannelString);
3052 // Remove the "\n" at the end.
3053 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 10:27:41 -08003054 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00003055
3056 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
3057 // No crash is a pass.
3058}
3059
zstein4b2e0822017-02-17 19:48:38 -08003060TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
3061 bool use_sctpmap = true;
3062 AddSctpDataChannel(use_sctpmap);
3063
3064 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 10:27:41 -08003065 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003066 MutateJsepSctpPort(&jdesc, desc_, kUnusualSctpPort);
wu@webrtc.org78187522013-10-07 23:32:02 +00003067
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00003068 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00003069 std::string sdp_with_data = kSdpString;
3070 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Anton1c9c9fc2019-02-14 15:13:09 -08003071 absl::StrReplaceAll(
3072 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}},
3073 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08003074 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:02 +00003075
3076 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3077 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08003078}
3079
3080TEST_F(WebRtcSdpTest,
3081 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
3082 bool use_sctpmap = false;
3083 AddSctpDataChannel(use_sctpmap);
3084
Steve Antona3a92c22017-12-07 10:27:41 -08003085 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003086 MutateJsepSctpPort(&jdesc, desc_, kUnusualSctpPort);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003087
3088 // We need to test the deserialized JsepSessionDescription from
3089 // kSdpSctpDataChannelStringWithSctpPort for
3090 // draft-ietf-mmusic-sctp-sdp-07
3091 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08003092 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003093 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Anton1c9c9fc2019-02-14 15:13:09 -08003094 absl::StrReplaceAll(
3095 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}},
3096 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08003097 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003098
3099 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3100 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00003101}
3102
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003103TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003104 // We want to test that deserializing data content limits bandwidth
3105 // settings (it should never be greater than the default).
3106 // This should prevent someone from using unlimited data bandwidth through
3107 // JS and "breaking the Internet".
3108 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003109 std::string sdp_with_bandwidth = kSdpString;
3110 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02003111 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003112 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08003113 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003114
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003115 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
3116}
3117
3118TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08003119 bool use_sctpmap = true;
3120 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08003121 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003122 SctpDataContentDescription* dcd = GetFirstSctpDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003123 dcd->set_bandwidth(100 * 1000);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003124 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003125
3126 std::string sdp_with_bandwidth = kSdpString;
3127 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02003128 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003129 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08003130 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003131
3132 // SCTP has congestion control, so we shouldn't limit the bandwidth
3133 // as we do for RTP.
3134 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003135 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
3136}
3137
Yves Gerey665174f2018-06-19 15:03:05 +02003138class WebRtcSdpExtmapTest : public WebRtcSdpTest,
Mirko Bonadei6a489f22019-04-09 15:11:12 +02003139 public ::testing::WithParamInterface<bool> {};
jbauch5869f502017-06-29 12:31:36 -07003140
3141TEST_P(WebRtcSdpExtmapTest,
Yves Gerey665174f2018-06-19 15:03:05 +02003142 DeserializeSessionDescriptionWithSessionLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003143 bool encrypted = GetParam();
3144 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003145}
3146
Yves Gerey665174f2018-06-19 15:03:05 +02003147TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003148 bool encrypted = GetParam();
3149 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003150}
3151
Yves Gerey665174f2018-06-19 15:03:05 +02003152TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithInvalidExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003153 bool encrypted = GetParam();
3154 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003155}
3156
Mirko Bonadeic84f6612019-01-31 12:20:57 +01003157INSTANTIATE_TEST_SUITE_P(Encrypted,
3158 WebRtcSdpExtmapTest,
3159 ::testing::Values(false, true));
jbauch5869f502017-06-29 12:31:36 -07003160
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003161TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 10:27:41 -08003162 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003163 std::string sdp = kSdpFullString;
3164 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
3165 // Deserialize
3166 SdpParseError error;
3167 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
Philipp Hanckee3f257c2020-02-19 16:25:52 +01003168 const std::string lastline = "a=ssrc:3 msid:local_stream_1 video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003169 EXPECT_EQ(lastline, error.line);
3170 EXPECT_EQ("Invalid SDP line.", error.description);
3171}
3172
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003173TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
3174 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
3175 std::string new_sdp = kSdpOneCandidate;
3176 Replace("udp", "unsupported_transport", &new_sdp);
3177 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3178 new_sdp = kSdpOneCandidate;
3179 Replace("udp", "uDP", &new_sdp);
3180 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3181 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3182 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3183 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
3184}
3185
honghaiza54a0802015-12-16 18:37:23 -08003186TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003187 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08003188 EXPECT_TRUE(
3189 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003190 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3191 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3192 Candidate ref_candidate = jcandidate_->candidate();
3193 ref_candidate.set_username("user_rtp");
3194 ref_candidate.set_password("password_rtp");
3195 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
3196}
3197
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003198TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08003199 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003200
3201 // Deserialize
3202 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
3203
3204 // Verify
3205 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08003206 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003207 EXPECT_TRUE(audio->conference_mode());
3208
3209 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 15:55:30 -08003210 cricket::GetFirstVideoContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003211 EXPECT_TRUE(video->conference_mode());
3212}
3213
deadbeefd45aea82017-09-16 01:24:29 -07003214TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08003215 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 01:24:29 -07003216
3217 // We tested deserialization already above, so just test that if we serialize
3218 // and deserialize the flag doesn't disappear.
3219 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 12:22:16 -08003220 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 01:24:29 -07003221 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
3222
3223 // Verify.
3224 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08003225 cricket::GetFirstAudioContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 01:24:29 -07003226 EXPECT_TRUE(audio->conference_mode());
3227
3228 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 15:55:30 -08003229 cricket::GetFirstVideoContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 01:24:29 -07003230 EXPECT_TRUE(video->conference_mode());
3231}
3232
Sebastian Jansson97321b62019-07-24 14:01:18 +02003233TEST_F(WebRtcSdpTest, SerializeAndDeserializeRemoteNetEstimate) {
3234 {
3235 // By default remote estimates are disabled.
3236 JsepSessionDescription dst(kDummyType);
3237 SdpDeserialize(webrtc::SdpSerialize(jdesc_), &dst);
3238 EXPECT_FALSE(cricket::GetFirstVideoContentDescription(dst.description())
3239 ->remote_estimate());
3240 }
3241 {
3242 // When remote estimate is enabled, the setting is propagated via SDP.
3243 cricket::GetFirstVideoContentDescription(jdesc_.description())
3244 ->set_remote_estimate(true);
3245 JsepSessionDescription dst(kDummyType);
3246 SdpDeserialize(webrtc::SdpSerialize(jdesc_), &dst);
3247 EXPECT_TRUE(cricket::GetFirstVideoContentDescription(dst.description())
3248 ->remote_estimate());
3249 }
3250}
3251
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003252TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
3253 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003254 const char kSdpEmptyType[] = " =candidate";
3255 const char kSdpEqualAsPlus[] = "a+candidate";
3256 const char kSdpSpaceAfterEqual[] = "a= candidate";
3257 const char kSdpUpperType[] = "A=candidate";
3258 const char kSdpEmptyLine[] = "";
3259 const char kSdpMissingValue[] = "a=";
3260
Yves Gerey665174f2018-06-19 15:03:05 +02003261 const char kSdpBrokenFingerprint[] =
3262 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003263 "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 +02003264 const char kSdpExtraField[] =
3265 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003266 "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 +02003267 const char kSdpMissingSpace[] =
3268 "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003269 "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 +00003270 // MD5 is not allowed in fingerprints.
Yves Gerey665174f2018-06-19 15:03:05 +02003271 const char kSdpMd5[] =
3272 "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003273 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003274
3275 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003276 ExpectParseFailure("v=", kSdpDestroyer);
3277 ExpectParseFailure("o=", kSdpDestroyer);
3278 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003279 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003280 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003281
3282 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003283 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
3284 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003285
3286 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003287 ExpectParseFailure("a=candidate", kSdpEmptyType);
3288 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
3289 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
3290 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003291
3292 // Bogus fingerprint replacing a=sendrev. We selected this attribute
3293 // because it's orthogonal to what we are replacing and hence
3294 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003295 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
3296 ExpectParseFailure("a=sendrecv", kSdpExtraField);
3297 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
3298 ExpectParseFailure("a=sendrecv", kSdpMd5);
3299
3300 // Empty Line
3301 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
3302 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003303}
3304
3305TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
3306 // ssrc
3307 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08003308 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003309 // crypto
3310 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
3311 // rtpmap
3312 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
3313 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
3314 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
3315 // candidate
3316 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
3317 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
3318 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
3319 ExpectParseFailure("rport 2346", "rport badvalue");
3320 ExpectParseFailure("rport 2346 generation 2",
3321 "rport 2346 generation badvalue");
3322 // m line
3323 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
3324 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
3325
3326 // bandwidth
3327 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003328 "b=AS:badvalue\r\n", "b=AS:badvalue");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003329 // rtcp-fb
3330 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3331 "a=rtcp-fb:badvalue nack\r\n",
3332 "a=rtcp-fb:badvalue nack");
3333 // extmap
3334 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3335 "a=extmap:badvalue http://example.com\r\n",
3336 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003337}
3338
3339TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 10:27:41 -08003340 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003341
3342 const char kSdpWithReorderedPlTypesString[] =
3343 "v=0\r\n"
3344 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3345 "s=-\r\n"
3346 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00003347 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
Yves Gerey665174f2018-06-19 15:03:05 +02003348 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
3349 // in the map.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003350 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003351 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003352
3353 // Deserialize
3354 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
3355
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003356 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003357 GetFirstAudioContentDescription(jdesc_output.description());
3358 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003359 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003360 EXPECT_EQ("ISAC", acd->codecs()[0].name);
3361 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003362 EXPECT_EQ(104, acd->codecs()[0].id);
3363}
3364
3365TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 10:27:41 -08003366 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003367 CodecParams params;
3368 params.max_ptime = 40;
3369 params.ptime = 30;
3370 params.min_ptime = 10;
3371 params.sprop_stereo = 1;
3372 params.stereo = 1;
3373 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003374 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003375 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 12:22:16 -08003376 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003377}
3378
3379TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
3380 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 10:27:41 -08003381 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003382 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003383 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003384}
3385
3386TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
3387 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 10:27:41 -08003388 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003389 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003390 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003391}
3392
3393TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 10:27:41 -08003394 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003395
3396 const char kSdpWithFmtpString[] =
3397 "v=0\r\n"
3398 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3399 "s=-\r\n"
3400 "t=0 0\r\n"
3401 "m=video 3457 RTP/SAVPF 120\r\n"
3402 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07003403 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3404
3405 // Deserialize
3406 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07003407 EXPECT_TRUE(
3408 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07003409
Donald Curtis0e07f922015-05-15 09:21:23 -07003410 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003411 GetFirstVideoContentDescription(jdesc_output.description());
3412 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 09:21:23 -07003413 ASSERT_FALSE(vcd->codecs().empty());
3414 cricket::VideoCodec vp8 = vcd->codecs()[0];
3415 EXPECT_EQ("VP8", vp8.name);
3416 EXPECT_EQ(120, vp8.id);
3417 cricket::CodecParameterMap::iterator found =
3418 vp8.params.find("x-google-min-bitrate");
3419 ASSERT_TRUE(found != vp8.params.end());
3420 EXPECT_EQ(found->second, "10");
3421 found = vp8.params.find("x-google-max-quantization");
3422 ASSERT_TRUE(found != vp8.params.end());
3423 EXPECT_EQ(found->second, "40");
3424}
3425
johan2d8d23e2016-06-03 01:22:42 -07003426TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 10:27:41 -08003427 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 01:22:42 -07003428
3429 const char kSdpWithFmtpString[] =
3430 "v=0\r\n"
3431 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3432 "s=-\r\n"
3433 "t=0 0\r\n"
3434 "m=video 49170 RTP/AVP 98\r\n"
3435 "a=rtpmap:98 H264/90000\r\n"
3436 "a=fmtp:98 profile-level-id=42A01E; "
3437 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3438
3439 // Deserialize.
3440 SdpParseError error;
3441 EXPECT_TRUE(
3442 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3443
johan2d8d23e2016-06-03 01:22:42 -07003444 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003445 GetFirstVideoContentDescription(jdesc_output.description());
3446 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 01:22:42 -07003447 ASSERT_FALSE(vcd->codecs().empty());
3448 cricket::VideoCodec h264 = vcd->codecs()[0];
3449 EXPECT_EQ("H264", h264.name);
3450 EXPECT_EQ(98, h264.id);
3451 cricket::CodecParameterMap::const_iterator found =
3452 h264.params.find("profile-level-id");
3453 ASSERT_TRUE(found != h264.params.end());
3454 EXPECT_EQ(found->second, "42A01E");
3455 found = h264.params.find("sprop-parameter-sets");
3456 ASSERT_TRUE(found != h264.params.end());
3457 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3458}
3459
Donald Curtis0e07f922015-05-15 09:21:23 -07003460TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 10:27:41 -08003461 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 09:21:23 -07003462
3463 const char kSdpWithFmtpString[] =
3464 "v=0\r\n"
3465 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3466 "s=-\r\n"
3467 "t=0 0\r\n"
3468 "m=video 3457 RTP/SAVPF 120\r\n"
3469 "a=rtpmap:120 VP8/90000\r\n"
3470 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003471
3472 // Deserialize
3473 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02003474 EXPECT_TRUE(
3475 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003476
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003477 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003478 GetFirstVideoContentDescription(jdesc_output.description());
3479 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003480 ASSERT_FALSE(vcd->codecs().empty());
3481 cricket::VideoCodec vp8 = vcd->codecs()[0];
3482 EXPECT_EQ("VP8", vp8.name);
3483 EXPECT_EQ(120, vp8.id);
3484 cricket::CodecParameterMap::iterator found =
3485 vp8.params.find("x-google-min-bitrate");
3486 ASSERT_TRUE(found != vp8.params.end());
3487 EXPECT_EQ(found->second, "10");
3488 found = vp8.params.find("x-google-max-quantization");
3489 ASSERT_TRUE(found != vp8.params.end());
3490 EXPECT_EQ(found->second, "40");
3491}
3492
Mirta Dvornicic479a3c02019-06-04 15:38:50 +02003493TEST_F(WebRtcSdpTest, DeserializePacketizationAttributeWithIllegalValue) {
3494 JsepSessionDescription jdesc_output(kDummyType);
3495
3496 const char kSdpWithPacketizationString[] =
3497 "v=0\r\n"
3498 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3499 "s=-\r\n"
3500 "t=0 0\r\n"
3501 "m=audio 9 RTP/SAVPF 111\r\n"
3502 "a=rtpmap:111 opus/48000/2\r\n"
3503 "a=packetization:111 unknownpacketizationattributeforaudio\r\n"
3504 "m=video 3457 RTP/SAVPF 120 121 122\r\n"
3505 "a=rtpmap:120 VP8/90000\r\n"
3506 "a=packetization:120 raw\r\n"
3507 "a=rtpmap:121 VP9/90000\r\n"
3508 "a=rtpmap:122 H264/90000\r\n"
3509 "a=packetization:122 unknownpacketizationattributevalue\r\n";
3510
3511 SdpParseError error;
3512 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithPacketizationString, &jdesc_output,
3513 &error));
3514
3515 AudioContentDescription* acd =
3516 GetFirstAudioContentDescription(jdesc_output.description());
3517 ASSERT_TRUE(acd);
3518 ASSERT_THAT(acd->codecs(), testing::SizeIs(1));
3519 cricket::AudioCodec opus = acd->codecs()[0];
3520 EXPECT_EQ(opus.name, "opus");
3521 EXPECT_EQ(opus.id, 111);
3522
3523 const VideoContentDescription* vcd =
3524 GetFirstVideoContentDescription(jdesc_output.description());
3525 ASSERT_TRUE(vcd);
3526 ASSERT_THAT(vcd->codecs(), testing::SizeIs(3));
3527 cricket::VideoCodec vp8 = vcd->codecs()[0];
3528 EXPECT_EQ(vp8.name, "VP8");
3529 EXPECT_EQ(vp8.id, 120);
3530 EXPECT_EQ(vp8.packetization, "raw");
3531 cricket::VideoCodec vp9 = vcd->codecs()[1];
3532 EXPECT_EQ(vp9.name, "VP9");
3533 EXPECT_EQ(vp9.id, 121);
3534 EXPECT_EQ(vp9.packetization, absl::nullopt);
3535 cricket::VideoCodec h264 = vcd->codecs()[2];
3536 EXPECT_EQ(h264.name, "H264");
3537 EXPECT_EQ(h264.id, 122);
3538 EXPECT_EQ(h264.packetization, absl::nullopt);
3539}
3540
ossuaa4b0772017-01-30 07:41:18 -08003541TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003542 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003543
3544 cricket::AudioCodecs codecs = acd->codecs();
3545 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3546 acd->set_codecs(codecs);
3547
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003548 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003549 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003550 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003551 std::string sdp_with_fmtp = kSdpFullString;
3552 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3553 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3554 &sdp_with_fmtp);
3555 EXPECT_EQ(sdp_with_fmtp, message);
3556}
3557
3558TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003559 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003560
3561 cricket::AudioCodecs codecs = acd->codecs();
3562 codecs[0].params["stereo"] = "1";
3563 acd->set_codecs(codecs);
3564
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003565 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003566 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003567 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003568 std::string sdp_with_fmtp = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003569 InjectAfter("a=rtpmap:111 opus/48000/2\r\n", "a=fmtp:111 stereo=1\r\n",
ossuaa4b0772017-01-30 07:41:18 -08003570 &sdp_with_fmtp);
3571 EXPECT_EQ(sdp_with_fmtp, message);
3572}
3573
3574TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003575 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003576
3577 cricket::AudioCodecs codecs = acd->codecs();
3578 codecs[0].params["ptime"] = "20";
3579 codecs[0].params["maxptime"] = "120";
3580 acd->set_codecs(codecs);
3581
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003582 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003583 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003584 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003585 std::string sdp_with_fmtp = kSdpFullString;
3586 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3587 "a=maxptime:120\r\n" // No comma here. String merging!
3588 "a=ptime:20\r\n",
3589 &sdp_with_fmtp);
3590 EXPECT_EQ(sdp_with_fmtp, message);
3591}
3592
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003593TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003594 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003595
3596 cricket::VideoCodecs codecs = vcd->codecs();
3597 codecs[0].params["x-google-min-bitrate"] = "10";
3598 vcd->set_codecs(codecs);
3599
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003600 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003601 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003602 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003603 std::string sdp_with_fmtp = kSdpFullString;
3604 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003605 "a=fmtp:120 x-google-min-bitrate=10\r\n", &sdp_with_fmtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003606 EXPECT_EQ(sdp_with_fmtp, message);
3607}
3608
Mirta Dvornicic479a3c02019-06-04 15:38:50 +02003609TEST_F(WebRtcSdpTest, SerializeVideoPacketizationAttribute) {
3610 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
3611
3612 cricket::VideoCodecs codecs = vcd->codecs();
3613 codecs[0].packetization = "raw";
3614 vcd->set_codecs(codecs);
3615
3616 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
3617 jdesc_.session_version()));
3618 std::string message = webrtc::SdpSerialize(jdesc_);
3619 std::string sdp_with_packetization = kSdpFullString;
3620 InjectAfter("a=rtpmap:120 VP8/90000\r\n", "a=packetization:120 raw\r\n",
3621 &sdp_with_packetization);
3622 EXPECT_EQ(sdp_with_packetization, message);
3623}
3624
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003625TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) {
3626 // Deserialize the baseline description, making sure it's ICE full.
Steve Antona3a92c22017-12-07 10:27:41 -08003627 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003628 std::string sdp_with_icelite = kSdpFullString;
3629 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3630 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3631 const cricket::TransportInfo* tinfo1 =
3632 desc->GetTransportInfoByName("audio_content_name");
3633 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3634 const cricket::TransportInfo* tinfo2 =
3635 desc->GetTransportInfoByName("video_content_name");
3636 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003637
3638 // Add "a=ice-lite" and deserialize, making sure it's ICE lite.
Yves Gerey665174f2018-06-19 15:03:05 +02003639 InjectAfter(kSessionTime, "a=ice-lite\r\n", &sdp_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003640 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3641 desc = jdesc_with_icelite.description();
3642 const cricket::TransportInfo* atinfo =
3643 desc->GetTransportInfoByName("audio_content_name");
3644 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3645 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003646 desc->GetTransportInfoByName("video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003647 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003648
3649 // Now that we know deserialization works, we can use TestSerialize to test
3650 // serialization.
3651 TestSerialize(jdesc_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003652}
3653
3654// Verifies that the candidates in the input SDP are parsed and serialized
3655// correctly in the output SDP.
3656TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3657 std::string sdp_with_data = kSdpString;
3658 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 10:27:41 -08003659 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003660
3661 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 12:22:16 -08003662 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003663}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003664
3665TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3666 AddFingerprint();
3667 TransportInfo audio_transport_info =
3668 *(desc_.GetTransportInfoByName(kAudioContentName));
3669 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3670 audio_transport_info.description.connection_role);
3671 audio_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003672 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003673
3674 TransportInfo video_transport_info =
3675 *(desc_.GetTransportInfoByName(kVideoContentName));
3676 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3677 video_transport_info.description.connection_role);
3678 video_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003679 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003680
3681 desc_.RemoveTransportInfoByName(kAudioContentName);
3682 desc_.RemoveTransportInfoByName(kVideoContentName);
3683
3684 desc_.AddTransportInfo(audio_transport_info);
3685 desc_.AddTransportInfo(video_transport_info);
3686
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003687 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003688 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003689 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003690 std::string sdp_with_dtlssetup = kSdpFullString;
3691
3692 // Fingerprint attribute is necessary to add DTLS setup attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003693 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_dtlssetup);
3694 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003695 // Now adding |setup| attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003696 InjectAfter(kFingerprint, "a=setup:active\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003697 EXPECT_EQ(sdp_with_dtlssetup, message);
3698}
3699
3700TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
Steve Antona3a92c22017-12-07 10:27:41 -08003701 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003702 std::string sdp_with_dtlssetup = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003703 InjectAfter(kSessionTime, "a=setup:actpass\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003704 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3705 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3706 const cricket::TransportInfo* atinfo =
3707 desc->GetTransportInfoByName("audio_content_name");
3708 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3709 atinfo->description.connection_role);
3710 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003711 desc->GetTransportInfoByName("video_content_name");
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003712 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3713 vtinfo->description.connection_role);
3714}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003715
3716// Verifies that the order of the serialized m-lines follows the order of the
3717// ContentInfo in SessionDescription, and vise versa for deserialization.
3718TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 10:27:41 -08003719 JsepSessionDescription jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02003720 const std::string media_content_sdps[3] = {kSdpAudioString, kSdpVideoString,
3721 kSdpSctpDataChannelString};
3722 const cricket::MediaType media_types[3] = {cricket::MEDIA_TYPE_AUDIO,
3723 cricket::MEDIA_TYPE_VIDEO,
3724 cricket::MEDIA_TYPE_DATA};
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003725
3726 // Verifies all 6 permutations.
3727 for (size_t i = 0; i < 6; ++i) {
3728 size_t media_content_in_sdp[3];
3729 // The index of the first media content.
3730 media_content_in_sdp[0] = i / 2;
3731 // The index of the second media content.
3732 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3733 // The index of the third media content.
3734 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3735
3736 std::string sdp_string = kSdpSessionString;
3737 for (size_t i = 0; i < 3; ++i)
3738 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3739
3740 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3741 cricket::SessionDescription* desc = jdesc.description();
3742 EXPECT_EQ(3u, desc->contents().size());
3743
3744 for (size_t i = 0; i < 3; ++i) {
3745 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 15:14:30 -08003746 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003747 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3748 }
3749
Steve Antone831b8c2018-02-01 12:22:16 -08003750 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003751 EXPECT_EQ(sdp_string, serialized_sdp);
3752 }
3753}
deadbeef9d3584c2016-02-16 17:54:10 -08003754
deadbeef25ed4352016-12-12 18:37:36 -08003755TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3756 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 10:27:41 -08003757 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003758 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003759 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3760 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3761}
3762
deadbeef12771a12017-01-03 13:53:47 -08003763// The semantics of "a=bundle-only" are only defined when it's used in
3764// combination with a 0 port on the m= line. We should ignore it if used with a
3765// nonzero port.
3766TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3767 // Make the base bundle-only description but unset the bundle-only flag.
3768 MakeBundleOnlyDescription();
3769 jdesc_.description()->contents()[1].bundle_only = false;
3770
3771 std::string modified_sdp = kBundleOnlySdpFullString;
3772 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08003773 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003774 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3775 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003776}
3777
3778TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3779 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003780 TestSerialize(jdesc_);
deadbeef25ed4352016-12-12 18:37:36 -08003781}
3782
deadbeef9d3584c2016-02-16 17:54:10 -08003783TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3784 MakePlanBDescription();
3785
Steve Antona3a92c22017-12-07 10:27:41 -08003786 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003787 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3788
3789 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3790}
3791
3792TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3793 MakePlanBDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003794 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-16 17:54:10 -08003795}
3796
3797TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3798 MakeUnifiedPlanDescription();
3799
Steve Antona3a92c22017-12-07 10:27:41 -08003800 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003801 EXPECT_TRUE(
3802 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3803
3804 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3805}
3806
3807TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3808 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003809 TestSerialize(jdesc_);
3810}
3811
Seth Hampson5b4f0752018-04-02 16:31:36 -07003812// This tests deserializing a Unified Plan SDP that is compatible with both
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003813// Unified Plan and Plan B style SDP, meaning that it contains both "a=ssrc
3814// msid" lines and "a=msid " lines. It tests the case for audio/video tracks
Seth Hampson5b4f0752018-04-02 16:31:36 -07003815// with no stream ids and multiple stream ids. For parsing this, the Unified
3816// Plan a=msid lines should take priority, because the Plan B style a=ssrc msid
3817// lines do not support multiple stream ids and no stream ids.
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003818TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionSpecialMsid) {
3819 // Create both msid lines for Plan B and Unified Plan support.
3820 MakeUnifiedPlanDescriptionMultipleStreamIds(
3821 cricket::kMsidSignalingMediaSection |
3822 cricket::kMsidSignalingSsrcAttribute);
Seth Hampson5b4f0752018-04-02 16:31:36 -07003823
3824 JsepSessionDescription deserialized_description(kDummyType);
3825 EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid,
3826 &deserialized_description));
3827
3828 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
Henrik Boström5b147782018-12-04 11:25:05 +01003829 EXPECT_EQ(cricket::kMsidSignalingMediaSection |
3830 cricket::kMsidSignalingSsrcAttribute,
3831 deserialized_description.description()->msid_signaling());
Seth Hampson5b4f0752018-04-02 16:31:36 -07003832}
3833
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003834// Tests the serialization of a Unified Plan SDP that is compatible for both
3835// Unified Plan and Plan B style SDPs, meaning that it contains both "a=ssrc
3836// msid" lines and "a=msid " lines. It tests the case for no stream ids and
3837// multiple stream ids.
3838TEST_F(WebRtcSdpTest, SerializeSessionDescriptionSpecialMsid) {
3839 // Create both msid lines for Plan B and Unified Plan support.
3840 MakeUnifiedPlanDescriptionMultipleStreamIds(
3841 cricket::kMsidSignalingMediaSection |
3842 cricket::kMsidSignalingSsrcAttribute);
3843 std::string serialized_sdp = webrtc::SdpSerialize(jdesc_);
3844 // We explicitly test that the serialized SDP string is equal to the hard
3845 // coded SDP string. This is necessary, because in the parser "a=msid" lines
3846 // take priority over "a=ssrc msid" lines. This means if we just used
3847 // TestSerialize(), it could serialize an SDP that omits "a=ssrc msid" lines,
3848 // and still pass, because the deserialized version would be the same.
3849 EXPECT_EQ(kUnifiedPlanSdpFullStringWithSpecialMsid, serialized_sdp);
3850}
3851
3852// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3853// that signal stream IDs) is deserialized appropriately. It tests the case for
3854// no stream ids and multiple stream ids.
3855TEST_F(WebRtcSdpTest, UnifiedPlanDeserializeSessionDescriptionSpecialMsid) {
3856 // Only create a=msid lines for strictly Unified Plan stream ID support.
3857 MakeUnifiedPlanDescriptionMultipleStreamIds(
3858 cricket::kMsidSignalingMediaSection);
3859
3860 JsepSessionDescription deserialized_description(kDummyType);
3861 std::string unified_plan_sdp_string =
3862 kUnifiedPlanSdpFullStringWithSpecialMsid;
3863 RemoveSsrcMsidLinesFromSdpString(&unified_plan_sdp_string);
3864 EXPECT_TRUE(
3865 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3866
3867 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3868}
3869
3870// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3871// that signal stream IDs) is serialized appropriately. It tests the case for no
3872// stream ids and multiple stream ids.
3873TEST_F(WebRtcSdpTest, UnifiedPlanSerializeSessionDescriptionSpecialMsid) {
3874 // Only create a=msid lines for strictly Unified Plan stream ID support.
3875 MakeUnifiedPlanDescriptionMultipleStreamIds(
3876 cricket::kMsidSignalingMediaSection);
3877
Seth Hampson5b4f0752018-04-02 16:31:36 -07003878 TestSerialize(jdesc_);
3879}
3880
Seth Hampson5897a6e2018-04-03 11:16:33 -07003881// This tests that a Unified Plan SDP with no a=ssrc lines is
3882// serialized/deserialized appropriately. In this case the
3883// MediaContentDescription will contain a StreamParams object that doesn't have
3884// any SSRCs. Vice versa, this will be created upon deserializing an SDP with no
3885// SSRC lines.
3886TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3887 MakeUnifiedPlanDescription();
3888 RemoveSsrcSignalingFromStreamParams();
3889 std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString;
3890 RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string);
3891
3892 JsepSessionDescription deserialized_description(kDummyType);
3893 EXPECT_TRUE(
3894 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3895 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3896}
3897
3898TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3899 MakeUnifiedPlanDescription();
3900 RemoveSsrcSignalingFromStreamParams();
3901
3902 TestSerialize(jdesc_);
3903}
3904
Steve Antone831b8c2018-02-01 12:22:16 -08003905TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
3906 JsepSessionDescription jsep_desc(kDummyType);
3907 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
3908 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3909}
3910
3911TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
3912 JsepSessionDescription jsep_desc(kDummyType);
3913 std::string sdp = kSdpSessionString;
3914 sdp += kSdpSctpDataChannelString;
3915 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3916 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3917}
3918
3919TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
3920 JsepSessionDescription jsep_desc(kDummyType);
3921 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
3922 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
3923 jsep_desc.description()->msid_signaling());
3924}
3925
3926TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
3927 JsepSessionDescription jsep_desc(kDummyType);
3928 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
3929 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
3930 jsep_desc.description()->msid_signaling());
3931}
3932
3933const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
3934const char kSsrcAttributeMsidLine[] =
3935 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
3936
3937TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
3938 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
3939 std::string sdp = webrtc::SdpSerialize(jdesc_);
3940
3941 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3942 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3943}
3944
3945TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
3946 jdesc_.description()->set_msid_signaling(
3947 cricket::kMsidSignalingSsrcAttribute);
3948 std::string sdp = webrtc::SdpSerialize(jdesc_);
3949
3950 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
3951 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3952}
3953
3954TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
3955 jdesc_.description()->set_msid_signaling(
3956 cricket::kMsidSignalingMediaSection |
3957 cricket::kMsidSignalingSsrcAttribute);
3958 std::string sdp = webrtc::SdpSerialize(jdesc_);
3959
3960 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3961 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-16 17:54:10 -08003962}
deadbeef7e146cb2016-09-28 10:04:34 -07003963
3964// Regression test for heap overflow bug:
3965// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3966TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 10:04:34 -07003967 // The issue occurs when the sctp-port attribute is found in a video
3968 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 12:43:58 -08003969 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 10:04:34 -07003970 "v=0\r\n"
3971 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3972 "s=-\r\n"
3973 "t=0 0\r\n"
3974 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3975 "a=sctp-port 5000\r\n"
3976 "a=fmtp:108 foo=10\r\n";
3977
3978 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3979 "sctp-port");
3980}
deadbeefb2362572016-12-13 16:37:06 -08003981
3982// Regression test for integer overflow bug:
3983// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3984TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003985 // Bandwidth attribute is the max signed 32-bit int, which will get
3986 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003987 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003988 "v=0\r\n"
3989 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3990 "s=-\r\n"
3991 "t=0 0\r\n"
3992 "m=video 3457 RTP/SAVPF 120\r\n"
3993 "b=AS:2147483647\r\n"
3994 "foo=fail\r\n";
3995
3996 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3997}
deadbeef7bcdb692017-01-20 12:43:58 -08003998
deadbeefbc88c6b2017-08-02 11:26:34 -07003999// Similar to the above, except that negative values are illegal, not just
4000// error-prone as large values are.
4001// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
4002TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
4003 static const char kSdpWithNegativeBandwidth[] =
4004 "v=0\r\n"
4005 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4006 "s=-\r\n"
4007 "t=0 0\r\n"
4008 "m=video 3457 RTP/SAVPF 120\r\n"
4009 "b=AS:-1000\r\n";
4010
4011 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
4012}
4013
deadbeef3e8016e2017-08-03 17:49:30 -07004014// An exception to the above rule: a value of -1 for b=AS should just be
4015// ignored, resulting in "kAutoBandwidth" in the deserialized object.
4016// Applications historically may be using "b=AS:-1" to mean "no bandwidth
4017// limit", but this is now what ommitting the attribute entirely will do, so
4018// ignoring it will have the intended effect.
4019TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
4020 static const char kSdpWithBandwidthOfNegativeOne[] =
4021 "v=0\r\n"
4022 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4023 "s=-\r\n"
4024 "t=0 0\r\n"
4025 "m=video 3457 RTP/SAVPF 120\r\n"
4026 "b=AS:-1\r\n";
4027
Steve Antona3a92c22017-12-07 10:27:41 -08004028 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-03 17:49:30 -07004029 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-03 17:49:30 -07004030 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08004031 GetFirstVideoContentDescription(jdesc_output.description());
4032 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-03 17:49:30 -07004033 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
4034}
4035
deadbeef7bcdb692017-01-20 12:43:58 -08004036// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
4037// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
4038// Regression test for:
4039// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
4040TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
4041 // Important piece is "ufrag foo pwd bar".
4042 static const char kSdpWithIceCredentialsInCandidateString[] =
4043 "v=0\r\n"
4044 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4045 "s=-\r\n"
4046 "t=0 0\r\n"
4047 "m=audio 9 RTP/SAVPF 111\r\n"
4048 "c=IN IP4 0.0.0.0\r\n"
4049 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4050 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4051 "a=rtpmap:111 opus/48000/2\r\n"
4052 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
4053 "generation 2 ufrag foo pwd bar\r\n";
4054
Steve Antona3a92c22017-12-07 10:27:41 -08004055 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 12:43:58 -08004056 EXPECT_TRUE(
4057 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
4058 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
4059 ASSERT_NE(nullptr, candidates);
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02004060 ASSERT_EQ(1U, candidates->count());
deadbeef7bcdb692017-01-20 12:43:58 -08004061 cricket::Candidate c = candidates->at(0)->candidate();
4062 EXPECT_EQ("ufrag_voice", c.username());
4063 EXPECT_EQ("pwd_voice", c.password());
4064}
deadbeef90f1e1e2017-02-10 12:35:05 -08004065
Johannes Kron211856b2018-09-06 12:12:28 +02004066// Test that attribute lines "a=ice-ufrag-something"/"a=ice-pwd-something" are
4067// ignored, and only the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
4068// Regression test for:
4069// https://bugs.chromium.org/p/webrtc/issues/detail?id=9712
4070TEST_F(WebRtcSdpTest, AttributeWithPartialMatchingNameIsIgnored) {
4071 static const char kSdpWithFooIceCredentials[] =
4072 "v=0\r\n"
4073 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4074 "s=-\r\n"
4075 "t=0 0\r\n"
4076 "m=audio 9 RTP/SAVPF 111\r\n"
4077 "c=IN IP4 0.0.0.0\r\n"
4078 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4079 "a=ice-ufrag-something:foo\r\na=ice-pwd-something:bar\r\n"
4080 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4081 "a=rtpmap:111 opus/48000/2\r\n"
4082 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
4083 "generation 2\r\n";
4084
4085 JsepSessionDescription jdesc_output(kDummyType);
4086 EXPECT_TRUE(SdpDeserialize(kSdpWithFooIceCredentials, &jdesc_output));
4087 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
4088 ASSERT_NE(nullptr, candidates);
4089 ASSERT_EQ(1U, candidates->count());
4090 cricket::Candidate c = candidates->at(0)->candidate();
4091 EXPECT_EQ("ufrag_voice", c.username());
4092 EXPECT_EQ("pwd_voice", c.password());
4093}
4094
deadbeef90f1e1e2017-02-10 12:35:05 -08004095// Test that SDP with an invalid port number in "a=candidate" lines is
4096// rejected, without crashing.
4097// Regression test for:
4098// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
4099TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
4100 static const char kSdpWithInvalidCandidatePort[] =
4101 "v=0\r\n"
4102 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4103 "s=-\r\n"
4104 "t=0 0\r\n"
4105 "m=audio 9 RTP/SAVPF 111\r\n"
4106 "c=IN IP4 0.0.0.0\r\n"
4107 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4108 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4109 "a=rtpmap:111 opus/48000/2\r\n"
4110 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
4111 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
4112
Steve Antona3a92c22017-12-07 10:27:41 -08004113 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 12:35:05 -08004114 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
4115}
deadbeefa4549d62017-02-10 17:26:22 -08004116
4117// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
4118// Regression test for:
4119// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
4120TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
4121 static const char kSdpWithMissingTrackId[] =
4122 "v=0\r\n"
4123 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4124 "s=-\r\n"
4125 "t=0 0\r\n"
4126 "m=audio 9 RTP/SAVPF 111\r\n"
4127 "c=IN IP4 0.0.0.0\r\n"
4128 "a=rtpmap:111 opus/48000/2\r\n"
4129 "a=msid:stream_id \r\n";
4130
Steve Antona3a92c22017-12-07 10:27:41 -08004131 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08004132 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
4133}
4134
4135TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
4136 static const char kSdpWithMissingStreamId[] =
4137 "v=0\r\n"
4138 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4139 "s=-\r\n"
4140 "t=0 0\r\n"
4141 "m=audio 9 RTP/SAVPF 111\r\n"
4142 "c=IN IP4 0.0.0.0\r\n"
4143 "a=rtpmap:111 opus/48000/2\r\n"
4144 "a=msid: track_id\r\n";
4145
Steve Antona3a92c22017-12-07 10:27:41 -08004146 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08004147 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
4148}
zhihuang38989e52017-03-21 11:04:53 -07004149
4150// Tests that if both session-level address and media-level address exist, use
4151// the media-level address.
4152TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 10:27:41 -08004153 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004154
4155 // Sesssion-level address.
4156 std::string sdp = kSdpFullString;
4157 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
4158 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4159
4160 const auto& content1 = jsep_desc.description()->contents()[0];
4161 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 15:14:30 -08004162 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004163 const auto& content2 = jsep_desc.description()->contents()[1];
4164 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 15:14:30 -08004165 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004166}
4167
4168// Tests that the session-level connection address will be used if the media
4169// level-addresses are not specified.
4170TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 10:27:41 -08004171 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004172
4173 // Sesssion-level address.
4174 std::string sdp = kSdpString;
4175 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
4176 // Remove the media level addresses.
4177 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
4178 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
4179 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4180
4181 const auto& content1 = jsep_desc.description()->contents()[0];
4182 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004183 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004184 const auto& content2 = jsep_desc.description()->contents()[1];
4185 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004186 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004187}
4188
4189TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 10:27:41 -08004190 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004191
4192 std::string sdp = kSdpString;
4193 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4194 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
4195 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
4196 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
4197 &sdp);
4198 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
4199 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
4200 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
4201 &sdp);
4202 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4203 const auto& content1 = jsep_desc.description()->contents()[0];
4204 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004205 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004206 const auto& content2 = jsep_desc.description()->contents()[1];
4207 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004208 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004209}
4210
Qingsi Wang56991422019-02-08 12:53:06 -08004211// Test that a c= line that contains a hostname connection address can be
4212// parsed.
4213TEST_F(WebRtcSdpTest, ParseConnectionDataWithHostnameConnectionAddress) {
4214 JsepSessionDescription jsep_desc(kDummyType);
4215 std::string sdp = kSdpString;
4216 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4217
4218 sdp = kSdpString;
4219 Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp);
4220 Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp);
4221 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4222
4223 ASSERT_NE(nullptr, jsep_desc.description());
4224 const auto& content1 = jsep_desc.description()->contents()[0];
4225 EXPECT_EQ("example.local:9",
4226 content1.media_description()->connection_address().ToString());
4227 const auto& content2 = jsep_desc.description()->contents()[1];
4228 EXPECT_EQ("example.local:9",
4229 content2.media_description()->connection_address().ToString());
4230}
4231
4232// Test that the invalid or unsupported connection data cannot be parsed.
zhihuang38989e52017-03-21 11:04:53 -07004233TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 10:27:41 -08004234 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004235 std::string sdp = kSdpString;
4236 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4237
4238 // Unsupported multicast IPv4 address.
4239 sdp = kSdpFullString;
4240 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
4241 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4242
4243 // Unsupported multicast IPv6 address.
4244 sdp = kSdpFullString;
4245 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
4246 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4247
4248 // Mismatched address type.
4249 sdp = kSdpFullString;
4250 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
4251 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4252
4253 sdp = kSdpFullString;
4254 Replace("c=IN IP4 74.125.224.39\r\n",
4255 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
4256 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4257}
4258
4259TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 10:27:41 -08004260 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004261 MakeDescriptionWithoutCandidates(&expected_jsep);
4262 // Serialization.
Steve Antone831b8c2018-02-01 12:22:16 -08004263 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 11:04:53 -07004264 // Deserialization.
Steve Antona3a92c22017-12-07 10:27:41 -08004265 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004266 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 15:14:30 -08004267 auto audio_desc = jdesc.description()
4268 ->GetContentByName(kAudioContentName)
4269 ->media_description();
4270 auto video_desc = jdesc.description()
4271 ->GetContentByName(kVideoContentName)
4272 ->media_description();
zhihuang38989e52017-03-21 11:04:53 -07004273 EXPECT_EQ(audio_desc_->connection_address().ToString(),
4274 audio_desc->connection_address().ToString());
4275 EXPECT_EQ(video_desc_->connection_address().ToString(),
4276 video_desc->connection_address().ToString());
4277}
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07004278
4279// RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be
4280// used (i.e., a single space as the session name)." So we should accept that.
4281TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) {
4282 JsepSessionDescription jsep_desc(kDummyType);
4283 std::string sdp = kSdpString;
4284 Replace("s=-\r\n", "s= \r\n", &sdp);
4285 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4286}
Amit Hilbucha2012042018-12-03 11:35:05 -08004287
4288// Simulcast malformed input test for invalid format.
4289TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_EmptyAttribute) {
Philipp Hanckee3f257c2020-02-19 16:25:52 +01004290 ExpectParseFailureWithNewLines(
4291 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n", "a=simulcast:\r\n",
4292 "a=simulcast:");
Amit Hilbucha2012042018-12-03 11:35:05 -08004293}
4294
4295// Tests that duplicate simulcast entries in the SDP triggers a parse failure.
4296TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_DuplicateAttribute) {
Philipp Hanckee3f257c2020-02-19 16:25:52 +01004297 ExpectParseFailureWithNewLines(
4298 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n",
4299 "a=simulcast:send 1\r\na=simulcast:recv 2\r\n", "a=simulcast:");
Amit Hilbucha2012042018-12-03 11:35:05 -08004300}
4301
4302// Validates that deserialization uses the a=simulcast: attribute
4303TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttribute) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004304 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4305 sdp += "a=rid:1 send\r\n";
4306 sdp += "a=rid:2 send\r\n";
4307 sdp += "a=rid:3 send\r\n";
4308 sdp += "a=rid:4 recv\r\n";
4309 sdp += "a=rid:5 recv\r\n";
4310 sdp += "a=rid:6 recv\r\n";
Amit Hilbucha2012042018-12-03 11:35:05 -08004311 sdp += "a=simulcast:send 1,2;3 recv 4;5;6\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 EXPECT_EQ(2ul, media->simulcast_description().send_layers().size());
4320 EXPECT_EQ(3ul, media->simulcast_description().receive_layers().size());
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004321 EXPECT_FALSE(media->streams().empty());
4322 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4323 CompareRidDescriptionIds(rids, {"1", "2", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004324}
4325
4326// Validates that deserialization removes rids that do not appear in SDP
4327TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttributeRemovesUnknownRids) {
4328 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4329 sdp += "a=rid:1 send\r\n";
4330 sdp += "a=rid:3 send\r\n";
4331 sdp += "a=rid:4 recv\r\n";
4332 sdp += "a=simulcast:send 1,2;3 recv 4;5,6\r\n";
4333 JsepSessionDescription output(kDummyType);
4334 SdpParseError error;
4335 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4336 const cricket::ContentInfos& contents = output.description()->contents();
4337 const cricket::MediaContentDescription* media =
4338 contents.back().media_description();
4339 EXPECT_TRUE(media->HasSimulcast());
4340 const SimulcastDescription& simulcast = media->simulcast_description();
4341 EXPECT_EQ(2ul, simulcast.send_layers().size());
4342 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4343
4344 std::vector<SimulcastLayer> all_send_layers =
4345 simulcast.send_layers().GetAllLayers();
4346 EXPECT_EQ(2ul, all_send_layers.size());
Steve Anton64b626b2019-01-28 17:25:26 -08004347 EXPECT_EQ(0,
4348 absl::c_count_if(all_send_layers, [](const SimulcastLayer& layer) {
4349 return layer.rid == "2";
4350 }));
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004351
4352 std::vector<SimulcastLayer> all_receive_layers =
4353 simulcast.receive_layers().GetAllLayers();
4354 ASSERT_EQ(1ul, all_receive_layers.size());
4355 EXPECT_EQ("4", all_receive_layers[0].rid);
4356
4357 EXPECT_FALSE(media->streams().empty());
4358 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4359 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004360}
4361
4362// Validates that Simulcast removes rids that appear in both send and receive.
4363TEST_F(WebRtcSdpTest,
4364 TestDeserializeSimulcastAttributeRemovesDuplicateSendReceive) {
4365 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4366 sdp += "a=rid:1 send\r\n";
4367 sdp += "a=rid:2 send\r\n";
4368 sdp += "a=rid:3 send\r\n";
4369 sdp += "a=rid:4 recv\r\n";
4370 sdp += "a=simulcast:send 1;2;3 recv 2;4\r\n";
4371 JsepSessionDescription output(kDummyType);
4372 SdpParseError error;
4373 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4374 const cricket::ContentInfos& contents = output.description()->contents();
4375 const cricket::MediaContentDescription* media =
4376 contents.back().media_description();
4377 EXPECT_TRUE(media->HasSimulcast());
4378 const SimulcastDescription& simulcast = media->simulcast_description();
4379 EXPECT_EQ(2ul, simulcast.send_layers().size());
4380 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4381 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4382 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4383
4384 EXPECT_FALSE(media->streams().empty());
4385 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4386 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004387}
4388
4389// Ignores empty rid line.
4390TEST_F(WebRtcSdpTest, TestDeserializeIgnoresEmptyRidLines) {
4391 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4392 sdp += "a=rid:1 send\r\n";
4393 sdp += "a=rid:2 send\r\n";
4394 sdp += "a=rid\r\n"; // Should ignore this line.
4395 sdp += "a=rid:\r\n"; // Should ignore this line.
4396 sdp += "a=simulcast:send 1;2\r\n";
4397 JsepSessionDescription output(kDummyType);
4398 SdpParseError error;
4399 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4400 const cricket::ContentInfos& contents = output.description()->contents();
4401 const cricket::MediaContentDescription* media =
4402 contents.back().media_description();
4403 EXPECT_TRUE(media->HasSimulcast());
4404 const SimulcastDescription& simulcast = media->simulcast_description();
4405 EXPECT_TRUE(simulcast.receive_layers().empty());
4406 EXPECT_EQ(2ul, simulcast.send_layers().size());
4407 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4408
4409 EXPECT_FALSE(media->streams().empty());
4410 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4411 CompareRidDescriptionIds(rids, {"1", "2"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004412}
4413
4414// Ignores malformed rid lines.
4415TEST_F(WebRtcSdpTest, TestDeserializeIgnoresMalformedRidLines) {
4416 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4417 sdp += "a=rid:1 send pt=\r\n"; // Should ignore this line.
4418 sdp += "a=rid:2 receive\r\n"; // Should ignore this line.
4419 sdp += "a=rid:3 max-width=720;pt=120\r\n"; // Should ignore this line.
4420 sdp += "a=rid:4\r\n"; // Should ignore this line.
4421 sdp += "a=rid:5 send\r\n";
4422 sdp += "a=simulcast:send 1,2,3;4,5\r\n";
4423 JsepSessionDescription output(kDummyType);
4424 SdpParseError error;
4425 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4426 const cricket::ContentInfos& contents = output.description()->contents();
4427 const cricket::MediaContentDescription* media =
4428 contents.back().media_description();
4429 EXPECT_TRUE(media->HasSimulcast());
4430 const SimulcastDescription& simulcast = media->simulcast_description();
4431 EXPECT_TRUE(simulcast.receive_layers().empty());
4432 EXPECT_EQ(1ul, simulcast.send_layers().size());
4433 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4434
4435 EXPECT_FALSE(media->streams().empty());
4436 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4437 CompareRidDescriptionIds(rids, {"5"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004438}
4439
4440// Removes RIDs that specify a different format than the m= section.
4441TEST_F(WebRtcSdpTest, TestDeserializeRemovesRidsWithInvalidCodec) {
4442 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4443 sdp += "a=rid:1 send pt=121,120\r\n"; // Should remove 121 and keep RID.
4444 sdp += "a=rid:2 send pt=121\r\n"; // Should remove RID altogether.
4445 sdp += "a=simulcast:send 1;2\r\n";
4446 JsepSessionDescription output(kDummyType);
4447 SdpParseError error;
4448 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4449 const cricket::ContentInfos& contents = output.description()->contents();
4450 const cricket::MediaContentDescription* media =
4451 contents.back().media_description();
4452 EXPECT_TRUE(media->HasSimulcast());
4453 const SimulcastDescription& simulcast = media->simulcast_description();
4454 EXPECT_TRUE(simulcast.receive_layers().empty());
4455 EXPECT_EQ(1ul, simulcast.send_layers().size());
4456 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4457 EXPECT_EQ("1", simulcast.send_layers()[0][0].rid);
4458 EXPECT_EQ(1ul, media->streams().size());
4459 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4460 EXPECT_EQ(1ul, rids.size());
4461 EXPECT_EQ("1", rids[0].rid);
4462 EXPECT_EQ(1ul, rids[0].payload_types.size());
4463 EXPECT_EQ(120, rids[0].payload_types[0]);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004464}
4465
4466// Ignores duplicate rid lines
4467TEST_F(WebRtcSdpTest, TestDeserializeIgnoresDuplicateRidLines) {
4468 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4469 sdp += "a=rid:1 send\r\n";
4470 sdp += "a=rid:2 send\r\n";
4471 sdp += "a=rid:2 send\r\n";
4472 sdp += "a=rid:3 send\r\n";
4473 sdp += "a=rid:4 recv\r\n";
4474 sdp += "a=simulcast:send 1,2;3 recv 4\r\n";
4475 JsepSessionDescription output(kDummyType);
4476 SdpParseError error;
4477 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4478 const cricket::ContentInfos& contents = output.description()->contents();
4479 const cricket::MediaContentDescription* media =
4480 contents.back().media_description();
4481 EXPECT_TRUE(media->HasSimulcast());
4482 const SimulcastDescription& simulcast = media->simulcast_description();
4483 EXPECT_EQ(2ul, simulcast.send_layers().size());
4484 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4485 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4486 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4487
4488 EXPECT_FALSE(media->streams().empty());
4489 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4490 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbucha2012042018-12-03 11:35:05 -08004491}
4492
Florent Castellic4421972019-07-02 20:27:42 +02004493TEST_F(WebRtcSdpTest, TestDeserializeRidSendDirection) {
4494 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4495 sdp += "a=rid:1 recv\r\n";
4496 sdp += "a=rid:2 recv\r\n";
4497 sdp += "a=simulcast:send 1;2\r\n";
4498 JsepSessionDescription output(kDummyType);
4499 SdpParseError error;
4500 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4501 const cricket::ContentInfos& contents = output.description()->contents();
4502 const cricket::MediaContentDescription* media =
4503 contents.back().media_description();
4504 EXPECT_FALSE(media->HasSimulcast());
4505}
4506
4507TEST_F(WebRtcSdpTest, TestDeserializeRidRecvDirection) {
4508 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4509 sdp += "a=rid:1 send\r\n";
4510 sdp += "a=rid:2 send\r\n";
4511 sdp += "a=simulcast:recv 1;2\r\n";
4512 JsepSessionDescription output(kDummyType);
4513 SdpParseError error;
4514 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4515 const cricket::ContentInfos& contents = output.description()->contents();
4516 const cricket::MediaContentDescription* media =
4517 contents.back().media_description();
4518 EXPECT_FALSE(media->HasSimulcast());
4519}
4520
4521TEST_F(WebRtcSdpTest, TestDeserializeIgnoresWrongRidDirectionLines) {
4522 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4523 sdp += "a=rid:1 send\r\n";
4524 sdp += "a=rid:2 send\r\n";
4525 sdp += "a=rid:3 send\r\n";
4526 sdp += "a=rid:4 recv\r\n";
4527 sdp += "a=rid:5 recv\r\n";
4528 sdp += "a=rid:6 recv\r\n";
4529 sdp += "a=simulcast:send 1;5;3 recv 4;2;6\r\n";
4530 JsepSessionDescription output(kDummyType);
4531 SdpParseError error;
4532 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4533 const cricket::ContentInfos& contents = output.description()->contents();
4534 const cricket::MediaContentDescription* media =
4535 contents.back().media_description();
4536 EXPECT_TRUE(media->HasSimulcast());
4537 const SimulcastDescription& simulcast = media->simulcast_description();
4538 EXPECT_EQ(2ul, simulcast.send_layers().size());
4539 EXPECT_EQ(2ul, simulcast.receive_layers().size());
4540 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4541 EXPECT_EQ(2ul, simulcast.receive_layers().GetAllLayers().size());
4542
4543 EXPECT_FALSE(media->streams().empty());
4544 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4545 CompareRidDescriptionIds(rids, {"1", "3"});
4546}
4547
Amit Hilbucha2012042018-12-03 11:35:05 -08004548// Simulcast serialization integration test.
4549// This test will serialize and deserialize the description and compare.
4550// More detailed tests for parsing simulcast can be found in
4551// unit tests for SdpSerializer.
4552TEST_F(WebRtcSdpTest, SerializeSimulcast_ComplexSerialization) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004553 MakeUnifiedPlanDescription(/* use_ssrcs = */ false);
Amit Hilbucha2012042018-12-03 11:35:05 -08004554 auto description = jdesc_.description();
4555 auto media = description->GetContentDescriptionByName(kVideoContentName3);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004556 ASSERT_EQ(media->streams().size(), 1ul);
4557 StreamParams& send_stream = media->mutable_streams()[0];
4558 std::vector<RidDescription> send_rids;
4559 send_rids.push_back(RidDescription("1", RidDirection::kSend));
4560 send_rids.push_back(RidDescription("2", RidDirection::kSend));
4561 send_rids.push_back(RidDescription("3", RidDirection::kSend));
4562 send_rids.push_back(RidDescription("4", RidDirection::kSend));
4563 send_stream.set_rids(send_rids);
Florent Castellib60141b2019-07-03 12:47:54 +02004564 std::vector<RidDescription> receive_rids;
4565 receive_rids.push_back(RidDescription("5", RidDirection::kReceive));
4566 receive_rids.push_back(RidDescription("6", RidDirection::kReceive));
4567 receive_rids.push_back(RidDescription("7", RidDirection::kReceive));
4568 media->set_receive_rids(receive_rids);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004569
Amit Hilbucha2012042018-12-03 11:35:05 -08004570 SimulcastDescription& simulcast = media->simulcast_description();
4571 simulcast.send_layers().AddLayerWithAlternatives(
4572 {SimulcastLayer("2", false), SimulcastLayer("1", true)});
4573 simulcast.send_layers().AddLayerWithAlternatives(
4574 {SimulcastLayer("4", false), SimulcastLayer("3", false)});
Florent Castellib60141b2019-07-03 12:47:54 +02004575 simulcast.receive_layers().AddLayer({SimulcastLayer("5", false)});
4576 simulcast.receive_layers().AddLayer({SimulcastLayer("6", false)});
4577 simulcast.receive_layers().AddLayer({SimulcastLayer("7", false)});
Amit Hilbucha2012042018-12-03 11:35:05 -08004578
Amit Hilbucha2012042018-12-03 11:35:05 -08004579 TestSerialize(jdesc_);
4580}
Steve Anton06817cd2018-12-18 15:55:30 -08004581
4582// Test that the content name is empty if the media section does not have an
4583// a=mid line.
4584TEST_F(WebRtcSdpTest, ParseNoMid) {
4585 std::string sdp = kSdpString;
4586 Replace("a=mid:audio_content_name\r\n", "", &sdp);
4587 Replace("a=mid:video_content_name\r\n", "", &sdp);
4588
4589 JsepSessionDescription output(kDummyType);
4590 SdpParseError error;
4591 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4592
4593 EXPECT_THAT(output.description()->contents(),
4594 ElementsAre(Field("name", &cricket::ContentInfo::name, ""),
4595 Field("name", &cricket::ContentInfo::name, "")));
4596}
Piotr (Peter) Slatala13e570f2019-02-27 11:34:26 -08004597
Guido Urdanetacecf87f2019-05-31 10:17:38 +00004598TEST_F(WebRtcSdpTest, SerializeWithDefaultSctpProtocol) {
4599 AddSctpDataChannel(false); // Don't use sctpmap
4600 JsepSessionDescription jsep_desc(kDummyType);
4601 MakeDescriptionWithoutCandidates(&jsep_desc);
4602 std::string message = webrtc::SdpSerialize(jsep_desc);
4603 EXPECT_NE(std::string::npos,
4604 message.find(cricket::kMediaProtocolUdpDtlsSctp));
4605}
4606
4607TEST_F(WebRtcSdpTest, DeserializeWithAllSctpProtocols) {
4608 AddSctpDataChannel(false);
4609 std::string protocols[] = {cricket::kMediaProtocolDtlsSctp,
4610 cricket::kMediaProtocolUdpDtlsSctp,
4611 cricket::kMediaProtocolTcpDtlsSctp};
4612 for (const auto& protocol : protocols) {
4613 sctp_desc_->set_protocol(protocol);
4614 JsepSessionDescription jsep_desc(kDummyType);
4615 MakeDescriptionWithoutCandidates(&jsep_desc);
4616 std::string message = webrtc::SdpSerialize(jsep_desc);
4617 EXPECT_NE(std::string::npos, message.find(protocol));
4618 JsepSessionDescription jsep_output(kDummyType);
4619 SdpParseError error;
4620 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jsep_output, &error));
4621 }
4622}
Taylor Brandstetter4256df02020-02-18 14:05:07 -08004623
4624// According to https://tools.ietf.org/html/rfc5576#section-6.1, the CNAME
4625// attribute is mandatory, but we relax that restriction.
4626TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCname) {
4627 std::string sdp_without_cname = kSdpFullString;
4628 Replace("a=ssrc:1 cname:stream_1_cname\r\n", "", &sdp_without_cname);
4629 JsepSessionDescription new_jdesc(kDummyType);
4630 EXPECT_TRUE(SdpDeserialize(sdp_without_cname, &new_jdesc));
4631
4632 audio_desc_->mutable_streams()[0].cname = "";
4633 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
4634 jdesc_.session_version()));
4635 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
4636}
Philipp Hanckee3f257c2020-02-19 16:25:52 +01004637
4638// This tests parsing of SDP with unknown ssrc-specific attributes.
4639TEST_F(WebRtcSdpTest, ParseIgnoreUnknownSsrcSpecificAttribute) {
4640 std::string sdp = kSdpString;
4641 sdp += "a=ssrc:1 mslabel:something\r\n";
4642
4643 JsepSessionDescription output(kDummyType);
4644 SdpParseError error;
4645 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4646}