blob: 6a95685b0a2050bd5de98fd15ae1462fbc01166b [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
kwibergd1fe2812016-04-27 06:47:29 -070011#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000012#include <set>
13#include <string>
14#include <vector>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "api/jsepsessiondescription.h"
17#include "media/base/mediaconstants.h"
18#include "media/engine/webrtcvideoengine.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "p2p/base/p2pconstants.h"
Yves Gerey665174f2018-06-19 15:03:05 +020020#include "p2p/base/port.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "pc/mediasession.h"
22#include "rtc_base/checks.h"
23#include "rtc_base/gunit.h"
24#include "rtc_base/logging.h"
Yves Gerey2e00abc2018-10-05 15:39:24 +020025#include "rtc_base/messagedigest.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020026#include "rtc_base/stringencode.h"
27#include "rtc_base/stringutils.h"
Patrik Höglund563934e2017-09-15 09:04:28 +020028
ossu7bb87ee2017-01-23 04:56:25 -080029#ifdef WEBRTC_ANDROID
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020030#include "pc/test/androidtestinitializer.h"
ossu7bb87ee2017-01-23 04:56:25 -080031#endif
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020032#include "pc/webrtcsdp.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000033
34using cricket::AudioCodec;
35using cricket::AudioContentDescription;
36using cricket::Candidate;
37using cricket::ContentInfo;
38using cricket::CryptoParams;
39using cricket::ContentGroup;
40using cricket::DataCodec;
41using cricket::DataContentDescription;
42using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
43using cricket::ICE_CANDIDATE_COMPONENT_RTP;
44using cricket::kFecSsrcGroupSemantics;
45using cricket::LOCAL_PORT_TYPE;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000046using cricket::RELAY_PORT_TYPE;
47using cricket::SessionDescription;
Steve Anton5adfafd2017-12-20 16:34:00 -080048using cricket::MediaProtocolType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049using cricket::StreamParams;
50using cricket::STUN_PORT_TYPE;
51using cricket::TransportDescription;
52using cricket::TransportInfo;
53using cricket::VideoCodec;
54using cricket::VideoContentDescription;
55using webrtc::IceCandidateCollection;
56using webrtc::IceCandidateInterface;
57using webrtc::JsepIceCandidate;
58using webrtc::JsepSessionDescription;
isheriff6f8d6862016-05-26 11:24:55 -070059using webrtc::RtpExtension;
Steve Anton4e70a722017-11-28 14:57:10 -080060using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061using webrtc::SdpParseError;
Steve Antona3a92c22017-12-07 10:27:41 -080062using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063using webrtc::SessionDescriptionInterface;
64
65typedef std::vector<AudioCodec> AudioCodecs;
66typedef std::vector<Candidate> Candidates;
67
Peter Boström0c4e06b2015-10-07 12:23:21 +020068static const uint32_t kDefaultSctpPort = 5000;
zstein4b2e0822017-02-17 19:48:38 -080069static const char kDefaultSctpPortStr[] = "5000";
70static const uint16_t kUnusualSctpPort = 9556;
71static const char kUnusualSctpPortStr[] = "9556";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020073static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 15:17:14 -080074static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 15:17:14 -080076static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020078static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079static const char kCandidateFoundation1[] = "a0+B/1";
80static const char kCandidateFoundation2[] = "a0+B/2";
81static const char kCandidateFoundation3[] = "a0+B/3";
82static const char kCandidateFoundation4[] = "a0+B/4";
83static const char kAttributeCryptoVoice[] =
84 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
85 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
86 "dummy_session_params\r\n";
87static const char kAttributeCryptoVideo[] =
88 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
89 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
Yves Gerey665174f2018-06-19 15:03:05 +020090static const char kFingerprint[] =
91 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092 "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 +020093static const char kExtmapAllowMixed[] = "a=extmap-allow-mixed\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094static const int kExtmapId = 1;
95static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
96static const char kExtmap[] =
97 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
98static const char kExtmapWithDirectionAndAttribute[] =
99 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
jbauch5869f502017-06-29 12:31:36 -0700100static const char kExtmapWithDirectionAndAttributeEncrypted[] =
101 "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt "
102 "http://example.com/082005/ext.htm#ttime a1 a2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103
Peter Boström0c4e06b2015-10-07 12:23:21 +0200104static const uint8_t kIdentityDigest[] = {
105 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
106 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107
lally@webrtc.org34807282015-02-24 20:19:39 +0000108static const char kDtlsSctp[] = "DTLS/SCTP";
109static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
110static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +0000111
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000112struct CodecParams {
113 int max_ptime;
114 int ptime;
115 int min_ptime;
116 int sprop_stereo;
117 int stereo;
118 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000119 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120};
121
deadbeef9d3584c2016-02-16 17:54:10 -0800122// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
123// instead of "a=crypto", and have an explicit test for adding "a=crypto".
124// Currently it's the other way around.
125
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000126// Reference sdp string
127static const char kSdpFullString[] =
128 "v=0\r\n"
129 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
130 "s=-\r\n"
131 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800132 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000133 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
134 "c=IN IP4 74.125.127.126\r\n"
135 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
136 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
137 "generation 2\r\n"
138 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
139 "generation 2\r\n"
140 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
141 "generation 2\r\n"
142 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
143 "generation 2\r\n"
144 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
145 "raddr 192.168.1.5 rport 2346 "
146 "generation 2\r\n"
147 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
148 "raddr 192.168.1.5 rport 2348 "
149 "generation 2\r\n"
150 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
151 "a=mid:audio_content_name\r\n"
152 "a=sendrecv\r\n"
153 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800154 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000155 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
156 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
157 "dummy_session_params\r\n"
158 "a=rtpmap:111 opus/48000/2\r\n"
159 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000160 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000161 "a=ssrc:1 cname:stream_1_cname\r\n"
162 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
163 "a=ssrc:1 mslabel:local_stream_1\r\n"
164 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000165 "m=video 3457 RTP/SAVPF 120\r\n"
166 "c=IN IP4 74.125.224.39\r\n"
167 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
168 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
169 "generation 2\r\n"
170 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
171 "generation 2\r\n"
172 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
173 "generation 2\r\n"
174 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
175 "generation 2\r\n"
176 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
177 "generation 2\r\n"
178 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
179 "generation 2\r\n"
180 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
181 "a=mid:video_content_name\r\n"
182 "a=sendrecv\r\n"
183 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
184 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
185 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800186 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187 "a=ssrc:2 cname:stream_1_cname\r\n"
188 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
189 "a=ssrc:2 mslabel:local_stream_1\r\n"
190 "a=ssrc:2 label:video_track_id_1\r\n"
191 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800192 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000193 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800194 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000195
196// SDP reference string without the candidates.
197static const char kSdpString[] =
198 "v=0\r\n"
199 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
200 "s=-\r\n"
201 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800202 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000203 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000204 "c=IN IP4 0.0.0.0\r\n"
205 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000206 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
207 "a=mid:audio_content_name\r\n"
208 "a=sendrecv\r\n"
209 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800210 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
212 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
213 "dummy_session_params\r\n"
214 "a=rtpmap:111 opus/48000/2\r\n"
215 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000216 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000217 "a=ssrc:1 cname:stream_1_cname\r\n"
218 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
219 "a=ssrc:1 mslabel:local_stream_1\r\n"
220 "a=ssrc:1 label:audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000221 "m=video 9 RTP/SAVPF 120\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_video\r\na=ice-pwd:pwd_video\r\n"
225 "a=mid:video_content_name\r\n"
226 "a=sendrecv\r\n"
227 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
228 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
229 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800230 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000231 "a=ssrc:2 cname:stream_1_cname\r\n"
232 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
233 "a=ssrc:2 mslabel:local_stream_1\r\n"
234 "a=ssrc:2 label:video_track_id_1\r\n"
235 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800236 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000237 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800238 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000239
240static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000241 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000242 "c=IN IP4 0.0.0.0\r\n"
243 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000244 "a=ice-ufrag:ufrag_data\r\n"
245 "a=ice-pwd:pwd_data\r\n"
246 "a=mid:data_content_name\r\n"
247 "a=sendrecv\r\n"
248 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
249 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
250 "a=rtpmap:101 google-data/90000\r\n"
251 "a=ssrc:10 cname:data_channel_cname\r\n"
252 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
253 "a=ssrc:10 mslabel:data_channel\r\n"
254 "a=ssrc:10 label:data_channeld0\r\n";
255
256static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000257 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000258 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000259 "a=ice-ufrag:ufrag_data\r\n"
260 "a=ice-pwd:pwd_data\r\n"
261 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000262 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000263
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000264// draft-ietf-mmusic-sctp-sdp-12
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000265static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000266 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
267 "a=max-message-size=100000\r\n"
268 "a=sctp-port 5000\r\n"
269 "c=IN IP4 0.0.0.0\r\n"
270 "a=ice-ufrag:ufrag_data\r\n"
271 "a=ice-pwd:pwd_data\r\n"
272 "a=mid:data_content_name\r\n";
273
lally69f57602015-10-08 10:15:04 -0700274static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
275 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
276 "a=max-message-size=100000\r\n"
277 "a=sctp-port:5000\r\n"
278 "c=IN IP4 0.0.0.0\r\n"
279 "a=ice-ufrag:ufrag_data\r\n"
280 "a=ice-pwd:pwd_data\r\n"
281 "a=mid:data_content_name\r\n";
282
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000283static const char kSdpSctpDataChannelWithCandidatesString[] =
284 "m=application 2345 DTLS/SCTP 5000\r\n"
285 "c=IN IP4 74.125.127.126\r\n"
286 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
287 "generation 2\r\n"
288 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
289 "generation 2\r\n"
290 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
291 "raddr 192.168.1.5 rport 2346 "
292 "generation 2\r\n"
293 "a=ice-ufrag:ufrag_data\r\n"
294 "a=ice-pwd:pwd_data\r\n"
295 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000296 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000297
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000298static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000299 "v=0\r\n"
300 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
301 "s=-\r\n"
302 "t=0 0\r\n"
303 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000304 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000305 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000306 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000307 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000308 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000309 "a=x-google-flag:conference\r\n";
310
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000311static const char kSdpSessionString[] =
312 "v=0\r\n"
313 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
314 "s=-\r\n"
315 "t=0 0\r\n"
316 "a=msid-semantic: WMS local_stream\r\n";
317
318static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000319 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000320 "c=IN IP4 0.0.0.0\r\n"
321 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000322 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
323 "a=mid:audio_content_name\r\n"
324 "a=sendrecv\r\n"
325 "a=rtpmap:111 opus/48000/2\r\n"
326 "a=ssrc:1 cname:stream_1_cname\r\n"
327 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
328 "a=ssrc:1 mslabel:local_stream\r\n"
329 "a=ssrc:1 label:audio_track_id_1\r\n";
330
331static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000332 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000333 "c=IN IP4 0.0.0.0\r\n"
334 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000335 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
336 "a=mid:video_content_name\r\n"
337 "a=sendrecv\r\n"
338 "a=rtpmap:120 VP8/90000\r\n"
339 "a=ssrc:2 cname:stream_1_cname\r\n"
340 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
341 "a=ssrc:2 mslabel:local_stream\r\n"
342 "a=ssrc:2 label:video_track_id_1\r\n";
343
deadbeef25ed4352016-12-12 18:37:36 -0800344// Reference sdp string using bundle-only.
345static const char kBundleOnlySdpFullString[] =
346 "v=0\r\n"
347 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
348 "s=-\r\n"
349 "t=0 0\r\n"
350 "a=group:BUNDLE audio_content_name video_content_name\r\n"
351 "a=msid-semantic: WMS local_stream_1\r\n"
352 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
353 "c=IN IP4 74.125.127.126\r\n"
354 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
355 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
356 "generation 2\r\n"
357 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
358 "generation 2\r\n"
359 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
360 "generation 2\r\n"
361 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
362 "generation 2\r\n"
363 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
364 "raddr 192.168.1.5 rport 2346 "
365 "generation 2\r\n"
366 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
367 "raddr 192.168.1.5 rport 2348 "
368 "generation 2\r\n"
369 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
370 "a=mid:audio_content_name\r\n"
371 "a=sendrecv\r\n"
372 "a=rtcp-mux\r\n"
373 "a=rtcp-rsize\r\n"
374 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
375 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
376 "dummy_session_params\r\n"
377 "a=rtpmap:111 opus/48000/2\r\n"
378 "a=rtpmap:103 ISAC/16000\r\n"
379 "a=rtpmap:104 ISAC/32000\r\n"
380 "a=ssrc:1 cname:stream_1_cname\r\n"
381 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
382 "a=ssrc:1 mslabel:local_stream_1\r\n"
383 "a=ssrc:1 label:audio_track_id_1\r\n"
384 "m=video 0 RTP/SAVPF 120\r\n"
385 "c=IN IP4 0.0.0.0\r\n"
386 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
387 "a=bundle-only\r\n"
388 "a=mid:video_content_name\r\n"
389 "a=sendrecv\r\n"
390 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
391 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
392 "a=rtpmap:120 VP8/90000\r\n"
393 "a=ssrc-group:FEC 2 3\r\n"
394 "a=ssrc:2 cname:stream_1_cname\r\n"
395 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
396 "a=ssrc:2 mslabel:local_stream_1\r\n"
397 "a=ssrc:2 label:video_track_id_1\r\n"
398 "a=ssrc:3 cname:stream_1_cname\r\n"
399 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
400 "a=ssrc:3 mslabel:local_stream_1\r\n"
401 "a=ssrc:3 label:video_track_id_1\r\n";
402
deadbeef9d3584c2016-02-16 17:54:10 -0800403// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
404// tracks.
405static const char kPlanBSdpFullString[] =
406 "v=0\r\n"
407 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
408 "s=-\r\n"
409 "t=0 0\r\n"
410 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
411 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
412 "c=IN IP4 74.125.127.126\r\n"
413 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
414 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
415 "generation 2\r\n"
416 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
417 "generation 2\r\n"
418 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
419 "generation 2\r\n"
420 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
421 "generation 2\r\n"
422 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
423 "raddr 192.168.1.5 rport 2346 "
424 "generation 2\r\n"
425 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
426 "raddr 192.168.1.5 rport 2348 "
427 "generation 2\r\n"
428 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
429 "a=mid:audio_content_name\r\n"
430 "a=sendrecv\r\n"
431 "a=rtcp-mux\r\n"
432 "a=rtcp-rsize\r\n"
433 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
434 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
435 "dummy_session_params\r\n"
436 "a=rtpmap:111 opus/48000/2\r\n"
437 "a=rtpmap:103 ISAC/16000\r\n"
438 "a=rtpmap:104 ISAC/32000\r\n"
439 "a=ssrc:1 cname:stream_1_cname\r\n"
440 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
441 "a=ssrc:1 mslabel:local_stream_1\r\n"
442 "a=ssrc:1 label:audio_track_id_1\r\n"
443 "a=ssrc:4 cname:stream_2_cname\r\n"
444 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
445 "a=ssrc:4 mslabel:local_stream_2\r\n"
446 "a=ssrc:4 label:audio_track_id_2\r\n"
447 "m=video 3457 RTP/SAVPF 120\r\n"
448 "c=IN IP4 74.125.224.39\r\n"
449 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
450 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
451 "generation 2\r\n"
452 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
453 "generation 2\r\n"
454 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
455 "generation 2\r\n"
456 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
457 "generation 2\r\n"
458 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
459 "generation 2\r\n"
460 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
461 "generation 2\r\n"
462 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
463 "a=mid:video_content_name\r\n"
464 "a=sendrecv\r\n"
465 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
466 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
467 "a=rtpmap:120 VP8/90000\r\n"
468 "a=ssrc-group:FEC 2 3\r\n"
469 "a=ssrc:2 cname:stream_1_cname\r\n"
470 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
471 "a=ssrc:2 mslabel:local_stream_1\r\n"
472 "a=ssrc:2 label:video_track_id_1\r\n"
473 "a=ssrc:3 cname:stream_1_cname\r\n"
474 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
475 "a=ssrc:3 mslabel:local_stream_1\r\n"
476 "a=ssrc:3 label:video_track_id_1\r\n"
477 "a=ssrc:5 cname:stream_2_cname\r\n"
478 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
479 "a=ssrc:5 mslabel:local_stream_2\r\n"
480 "a=ssrc:5 label:video_track_id_2\r\n"
481 "a=ssrc:6 cname:stream_2_cname\r\n"
482 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
483 "a=ssrc:6 mslabel:local_stream_2\r\n"
484 "a=ssrc:6 label:video_track_id_3\r\n";
485
486// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
487// tracks.
488static const char kUnifiedPlanSdpFullString[] =
489 "v=0\r\n"
490 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
491 "s=-\r\n"
492 "t=0 0\r\n"
493 "a=msid-semantic: WMS local_stream_1\r\n"
494 // Audio track 1, stream 1 (with candidates).
495 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
496 "c=IN IP4 74.125.127.126\r\n"
497 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
498 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
499 "generation 2\r\n"
500 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
501 "generation 2\r\n"
502 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
503 "generation 2\r\n"
504 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
505 "generation 2\r\n"
506 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
507 "raddr 192.168.1.5 rport 2346 "
508 "generation 2\r\n"
509 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
510 "raddr 192.168.1.5 rport 2348 "
511 "generation 2\r\n"
512 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
513 "a=mid:audio_content_name\r\n"
514 "a=msid:local_stream_1 audio_track_id_1\r\n"
515 "a=sendrecv\r\n"
516 "a=rtcp-mux\r\n"
517 "a=rtcp-rsize\r\n"
518 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
519 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
520 "dummy_session_params\r\n"
521 "a=rtpmap:111 opus/48000/2\r\n"
522 "a=rtpmap:103 ISAC/16000\r\n"
523 "a=rtpmap:104 ISAC/32000\r\n"
524 "a=ssrc:1 cname:stream_1_cname\r\n"
525 // Video track 1, stream 1 (with candidates).
526 "m=video 3457 RTP/SAVPF 120\r\n"
527 "c=IN IP4 74.125.224.39\r\n"
528 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
529 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
530 "generation 2\r\n"
531 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
532 "generation 2\r\n"
533 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
534 "generation 2\r\n"
535 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
536 "generation 2\r\n"
537 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
538 "generation 2\r\n"
539 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
540 "generation 2\r\n"
541 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
542 "a=mid:video_content_name\r\n"
543 "a=msid:local_stream_1 video_track_id_1\r\n"
544 "a=sendrecv\r\n"
545 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
546 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
547 "a=rtpmap:120 VP8/90000\r\n"
548 "a=ssrc-group:FEC 2 3\r\n"
549 "a=ssrc:2 cname:stream_1_cname\r\n"
550 "a=ssrc:3 cname:stream_1_cname\r\n"
551 // Audio track 2, stream 2.
552 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
553 "c=IN IP4 0.0.0.0\r\n"
554 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
555 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
556 "a=mid:audio_content_name_2\r\n"
557 "a=msid:local_stream_2 audio_track_id_2\r\n"
558 "a=sendrecv\r\n"
559 "a=rtcp-mux\r\n"
560 "a=rtcp-rsize\r\n"
561 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
562 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
563 "dummy_session_params\r\n"
564 "a=rtpmap:111 opus/48000/2\r\n"
565 "a=rtpmap:103 ISAC/16000\r\n"
566 "a=rtpmap:104 ISAC/32000\r\n"
567 "a=ssrc:4 cname:stream_2_cname\r\n"
568 // Video track 2, stream 2.
569 "m=video 9 RTP/SAVPF 120\r\n"
570 "c=IN IP4 0.0.0.0\r\n"
571 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
572 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
573 "a=mid:video_content_name_2\r\n"
574 "a=msid:local_stream_2 video_track_id_2\r\n"
575 "a=sendrecv\r\n"
576 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
577 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
578 "a=rtpmap:120 VP8/90000\r\n"
579 "a=ssrc:5 cname:stream_2_cname\r\n"
580 // Video track 3, stream 2.
581 "m=video 9 RTP/SAVPF 120\r\n"
582 "c=IN IP4 0.0.0.0\r\n"
583 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
584 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
585 "a=mid:video_content_name_3\r\n"
586 "a=msid:local_stream_2 video_track_id_3\r\n"
587 "a=sendrecv\r\n"
588 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
589 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
590 "a=rtpmap:120 VP8/90000\r\n"
591 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000592
Seth Hampson5b4f0752018-04-02 16:31:36 -0700593// Unified Plan SDP reference string:
594// - audio track 1 has 1 a=msid lines
595// - audio track 2 has 2 a=msid lines
596// - audio track 3 has 1 a=msid line with the special "-" marker signifying that
597// there are 0 media stream ids.
598// This Unified Plan SDP represents a SDP that signals the msid using both
599// a=msid and a=ssrc msid semantics.
600static const char kUnifiedPlanSdpFullStringWithSpecialMsid[] =
601 "v=0\r\n"
602 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
603 "s=-\r\n"
604 "t=0 0\r\n"
605 "a=msid-semantic: WMS local_stream_1\r\n"
606 // Audio track 1, with 1 stream id.
607 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
608 "c=IN IP4 74.125.127.126\r\n"
609 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
610 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
611 "generation 2\r\n"
612 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
613 "generation 2\r\n"
614 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
615 "generation 2\r\n"
616 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
617 "generation 2\r\n"
618 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
619 "raddr 192.168.1.5 rport 2346 "
620 "generation 2\r\n"
621 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
622 "raddr 192.168.1.5 rport 2348 "
623 "generation 2\r\n"
624 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
625 "a=mid:audio_content_name\r\n"
626 "a=msid:local_stream_1 audio_track_id_1\r\n"
627 "a=sendrecv\r\n"
628 "a=rtcp-mux\r\n"
629 "a=rtcp-rsize\r\n"
630 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
631 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
632 "dummy_session_params\r\n"
633 "a=rtpmap:111 opus/48000/2\r\n"
634 "a=rtpmap:103 ISAC/16000\r\n"
635 "a=rtpmap:104 ISAC/32000\r\n"
636 "a=ssrc:1 cname:stream_1_cname\r\n"
637 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
638 "a=ssrc:1 mslabel:local_stream_1\r\n"
639 "a=ssrc:1 label:audio_track_id_1\r\n"
640 // Audio track 2, with two stream ids.
641 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
642 "c=IN IP4 0.0.0.0\r\n"
643 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
644 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
645 "a=mid:audio_content_name_2\r\n"
646 "a=msid:local_stream_1 audio_track_id_2\r\n"
647 "a=msid:local_stream_2 audio_track_id_2\r\n"
648 "a=sendrecv\r\n"
649 "a=rtcp-mux\r\n"
650 "a=rtcp-rsize\r\n"
651 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
652 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
653 "dummy_session_params\r\n"
654 "a=rtpmap:111 opus/48000/2\r\n"
655 "a=rtpmap:103 ISAC/16000\r\n"
656 "a=rtpmap:104 ISAC/32000\r\n"
657 "a=ssrc:4 cname:stream_1_cname\r\n"
658 // The support for Plan B msid signaling only includes the
659 // first media stream id "local_stream_1."
660 "a=ssrc:4 msid:local_stream_1 audio_track_id_2\r\n"
661 "a=ssrc:4 mslabel:local_stream_1\r\n"
662 "a=ssrc:4 label:audio_track_id_2\r\n"
663 // Audio track 3, with no stream ids.
664 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
665 "c=IN IP4 0.0.0.0\r\n"
666 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
667 "a=ice-ufrag:ufrag_voice_3\r\na=ice-pwd:pwd_voice_3\r\n"
668 "a=mid:audio_content_name_3\r\n"
669 "a=msid:- audio_track_id_3\r\n"
670 "a=sendrecv\r\n"
671 "a=rtcp-mux\r\n"
672 "a=rtcp-rsize\r\n"
673 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
674 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
675 "dummy_session_params\r\n"
676 "a=rtpmap:111 opus/48000/2\r\n"
677 "a=rtpmap:103 ISAC/16000\r\n"
678 "a=rtpmap:104 ISAC/32000\r\n"
679 "a=ssrc:7 cname:stream_2_cname\r\n";
680
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000681// One candidate reference string as per W3c spec.
682// candidate:<blah> not a=candidate:<blah>CRLF
683static const char kRawCandidate[] =
684 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
685// One candidate reference string.
686static const char kSdpOneCandidate[] =
687 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
688 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000689
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000690static const char kSdpTcpActiveCandidate[] =
691 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
692 "tcptype active generation 2";
693static const char kSdpTcpPassiveCandidate[] =
694 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
695 "tcptype passive generation 2";
696static const char kSdpTcpSOCandidate[] =
697 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
698 "tcptype so generation 2";
699static const char kSdpTcpInvalidCandidate[] =
700 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
701 "tcptype invalid generation 2";
702
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000703// One candidate reference string with IPV6 address.
704static const char kRawIPV6Candidate[] =
705 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 12:04:36 -0700706 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000707
708// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800709static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000710 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800711 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712
Zach Steinb336c272018-08-09 01:16:13 -0700713static const char kRawHostnameCandidate[] =
714 "candidate:a0+B/1 1 udp 2130706432 a.test 1234 typ host generation 2";
715
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000716// Session id and version
717static const char kSessionId[] = "18446744069414584320";
718static const char kSessionVersion[] = "18446462598732840960";
719
deadbeef9d3584c2016-02-16 17:54:10 -0800720// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000721static const char kIceOption1[] = "iceoption1";
722static const char kIceOption2[] = "iceoption2";
723static const char kIceOption3[] = "iceoption3";
724
deadbeef9d3584c2016-02-16 17:54:10 -0800725// ICE ufrags/passwords.
726static const char kUfragVoice[] = "ufrag_voice";
727static const char kPwdVoice[] = "pwd_voice";
728static const char kUfragVideo[] = "ufrag_video";
729static const char kPwdVideo[] = "pwd_video";
730static const char kUfragData[] = "ufrag_data";
731static const char kPwdData[] = "pwd_data";
732
733// Extra ufrags/passwords for extra unified plan m= sections.
734static const char kUfragVoice2[] = "ufrag_voice_2";
735static const char kPwdVoice2[] = "pwd_voice_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700736static const char kUfragVoice3[] = "ufrag_voice_3";
737static const char kPwdVoice3[] = "pwd_voice_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800738static const char kUfragVideo2[] = "ufrag_video_2";
739static const char kPwdVideo2[] = "pwd_video_2";
740static const char kUfragVideo3[] = "ufrag_video_3";
741static const char kPwdVideo3[] = "pwd_video_3";
742
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000743// Content name
744static const char kAudioContentName[] = "audio_content_name";
745static const char kVideoContentName[] = "video_content_name";
746static const char kDataContentName[] = "data_content_name";
747
deadbeef9d3584c2016-02-16 17:54:10 -0800748// Extra content names for extra unified plan m= sections.
749static const char kAudioContentName2[] = "audio_content_name_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700750static const char kAudioContentName3[] = "audio_content_name_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800751static const char kVideoContentName2[] = "video_content_name_2";
752static const char kVideoContentName3[] = "video_content_name_3";
753
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000754// MediaStream 1
Seth Hampson845e8782018-03-02 11:34:10 -0800755static const char kStreamId1[] = "local_stream_1";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000756static const char kStream1Cname[] = "stream_1_cname";
757static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200758static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000759static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800760static const uint32_t kVideoTrack1Ssrc1 = 2;
761static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000762
763// MediaStream 2
Seth Hampson845e8782018-03-02 11:34:10 -0800764static const char kStreamId2[] = "local_stream_2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000765static const char kStream2Cname[] = "stream_2_cname";
766static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200767static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800768static const char kVideoTrackId2[] = "video_track_id_2";
769static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000770static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800771static const uint32_t kVideoTrack3Ssrc = 6;
Seth Hampson5b4f0752018-04-02 16:31:36 -0700772static const char kAudioTrackId3[] = "audio_track_id_3";
773static const uint32_t kAudioTrack3Ssrc = 7;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000774
775// DataChannel
776static const char kDataChannelLabel[] = "data_channel";
777static const char kDataChannelMsid[] = "data_channeld0";
778static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200779static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000780
781// Candidate
782static const char kDummyMid[] = "dummy_mid";
783static const int kDummyIndex = 123;
784
785// Misc
Steve Antona3a92c22017-12-07 10:27:41 -0800786static SdpType kDummyType = SdpType::kOffer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000787
788// Helper functions
789
790static bool SdpDeserialize(const std::string& message,
791 JsepSessionDescription* jdesc) {
792 return webrtc::SdpDeserialize(message, jdesc, NULL);
793}
794
795static bool SdpDeserializeCandidate(const std::string& message,
796 JsepIceCandidate* candidate) {
797 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
798}
799
800// Add some extra |newlines| to the |message| after |line|.
801static void InjectAfter(const std::string& line,
802 const std::string& newlines,
803 std::string* message) {
804 const std::string tmp = line + newlines;
Yves Gerey665174f2018-06-19 15:03:05 +0200805 rtc::replace_substrs(line.c_str(), line.length(), tmp.c_str(), tmp.length(),
806 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000807}
808
809static void Replace(const std::string& line,
810 const std::string& newlines,
811 std::string* message) {
Yves Gerey665174f2018-06-19 15:03:05 +0200812 rtc::replace_substrs(line.c_str(), line.length(), newlines.c_str(),
813 newlines.length(), message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000814}
815
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000816// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
817// message.
818static void ExpectParseFailure(const std::string& bad_sdp,
819 const std::string& bad_part) {
Steve Antona3a92c22017-12-07 10:27:41 -0800820 JsepSessionDescription desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000821 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000822 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000823 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000824 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
825}
826
827// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
828static void ExpectParseFailure(const char* good_part, const char* bad_part) {
829 std::string bad_sdp = kSdpFullString;
830 Replace(good_part, bad_part, &bad_sdp);
831 ExpectParseFailure(bad_sdp, bad_part);
832}
833
834// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
835static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
836 const std::string& newlines,
837 const std::string& bad_part) {
838 std::string bad_sdp = kSdpFullString;
839 InjectAfter(injectpoint, newlines, &bad_sdp);
840 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000841}
842
Steve Anton4e70a722017-11-28 14:57:10 -0800843static void ReplaceDirection(RtpTransceiverDirection direction,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844 std::string* message) {
845 std::string new_direction;
846 switch (direction) {
Steve Anton4e70a722017-11-28 14:57:10 -0800847 case RtpTransceiverDirection::kInactive:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000848 new_direction = "a=inactive";
849 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800850 case RtpTransceiverDirection::kSendOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000851 new_direction = "a=sendonly";
852 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800853 case RtpTransceiverDirection::kRecvOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854 new_direction = "a=recvonly";
855 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800856 case RtpTransceiverDirection::kSendRecv:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000857 default:
858 new_direction = "a=sendrecv";
859 break;
860 }
861 Replace("a=sendrecv", new_direction, message);
862}
863
Yves Gerey665174f2018-06-19 15:03:05 +0200864static void ReplaceRejected(bool audio_rejected,
865 bool video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000866 std::string* message) {
867 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800868 Replace("m=audio 9", "m=audio 0", message);
869 Replace(kAttributeIceUfragVoice, "", message);
870 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000871 }
872 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800873 Replace("m=video 9", "m=video 0", message);
874 Replace(kAttributeIceUfragVideo, "", message);
875 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876 }
877}
878
879// WebRtcSdpTest
880
881class WebRtcSdpTest : public testing::Test {
882 public:
Steve Antona3a92c22017-12-07 10:27:41 -0800883 WebRtcSdpTest() : jdesc_(kDummyType) {
phoglund37ebcf02016-01-08 05:04:57 -0800884#ifdef WEBRTC_ANDROID
885 webrtc::InitializeAndroidObjects();
886#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000887 // AudioContentDescription
888 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -0800889 StreamParams audio_stream;
890 audio_stream.id = kAudioTrackId1;
891 audio_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -0800892 audio_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -0800893 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
894 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 11:04:53 -0700895 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
896 audio_desc_->set_connection_address(audio_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -0800897 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000898
899 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -0800900 video_desc_ = CreateVideoContentDescription();
901 StreamParams video_stream;
902 video_stream.id = kVideoTrackId1;
903 video_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -0800904 video_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -0800905 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
906 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
907 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
908 video_stream.ssrc_groups.push_back(ssrc_group);
909 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 11:04:53 -0700910 rtc::SocketAddress video_addr("74.125.224.39", 3457);
911 video_desc_->set_connection_address(video_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -0800912 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000913
914 // TransportInfo
deadbeef9d3584c2016-02-16 17:54:10 -0800915 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
916 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice))));
917 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
918 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919
920 // v4 host
921 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000922 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000923 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000924 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
925 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000926 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000927 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000928 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
929 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000930 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000931 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000932 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
933 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000934 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000935 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000936 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
937 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000938
939 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000940 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000941 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
942 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000943 cricket::LOCAL_PORT_TYPE,
944 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000946 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
947 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000948 cricket::LOCAL_PORT_TYPE,
949 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000950 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000951 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
952 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000953 cricket::LOCAL_PORT_TYPE,
954 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000955 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000956 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
957 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000958 cricket::LOCAL_PORT_TYPE,
959 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000960
961 // stun
962 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000963 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
964 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000965 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
966 address_stun, kCandidatePriority, "", "",
967 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000968 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969 candidate9.set_related_address(rel_address_stun);
970
971 address_stun.SetPort(port_stun++);
972 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000973 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
974 address_stun, kCandidatePriority, "", "",
975 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000976 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000977 candidate10.set_related_address(rel_address_stun);
978
979 // relay
980 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000981 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000982 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
983 address_relay, kCandidatePriority, "", "",
984 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000985 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000986 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000987 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
988 address_relay, kCandidatePriority, "", "",
989 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000990 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000991
992 // voice
993 candidates_.push_back(candidate1);
994 candidates_.push_back(candidate2);
995 candidates_.push_back(candidate5);
996 candidates_.push_back(candidate6);
997 candidates_.push_back(candidate9);
998 candidates_.push_back(candidate10);
999
1000 // video
1001 candidates_.push_back(candidate3);
1002 candidates_.push_back(candidate4);
1003 candidates_.push_back(candidate7);
1004 candidates_.push_back(candidate8);
1005 candidates_.push_back(candidate11);
1006 candidates_.push_back(candidate12);
1007
Yves Gerey665174f2018-06-19 15:03:05 +02001008 jcandidate_.reset(
1009 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001010
1011 // Set up JsepSessionDescription.
1012 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
1013 std::string mline_id;
1014 int mline_index = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001015 for (size_t i = 0; i < candidates_.size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001016 // In this test, the audio m line index will be 0, and the video m line
1017 // will be 1.
1018 bool is_video = (i > 5);
1019 mline_id = is_video ? "video_content_name" : "audio_content_name";
1020 mline_index = is_video ? 1 : 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001021 JsepIceCandidate jice(mline_id, mline_index, candidates_.at(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001022 jdesc_.AddCandidate(&jice);
1023 }
1024 }
1025
Seth Hampson5b4f0752018-04-02 16:31:36 -07001026 void RemoveVideoCandidates() {
deadbeef25ed4352016-12-12 18:37:36 -08001027 const IceCandidateCollection* video_candidates_collection =
1028 jdesc_.candidates(1);
1029 ASSERT_NE(nullptr, video_candidates_collection);
1030 std::vector<cricket::Candidate> video_candidates;
1031 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1032 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1033 c.set_transport_name("video_content_name");
1034 video_candidates.push_back(c);
1035 }
1036 jdesc_.RemoveCandidates(video_candidates);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001037 }
1038
1039 // Turns the existing reference description into a description using
1040 // a=bundle-only. This means no transport attributes and a 0 port value on
1041 // the m= sections not associated with the BUNDLE-tag.
1042 void MakeBundleOnlyDescription() {
1043 RemoveVideoCandidates();
deadbeef25ed4352016-12-12 18:37:36 -08001044
1045 // And the rest of the transport attributes.
1046 desc_.transport_infos()[1].description.ice_ufrag.clear();
1047 desc_.transport_infos()[1].description.ice_pwd.clear();
1048 desc_.transport_infos()[1].description.connection_role =
1049 cricket::CONNECTIONROLE_NONE;
1050
1051 // Set bundle-only flag.
1052 desc_.contents()[1].bundle_only = true;
1053
1054 // Add BUNDLE group.
1055 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1056 group.AddContentName(kAudioContentName);
1057 group.AddContentName(kVideoContentName);
1058 desc_.AddGroup(group);
1059
1060 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1061 jdesc_.session_version()));
1062 }
1063
deadbeef9d3584c2016-02-16 17:54:10 -08001064 // Turns the existing reference description into a plan B description,
1065 // with 2 audio tracks and 3 video tracks.
1066 void MakePlanBDescription() {
Steve Antonb1c1de12017-12-21 15:14:30 -08001067 audio_desc_ = audio_desc_->Copy();
1068 video_desc_ = video_desc_->Copy();
deadbeef9d3584c2016-02-16 17:54:10 -08001069
1070 StreamParams audio_track_2;
1071 audio_track_2.id = kAudioTrackId2;
1072 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001073 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001074 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1075 audio_desc_->AddStream(audio_track_2);
1076
1077 StreamParams video_track_2;
1078 video_track_2.id = kVideoTrackId2;
1079 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001080 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001081 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1082 video_desc_->AddStream(video_track_2);
1083
1084 StreamParams video_track_3;
1085 video_track_3.id = kVideoTrackId3;
1086 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001087 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001088 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1089 video_desc_->AddStream(video_track_3);
1090
1091 desc_.RemoveContentByName(kAudioContentName);
1092 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001093 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1094 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001095
1096 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1097 jdesc_.session_version()));
1098 }
1099
1100 // Turns the existing reference description into a unified plan description,
1101 // with 2 audio tracks and 3 video tracks.
1102 void MakeUnifiedPlanDescription() {
1103 // Audio track 2.
1104 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1105 StreamParams audio_track_2;
1106 audio_track_2.id = kAudioTrackId2;
1107 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001108 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001109 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1110 audio_desc_2->AddStream(audio_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001111 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
deadbeef9d3584c2016-02-16 17:54:10 -08001112 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1113 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
deadbeef9d3584c2016-02-16 17:54:10 -08001114 // Video track 2, in stream 2.
1115 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1116 StreamParams video_track_2;
1117 video_track_2.id = kVideoTrackId2;
1118 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001119 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001120 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1121 video_desc_2->AddStream(video_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001122 desc_.AddContent(kVideoContentName2, MediaProtocolType::kRtp, video_desc_2);
deadbeef9d3584c2016-02-16 17:54:10 -08001123 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1124 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2))));
1125
1126 // Video track 3, in stream 2.
1127 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1128 StreamParams video_track_3;
1129 video_track_3.id = kVideoTrackId3;
1130 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001131 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001132 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1133 video_desc_3->AddStream(video_track_3);
Steve Anton5adfafd2017-12-20 16:34:00 -08001134 desc_.AddContent(kVideoContentName3, MediaProtocolType::kRtp, video_desc_3);
deadbeef9d3584c2016-02-16 17:54:10 -08001135 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1136 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3))));
Steve Antone831b8c2018-02-01 12:22:16 -08001137 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
deadbeef9d3584c2016-02-16 17:54:10 -08001138
1139 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1140 jdesc_.session_version()));
1141 }
1142
1143 // Creates an audio content description with no streams, and some default
1144 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001145 AudioContentDescription* CreateAudioContentDescription() {
1146 AudioContentDescription* audio = new AudioContentDescription();
1147 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -08001148 audio->set_rtcp_reduced_size(true);
Yves Gerey665174f2018-06-19 15:03:05 +02001149 audio->AddCrypto(CryptoParams(
1150 1, "AES_CM_128_HMAC_SHA1_32",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001151 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1152 "dummy_session_params"));
1153 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef67cf2c12016-04-13 10:07:16 -07001154 AudioCodec opus(111, "opus", 48000, 0, 2);
deadbeef9d3584c2016-02-16 17:54:10 -08001155 audio->AddCodec(opus);
ossue1405ad2017-01-23 08:55:48 -08001156 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1157 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001158 return audio;
1159 }
1160
Seth Hampson5b4f0752018-04-02 16:31:36 -07001161 // Turns the existing reference description into a unified plan description,
1162 // with 3 audio MediaContentDescriptions with special StreamParams that
1163 // contain 0 or multiple stream ids: - audio track 1 has 1 media stream id -
1164 // audio track 2 has 2 media stream ids - audio track 3 has 0 media stream ids
1165 void MakeUnifiedPlanDescriptionMultipleStreamIds() {
1166 desc_.RemoveContentByName(kVideoContentName);
1167 desc_.RemoveTransportInfoByName(kVideoContentName);
1168 RemoveVideoCandidates();
1169
1170 // Audio track 2 has 2 media stream ids.
1171 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1172 StreamParams audio_track_2;
1173 audio_track_2.id = kAudioTrackId2;
1174 audio_track_2.cname = kStream1Cname;
1175 audio_track_2.set_stream_ids({kStreamId1, kStreamId2});
1176 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1177 audio_desc_2->AddStream(audio_track_2);
1178 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
1179 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1180 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
1181
1182 // Audio track 3 has no stream ids.
1183 AudioContentDescription* audio_desc_3 = CreateAudioContentDescription();
1184 StreamParams audio_track_3;
1185 audio_track_3.id = kAudioTrackId3;
1186 audio_track_3.cname = kStream2Cname;
1187 audio_track_3.set_stream_ids({});
1188 audio_track_3.ssrcs.push_back(kAudioTrack3Ssrc);
1189 audio_desc_3->AddStream(audio_track_3);
1190 desc_.AddContent(kAudioContentName3, MediaProtocolType::kRtp, audio_desc_3);
1191 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1192 kAudioContentName3, TransportDescription(kUfragVoice3, kPwdVoice3))));
1193 // Make sure to create both a=msid lines.
1194 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection |
1195 cricket::kMsidSignalingSsrcAttribute);
1196 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1197 jdesc_.session_version()));
1198 }
1199
Seth Hampson5897a6e2018-04-03 11:16:33 -07001200 // Turns the existing reference description into a unified plan description
1201 // with one audio MediaContentDescription that contains one StreamParams with
1202 // 0 ssrcs.
1203 void MakeUnifiedPlanDescriptionNoSsrcSignaling() {
1204 desc_.RemoveContentByName(kVideoContentName);
1205 desc_.RemoveContentByName(kAudioContentName);
1206 desc_.RemoveTransportInfoByName(kVideoContentName);
1207 RemoveVideoCandidates();
1208
1209 AudioContentDescription* audio_desc = CreateAudioContentDescription();
1210 StreamParams audio_track;
1211 audio_track.id = kAudioTrackId1;
1212 audio_track.set_stream_ids({kStreamId1});
1213 audio_desc->AddStream(audio_track);
1214 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc);
1215
1216 // Enable signaling a=msid lines.
1217 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
1218 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1219 jdesc_.session_version()));
1220 }
1221
deadbeef9d3584c2016-02-16 17:54:10 -08001222 // Creates a video content description with no streams, and some default
1223 // configuration.
1224 VideoContentDescription* CreateVideoContentDescription() {
1225 VideoContentDescription* video = new VideoContentDescription();
1226 video->AddCrypto(CryptoParams(
1227 1, "AES_CM_128_HMAC_SHA1_80",
1228 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1229 video->set_protocol(cricket::kMediaProtocolSavpf);
1230 video->AddCodec(
perkj26752742016-10-24 01:21:16 -07001231 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-16 17:54:10 -08001232 return video;
1233 }
1234
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001235 template <class MCD>
Yves Gerey665174f2018-06-19 15:03:05 +02001236 void CompareMediaContentDescription(const MCD* cd1, const MCD* cd2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001237 // type
1238 EXPECT_EQ(cd1->type(), cd1->type());
1239
1240 // content direction
1241 EXPECT_EQ(cd1->direction(), cd2->direction());
1242
1243 // rtcp_mux
1244 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1245
deadbeef13871492015-12-09 12:37:51 -08001246 // rtcp_reduced_size
1247 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1248
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001249 // cryptos
1250 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1251 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1252 ADD_FAILURE();
1253 return;
1254 }
Yves Gerey665174f2018-06-19 15:03:05 +02001255 for (size_t i = 0; i < cd1->cryptos().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001256 const CryptoParams c1 = cd1->cryptos().at(i);
1257 const CryptoParams c2 = cd2->cryptos().at(i);
1258 EXPECT_TRUE(c1.Matches(c2));
1259 EXPECT_EQ(c1.key_params, c2.key_params);
1260 EXPECT_EQ(c1.session_params, c2.session_params);
1261 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001262
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001263 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001264 // Use an equivalence class here, for old and new versions of the
1265 // protocol description.
Yves Gerey665174f2018-06-19 15:03:05 +02001266 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp ||
1267 cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1268 cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
lally@webrtc.org36300852015-02-24 20:19:35 +00001269 const bool cd2_is_also_dtls_sctp =
Yves Gerey665174f2018-06-19 15:03:05 +02001270 cd2->protocol() == cricket::kMediaProtocolDtlsSctp ||
1271 cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1272 cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
lally@webrtc.org36300852015-02-24 20:19:35 +00001273 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001274 } else {
1275 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1276 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001277
1278 // codecs
1279 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1280
1281 // bandwidth
1282 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1283
1284 // streams
1285 EXPECT_EQ(cd1->streams(), cd2->streams());
1286
Johannes Kron0854eb62018-10-10 22:33:20 +02001287 // extmap-allow-mixed
1288 EXPECT_EQ(cd1->mixed_one_two_byte_header_extensions_supported(),
1289 cd2->mixed_one_two_byte_header_extensions_supported());
1290
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001291 // extmap
1292 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1293 cd2->rtp_header_extensions().size());
Yves Gerey665174f2018-06-19 15:03:05 +02001294 for (size_t i = 0; i < cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 11:24:55 -07001295 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1296 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001297 EXPECT_EQ(ext1.uri, ext2.uri);
1298 EXPECT_EQ(ext1.id, ext2.id);
jbauch5869f502017-06-29 12:31:36 -07001299 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001300 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001301 }
1302
zstein4b2e0822017-02-17 19:48:38 -08001303 void CompareDataContentDescription(const DataContentDescription* dcd1,
1304 const DataContentDescription* dcd2) {
1305 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
1306 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
1307 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001308
1309 void CompareSessionDescription(const SessionDescription& desc1,
1310 const SessionDescription& desc2) {
1311 // Compare content descriptions.
1312 if (desc1.contents().size() != desc2.contents().size()) {
1313 ADD_FAILURE();
1314 return;
1315 }
Yves Gerey665174f2018-06-19 15:03:05 +02001316 for (size_t i = 0; i < desc1.contents().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001317 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1318 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-12 18:37:36 -08001319 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001320 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-12 18:37:36 -08001321 EXPECT_EQ(c1.type, c2.type);
1322 EXPECT_EQ(c1.rejected, c2.rejected);
1323 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001324
1325 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1326 if (IsAudioContent(&c1)) {
1327 const AudioContentDescription* acd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001328 c1.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001329 const AudioContentDescription* acd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001330 c2.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001331 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1332 }
1333
1334 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1335 if (IsVideoContent(&c1)) {
1336 const VideoContentDescription* vcd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001337 c1.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001338 const VideoContentDescription* vcd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001339 c2.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001340 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1341 }
1342
1343 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
1344 if (IsDataContent(&c1)) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001345 const DataContentDescription* dcd1 = c1.media_description()->as_data();
1346 const DataContentDescription* dcd2 = c2.media_description()->as_data();
zstein4b2e0822017-02-17 19:48:38 -08001347 CompareDataContentDescription(dcd1, dcd2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001348 }
1349 }
1350
1351 // group
1352 const cricket::ContentGroups groups1 = desc1.groups();
1353 const cricket::ContentGroups groups2 = desc2.groups();
1354 EXPECT_EQ(groups1.size(), groups1.size());
1355 if (groups1.size() != groups2.size()) {
1356 ADD_FAILURE();
1357 return;
1358 }
1359 for (size_t i = 0; i < groups1.size(); ++i) {
1360 const cricket::ContentGroup group1 = groups1.at(i);
1361 const cricket::ContentGroup group2 = groups2.at(i);
1362 EXPECT_EQ(group1.semantics(), group2.semantics());
1363 const cricket::ContentNames names1 = group1.content_names();
1364 const cricket::ContentNames names2 = group2.content_names();
1365 EXPECT_EQ(names1.size(), names2.size());
1366 if (names1.size() != names2.size()) {
1367 ADD_FAILURE();
1368 return;
1369 }
1370 cricket::ContentNames::const_iterator iter1 = names1.begin();
1371 cricket::ContentNames::const_iterator iter2 = names2.begin();
1372 while (iter1 != names1.end()) {
1373 EXPECT_EQ(*iter1++, *iter2++);
1374 }
1375 }
1376
1377 // transport info
1378 const cricket::TransportInfos transports1 = desc1.transport_infos();
1379 const cricket::TransportInfos transports2 = desc2.transport_infos();
1380 EXPECT_EQ(transports1.size(), transports2.size());
1381 if (transports1.size() != transports2.size()) {
1382 ADD_FAILURE();
1383 return;
1384 }
1385 for (size_t i = 0; i < transports1.size(); ++i) {
1386 const cricket::TransportInfo transport1 = transports1.at(i);
1387 const cricket::TransportInfo transport2 = transports2.at(i);
1388 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001389 EXPECT_EQ(transport1.description.ice_ufrag,
1390 transport2.description.ice_ufrag);
Yves Gerey665174f2018-06-19 15:03:05 +02001391 EXPECT_EQ(transport1.description.ice_pwd, transport2.description.ice_pwd);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07001392 EXPECT_EQ(transport1.description.ice_mode,
1393 transport2.description.ice_mode);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001394 if (transport1.description.identity_fingerprint) {
1395 EXPECT_EQ(*transport1.description.identity_fingerprint,
1396 *transport2.description.identity_fingerprint);
1397 } else {
1398 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1399 transport2.description.identity_fingerprint.get());
1400 }
1401 EXPECT_EQ(transport1.description.transport_options,
1402 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001403 }
deadbeefc80741f2015-10-22 13:14:45 -07001404
1405 // global attributes
1406 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
Johannes Kron0854eb62018-10-10 22:33:20 +02001407 EXPECT_EQ(desc1.mixed_one_two_byte_header_extensions_supported(),
1408 desc2.mixed_one_two_byte_header_extensions_supported());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001409 }
1410
Yves Gerey665174f2018-06-19 15:03:05 +02001411 bool CompareSessionDescription(const JsepSessionDescription& desc1,
1412 const JsepSessionDescription& desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001413 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1414 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1415 CompareSessionDescription(*desc1.description(), *desc2.description());
1416 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1417 return false;
1418 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1419 const IceCandidateCollection* cc1 = desc1.candidates(i);
1420 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-12 18:37:36 -08001421 if (cc1->count() != cc2->count()) {
1422 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001423 return false;
deadbeef25ed4352016-12-12 18:37:36 -08001424 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001425 for (size_t j = 0; j < cc1->count(); ++j) {
1426 const IceCandidateInterface* c1 = cc1->at(j);
1427 const IceCandidateInterface* c2 = cc2->at(j);
1428 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1429 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1430 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1431 }
1432 }
1433 return true;
1434 }
1435
1436 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1437 // them with invalid keywords so that the parser will just ignore them.
1438 bool RemoveCandidateUfragPwd(std::string* sdp) {
1439 const char ice_ufrag[] = "a=ice-ufrag";
1440 const char ice_ufragx[] = "a=xice-ufrag";
1441 const char ice_pwd[] = "a=ice-pwd";
1442 const char ice_pwdx[] = "a=xice-pwd";
Yves Gerey665174f2018-06-19 15:03:05 +02001443 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag), ice_ufragx,
1444 strlen(ice_ufragx), sdp);
1445 rtc::replace_substrs(ice_pwd, strlen(ice_pwd), ice_pwdx, strlen(ice_pwdx),
1446 sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001447 return true;
1448 }
1449
1450 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
Yves Gerey665174f2018-06-19 15:03:05 +02001451 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc,
1452 int mline_index,
1453 const std::string& ufrag,
1454 const std::string& pwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001455 std::string content_name;
1456 if (mline_index == 0) {
1457 content_name = kAudioContentName;
1458 } else if (mline_index == 1) {
1459 content_name = kVideoContentName;
1460 } else {
nissec80e7412017-01-11 05:56:46 -08001461 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001462 }
Yves Gerey665174f2018-06-19 15:03:05 +02001463 TransportInfo transport_info(content_name,
1464 TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001465 SessionDescription* desc =
1466 const_cast<SessionDescription*>(jdesc->description());
1467 desc->RemoveTransportInfoByName(content_name);
1468 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
1469 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1470 const IceCandidateCollection* cc = jdesc_.candidates(i);
1471 for (size_t j = 0; j < cc->count(); ++j) {
1472 if (cc->at(j)->sdp_mline_index() == mline_index) {
Yves Gerey665174f2018-06-19 15:03:05 +02001473 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(ufrag);
1474 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001475 }
1476 }
1477 }
1478 return true;
1479 }
1480
1481 void AddIceOptions(const std::string& content_name,
1482 const std::vector<std::string>& transport_options) {
1483 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1484 cricket::TransportInfo transport_info =
1485 *(desc_.GetTransportInfoByName(content_name));
1486 desc_.RemoveTransportInfoByName(content_name);
1487 transport_info.description.transport_options = transport_options;
1488 desc_.AddTransportInfo(transport_info);
1489 }
1490
deadbeef3f7219b2015-12-28 15:17:14 -08001491 void SetIceUfragPwd(const std::string& content_name,
1492 const std::string& ice_ufrag,
1493 const std::string& ice_pwd) {
1494 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1495 cricket::TransportInfo transport_info =
1496 *(desc_.GetTransportInfoByName(content_name));
1497 desc_.RemoveTransportInfoByName(content_name);
1498 transport_info.description.ice_ufrag = ice_ufrag;
1499 transport_info.description.ice_pwd = ice_pwd;
1500 desc_.AddTransportInfo(transport_info);
1501 }
1502
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001503 void AddFingerprint() {
1504 desc_.RemoveTransportInfoByName(kAudioContentName);
1505 desc_.RemoveTransportInfoByName(kVideoContentName);
Yves Gerey665174f2018-06-19 15:03:05 +02001506 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, kIdentityDigest,
1507 sizeof(kIdentityDigest));
deadbeef46eed762016-01-28 13:24:37 -08001508 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1509 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001510 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1511 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001512 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1513 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1514 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001515 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1516 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001517 cricket::CONNECTIONROLE_NONE, &fingerprint))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001518 }
1519
jbauch5869f502017-06-29 12:31:36 -07001520 void AddExtmap(bool encrypted) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001521 audio_desc_ = audio_desc_->Copy();
1522 video_desc_ = video_desc_->Copy();
jbauch5869f502017-06-29 12:31:36 -07001523 audio_desc_->AddRtpHeaderExtension(
1524 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1525 video_desc_->AddRtpHeaderExtension(
1526 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001527 desc_.RemoveContentByName(kAudioContentName);
1528 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001529 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1530 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001531 }
1532
1533 void RemoveCryptos() {
1534 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1535 video_desc_->set_cryptos(std::vector<CryptoParams>());
1536 }
1537
Seth Hampson5897a6e2018-04-03 11:16:33 -07001538 // Removes everything in StreamParams from the session description that is
1539 // used for a=ssrc lines.
1540 void RemoveSsrcSignalingFromStreamParams() {
1541 for (cricket::ContentInfo content_info : jdesc_.description()->contents()) {
1542 // With Unified Plan there should be one StreamParams per m= section.
1543 StreamParams& stream =
1544 content_info.media_description()->mutable_streams()[0];
1545 stream.ssrcs.clear();
1546 stream.ssrc_groups.clear();
1547 stream.cname.clear();
1548 }
1549 }
1550
1551 // Removes all a=ssrc lines from the SDP string.
1552 void RemoveSsrcLinesFromSdpString(std::string* sdp_string) {
1553 const char kAttributeSsrc[] = "a=ssrc";
1554 while (sdp_string->find(kAttributeSsrc) != std::string::npos) {
1555 size_t pos_ssrc_attribute = sdp_string->find(kAttributeSsrc);
1556 size_t beg_line_pos = sdp_string->rfind('\n', pos_ssrc_attribute);
1557 size_t end_line_pos = sdp_string->find('\n', pos_ssrc_attribute);
1558 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1559 }
1560 }
1561
Steve Anton4e70a722017-11-28 14:57:10 -08001562 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001563 audio_desc_->set_direction(direction);
1564 video_desc_->set_direction(direction);
1565 std::string new_sdp = kSdpFullString;
1566 ReplaceDirection(direction, &new_sdp);
1567
Yves Gerey665174f2018-06-19 15:03:05 +02001568 if (!jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001569 jdesc_.session_version())) {
1570 return false;
1571 }
Steve Antone831b8c2018-02-01 12:22:16 -08001572 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001573 EXPECT_EQ(new_sdp, message);
1574 return true;
1575 }
1576
1577 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001578 audio_desc_ = audio_desc_->Copy();
1579 video_desc_ = video_desc_->Copy();
zhihuang38989e52017-03-21 11:04:53 -07001580
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001581 desc_.RemoveContentByName(kAudioContentName);
1582 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001583 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001584 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001585 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001586 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001587 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1588 audio_rejected ? "" : kPwdVoice);
1589 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1590 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001591
1592 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001593 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1594
Steve Antona3a92c22017-12-07 10:27:41 -08001595 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001596 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001597 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001598 EXPECT_EQ(new_sdp, message);
1599 return true;
1600 }
1601
zstein4b2e0822017-02-17 19:48:38 -08001602 void AddSctpDataChannel(bool use_sctpmap) {
kwibergd1fe2812016-04-27 06:47:29 -07001603 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001604 data_desc_ = data.get();
zstein4b2e0822017-02-17 19:48:38 -08001605 data_desc_->set_use_sctpmap(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001606 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
solenberg9fa49752016-10-08 13:02:44 -07001607 DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07001608 cricket::kGoogleSctpDataCodecName);
wu@webrtc.org78187522013-10-07 23:32:02 +00001609 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1610 data_desc_->AddCodec(codec);
Steve Anton5adfafd2017-12-20 16:34:00 -08001611 desc_.AddContent(kDataContentName, MediaProtocolType::kSctp,
1612 data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001613 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1614 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001615 }
1616
1617 void AddRtpDataChannel() {
kwibergd1fe2812016-04-27 06:47:29 -07001618 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001619 data_desc_ = data.get();
1620
deadbeef67cf2c12016-04-13 10:07:16 -07001621 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001622 StreamParams data_stream;
1623 data_stream.id = kDataChannelMsid;
1624 data_stream.cname = kDataChannelCname;
Seth Hampson845e8782018-03-02 11:34:10 -08001625 data_stream.set_stream_ids({kDataChannelLabel});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001626 data_stream.ssrcs.push_back(kDataChannelSsrc);
1627 data_desc_->AddStream(data_stream);
Yves Gerey665174f2018-06-19 15:03:05 +02001628 data_desc_->AddCrypto(
1629 CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
1630 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001631 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
Steve Anton5adfafd2017-12-20 16:34:00 -08001632 desc_.AddContent(kDataContentName, MediaProtocolType::kRtp, data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001633 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1634 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001635 }
1636
Steve Anton4e70a722017-11-28 14:57:10 -08001637 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001638 std::string new_sdp = kSdpFullString;
1639 ReplaceDirection(direction, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001640 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001641
1642 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1643
1644 audio_desc_->set_direction(direction);
1645 video_desc_->set_direction(direction);
Yves Gerey665174f2018-06-19 15:03:05 +02001646 if (!jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001647 jdesc_.session_version())) {
1648 return false;
1649 }
1650 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1651 return true;
1652 }
1653
1654 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001655 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001656 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001657 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001658 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001659
Steve Antonb1c1de12017-12-21 15:14:30 -08001660 audio_desc_ = audio_desc_->Copy();
1661 video_desc_ = video_desc_->Copy();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001662 desc_.RemoveContentByName(kAudioContentName);
1663 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001664 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001665 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001666 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001667 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001668 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1669 audio_rejected ? "" : kPwdVoice);
1670 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1671 video_rejected ? "" : kPwdVideo);
Steve Antona3a92c22017-12-07 10:27:41 -08001672 JsepSessionDescription jdesc_no_candidates(kDummyType);
deadbeef3f7219b2015-12-28 15:17:14 -08001673 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1674 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001675 return false;
1676 }
deadbeef3f7219b2015-12-28 15:17:14 -08001677 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001678 return true;
1679 }
1680
Yves Gerey665174f2018-06-19 15:03:05 +02001681 void TestDeserializeExtmap(bool session_level,
1682 bool media_level,
1683 bool encrypted) {
jbauch5869f502017-06-29 12:31:36 -07001684 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08001685 JsepSessionDescription new_jdesc(SdpType::kOffer);
Yves Gerey665174f2018-06-19 15:03:05 +02001686 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001687 jdesc_.session_version()));
Steve Antona3a92c22017-12-07 10:27:41 -08001688 JsepSessionDescription jdesc_with_extmap(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001689 std::string sdp_with_extmap = kSdpString;
1690 if (session_level) {
jbauch5869f502017-06-29 12:31:36 -07001691 InjectAfter(kSessionTime,
1692 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1693 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001694 &sdp_with_extmap);
1695 }
1696 if (media_level) {
jbauch5869f502017-06-29 12:31:36 -07001697 InjectAfter(kAttributeIcePwdVoice,
1698 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1699 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001700 &sdp_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07001701 InjectAfter(kAttributeIcePwdVideo,
1702 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1703 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001704 &sdp_with_extmap);
1705 }
1706 // The extmap can't be present at the same time in both session level and
1707 // media level.
1708 if (session_level && media_level) {
1709 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02001710 EXPECT_FALSE(
1711 webrtc::SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001712 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1713 } else {
1714 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1715 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1716 }
1717 }
1718
1719 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
Yves Gerey665174f2018-06-19 15:03:05 +02001720 const std::string& name,
1721 int expected_value) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001722 cricket::CodecParameterMap::const_iterator found = params.find(name);
1723 ASSERT_TRUE(found != params.end());
Jonas Olsson6b1985d2018-07-05 11:59:48 +02001724 EXPECT_EQ(found->second, rtc::ToString(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001725 }
1726
1727 void TestDeserializeCodecParams(const CodecParams& params,
1728 JsepSessionDescription* jdesc_output) {
1729 std::string sdp =
1730 "v=0\r\n"
1731 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1732 "s=-\r\n"
1733 "t=0 0\r\n"
1734 // Include semantics for WebRTC Media Streams since it is supported by
1735 // this parser, and will be added to the SDP when serializing a session
1736 // description.
1737 "a=msid-semantic: WMS\r\n"
1738 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001739 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001740 // Pltype 111 listed before 103 and 104 in the map.
1741 "a=rtpmap:111 opus/48000/2\r\n"
1742 // Pltype 103 listed before 104.
1743 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001744 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001745 "a=fmtp:111 0-15,66,70\r\n"
1746 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001747 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001748 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001749 << "; sprop-stereo=" << params.sprop_stereo
1750 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001751 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001752 << "a=ptime:" << params.ptime << "\r\n"
1753 << "a=maxptime:" << params.max_ptime << "\r\n";
1754 sdp += os.str();
1755
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001756 os.clear();
1757 os.str("");
1758 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001759 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001760 << "a=rtpmap:99 VP8/90000\r\n"
1761 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001762 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001763 sdp += os.str();
1764
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765 // Deserialize
1766 SdpParseError error;
1767 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1768
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001769 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001770 GetFirstAudioContentDescription(jdesc_output->description());
1771 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001772 ASSERT_FALSE(acd->codecs().empty());
1773 cricket::AudioCodec opus = acd->codecs()[0];
1774 EXPECT_EQ("opus", opus.name);
1775 EXPECT_EQ(111, opus.id);
1776 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1777 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1778 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1779 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001780 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1781 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001782 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1783 cricket::AudioCodec codec = acd->codecs()[i];
1784 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1785 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001786 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001787
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001788 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001789 GetFirstVideoContentDescription(jdesc_output->description());
1790 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001791 ASSERT_FALSE(vcd->codecs().empty());
1792 cricket::VideoCodec vp8 = vcd->codecs()[0];
1793 EXPECT_EQ("VP8", vp8.name);
1794 EXPECT_EQ(99, vp8.id);
1795 cricket::VideoCodec rtx = vcd->codecs()[1];
1796 EXPECT_EQ("RTX", rtx.name);
1797 EXPECT_EQ(95, rtx.id);
1798 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001799 }
1800
1801 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1802 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001803 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001804 "v=0\r\n"
1805 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1806 "s=-\r\n"
1807 "t=0 0\r\n"
1808 // Include semantics for WebRTC Media Streams since it is supported by
1809 // this parser, and will be added to the SDP when serializing a session
1810 // description.
1811 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001812 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001813 "a=rtpmap:111 opus/48000/2\r\n";
1814 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001815 "m=video 3457 RTP/SAVPF 101\r\n"
1816 "a=rtpmap:101 VP8/90000\r\n"
1817 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001818 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001819 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001820 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001821 os << sdp_session_and_audio;
Yves Gerey665174f2018-06-19 15:03:05 +02001822 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001823 os << sdp_video;
Yves Gerey665174f2018-06-19 15:03:05 +02001824 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001825 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001826 // Deserialize
1827 SdpParseError error;
1828 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001829 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001830 GetFirstAudioContentDescription(jdesc_output->description());
1831 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001832 ASSERT_FALSE(acd->codecs().empty());
1833 cricket::AudioCodec opus = acd->codecs()[0];
1834 EXPECT_EQ(111, opus.id);
Yves Gerey665174f2018-06-19 15:03:05 +02001835 EXPECT_TRUE(opus.HasFeedbackParam(cricket::FeedbackParam(
1836 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001837
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001838 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001839 GetFirstVideoContentDescription(jdesc_output->description());
1840 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001841 ASSERT_FALSE(vcd->codecs().empty());
1842 cricket::VideoCodec vp8 = vcd->codecs()[0];
1843 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1844 vp8.name.c_str());
1845 EXPECT_EQ(101, vp8.id);
Yves Gerey665174f2018-06-19 15:03:05 +02001846 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1847 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
1848 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1849 cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli)));
1850 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1851 cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty)));
1852 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1853 cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001854 }
1855
1856 // Two SDP messages can mean the same thing but be different strings, e.g.
1857 // some of the lines can be serialized in different order.
1858 // However, a deserialized description can be compared field by field and has
1859 // no order. If deserializer has already been tested, serializing then
1860 // deserializing and comparing JsepSessionDescription will test
1861 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 12:22:16 -08001862 void TestSerialize(const JsepSessionDescription& jdesc) {
1863 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 10:27:41 -08001864 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001865 SdpParseError error;
1866 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1867 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1868 }
1869
zhihuang38989e52017-03-21 11:04:53 -07001870 // Calling 'Initialize' with a copy of the inner SessionDescription will
1871 // create a copy of the JsepSessionDescription without candidates. The
1872 // 'connection address' field, previously set from the candidates, must also
1873 // be reset.
1874 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
1875 rtc::SocketAddress audio_addr("0.0.0.0", 9);
1876 rtc::SocketAddress video_addr("0.0.0.0", 9);
1877 audio_desc_->set_connection_address(audio_addr);
1878 video_desc_->set_connection_address(video_addr);
1879 ASSERT_TRUE(jdesc->Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1880 }
1881
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001882 protected:
1883 SessionDescription desc_;
1884 AudioContentDescription* audio_desc_;
1885 VideoContentDescription* video_desc_;
1886 DataContentDescription* data_desc_;
1887 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07001888 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001889 JsepSessionDescription jdesc_;
1890};
1891
1892void TestMismatch(const std::string& string1, const std::string& string2) {
1893 int position = 0;
1894 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1895 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001896 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001897 break;
1898 }
1899 }
1900 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1901 << " character\n"
1902 << " 1: " << string1.substr(position, 20) << "\n"
1903 << " 2: " << string2.substr(position, 20) << "\n";
1904}
1905
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001906TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1907 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 12:22:16 -08001908 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001909 TestMismatch(std::string(kSdpFullString), message);
1910}
1911
1912TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 10:27:41 -08001913 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 12:22:16 -08001914 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001915}
1916
1917// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1918// the case in a DTLS offer.
1919TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1920 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08001921 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001922 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08001923 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001924
1925 std::string sdp_with_fingerprint = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02001926 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1927 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001928
1929 EXPECT_EQ(sdp_with_fingerprint, message);
1930}
1931
1932// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1933// be the case in a DTLS answer.
1934TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1935 AddFingerprint();
1936 RemoveCryptos();
Steve Antona3a92c22017-12-07 10:27:41 -08001937 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001938 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08001939 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001940
1941 std::string sdp_with_fingerprint = kSdpString;
1942 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1943 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
Yves Gerey665174f2018-06-19 15:03:05 +02001944 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1945 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001946
1947 EXPECT_EQ(sdp_with_fingerprint, message);
1948}
1949
1950TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1951 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08001952 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001953 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001954 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001955 EXPECT_EQ(std::string(kSdpString), message);
1956}
1957
1958TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1959 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1960 group.AddContentName(kAudioContentName);
1961 group.AddContentName(kVideoContentName);
1962 desc_.AddGroup(group);
Yves Gerey665174f2018-06-19 15:03:05 +02001963 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001964 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08001965 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001966 std::string sdp_with_bundle = kSdpFullString;
1967 InjectAfter(kSessionTime,
1968 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1969 &sdp_with_bundle);
1970 EXPECT_EQ(sdp_with_bundle, message);
1971}
1972
1973TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001974 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001975 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08001976 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001977 acd->set_bandwidth(50 * 1000);
Yves Gerey665174f2018-06-19 15:03:05 +02001978 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001979 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08001980 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001981 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02001982 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001983 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02001984 InjectAfter("c=IN IP4 74.125.127.126\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001985 &sdp_with_bandwidth);
1986 EXPECT_EQ(sdp_with_bandwidth, message);
1987}
1988
1989TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1990 std::vector<std::string> transport_options;
1991 transport_options.push_back(kIceOption1);
1992 transport_options.push_back(kIceOption3);
1993 AddIceOptions(kAudioContentName, transport_options);
1994 transport_options.clear();
1995 transport_options.push_back(kIceOption2);
1996 transport_options.push_back(kIceOption3);
1997 AddIceOptions(kVideoContentName, transport_options);
Yves Gerey665174f2018-06-19 15:03:05 +02001998 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001999 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002000 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002001 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002002 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002003 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002004 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002005 &sdp_with_ice_options);
2006 EXPECT_EQ(sdp_with_ice_options, message);
2007}
2008
2009TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002010 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002011}
2012
2013TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002014 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002015}
2016
2017TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002018 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002019}
2020
2021TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2022 EXPECT_TRUE(TestSerializeRejected(true, false));
2023}
2024
2025TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2026 EXPECT_TRUE(TestSerializeRejected(false, true));
2027}
2028
2029TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2030 EXPECT_TRUE(TestSerializeRejected(true, true));
2031}
2032
2033TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
2034 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002035 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002036
zhihuang38989e52017-03-21 11:04:53 -07002037 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002038 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002039
2040 std::string expected_sdp = kSdpString;
2041 expected_sdp.append(kSdpRtpDataChannelString);
2042 EXPECT_EQ(expected_sdp, message);
2043}
2044
2045TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08002046 bool use_sctpmap = true;
2047 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002048 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002049
zhihuang38989e52017-03-21 11:04:53 -07002050 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002051 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002052
2053 std::string expected_sdp = kSdpString;
2054 expected_sdp.append(kSdpSctpDataChannelString);
2055 EXPECT_EQ(message, expected_sdp);
2056}
2057
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002058TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08002059 bool use_sctpmap = true;
2060 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002061 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002062 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antonb1c1de12017-12-21 15:14:30 -08002063 DataContentDescription* dcdesc =
2064 jsep_desc.description()
2065 ->GetContentDescriptionByName(kDataContentName)
2066 ->as_data();
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002067
2068 const int kNewPort = 1234;
solenberg9fa49752016-10-08 13:02:44 -07002069 cricket::DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07002070 cricket::kGoogleSctpDataCodecName);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002071 codec.SetParam(cricket::kCodecParamPort, kNewPort);
2072 dcdesc->AddOrReplaceCodec(codec);
2073
Steve Antone831b8c2018-02-01 12:22:16 -08002074 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002075
2076 std::string expected_sdp = kSdpString;
2077 expected_sdp.append(kSdpSctpDataChannelString);
2078
2079 char default_portstr[16];
2080 char new_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002081 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
Yves Gerey665174f2018-06-19 15:03:05 +02002082 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002083 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
Yves Gerey665174f2018-06-19 15:03:05 +02002084 rtc::replace_substrs(default_portstr, strlen(default_portstr), new_portstr,
2085 strlen(new_portstr), &expected_sdp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002086
2087 EXPECT_EQ(expected_sdp, message);
2088}
2089
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002090TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002091 JsepSessionDescription jsep_desc(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002092 AddRtpDataChannel();
Yves Gerey665174f2018-06-19 15:03:05 +02002093 data_desc_->set_bandwidth(100 * 1000);
zhihuang38989e52017-03-21 11:04:53 -07002094 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002095 std::string message = webrtc::SdpSerialize(jsep_desc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002096
2097 std::string expected_sdp = kSdpString;
2098 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002099 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00002100 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02002101 "b=AS:100\r\n", &expected_sdp);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002102 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002103}
2104
Johannes Kron0854eb62018-10-10 22:33:20 +02002105TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapAllowMixed) {
2106 jdesc_.description()->set_mixed_one_two_byte_header_extensions_supported(
2107 true);
2108 TestSerialize(jdesc_);
2109}
2110
2111TEST_F(WebRtcSdpTest, SerializeMediaContentDescriptionWithExtmapAllowMixed) {
2112 cricket::MediaContentDescription* video_desc =
2113 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2114 ASSERT_TRUE(video_desc);
2115 cricket::MediaContentDescription* audio_desc =
2116 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2117 ASSERT_TRUE(audio_desc);
2118 video_desc->set_mixed_one_two_byte_header_extensions_supported(
2119 cricket::MediaContentDescription::kMedia);
2120 audio_desc->set_mixed_one_two_byte_header_extensions_supported(
2121 cricket::MediaContentDescription::kMedia);
2122 TestSerialize(jdesc_);
2123}
2124
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002125TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002126 bool encrypted = false;
2127 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002128 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002129 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 12:22:16 -08002130 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002131
2132 std::string sdp_with_extmap = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002133 InjectAfter("a=mid:audio_content_name\r\n", kExtmap, &sdp_with_extmap);
2134 InjectAfter("a=mid:video_content_name\r\n", kExtmap, &sdp_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002135
2136 EXPECT_EQ(sdp_with_extmap, message);
2137}
2138
jbauch5869f502017-06-29 12:31:36 -07002139TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2140 bool encrypted = true;
2141 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002142 JsepSessionDescription desc_with_extmap(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002143 ASSERT_TRUE(
2144 desc_with_extmap.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 12:22:16 -08002145 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07002146}
2147
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002148TEST_F(WebRtcSdpTest, SerializeCandidates) {
2149 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002150 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002151
2152 Candidate candidate_with_ufrag(candidates_.front());
2153 candidate_with_ufrag.set_username("ABC");
2154 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2155 candidate_with_ufrag));
2156 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2157 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002158
2159 Candidate candidate_with_network_info(candidates_.front());
2160 candidate_with_network_info.set_network_id(1);
2161 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2162 candidate_with_network_info));
2163 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2164 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2165 candidate_with_network_info.set_network_cost(999);
2166 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2167 candidate_with_network_info));
2168 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2169 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2170 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002171}
2172
Zach Steinb336c272018-08-09 01:16:13 -07002173TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) {
2174 rtc::SocketAddress address("a.test", 1234);
2175 cricket::Candidate candidate(
2176 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
2177 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
2178 JsepIceCandidate jcandidate(std::string("audio_content_name"), 0, candidate);
2179 std::string message = webrtc::SdpSerializeCandidate(jcandidate);
2180 EXPECT_EQ(std::string(kRawHostnameCandidate), message);
2181}
2182
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002183// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2184// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002185TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002186 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002187 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2188 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2189 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002190 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002191 std::unique_ptr<IceCandidateInterface> jcandidate(
2192 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002193
2194 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2195 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2196}
2197
htaa6b99442016-04-12 10:29:17 -07002198TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002199 cricket::VideoCodec h264_codec("H264");
2200 h264_codec.SetParam("profile-level-id", "42e01f");
2201 h264_codec.SetParam("level-asymmetry-allowed", "1");
2202 h264_codec.SetParam("packetization-mode", "1");
2203 video_desc_->AddCodec(h264_codec);
2204
htaa6b99442016-04-12 10:29:17 -07002205 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
2206
Steve Antone831b8c2018-02-01 12:22:16 -08002207 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 10:29:17 -07002208 size_t after_pt = message.find(" H264/90000");
2209 ASSERT_NE(after_pt, std::string::npos);
2210 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2211 ASSERT_NE(before_pt, std::string::npos);
2212 before_pt += strlen("a=rtpmap:");
2213 std::string pt = message.substr(before_pt, after_pt - before_pt);
2214 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2215 std::string to_find = "a=fmtp:" + pt + " ";
2216 size_t fmtp_pos = message.find(to_find);
2217 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
2218 size_t fmtp_endpos = message.find("\n", fmtp_pos);
2219 ASSERT_NE(std::string::npos, fmtp_endpos);
2220 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2221 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2222 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2223 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002224 // Check that there are no spaces after semicolons.
2225 // https://bugs.webrtc.org/5793
2226 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002227}
2228
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002229TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 10:27:41 -08002230 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002231 // Deserialize
2232 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2233 // Verify
2234 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2235}
2236
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002237TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 10:27:41 -08002238 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002239 const char kSdpWithoutMline[] =
Yves Gerey665174f2018-06-19 15:03:05 +02002240 "v=0\r\n"
2241 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2242 "s=-\r\n"
2243 "t=0 0\r\n"
2244 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002245 // Deserialize
2246 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2247 EXPECT_EQ(0u, jdesc.description()->contents().size());
2248}
2249
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002250TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 10:27:41 -08002251 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002252 std::string sdp_without_carriage_return = kSdpFullString;
2253 Replace("\r\n", "\n", &sdp_without_carriage_return);
2254 // Deserialize
2255 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2256 // Verify
2257 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2258}
2259
2260TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2261 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002262 JsepSessionDescription jdesc_no_candidates(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002263 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
2264 kSessionVersion));
Steve Antona3a92c22017-12-07 10:27:41 -08002265 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002266 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2267 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2268}
2269
2270TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2271 static const char kSdpNoRtpmapString[] =
2272 "v=0\r\n"
2273 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2274 "s=-\r\n"
2275 "t=0 0\r\n"
2276 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2277 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002278 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002279 // The rtpmap line for static payload codec is optional.
2280 "a=rtpmap:18 G729/16000\r\n"
2281 "a=rtpmap:103 ISAC/16000\r\n";
2282
Steve Antona3a92c22017-12-07 10:27:41 -08002283 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002284 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2285 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002286 jdesc.description()
2287 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2288 ->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002289 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002290 // The codecs in the AudioContentDescription should be in the same order as
2291 // the payload types (<fmt>s) on the m= line.
2292 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2293 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002294 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002295 EXPECT_EQ(ref_codecs, audio->codecs());
2296}
2297
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002298TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2299 static const char kSdpNoRtpmapString[] =
2300 "v=0\r\n"
2301 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2302 "s=-\r\n"
2303 "t=0 0\r\n"
2304 "m=audio 49232 RTP/AVP 18 103\r\n"
2305 "a=fmtp:18 annexb=yes\r\n"
2306 "a=rtpmap:103 ISAC/16000\r\n";
2307
Steve Antona3a92c22017-12-07 10:27:41 -08002308 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002309 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2310 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002311 jdesc.description()
2312 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2313 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002314
2315 cricket::AudioCodec g729 = audio->codecs()[0];
2316 EXPECT_EQ("G729", g729.name);
2317 EXPECT_EQ(8000, g729.clockrate);
2318 EXPECT_EQ(18, g729.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002319 cricket::CodecParameterMap::iterator found = g729.params.find("annexb");
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002320 ASSERT_TRUE(found != g729.params.end());
2321 EXPECT_EQ(found->second, "yes");
2322
2323 cricket::AudioCodec isac = audio->codecs()[1];
2324 EXPECT_EQ("ISAC", isac.name);
2325 EXPECT_EQ(103, isac.id);
2326 EXPECT_EQ(16000, isac.clockrate);
2327}
2328
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002329// Ensure that we can deserialize SDP with a=fingerprint properly.
2330TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2331 // Add a DTLS a=fingerprint attribute to our session description.
2332 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002333 JsepSessionDescription new_jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002334 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002335 jdesc_.session_version()));
2336
Steve Antona3a92c22017-12-07 10:27:41 -08002337 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002338 std::string sdp_with_fingerprint = kSdpString;
2339 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2340 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2341 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2342 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2343}
2344
2345TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 10:27:41 -08002346 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002347 std::string sdp_with_bundle = kSdpFullString;
2348 InjectAfter(kSessionTime,
2349 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2350 &sdp_with_bundle);
2351 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2352 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2353 group.AddContentName(kAudioContentName);
2354 group.AddContentName(kVideoContentName);
2355 desc_.AddGroup(group);
Yves Gerey665174f2018-06-19 15:03:05 +02002356 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002357 jdesc_.session_version()));
2358 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2359}
2360
2361TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002362 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002363 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002364 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002365 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002366 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002367 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002368 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 15:14:30 -08002369 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002370 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002371 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002372 acd->set_bandwidth(50 * 1000);
Yves Gerey665174f2018-06-19 15:03:05 +02002373 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002374 jdesc_.session_version()));
2375 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2376}
2377
2378TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 10:27:41 -08002379 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002380 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002381 InjectAfter(kSessionTime, "a=ice-options:iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002382 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002383 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002384 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002385 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002386 &sdp_with_ice_options);
2387 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2388 std::vector<std::string> transport_options;
2389 transport_options.push_back(kIceOption3);
2390 transport_options.push_back(kIceOption1);
2391 AddIceOptions(kAudioContentName, transport_options);
2392 transport_options.clear();
2393 transport_options.push_back(kIceOption3);
2394 transport_options.push_back(kIceOption2);
2395 AddIceOptions(kVideoContentName, transport_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002396 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002397 jdesc_.session_version()));
2398 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2399}
2400
2401TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2402 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 10:27:41 -08002403 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002404 std::string sdp_with_ufrag_pwd = kSdpFullString;
2405 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2406 // Add session level ufrag and pwd
2407 InjectAfter(kSessionTime,
Yves Gerey665174f2018-06-19 15:03:05 +02002408 "a=ice-pwd:session+level+icepwd\r\n"
2409 "a=ice-ufrag:session+level+iceufrag\r\n",
2410 &sdp_with_ufrag_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002411 // Add media level ufrag and pwd for audio
Yves Gerey665174f2018-06-19 15:03:05 +02002412 InjectAfter(
2413 "a=mid:audio_content_name\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002414 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2415 &sdp_with_ufrag_pwd);
2416 // Update the candidate ufrag and pwd to the expected ones.
Yves Gerey665174f2018-06-19 15:03:05 +02002417 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, "media+level+iceufrag",
2418 "media+level+icepwd"));
2419 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, "session+level+iceufrag",
2420 "session+level+icepwd"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002421 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2422 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2423}
2424
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002425TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002426 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002427}
2428
2429TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002430 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002431}
2432
2433TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002434 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002435}
2436
2437TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2438 EXPECT_TRUE(TestDeserializeRejected(true, false));
2439}
2440
2441TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2442 EXPECT_TRUE(TestDeserializeRejected(false, true));
2443}
2444
2445TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2446 EXPECT_TRUE(TestDeserializeRejected(true, true));
2447}
2448
2449// Tests that we can still handle the sdp uses mslabel and label instead of
2450// msid for backward compatibility.
2451TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07002452 jdesc_.description()->set_msid_supported(false);
Steve Antona3a92c22017-12-07 10:27:41 -08002453 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002454 std::string sdp_without_msid = kSdpFullString;
2455 Replace("msid", "xmsid", &sdp_without_msid);
2456 // Deserialize
2457 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2458 // Verify
2459 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2460}
2461
Johannes Kron0854eb62018-10-10 22:33:20 +02002462TEST_F(WebRtcSdpTest, SessionLevelMixedHeaderExtensionsAlsoSetsMediaSetting) {
2463 cricket::MediaContentDescription* video_desc =
2464 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2465 ASSERT_TRUE(video_desc);
2466 cricket::MediaContentDescription* audio_desc =
2467 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2468 ASSERT_TRUE(audio_desc);
2469
2470 // Setting true on session level propagates to media level.
2471 jdesc_.description()->set_mixed_one_two_byte_header_extensions_supported(
2472 true);
2473 EXPECT_EQ(cricket::MediaContentDescription::kSession,
2474 video_desc->mixed_one_two_byte_header_extensions_supported());
2475 EXPECT_EQ(cricket::MediaContentDescription::kSession,
2476 audio_desc->mixed_one_two_byte_header_extensions_supported());
2477
2478 // Don't downgrade from session level to media level
2479 video_desc->set_mixed_one_two_byte_header_extensions_supported(
2480 cricket::MediaContentDescription::kMedia);
2481 EXPECT_EQ(cricket::MediaContentDescription::kSession,
2482 video_desc->mixed_one_two_byte_header_extensions_supported());
2483
2484 // Setting false on session level propagates to media level.
2485 jdesc_.description()->set_mixed_one_two_byte_header_extensions_supported(
2486 false);
2487 EXPECT_EQ(cricket::MediaContentDescription::kNo,
2488 video_desc->mixed_one_two_byte_header_extensions_supported());
2489 EXPECT_EQ(cricket::MediaContentDescription::kNo,
2490 audio_desc->mixed_one_two_byte_header_extensions_supported());
2491
2492 // Now possible to set at media level.
2493 video_desc->set_mixed_one_two_byte_header_extensions_supported(
2494 cricket::MediaContentDescription::kMedia);
2495 EXPECT_EQ(cricket::MediaContentDescription::kMedia,
2496 video_desc->mixed_one_two_byte_header_extensions_supported());
2497}
2498
2499TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithExtmapAllowMixed) {
2500 jdesc_.description()->set_mixed_one_two_byte_header_extensions_supported(
2501 true);
2502 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2503 InjectAfter("t=0 0\r\n", kExtmapAllowMixed, &sdp_with_extmap_allow_mixed);
2504 // Deserialize
2505 JsepSessionDescription jdesc_deserialized(kDummyType);
2506 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2507 // Verify
2508 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2509}
2510
2511TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutExtmapAllowMixed) {
2512 jdesc_.description()->set_mixed_one_two_byte_header_extensions_supported(
2513 false);
2514 std::string sdp_without_extmap_allow_mixed = kSdpFullString;
2515 // Deserialize
2516 JsepSessionDescription jdesc_deserialized(kDummyType);
2517 EXPECT_TRUE(
2518 SdpDeserialize(sdp_without_extmap_allow_mixed, &jdesc_deserialized));
2519 // Verify
2520 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2521}
2522
2523TEST_F(WebRtcSdpTest, DeserializeMediaContentDescriptionWithExtmapAllowMixed) {
2524 cricket::MediaContentDescription* video_desc =
2525 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2526 ASSERT_TRUE(video_desc);
2527 cricket::MediaContentDescription* audio_desc =
2528 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2529 ASSERT_TRUE(audio_desc);
2530 video_desc->set_mixed_one_two_byte_header_extensions_supported(
2531 cricket::MediaContentDescription::kMedia);
2532 audio_desc->set_mixed_one_two_byte_header_extensions_supported(
2533 cricket::MediaContentDescription::kMedia);
2534
2535 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2536 InjectAfter("a=mid:audio_content_name\r\n", kExtmapAllowMixed,
2537 &sdp_with_extmap_allow_mixed);
2538 InjectAfter("a=mid:video_content_name\r\n", kExtmapAllowMixed,
2539 &sdp_with_extmap_allow_mixed);
2540
2541 // Deserialize
2542 JsepSessionDescription jdesc_deserialized(kDummyType);
2543 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2544 // Verify
2545 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2546}
2547
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002548TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2549 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2550
2551 std::string sdp = kSdpOneCandidate;
2552 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2553 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2554 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2555 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002556 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002557
2558 // Candidate line without generation extension.
2559 sdp = kSdpOneCandidate;
2560 Replace(" generation 2", "", &sdp);
2561 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2562 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2563 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2564 Candidate expected = jcandidate_->candidate();
2565 expected.set_generation(0);
2566 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2567
honghaiza0c44ea2016-03-23 16:07:48 -07002568 // Candidate with network id and/or cost.
2569 sdp = kSdpOneCandidate;
2570 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2571 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2572 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2573 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2574 expected = jcandidate_->candidate();
2575 expected.set_network_id(2);
2576 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2577 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2578 // Add network cost
2579 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2580 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2581 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2582 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2583
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002584 sdp = kSdpTcpActiveCandidate;
2585 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2586 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002587 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002588 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2589 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2590 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002591 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2592 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
Yves Gerey665174f2018-06-19 15:03:05 +02002593 EXPECT_TRUE(
2594 jcandidate.candidate().IsEquivalent(jcandidate_template->candidate()));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002595 sdp = kSdpTcpPassiveCandidate;
2596 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2597 sdp = kSdpTcpSOCandidate;
2598 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002599}
2600
2601// This test verifies the deserialization of candidate-attribute
2602// as per RFC 5245. Candiate-attribute will be of the format
2603// candidate:<blah>. This format will be used when candidates
2604// are trickled.
2605TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2606 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2607
2608 std::string candidate_attribute = kRawCandidate;
2609 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2610 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2611 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2612 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2613 EXPECT_EQ(2u, jcandidate.candidate().generation());
2614
2615 // Candidate line without generation extension.
2616 candidate_attribute = kRawCandidate;
2617 Replace(" generation 2", "", &candidate_attribute);
2618 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2619 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2620 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2621 Candidate expected = jcandidate_->candidate();
2622 expected.set_generation(0);
2623 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2624
2625 // Candidate line without candidate:
2626 candidate_attribute = kRawCandidate;
2627 Replace("candidate:", "", &candidate_attribute);
2628 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2629
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002630 // Candidate line with IPV6 address.
2631 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
Zach Steinb336c272018-08-09 01:16:13 -07002632
2633 // Candidate line with hostname address.
2634 EXPECT_TRUE(SdpDeserializeCandidate(kRawHostnameCandidate, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002635}
2636
2637// This test verifies that the deserialization of an invalid candidate string
2638// fails.
2639TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
Yves Gerey665174f2018-06-19 15:03:05 +02002640 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002641
2642 std::string candidate_attribute = kRawCandidate;
2643 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002644 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002645
2646 candidate_attribute = kSdpOneCandidate;
2647 candidate_attribute.replace(0, 1, "x");
2648 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2649
2650 candidate_attribute = kRawCandidate;
2651 candidate_attribute.append("\r\n");
2652 candidate_attribute.append(kRawCandidate);
2653 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2654
2655 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002656}
2657
2658TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2659 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002660 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002661 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2662
2663 std::string sdp_with_data = kSdpString;
2664 sdp_with_data.append(kSdpRtpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002665 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002666
2667 // Deserialize
2668 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2669 // Verify
2670 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2671}
2672
2673TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002674 bool use_sctpmap = true;
2675 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002676 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002677 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2678
2679 std::string sdp_with_data = kSdpString;
2680 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002681 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002682
lally@webrtc.org36300852015-02-24 20:19:35 +00002683 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2684 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2685 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2686
2687 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002688 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2689 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002690 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2691 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2692
2693 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002694 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2695 kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002696 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2697 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2698}
2699
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002700TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002701 bool use_sctpmap = false;
2702 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002703 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002704 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2705
2706 std::string sdp_with_data = kSdpString;
2707 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002708 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002709
lally@webrtc.org36300852015-02-24 20:19:35 +00002710 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002711 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2712 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002713
lally@webrtc.org36300852015-02-24 20:19:35 +00002714 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002715 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2716 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002717 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2718 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002719
lally@webrtc.org36300852015-02-24 20:19:35 +00002720 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002721 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2722 kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002723 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2724 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2725}
2726
lally69f57602015-10-08 10:15:04 -07002727TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002728 bool use_sctpmap = false;
2729 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002730 JsepSessionDescription jdesc(kDummyType);
lally69f57602015-10-08 10:15:04 -07002731 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2732
2733 std::string sdp_with_data = kSdpString;
2734 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002735 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 10:15:04 -07002736
2737 // Verify with DTLS/SCTP.
2738 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2739 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2740
2741 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002742 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2743 kUdpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002744 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2745 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2746
2747 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002748 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2749 kTcpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002750 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2751 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2752}
2753
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002754// Test to check the behaviour if sctp-port is specified
2755// on the m= line and in a=sctp-port.
2756TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002757 bool use_sctpmap = true;
2758 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002759 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002760 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2761
2762 std::string sdp_with_data = kSdpString;
2763 // Append m= attributes
2764 sdp_with_data.append(kSdpSctpDataChannelString);
2765 // Append a=sctp-port attribute
2766 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 10:27:41 -08002767 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002768
2769 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2770}
2771
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002772// For crbug/344475.
2773TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2774 std::string sdp_with_data = kSdpString;
2775 sdp_with_data.append(kSdpSctpDataChannelString);
2776 // Remove the "\n" at the end.
2777 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 10:27:41 -08002778 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002779
2780 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2781 // No crash is a pass.
2782}
2783
Steve Anton36b29d12017-10-30 09:57:42 -07002784void MutateJsepSctpPort(JsepSessionDescription* jdesc,
zstein4b2e0822017-02-17 19:48:38 -08002785 const SessionDescription& desc) {
wu@webrtc.org78187522013-10-07 23:32:02 +00002786 // take our pre-built session description and change the SCTP port.
zstein4b2e0822017-02-17 19:48:38 -08002787 cricket::SessionDescription* mutant = desc.Copy();
Steve Antonb1c1de12017-12-21 15:14:30 -08002788 DataContentDescription* dcdesc =
2789 mutant->GetContentDescriptionByName(kDataContentName)->as_data();
wu@webrtc.org78187522013-10-07 23:32:02 +00002790 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002791 EXPECT_EQ(1U, codecs.size());
solenberg9fa49752016-10-08 13:02:44 -07002792 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002793 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002794 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002795
2796 // note: mutant's owned by jdesc now.
Steve Anton36b29d12017-10-30 09:57:42 -07002797 ASSERT_TRUE(jdesc->Initialize(mutant, kSessionId, kSessionVersion));
wu@webrtc.org78187522013-10-07 23:32:02 +00002798 mutant = NULL;
zstein4b2e0822017-02-17 19:48:38 -08002799}
2800
2801TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
2802 bool use_sctpmap = true;
2803 AddSctpDataChannel(use_sctpmap);
2804
2805 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 10:27:41 -08002806 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002807 MutateJsepSctpPort(&jdesc, desc_);
wu@webrtc.org78187522013-10-07 23:32:02 +00002808
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002809 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002810 std::string sdp_with_data = kSdpString;
2811 sdp_with_data.append(kSdpSctpDataChannelString);
zstein4b2e0822017-02-17 19:48:38 -08002812 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2813 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2814 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002815 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:02 +00002816
2817 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2818 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08002819}
2820
2821TEST_F(WebRtcSdpTest,
2822 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
2823 bool use_sctpmap = false;
2824 AddSctpDataChannel(use_sctpmap);
2825
Steve Antona3a92c22017-12-07 10:27:41 -08002826 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002827 MutateJsepSctpPort(&jdesc, desc_);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002828
2829 // We need to test the deserialized JsepSessionDescription from
2830 // kSdpSctpDataChannelStringWithSctpPort for
2831 // draft-ietf-mmusic-sctp-sdp-07
2832 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08002833 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002834 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
zstein4b2e0822017-02-17 19:48:38 -08002835 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2836 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2837 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002838 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002839
2840 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2841 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002842}
2843
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002844TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002845 // We want to test that deserializing data content limits bandwidth
2846 // settings (it should never be greater than the default).
2847 // This should prevent someone from using unlimited data bandwidth through
2848 // JS and "breaking the Internet".
2849 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002850 std::string sdp_with_bandwidth = kSdpString;
2851 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02002852 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002853 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002854 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002855
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002856 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2857}
2858
2859TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08002860 bool use_sctpmap = true;
2861 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002862 JsepSessionDescription jdesc(kDummyType);
Steve Antonb1c1de12017-12-21 15:14:30 -08002863 DataContentDescription* dcd = GetFirstDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002864 dcd->set_bandwidth(100 * 1000);
2865 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2866
2867 std::string sdp_with_bandwidth = kSdpString;
2868 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02002869 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002870 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002871 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002872
2873 // SCTP has congestion control, so we shouldn't limit the bandwidth
2874 // as we do for RTP.
2875 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002876 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2877}
2878
Yves Gerey665174f2018-06-19 15:03:05 +02002879class WebRtcSdpExtmapTest : public WebRtcSdpTest,
2880 public testing::WithParamInterface<bool> {};
jbauch5869f502017-06-29 12:31:36 -07002881
2882TEST_P(WebRtcSdpExtmapTest,
Yves Gerey665174f2018-06-19 15:03:05 +02002883 DeserializeSessionDescriptionWithSessionLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002884 bool encrypted = GetParam();
2885 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002886}
2887
Yves Gerey665174f2018-06-19 15:03:05 +02002888TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002889 bool encrypted = GetParam();
2890 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002891}
2892
Yves Gerey665174f2018-06-19 15:03:05 +02002893TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithInvalidExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002894 bool encrypted = GetParam();
2895 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002896}
2897
jbauch5869f502017-06-29 12:31:36 -07002898INSTANTIATE_TEST_CASE_P(Encrypted,
2899 WebRtcSdpExtmapTest,
2900 ::testing::Values(false, true));
2901
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002902TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 10:27:41 -08002903 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002904 std::string sdp = kSdpFullString;
2905 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2906 // Deserialize
2907 SdpParseError error;
2908 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-16 17:54:10 -08002909 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002910 EXPECT_EQ(lastline, error.line);
2911 EXPECT_EQ("Invalid SDP line.", error.description);
2912}
2913
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002914TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2915 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2916 std::string new_sdp = kSdpOneCandidate;
2917 Replace("udp", "unsupported_transport", &new_sdp);
2918 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2919 new_sdp = kSdpOneCandidate;
2920 Replace("udp", "uDP", &new_sdp);
2921 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2922 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2923 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2924 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2925}
2926
honghaiza54a0802015-12-16 18:37:23 -08002927TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002928 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08002929 EXPECT_TRUE(
2930 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002931 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2932 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2933 Candidate ref_candidate = jcandidate_->candidate();
2934 ref_candidate.set_username("user_rtp");
2935 ref_candidate.set_password("password_rtp");
2936 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2937}
2938
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002939TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08002940 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002941
2942 // Deserialize
2943 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2944
2945 // Verify
2946 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002947 jdesc.description()
2948 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2949 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002950 EXPECT_TRUE(audio->conference_mode());
2951
2952 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 15:14:30 -08002953 jdesc.description()
2954 ->GetContentDescriptionByName(cricket::CN_VIDEO)
2955 ->as_video();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002956 EXPECT_TRUE(video->conference_mode());
2957}
2958
deadbeefd45aea82017-09-16 01:24:29 -07002959TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08002960 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 01:24:29 -07002961
2962 // We tested deserialization already above, so just test that if we serialize
2963 // and deserialize the flag doesn't disappear.
2964 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 12:22:16 -08002965 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 01:24:29 -07002966 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
2967
2968 // Verify.
2969 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002970 jdesc.description()
2971 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2972 ->as_audio();
deadbeefd45aea82017-09-16 01:24:29 -07002973 EXPECT_TRUE(audio->conference_mode());
2974
2975 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 15:14:30 -08002976 jdesc.description()
2977 ->GetContentDescriptionByName(cricket::CN_VIDEO)
2978 ->as_video();
deadbeefd45aea82017-09-16 01:24:29 -07002979 EXPECT_TRUE(video->conference_mode());
2980}
2981
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002982TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2983 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002984 const char kSdpEmptyType[] = " =candidate";
2985 const char kSdpEqualAsPlus[] = "a+candidate";
2986 const char kSdpSpaceAfterEqual[] = "a= candidate";
2987 const char kSdpUpperType[] = "A=candidate";
2988 const char kSdpEmptyLine[] = "";
2989 const char kSdpMissingValue[] = "a=";
2990
Yves Gerey665174f2018-06-19 15:03:05 +02002991 const char kSdpBrokenFingerprint[] =
2992 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002993 "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 +02002994 const char kSdpExtraField[] =
2995 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002996 "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 +02002997 const char kSdpMissingSpace[] =
2998 "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002999 "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 +00003000 // MD5 is not allowed in fingerprints.
Yves Gerey665174f2018-06-19 15:03:05 +02003001 const char kSdpMd5[] =
3002 "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003003 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003004
3005 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003006 ExpectParseFailure("v=", kSdpDestroyer);
3007 ExpectParseFailure("o=", kSdpDestroyer);
3008 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003009 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003010 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003011
3012 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003013 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
3014 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003015
3016 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003017 ExpectParseFailure("a=candidate", kSdpEmptyType);
3018 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
3019 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
3020 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003021
3022 // Bogus fingerprint replacing a=sendrev. We selected this attribute
3023 // because it's orthogonal to what we are replacing and hence
3024 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003025 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
3026 ExpectParseFailure("a=sendrecv", kSdpExtraField);
3027 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
3028 ExpectParseFailure("a=sendrecv", kSdpMd5);
3029
3030 // Empty Line
3031 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
3032 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003033}
3034
3035TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
3036 // ssrc
3037 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08003038 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003039 // crypto
3040 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
3041 // rtpmap
3042 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
3043 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
3044 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
3045 // candidate
3046 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
3047 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
3048 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
3049 ExpectParseFailure("rport 2346", "rport badvalue");
3050 ExpectParseFailure("rport 2346 generation 2",
3051 "rport 2346 generation badvalue");
3052 // m line
3053 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
3054 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
3055
3056 // bandwidth
3057 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003058 "b=AS:badvalue\r\n", "b=AS:badvalue");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003059 // rtcp-fb
3060 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3061 "a=rtcp-fb:badvalue nack\r\n",
3062 "a=rtcp-fb:badvalue nack");
3063 // extmap
3064 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3065 "a=extmap:badvalue http://example.com\r\n",
3066 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003067}
3068
3069TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 10:27:41 -08003070 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003071
3072 const char kSdpWithReorderedPlTypesString[] =
3073 "v=0\r\n"
3074 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3075 "s=-\r\n"
3076 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00003077 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
Yves Gerey665174f2018-06-19 15:03:05 +02003078 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
3079 // in the map.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003080 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003081 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003082
3083 // Deserialize
3084 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
3085
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003086 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003087 GetFirstAudioContentDescription(jdesc_output.description());
3088 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003089 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003090 EXPECT_EQ("ISAC", acd->codecs()[0].name);
3091 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003092 EXPECT_EQ(104, acd->codecs()[0].id);
3093}
3094
3095TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 10:27:41 -08003096 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003097 CodecParams params;
3098 params.max_ptime = 40;
3099 params.ptime = 30;
3100 params.min_ptime = 10;
3101 params.sprop_stereo = 1;
3102 params.stereo = 1;
3103 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003104 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003105 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 12:22:16 -08003106 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003107}
3108
3109TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
3110 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 10:27:41 -08003111 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003112 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003113 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003114}
3115
3116TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
3117 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 10:27:41 -08003118 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003119 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003120 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003121}
3122
3123TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 10:27:41 -08003124 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003125
3126 const char kSdpWithFmtpString[] =
3127 "v=0\r\n"
3128 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3129 "s=-\r\n"
3130 "t=0 0\r\n"
3131 "m=video 3457 RTP/SAVPF 120\r\n"
3132 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07003133 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3134
3135 // Deserialize
3136 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07003137 EXPECT_TRUE(
3138 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07003139
Donald Curtis0e07f922015-05-15 09:21:23 -07003140 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003141 GetFirstVideoContentDescription(jdesc_output.description());
3142 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 09:21:23 -07003143 ASSERT_FALSE(vcd->codecs().empty());
3144 cricket::VideoCodec vp8 = vcd->codecs()[0];
3145 EXPECT_EQ("VP8", vp8.name);
3146 EXPECT_EQ(120, vp8.id);
3147 cricket::CodecParameterMap::iterator found =
3148 vp8.params.find("x-google-min-bitrate");
3149 ASSERT_TRUE(found != vp8.params.end());
3150 EXPECT_EQ(found->second, "10");
3151 found = vp8.params.find("x-google-max-quantization");
3152 ASSERT_TRUE(found != vp8.params.end());
3153 EXPECT_EQ(found->second, "40");
3154}
3155
johan2d8d23e2016-06-03 01:22:42 -07003156TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 10:27:41 -08003157 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 01:22:42 -07003158
3159 const char kSdpWithFmtpString[] =
3160 "v=0\r\n"
3161 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3162 "s=-\r\n"
3163 "t=0 0\r\n"
3164 "m=video 49170 RTP/AVP 98\r\n"
3165 "a=rtpmap:98 H264/90000\r\n"
3166 "a=fmtp:98 profile-level-id=42A01E; "
3167 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3168
3169 // Deserialize.
3170 SdpParseError error;
3171 EXPECT_TRUE(
3172 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3173
johan2d8d23e2016-06-03 01:22:42 -07003174 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003175 GetFirstVideoContentDescription(jdesc_output.description());
3176 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 01:22:42 -07003177 ASSERT_FALSE(vcd->codecs().empty());
3178 cricket::VideoCodec h264 = vcd->codecs()[0];
3179 EXPECT_EQ("H264", h264.name);
3180 EXPECT_EQ(98, h264.id);
3181 cricket::CodecParameterMap::const_iterator found =
3182 h264.params.find("profile-level-id");
3183 ASSERT_TRUE(found != h264.params.end());
3184 EXPECT_EQ(found->second, "42A01E");
3185 found = h264.params.find("sprop-parameter-sets");
3186 ASSERT_TRUE(found != h264.params.end());
3187 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3188}
3189
Donald Curtis0e07f922015-05-15 09:21:23 -07003190TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 10:27:41 -08003191 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 09:21:23 -07003192
3193 const char kSdpWithFmtpString[] =
3194 "v=0\r\n"
3195 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3196 "s=-\r\n"
3197 "t=0 0\r\n"
3198 "m=video 3457 RTP/SAVPF 120\r\n"
3199 "a=rtpmap:120 VP8/90000\r\n"
3200 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003201
3202 // Deserialize
3203 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02003204 EXPECT_TRUE(
3205 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003206
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003207 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003208 GetFirstVideoContentDescription(jdesc_output.description());
3209 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003210 ASSERT_FALSE(vcd->codecs().empty());
3211 cricket::VideoCodec vp8 = vcd->codecs()[0];
3212 EXPECT_EQ("VP8", vp8.name);
3213 EXPECT_EQ(120, vp8.id);
3214 cricket::CodecParameterMap::iterator found =
3215 vp8.params.find("x-google-min-bitrate");
3216 ASSERT_TRUE(found != vp8.params.end());
3217 EXPECT_EQ(found->second, "10");
3218 found = vp8.params.find("x-google-max-quantization");
3219 ASSERT_TRUE(found != vp8.params.end());
3220 EXPECT_EQ(found->second, "40");
3221}
3222
ossuaa4b0772017-01-30 07:41:18 -08003223TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003224 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003225
3226 cricket::AudioCodecs codecs = acd->codecs();
3227 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3228 acd->set_codecs(codecs);
3229
Yves Gerey665174f2018-06-19 15:03:05 +02003230 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003231 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003232 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003233 std::string sdp_with_fmtp = kSdpFullString;
3234 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3235 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3236 &sdp_with_fmtp);
3237 EXPECT_EQ(sdp_with_fmtp, message);
3238}
3239
3240TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003241 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003242
3243 cricket::AudioCodecs codecs = acd->codecs();
3244 codecs[0].params["stereo"] = "1";
3245 acd->set_codecs(codecs);
3246
Yves Gerey665174f2018-06-19 15:03:05 +02003247 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003248 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003249 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003250 std::string sdp_with_fmtp = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003251 InjectAfter("a=rtpmap:111 opus/48000/2\r\n", "a=fmtp:111 stereo=1\r\n",
ossuaa4b0772017-01-30 07:41:18 -08003252 &sdp_with_fmtp);
3253 EXPECT_EQ(sdp_with_fmtp, message);
3254}
3255
3256TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003257 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003258
3259 cricket::AudioCodecs codecs = acd->codecs();
3260 codecs[0].params["ptime"] = "20";
3261 codecs[0].params["maxptime"] = "120";
3262 acd->set_codecs(codecs);
3263
Yves Gerey665174f2018-06-19 15:03:05 +02003264 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003265 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003266 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003267 std::string sdp_with_fmtp = kSdpFullString;
3268 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3269 "a=maxptime:120\r\n" // No comma here. String merging!
3270 "a=ptime:20\r\n",
3271 &sdp_with_fmtp);
3272 EXPECT_EQ(sdp_with_fmtp, message);
3273}
3274
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003275TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003276 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003277
3278 cricket::VideoCodecs codecs = vcd->codecs();
3279 codecs[0].params["x-google-min-bitrate"] = "10";
3280 vcd->set_codecs(codecs);
3281
Yves Gerey665174f2018-06-19 15:03:05 +02003282 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003283 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003284 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003285 std::string sdp_with_fmtp = kSdpFullString;
3286 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003287 "a=fmtp:120 x-google-min-bitrate=10\r\n", &sdp_with_fmtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003288 EXPECT_EQ(sdp_with_fmtp, message);
3289}
3290
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003291TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) {
3292 // Deserialize the baseline description, making sure it's ICE full.
Steve Antona3a92c22017-12-07 10:27:41 -08003293 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003294 std::string sdp_with_icelite = kSdpFullString;
3295 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3296 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3297 const cricket::TransportInfo* tinfo1 =
3298 desc->GetTransportInfoByName("audio_content_name");
3299 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3300 const cricket::TransportInfo* tinfo2 =
3301 desc->GetTransportInfoByName("video_content_name");
3302 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003303
3304 // Add "a=ice-lite" and deserialize, making sure it's ICE lite.
Yves Gerey665174f2018-06-19 15:03:05 +02003305 InjectAfter(kSessionTime, "a=ice-lite\r\n", &sdp_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003306 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3307 desc = jdesc_with_icelite.description();
3308 const cricket::TransportInfo* atinfo =
3309 desc->GetTransportInfoByName("audio_content_name");
3310 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3311 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003312 desc->GetTransportInfoByName("video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003313 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003314
3315 // Now that we know deserialization works, we can use TestSerialize to test
3316 // serialization.
3317 TestSerialize(jdesc_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003318}
3319
3320// Verifies that the candidates in the input SDP are parsed and serialized
3321// correctly in the output SDP.
3322TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3323 std::string sdp_with_data = kSdpString;
3324 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 10:27:41 -08003325 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003326
3327 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 12:22:16 -08003328 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003329}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003330
3331TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3332 AddFingerprint();
3333 TransportInfo audio_transport_info =
3334 *(desc_.GetTransportInfoByName(kAudioContentName));
3335 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3336 audio_transport_info.description.connection_role);
3337 audio_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003338 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003339
3340 TransportInfo video_transport_info =
3341 *(desc_.GetTransportInfoByName(kVideoContentName));
3342 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3343 video_transport_info.description.connection_role);
3344 video_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003345 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003346
3347 desc_.RemoveTransportInfoByName(kAudioContentName);
3348 desc_.RemoveTransportInfoByName(kVideoContentName);
3349
3350 desc_.AddTransportInfo(audio_transport_info);
3351 desc_.AddTransportInfo(video_transport_info);
3352
Yves Gerey665174f2018-06-19 15:03:05 +02003353 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003354 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003355 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003356 std::string sdp_with_dtlssetup = kSdpFullString;
3357
3358 // Fingerprint attribute is necessary to add DTLS setup attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003359 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_dtlssetup);
3360 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003361 // Now adding |setup| attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003362 InjectAfter(kFingerprint, "a=setup:active\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003363 EXPECT_EQ(sdp_with_dtlssetup, message);
3364}
3365
3366TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
Steve Antona3a92c22017-12-07 10:27:41 -08003367 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003368 std::string sdp_with_dtlssetup = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003369 InjectAfter(kSessionTime, "a=setup:actpass\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003370 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3371 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3372 const cricket::TransportInfo* atinfo =
3373 desc->GetTransportInfoByName("audio_content_name");
3374 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3375 atinfo->description.connection_role);
3376 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003377 desc->GetTransportInfoByName("video_content_name");
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003378 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3379 vtinfo->description.connection_role);
3380}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003381
3382// Verifies that the order of the serialized m-lines follows the order of the
3383// ContentInfo in SessionDescription, and vise versa for deserialization.
3384TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 10:27:41 -08003385 JsepSessionDescription jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02003386 const std::string media_content_sdps[3] = {kSdpAudioString, kSdpVideoString,
3387 kSdpSctpDataChannelString};
3388 const cricket::MediaType media_types[3] = {cricket::MEDIA_TYPE_AUDIO,
3389 cricket::MEDIA_TYPE_VIDEO,
3390 cricket::MEDIA_TYPE_DATA};
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003391
3392 // Verifies all 6 permutations.
3393 for (size_t i = 0; i < 6; ++i) {
3394 size_t media_content_in_sdp[3];
3395 // The index of the first media content.
3396 media_content_in_sdp[0] = i / 2;
3397 // The index of the second media content.
3398 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3399 // The index of the third media content.
3400 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3401
3402 std::string sdp_string = kSdpSessionString;
3403 for (size_t i = 0; i < 3; ++i)
3404 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3405
3406 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3407 cricket::SessionDescription* desc = jdesc.description();
3408 EXPECT_EQ(3u, desc->contents().size());
3409
3410 for (size_t i = 0; i < 3; ++i) {
3411 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 15:14:30 -08003412 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003413 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3414 }
3415
Steve Antone831b8c2018-02-01 12:22:16 -08003416 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003417 EXPECT_EQ(sdp_string, serialized_sdp);
3418 }
3419}
deadbeef9d3584c2016-02-16 17:54:10 -08003420
deadbeef25ed4352016-12-12 18:37:36 -08003421TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3422 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 10:27:41 -08003423 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003424 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003425 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3426 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3427}
3428
deadbeef12771a12017-01-03 13:53:47 -08003429// The semantics of "a=bundle-only" are only defined when it's used in
3430// combination with a 0 port on the m= line. We should ignore it if used with a
3431// nonzero port.
3432TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3433 // Make the base bundle-only description but unset the bundle-only flag.
3434 MakeBundleOnlyDescription();
3435 jdesc_.description()->contents()[1].bundle_only = false;
3436
3437 std::string modified_sdp = kBundleOnlySdpFullString;
3438 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08003439 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003440 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3441 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003442}
3443
3444TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3445 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003446 TestSerialize(jdesc_);
deadbeef25ed4352016-12-12 18:37:36 -08003447}
3448
deadbeef9d3584c2016-02-16 17:54:10 -08003449TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3450 MakePlanBDescription();
3451
Steve Antona3a92c22017-12-07 10:27:41 -08003452 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003453 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3454
3455 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3456}
3457
3458TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3459 MakePlanBDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003460 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-16 17:54:10 -08003461}
3462
3463TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3464 MakeUnifiedPlanDescription();
3465
Steve Antona3a92c22017-12-07 10:27:41 -08003466 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003467 EXPECT_TRUE(
3468 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3469
3470 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3471}
3472
3473TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3474 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003475 TestSerialize(jdesc_);
3476}
3477
Seth Hampson5b4f0752018-04-02 16:31:36 -07003478// This tests deserializing a Unified Plan SDP that is compatible with both
3479// Unified Plan and Plan B style SDP. It tests the case for audio/video tracks
3480// with no stream ids and multiple stream ids. For parsing this, the Unified
3481// Plan a=msid lines should take priority, because the Plan B style a=ssrc msid
3482// lines do not support multiple stream ids and no stream ids.
3483TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionSpecialMsid) {
3484 MakeUnifiedPlanDescriptionMultipleStreamIds();
3485
3486 JsepSessionDescription deserialized_description(kDummyType);
3487 EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid,
3488 &deserialized_description));
3489
3490 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3491}
3492
3493TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionSpecialMsid) {
3494 MakeUnifiedPlanDescriptionMultipleStreamIds();
3495 TestSerialize(jdesc_);
3496}
3497
Seth Hampson5897a6e2018-04-03 11:16:33 -07003498// This tests that a Unified Plan SDP with no a=ssrc lines is
3499// serialized/deserialized appropriately. In this case the
3500// MediaContentDescription will contain a StreamParams object that doesn't have
3501// any SSRCs. Vice versa, this will be created upon deserializing an SDP with no
3502// SSRC lines.
3503TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3504 MakeUnifiedPlanDescription();
3505 RemoveSsrcSignalingFromStreamParams();
3506 std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString;
3507 RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string);
3508
3509 JsepSessionDescription deserialized_description(kDummyType);
3510 EXPECT_TRUE(
3511 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3512 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3513}
3514
3515TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3516 MakeUnifiedPlanDescription();
3517 RemoveSsrcSignalingFromStreamParams();
3518
3519 TestSerialize(jdesc_);
3520}
3521
Steve Antone831b8c2018-02-01 12:22:16 -08003522TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
3523 JsepSessionDescription jsep_desc(kDummyType);
3524 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
3525 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3526}
3527
3528TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
3529 JsepSessionDescription jsep_desc(kDummyType);
3530 std::string sdp = kSdpSessionString;
3531 sdp += kSdpSctpDataChannelString;
3532 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3533 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3534}
3535
3536TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
3537 JsepSessionDescription jsep_desc(kDummyType);
3538 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
3539 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
3540 jsep_desc.description()->msid_signaling());
3541}
3542
3543TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
3544 JsepSessionDescription jsep_desc(kDummyType);
3545 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
3546 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
3547 jsep_desc.description()->msid_signaling());
3548}
3549
3550const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
3551const char kSsrcAttributeMsidLine[] =
3552 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
3553
3554TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
3555 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
3556 std::string sdp = webrtc::SdpSerialize(jdesc_);
3557
3558 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3559 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3560}
3561
3562TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
3563 jdesc_.description()->set_msid_signaling(
3564 cricket::kMsidSignalingSsrcAttribute);
3565 std::string sdp = webrtc::SdpSerialize(jdesc_);
3566
3567 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
3568 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3569}
3570
3571TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
3572 jdesc_.description()->set_msid_signaling(
3573 cricket::kMsidSignalingMediaSection |
3574 cricket::kMsidSignalingSsrcAttribute);
3575 std::string sdp = webrtc::SdpSerialize(jdesc_);
3576
3577 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3578 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-16 17:54:10 -08003579}
deadbeef7e146cb2016-09-28 10:04:34 -07003580
3581// Regression test for heap overflow bug:
3582// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3583TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 10:04:34 -07003584 // The issue occurs when the sctp-port attribute is found in a video
3585 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 12:43:58 -08003586 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 10:04:34 -07003587 "v=0\r\n"
3588 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3589 "s=-\r\n"
3590 "t=0 0\r\n"
3591 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3592 "a=sctp-port 5000\r\n"
3593 "a=fmtp:108 foo=10\r\n";
3594
3595 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3596 "sctp-port");
3597}
deadbeefb2362572016-12-13 16:37:06 -08003598
3599// Regression test for integer overflow bug:
3600// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3601TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003602 // Bandwidth attribute is the max signed 32-bit int, which will get
3603 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003604 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003605 "v=0\r\n"
3606 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3607 "s=-\r\n"
3608 "t=0 0\r\n"
3609 "m=video 3457 RTP/SAVPF 120\r\n"
3610 "b=AS:2147483647\r\n"
3611 "foo=fail\r\n";
3612
3613 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3614}
deadbeef7bcdb692017-01-20 12:43:58 -08003615
deadbeefbc88c6b2017-08-02 11:26:34 -07003616// Similar to the above, except that negative values are illegal, not just
3617// error-prone as large values are.
3618// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3619TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3620 static const char kSdpWithNegativeBandwidth[] =
3621 "v=0\r\n"
3622 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3623 "s=-\r\n"
3624 "t=0 0\r\n"
3625 "m=video 3457 RTP/SAVPF 120\r\n"
3626 "b=AS:-1000\r\n";
3627
3628 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3629}
3630
deadbeef3e8016e2017-08-03 17:49:30 -07003631// An exception to the above rule: a value of -1 for b=AS should just be
3632// ignored, resulting in "kAutoBandwidth" in the deserialized object.
3633// Applications historically may be using "b=AS:-1" to mean "no bandwidth
3634// limit", but this is now what ommitting the attribute entirely will do, so
3635// ignoring it will have the intended effect.
3636TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
3637 static const char kSdpWithBandwidthOfNegativeOne[] =
3638 "v=0\r\n"
3639 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3640 "s=-\r\n"
3641 "t=0 0\r\n"
3642 "m=video 3457 RTP/SAVPF 120\r\n"
3643 "b=AS:-1\r\n";
3644
Steve Antona3a92c22017-12-07 10:27:41 -08003645 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-03 17:49:30 -07003646 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-03 17:49:30 -07003647 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003648 GetFirstVideoContentDescription(jdesc_output.description());
3649 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-03 17:49:30 -07003650 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
3651}
3652
deadbeef7bcdb692017-01-20 12:43:58 -08003653// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3654// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3655// Regression test for:
3656// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3657TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3658 // Important piece is "ufrag foo pwd bar".
3659 static const char kSdpWithIceCredentialsInCandidateString[] =
3660 "v=0\r\n"
3661 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3662 "s=-\r\n"
3663 "t=0 0\r\n"
3664 "m=audio 9 RTP/SAVPF 111\r\n"
3665 "c=IN IP4 0.0.0.0\r\n"
3666 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3667 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3668 "a=rtpmap:111 opus/48000/2\r\n"
3669 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3670 "generation 2 ufrag foo pwd bar\r\n";
3671
Steve Antona3a92c22017-12-07 10:27:41 -08003672 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 12:43:58 -08003673 EXPECT_TRUE(
3674 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
3675 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3676 ASSERT_NE(nullptr, candidates);
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003677 ASSERT_EQ(1U, candidates->count());
deadbeef7bcdb692017-01-20 12:43:58 -08003678 cricket::Candidate c = candidates->at(0)->candidate();
3679 EXPECT_EQ("ufrag_voice", c.username());
3680 EXPECT_EQ("pwd_voice", c.password());
3681}
deadbeef90f1e1e2017-02-10 12:35:05 -08003682
Johannes Kron211856b2018-09-06 12:12:28 +02003683// Test that attribute lines "a=ice-ufrag-something"/"a=ice-pwd-something" are
3684// ignored, and only the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3685// Regression test for:
3686// https://bugs.chromium.org/p/webrtc/issues/detail?id=9712
3687TEST_F(WebRtcSdpTest, AttributeWithPartialMatchingNameIsIgnored) {
3688 static const char kSdpWithFooIceCredentials[] =
3689 "v=0\r\n"
3690 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3691 "s=-\r\n"
3692 "t=0 0\r\n"
3693 "m=audio 9 RTP/SAVPF 111\r\n"
3694 "c=IN IP4 0.0.0.0\r\n"
3695 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3696 "a=ice-ufrag-something:foo\r\na=ice-pwd-something:bar\r\n"
3697 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3698 "a=rtpmap:111 opus/48000/2\r\n"
3699 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3700 "generation 2\r\n";
3701
3702 JsepSessionDescription jdesc_output(kDummyType);
3703 EXPECT_TRUE(SdpDeserialize(kSdpWithFooIceCredentials, &jdesc_output));
3704 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3705 ASSERT_NE(nullptr, candidates);
3706 ASSERT_EQ(1U, candidates->count());
3707 cricket::Candidate c = candidates->at(0)->candidate();
3708 EXPECT_EQ("ufrag_voice", c.username());
3709 EXPECT_EQ("pwd_voice", c.password());
3710}
3711
deadbeef90f1e1e2017-02-10 12:35:05 -08003712// Test that SDP with an invalid port number in "a=candidate" lines is
3713// rejected, without crashing.
3714// Regression test for:
3715// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
3716TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
3717 static const char kSdpWithInvalidCandidatePort[] =
3718 "v=0\r\n"
3719 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3720 "s=-\r\n"
3721 "t=0 0\r\n"
3722 "m=audio 9 RTP/SAVPF 111\r\n"
3723 "c=IN IP4 0.0.0.0\r\n"
3724 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3725 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3726 "a=rtpmap:111 opus/48000/2\r\n"
3727 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
3728 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
3729
Steve Antona3a92c22017-12-07 10:27:41 -08003730 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 12:35:05 -08003731 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
3732}
deadbeefa4549d62017-02-10 17:26:22 -08003733
3734// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
3735// Regression test for:
3736// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
3737TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
3738 static const char kSdpWithMissingTrackId[] =
3739 "v=0\r\n"
3740 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3741 "s=-\r\n"
3742 "t=0 0\r\n"
3743 "m=audio 9 RTP/SAVPF 111\r\n"
3744 "c=IN IP4 0.0.0.0\r\n"
3745 "a=rtpmap:111 opus/48000/2\r\n"
3746 "a=msid:stream_id \r\n";
3747
Steve Antona3a92c22017-12-07 10:27:41 -08003748 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003749 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
3750}
3751
3752TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
3753 static const char kSdpWithMissingStreamId[] =
3754 "v=0\r\n"
3755 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3756 "s=-\r\n"
3757 "t=0 0\r\n"
3758 "m=audio 9 RTP/SAVPF 111\r\n"
3759 "c=IN IP4 0.0.0.0\r\n"
3760 "a=rtpmap:111 opus/48000/2\r\n"
3761 "a=msid: track_id\r\n";
3762
Steve Antona3a92c22017-12-07 10:27:41 -08003763 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003764 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
3765}
zhihuang38989e52017-03-21 11:04:53 -07003766
3767// Tests that if both session-level address and media-level address exist, use
3768// the media-level address.
3769TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 10:27:41 -08003770 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003771
3772 // Sesssion-level address.
3773 std::string sdp = kSdpFullString;
3774 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3775 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3776
3777 const auto& content1 = jsep_desc.description()->contents()[0];
3778 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 15:14:30 -08003779 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003780 const auto& content2 = jsep_desc.description()->contents()[1];
3781 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 15:14:30 -08003782 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003783}
3784
3785// Tests that the session-level connection address will be used if the media
3786// level-addresses are not specified.
3787TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 10:27:41 -08003788 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003789
3790 // Sesssion-level address.
3791 std::string sdp = kSdpString;
3792 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3793 // Remove the media level addresses.
3794 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3795 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3796 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3797
3798 const auto& content1 = jsep_desc.description()->contents()[0];
3799 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003800 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003801 const auto& content2 = jsep_desc.description()->contents()[1];
3802 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003803 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003804}
3805
3806TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 10:27:41 -08003807 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003808
3809 std::string sdp = kSdpString;
3810 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3811 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
3812 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
3813 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
3814 &sdp);
3815 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
3816 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
3817 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
3818 &sdp);
3819 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3820 const auto& content1 = jsep_desc.description()->contents()[0];
3821 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003822 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003823 const auto& content2 = jsep_desc.description()->contents()[1];
3824 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003825 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003826}
3827
3828// Test that the invalid or unsupprted connection data cannot be parsed.
3829TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 10:27:41 -08003830 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003831 std::string sdp = kSdpString;
3832 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3833
3834 // Unsupported multicast IPv4 address.
3835 sdp = kSdpFullString;
3836 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
3837 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3838
3839 // Unsupported multicast IPv6 address.
3840 sdp = kSdpFullString;
3841 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
3842 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3843
3844 // Mismatched address type.
3845 sdp = kSdpFullString;
3846 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
3847 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3848
3849 sdp = kSdpFullString;
3850 Replace("c=IN IP4 74.125.224.39\r\n",
3851 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
3852 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3853}
3854
3855TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 10:27:41 -08003856 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003857 MakeDescriptionWithoutCandidates(&expected_jsep);
3858 // Serialization.
Steve Antone831b8c2018-02-01 12:22:16 -08003859 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 11:04:53 -07003860 // Deserialization.
Steve Antona3a92c22017-12-07 10:27:41 -08003861 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003862 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 15:14:30 -08003863 auto audio_desc = jdesc.description()
3864 ->GetContentByName(kAudioContentName)
3865 ->media_description();
3866 auto video_desc = jdesc.description()
3867 ->GetContentByName(kVideoContentName)
3868 ->media_description();
zhihuang38989e52017-03-21 11:04:53 -07003869 EXPECT_EQ(audio_desc_->connection_address().ToString(),
3870 audio_desc->connection_address().ToString());
3871 EXPECT_EQ(video_desc_->connection_address().ToString(),
3872 video_desc->connection_address().ToString());
3873}
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07003874
3875// RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be
3876// used (i.e., a single space as the session name)." So we should accept that.
3877TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) {
3878 JsepSessionDescription jsep_desc(kDummyType);
3879 std::string sdp = kSdpString;
3880 Replace("s=-\r\n", "s= \r\n", &sdp);
3881 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3882}