blob: e3ccd06b89b635ce9d5df6762ccc64da88f0e4f9 [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
Johannes Kron9ac3c912018-10-12 10:54:26 +02001288 EXPECT_EQ(cd1->extmap_allow_mixed_headers(),
1289 cd2->extmap_allow_mixed_headers());
Johannes Kron0854eb62018-10-10 22:33:20 +02001290
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 Kron9ac3c912018-10-12 10:54:26 +02001407 EXPECT_EQ(desc1.extmap_allow_mixed_headers(),
1408 desc2.extmap_allow_mixed_headers());
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);
Steve Anton4905edb2018-10-15 19:27:44 -07001506 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, kIdentityDigest);
deadbeef46eed762016-01-28 13:24:37 -08001507 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1508 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001509 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1510 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001511 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1512 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1513 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001514 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1515 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001516 cricket::CONNECTIONROLE_NONE, &fingerprint))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001517 }
1518
jbauch5869f502017-06-29 12:31:36 -07001519 void AddExtmap(bool encrypted) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001520 audio_desc_ = audio_desc_->Copy();
1521 video_desc_ = video_desc_->Copy();
jbauch5869f502017-06-29 12:31:36 -07001522 audio_desc_->AddRtpHeaderExtension(
1523 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1524 video_desc_->AddRtpHeaderExtension(
1525 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001526 desc_.RemoveContentByName(kAudioContentName);
1527 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001528 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1529 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001530 }
1531
1532 void RemoveCryptos() {
1533 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1534 video_desc_->set_cryptos(std::vector<CryptoParams>());
1535 }
1536
Seth Hampson5897a6e2018-04-03 11:16:33 -07001537 // Removes everything in StreamParams from the session description that is
1538 // used for a=ssrc lines.
1539 void RemoveSsrcSignalingFromStreamParams() {
1540 for (cricket::ContentInfo content_info : jdesc_.description()->contents()) {
1541 // With Unified Plan there should be one StreamParams per m= section.
1542 StreamParams& stream =
1543 content_info.media_description()->mutable_streams()[0];
1544 stream.ssrcs.clear();
1545 stream.ssrc_groups.clear();
1546 stream.cname.clear();
1547 }
1548 }
1549
1550 // Removes all a=ssrc lines from the SDP string.
1551 void RemoveSsrcLinesFromSdpString(std::string* sdp_string) {
1552 const char kAttributeSsrc[] = "a=ssrc";
1553 while (sdp_string->find(kAttributeSsrc) != std::string::npos) {
1554 size_t pos_ssrc_attribute = sdp_string->find(kAttributeSsrc);
1555 size_t beg_line_pos = sdp_string->rfind('\n', pos_ssrc_attribute);
1556 size_t end_line_pos = sdp_string->find('\n', pos_ssrc_attribute);
1557 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1558 }
1559 }
1560
Steve Anton4e70a722017-11-28 14:57:10 -08001561 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001562 audio_desc_->set_direction(direction);
1563 video_desc_->set_direction(direction);
1564 std::string new_sdp = kSdpFullString;
1565 ReplaceDirection(direction, &new_sdp);
1566
Yves Gerey665174f2018-06-19 15:03:05 +02001567 if (!jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001568 jdesc_.session_version())) {
1569 return false;
1570 }
Steve Antone831b8c2018-02-01 12:22:16 -08001571 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001572 EXPECT_EQ(new_sdp, message);
1573 return true;
1574 }
1575
1576 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001577 audio_desc_ = audio_desc_->Copy();
1578 video_desc_ = video_desc_->Copy();
zhihuang38989e52017-03-21 11:04:53 -07001579
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001580 desc_.RemoveContentByName(kAudioContentName);
1581 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001582 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001583 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001584 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001585 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001586 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1587 audio_rejected ? "" : kPwdVoice);
1588 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1589 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001590
1591 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001592 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1593
Steve Antona3a92c22017-12-07 10:27:41 -08001594 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001595 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001596 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001597 EXPECT_EQ(new_sdp, message);
1598 return true;
1599 }
1600
zstein4b2e0822017-02-17 19:48:38 -08001601 void AddSctpDataChannel(bool use_sctpmap) {
kwibergd1fe2812016-04-27 06:47:29 -07001602 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001603 data_desc_ = data.get();
zstein4b2e0822017-02-17 19:48:38 -08001604 data_desc_->set_use_sctpmap(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001605 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
solenberg9fa49752016-10-08 13:02:44 -07001606 DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07001607 cricket::kGoogleSctpDataCodecName);
wu@webrtc.org78187522013-10-07 23:32:02 +00001608 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1609 data_desc_->AddCodec(codec);
Steve Anton5adfafd2017-12-20 16:34:00 -08001610 desc_.AddContent(kDataContentName, MediaProtocolType::kSctp,
1611 data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001612 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1613 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001614 }
1615
1616 void AddRtpDataChannel() {
kwibergd1fe2812016-04-27 06:47:29 -07001617 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001618 data_desc_ = data.get();
1619
deadbeef67cf2c12016-04-13 10:07:16 -07001620 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001621 StreamParams data_stream;
1622 data_stream.id = kDataChannelMsid;
1623 data_stream.cname = kDataChannelCname;
Seth Hampson845e8782018-03-02 11:34:10 -08001624 data_stream.set_stream_ids({kDataChannelLabel});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001625 data_stream.ssrcs.push_back(kDataChannelSsrc);
1626 data_desc_->AddStream(data_stream);
Yves Gerey665174f2018-06-19 15:03:05 +02001627 data_desc_->AddCrypto(
1628 CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
1629 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001630 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
Steve Anton5adfafd2017-12-20 16:34:00 -08001631 desc_.AddContent(kDataContentName, MediaProtocolType::kRtp, data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001632 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1633 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001634 }
1635
Steve Anton4e70a722017-11-28 14:57:10 -08001636 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001637 std::string new_sdp = kSdpFullString;
1638 ReplaceDirection(direction, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001639 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001640
1641 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1642
1643 audio_desc_->set_direction(direction);
1644 video_desc_->set_direction(direction);
Yves Gerey665174f2018-06-19 15:03:05 +02001645 if (!jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001646 jdesc_.session_version())) {
1647 return false;
1648 }
1649 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1650 return true;
1651 }
1652
1653 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001654 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001655 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001656 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001657 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001658
Steve Antonb1c1de12017-12-21 15:14:30 -08001659 audio_desc_ = audio_desc_->Copy();
1660 video_desc_ = video_desc_->Copy();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001661 desc_.RemoveContentByName(kAudioContentName);
1662 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001663 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001664 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001665 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001666 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001667 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1668 audio_rejected ? "" : kPwdVoice);
1669 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1670 video_rejected ? "" : kPwdVideo);
Steve Antona3a92c22017-12-07 10:27:41 -08001671 JsepSessionDescription jdesc_no_candidates(kDummyType);
deadbeef3f7219b2015-12-28 15:17:14 -08001672 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1673 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001674 return false;
1675 }
deadbeef3f7219b2015-12-28 15:17:14 -08001676 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001677 return true;
1678 }
1679
Yves Gerey665174f2018-06-19 15:03:05 +02001680 void TestDeserializeExtmap(bool session_level,
1681 bool media_level,
1682 bool encrypted) {
jbauch5869f502017-06-29 12:31:36 -07001683 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08001684 JsepSessionDescription new_jdesc(SdpType::kOffer);
Yves Gerey665174f2018-06-19 15:03:05 +02001685 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001686 jdesc_.session_version()));
Steve Antona3a92c22017-12-07 10:27:41 -08001687 JsepSessionDescription jdesc_with_extmap(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001688 std::string sdp_with_extmap = kSdpString;
1689 if (session_level) {
jbauch5869f502017-06-29 12:31:36 -07001690 InjectAfter(kSessionTime,
1691 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1692 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001693 &sdp_with_extmap);
1694 }
1695 if (media_level) {
jbauch5869f502017-06-29 12:31:36 -07001696 InjectAfter(kAttributeIcePwdVoice,
1697 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1698 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001699 &sdp_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07001700 InjectAfter(kAttributeIcePwdVideo,
1701 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1702 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001703 &sdp_with_extmap);
1704 }
1705 // The extmap can't be present at the same time in both session level and
1706 // media level.
1707 if (session_level && media_level) {
1708 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02001709 EXPECT_FALSE(
1710 webrtc::SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001711 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1712 } else {
1713 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1714 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1715 }
1716 }
1717
1718 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
Yves Gerey665174f2018-06-19 15:03:05 +02001719 const std::string& name,
1720 int expected_value) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001721 cricket::CodecParameterMap::const_iterator found = params.find(name);
1722 ASSERT_TRUE(found != params.end());
Jonas Olsson6b1985d2018-07-05 11:59:48 +02001723 EXPECT_EQ(found->second, rtc::ToString(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001724 }
1725
1726 void TestDeserializeCodecParams(const CodecParams& params,
1727 JsepSessionDescription* jdesc_output) {
1728 std::string sdp =
1729 "v=0\r\n"
1730 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1731 "s=-\r\n"
1732 "t=0 0\r\n"
1733 // Include semantics for WebRTC Media Streams since it is supported by
1734 // this parser, and will be added to the SDP when serializing a session
1735 // description.
1736 "a=msid-semantic: WMS\r\n"
1737 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001738 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001739 // Pltype 111 listed before 103 and 104 in the map.
1740 "a=rtpmap:111 opus/48000/2\r\n"
1741 // Pltype 103 listed before 104.
1742 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001743 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001744 "a=fmtp:111 0-15,66,70\r\n"
1745 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001746 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001747 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001748 << "; sprop-stereo=" << params.sprop_stereo
1749 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001750 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001751 << "a=ptime:" << params.ptime << "\r\n"
1752 << "a=maxptime:" << params.max_ptime << "\r\n";
1753 sdp += os.str();
1754
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001755 os.clear();
1756 os.str("");
1757 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001758 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001759 << "a=rtpmap:99 VP8/90000\r\n"
1760 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001761 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001762 sdp += os.str();
1763
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001764 // Deserialize
1765 SdpParseError error;
1766 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1767
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001768 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001769 GetFirstAudioContentDescription(jdesc_output->description());
1770 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001771 ASSERT_FALSE(acd->codecs().empty());
1772 cricket::AudioCodec opus = acd->codecs()[0];
1773 EXPECT_EQ("opus", opus.name);
1774 EXPECT_EQ(111, opus.id);
1775 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1776 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1777 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1778 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001779 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1780 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001781 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1782 cricket::AudioCodec codec = acd->codecs()[i];
1783 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1784 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001785 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001786
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001787 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001788 GetFirstVideoContentDescription(jdesc_output->description());
1789 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001790 ASSERT_FALSE(vcd->codecs().empty());
1791 cricket::VideoCodec vp8 = vcd->codecs()[0];
1792 EXPECT_EQ("VP8", vp8.name);
1793 EXPECT_EQ(99, vp8.id);
1794 cricket::VideoCodec rtx = vcd->codecs()[1];
1795 EXPECT_EQ("RTX", rtx.name);
1796 EXPECT_EQ(95, rtx.id);
1797 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001798 }
1799
1800 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1801 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001802 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001803 "v=0\r\n"
1804 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1805 "s=-\r\n"
1806 "t=0 0\r\n"
1807 // Include semantics for WebRTC Media Streams since it is supported by
1808 // this parser, and will be added to the SDP when serializing a session
1809 // description.
1810 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001811 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001812 "a=rtpmap:111 opus/48000/2\r\n";
1813 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001814 "m=video 3457 RTP/SAVPF 101\r\n"
1815 "a=rtpmap:101 VP8/90000\r\n"
1816 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001817 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001818 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001819 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001820 os << sdp_session_and_audio;
Yves Gerey665174f2018-06-19 15:03:05 +02001821 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001822 os << sdp_video;
Yves Gerey665174f2018-06-19 15:03:05 +02001823 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001824 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001825 // Deserialize
1826 SdpParseError error;
1827 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001828 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001829 GetFirstAudioContentDescription(jdesc_output->description());
1830 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001831 ASSERT_FALSE(acd->codecs().empty());
1832 cricket::AudioCodec opus = acd->codecs()[0];
1833 EXPECT_EQ(111, opus.id);
Yves Gerey665174f2018-06-19 15:03:05 +02001834 EXPECT_TRUE(opus.HasFeedbackParam(cricket::FeedbackParam(
1835 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001836
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001837 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001838 GetFirstVideoContentDescription(jdesc_output->description());
1839 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001840 ASSERT_FALSE(vcd->codecs().empty());
1841 cricket::VideoCodec vp8 = vcd->codecs()[0];
1842 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1843 vp8.name.c_str());
1844 EXPECT_EQ(101, vp8.id);
Yves Gerey665174f2018-06-19 15:03:05 +02001845 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1846 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
1847 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1848 cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli)));
1849 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1850 cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty)));
1851 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1852 cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001853 }
1854
1855 // Two SDP messages can mean the same thing but be different strings, e.g.
1856 // some of the lines can be serialized in different order.
1857 // However, a deserialized description can be compared field by field and has
1858 // no order. If deserializer has already been tested, serializing then
1859 // deserializing and comparing JsepSessionDescription will test
1860 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 12:22:16 -08001861 void TestSerialize(const JsepSessionDescription& jdesc) {
1862 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 10:27:41 -08001863 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001864 SdpParseError error;
1865 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1866 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1867 }
1868
zhihuang38989e52017-03-21 11:04:53 -07001869 // Calling 'Initialize' with a copy of the inner SessionDescription will
1870 // create a copy of the JsepSessionDescription without candidates. The
1871 // 'connection address' field, previously set from the candidates, must also
1872 // be reset.
1873 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
1874 rtc::SocketAddress audio_addr("0.0.0.0", 9);
1875 rtc::SocketAddress video_addr("0.0.0.0", 9);
1876 audio_desc_->set_connection_address(audio_addr);
1877 video_desc_->set_connection_address(video_addr);
1878 ASSERT_TRUE(jdesc->Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1879 }
1880
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001881 protected:
1882 SessionDescription desc_;
1883 AudioContentDescription* audio_desc_;
1884 VideoContentDescription* video_desc_;
1885 DataContentDescription* data_desc_;
1886 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07001887 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001888 JsepSessionDescription jdesc_;
1889};
1890
1891void TestMismatch(const std::string& string1, const std::string& string2) {
1892 int position = 0;
1893 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1894 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001895 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001896 break;
1897 }
1898 }
1899 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1900 << " character\n"
1901 << " 1: " << string1.substr(position, 20) << "\n"
1902 << " 2: " << string2.substr(position, 20) << "\n";
1903}
1904
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001905TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1906 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 12:22:16 -08001907 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001908 TestMismatch(std::string(kSdpFullString), message);
1909}
1910
1911TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 10:27:41 -08001912 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 12:22:16 -08001913 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001914}
1915
1916// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1917// the case in a DTLS offer.
1918TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1919 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08001920 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001921 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08001922 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001923
1924 std::string sdp_with_fingerprint = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02001925 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1926 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001927
1928 EXPECT_EQ(sdp_with_fingerprint, message);
1929}
1930
1931// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1932// be the case in a DTLS answer.
1933TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1934 AddFingerprint();
1935 RemoveCryptos();
Steve Antona3a92c22017-12-07 10:27:41 -08001936 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001937 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08001938 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001939
1940 std::string sdp_with_fingerprint = kSdpString;
1941 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1942 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
Yves Gerey665174f2018-06-19 15:03:05 +02001943 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1944 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001945
1946 EXPECT_EQ(sdp_with_fingerprint, message);
1947}
1948
1949TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1950 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08001951 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001952 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001953 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001954 EXPECT_EQ(std::string(kSdpString), message);
1955}
1956
1957TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1958 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1959 group.AddContentName(kAudioContentName);
1960 group.AddContentName(kVideoContentName);
1961 desc_.AddGroup(group);
Yves Gerey665174f2018-06-19 15:03:05 +02001962 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001963 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08001964 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001965 std::string sdp_with_bundle = kSdpFullString;
1966 InjectAfter(kSessionTime,
1967 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1968 &sdp_with_bundle);
1969 EXPECT_EQ(sdp_with_bundle, message);
1970}
1971
1972TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001973 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001974 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08001975 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001976 acd->set_bandwidth(50 * 1000);
Yves Gerey665174f2018-06-19 15:03:05 +02001977 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001978 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08001979 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001980 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02001981 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001982 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02001983 InjectAfter("c=IN IP4 74.125.127.126\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001984 &sdp_with_bandwidth);
1985 EXPECT_EQ(sdp_with_bandwidth, message);
1986}
1987
1988TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1989 std::vector<std::string> transport_options;
1990 transport_options.push_back(kIceOption1);
1991 transport_options.push_back(kIceOption3);
1992 AddIceOptions(kAudioContentName, transport_options);
1993 transport_options.clear();
1994 transport_options.push_back(kIceOption2);
1995 transport_options.push_back(kIceOption3);
1996 AddIceOptions(kVideoContentName, transport_options);
Yves Gerey665174f2018-06-19 15:03:05 +02001997 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001998 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08001999 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002000 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002001 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002002 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002003 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002004 &sdp_with_ice_options);
2005 EXPECT_EQ(sdp_with_ice_options, message);
2006}
2007
2008TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002009 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002010}
2011
2012TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002013 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002014}
2015
2016TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002017 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002018}
2019
2020TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2021 EXPECT_TRUE(TestSerializeRejected(true, false));
2022}
2023
2024TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2025 EXPECT_TRUE(TestSerializeRejected(false, true));
2026}
2027
2028TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2029 EXPECT_TRUE(TestSerializeRejected(true, true));
2030}
2031
2032TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
2033 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002034 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002035
zhihuang38989e52017-03-21 11:04:53 -07002036 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002037 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002038
2039 std::string expected_sdp = kSdpString;
2040 expected_sdp.append(kSdpRtpDataChannelString);
2041 EXPECT_EQ(expected_sdp, message);
2042}
2043
2044TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08002045 bool use_sctpmap = true;
2046 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002047 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002048
zhihuang38989e52017-03-21 11:04:53 -07002049 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002050 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002051
2052 std::string expected_sdp = kSdpString;
2053 expected_sdp.append(kSdpSctpDataChannelString);
2054 EXPECT_EQ(message, expected_sdp);
2055}
2056
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002057TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08002058 bool use_sctpmap = true;
2059 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002060 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002061 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antonb1c1de12017-12-21 15:14:30 -08002062 DataContentDescription* dcdesc =
2063 jsep_desc.description()
2064 ->GetContentDescriptionByName(kDataContentName)
2065 ->as_data();
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002066
2067 const int kNewPort = 1234;
solenberg9fa49752016-10-08 13:02:44 -07002068 cricket::DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07002069 cricket::kGoogleSctpDataCodecName);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002070 codec.SetParam(cricket::kCodecParamPort, kNewPort);
2071 dcdesc->AddOrReplaceCodec(codec);
2072
Steve Antone831b8c2018-02-01 12:22:16 -08002073 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002074
2075 std::string expected_sdp = kSdpString;
2076 expected_sdp.append(kSdpSctpDataChannelString);
2077
2078 char default_portstr[16];
2079 char new_portstr[16];
Niels Mölleraba06332018-10-16 15:14:15 +02002080 snprintf(default_portstr, sizeof(default_portstr), "%d", kDefaultSctpPort);
2081 snprintf(new_portstr, sizeof(new_portstr), "%d", kNewPort);
Yves Gerey665174f2018-06-19 15:03:05 +02002082 rtc::replace_substrs(default_portstr, strlen(default_portstr), new_portstr,
2083 strlen(new_portstr), &expected_sdp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002084
2085 EXPECT_EQ(expected_sdp, message);
2086}
2087
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002088TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002089 JsepSessionDescription jsep_desc(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002090 AddRtpDataChannel();
Yves Gerey665174f2018-06-19 15:03:05 +02002091 data_desc_->set_bandwidth(100 * 1000);
zhihuang38989e52017-03-21 11:04:53 -07002092 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002093 std::string message = webrtc::SdpSerialize(jsep_desc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002094
2095 std::string expected_sdp = kSdpString;
2096 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002097 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00002098 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02002099 "b=AS:100\r\n", &expected_sdp);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002100 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002101}
2102
Johannes Kron0854eb62018-10-10 22:33:20 +02002103TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9ac3c912018-10-12 10:54:26 +02002104 jdesc_.description()->set_extmap_allow_mixed_headers(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002105 TestSerialize(jdesc_);
2106}
2107
2108TEST_F(WebRtcSdpTest, SerializeMediaContentDescriptionWithExtmapAllowMixed) {
2109 cricket::MediaContentDescription* video_desc =
2110 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2111 ASSERT_TRUE(video_desc);
2112 cricket::MediaContentDescription* audio_desc =
2113 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2114 ASSERT_TRUE(audio_desc);
Johannes Kron9ac3c912018-10-12 10:54:26 +02002115 video_desc->set_extmap_allow_mixed_headers(
Johannes Kron0854eb62018-10-10 22:33:20 +02002116 cricket::MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 10:54:26 +02002117 audio_desc->set_extmap_allow_mixed_headers(
Johannes Kron0854eb62018-10-10 22:33:20 +02002118 cricket::MediaContentDescription::kMedia);
2119 TestSerialize(jdesc_);
2120}
2121
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002122TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002123 bool encrypted = false;
2124 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002125 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002126 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 12:22:16 -08002127 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002128
2129 std::string sdp_with_extmap = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002130 InjectAfter("a=mid:audio_content_name\r\n", kExtmap, &sdp_with_extmap);
2131 InjectAfter("a=mid:video_content_name\r\n", kExtmap, &sdp_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002132
2133 EXPECT_EQ(sdp_with_extmap, message);
2134}
2135
jbauch5869f502017-06-29 12:31:36 -07002136TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2137 bool encrypted = true;
2138 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002139 JsepSessionDescription desc_with_extmap(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002140 ASSERT_TRUE(
2141 desc_with_extmap.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 12:22:16 -08002142 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07002143}
2144
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002145TEST_F(WebRtcSdpTest, SerializeCandidates) {
2146 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002147 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002148
2149 Candidate candidate_with_ufrag(candidates_.front());
2150 candidate_with_ufrag.set_username("ABC");
2151 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2152 candidate_with_ufrag));
2153 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2154 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002155
2156 Candidate candidate_with_network_info(candidates_.front());
2157 candidate_with_network_info.set_network_id(1);
2158 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2159 candidate_with_network_info));
2160 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2161 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2162 candidate_with_network_info.set_network_cost(999);
2163 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2164 candidate_with_network_info));
2165 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2166 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2167 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002168}
2169
Zach Steinb336c272018-08-09 01:16:13 -07002170TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) {
2171 rtc::SocketAddress address("a.test", 1234);
2172 cricket::Candidate candidate(
2173 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
2174 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
2175 JsepIceCandidate jcandidate(std::string("audio_content_name"), 0, candidate);
2176 std::string message = webrtc::SdpSerializeCandidate(jcandidate);
2177 EXPECT_EQ(std::string(kRawHostnameCandidate), message);
2178}
2179
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002180// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2181// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002182TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002183 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002184 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2185 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2186 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002187 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002188 std::unique_ptr<IceCandidateInterface> jcandidate(
2189 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002190
2191 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2192 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2193}
2194
htaa6b99442016-04-12 10:29:17 -07002195TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002196 cricket::VideoCodec h264_codec("H264");
2197 h264_codec.SetParam("profile-level-id", "42e01f");
2198 h264_codec.SetParam("level-asymmetry-allowed", "1");
2199 h264_codec.SetParam("packetization-mode", "1");
2200 video_desc_->AddCodec(h264_codec);
2201
htaa6b99442016-04-12 10:29:17 -07002202 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
2203
Steve Antone831b8c2018-02-01 12:22:16 -08002204 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 10:29:17 -07002205 size_t after_pt = message.find(" H264/90000");
2206 ASSERT_NE(after_pt, std::string::npos);
2207 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2208 ASSERT_NE(before_pt, std::string::npos);
2209 before_pt += strlen("a=rtpmap:");
2210 std::string pt = message.substr(before_pt, after_pt - before_pt);
2211 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2212 std::string to_find = "a=fmtp:" + pt + " ";
2213 size_t fmtp_pos = message.find(to_find);
2214 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
2215 size_t fmtp_endpos = message.find("\n", fmtp_pos);
2216 ASSERT_NE(std::string::npos, fmtp_endpos);
2217 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2218 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2219 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2220 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002221 // Check that there are no spaces after semicolons.
2222 // https://bugs.webrtc.org/5793
2223 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002224}
2225
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002226TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 10:27:41 -08002227 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002228 // Deserialize
2229 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2230 // Verify
2231 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2232}
2233
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002234TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 10:27:41 -08002235 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002236 const char kSdpWithoutMline[] =
Yves Gerey665174f2018-06-19 15:03:05 +02002237 "v=0\r\n"
2238 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2239 "s=-\r\n"
2240 "t=0 0\r\n"
2241 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002242 // Deserialize
2243 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2244 EXPECT_EQ(0u, jdesc.description()->contents().size());
2245}
2246
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002247TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 10:27:41 -08002248 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002249 std::string sdp_without_carriage_return = kSdpFullString;
2250 Replace("\r\n", "\n", &sdp_without_carriage_return);
2251 // Deserialize
2252 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2253 // Verify
2254 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2255}
2256
2257TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2258 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002259 JsepSessionDescription jdesc_no_candidates(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002260 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
2261 kSessionVersion));
Steve Antona3a92c22017-12-07 10:27:41 -08002262 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002263 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2264 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2265}
2266
2267TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2268 static const char kSdpNoRtpmapString[] =
2269 "v=0\r\n"
2270 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2271 "s=-\r\n"
2272 "t=0 0\r\n"
2273 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2274 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002275 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002276 // The rtpmap line for static payload codec is optional.
2277 "a=rtpmap:18 G729/16000\r\n"
2278 "a=rtpmap:103 ISAC/16000\r\n";
2279
Steve Antona3a92c22017-12-07 10:27:41 -08002280 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002281 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2282 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002283 jdesc.description()
2284 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2285 ->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002286 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002287 // The codecs in the AudioContentDescription should be in the same order as
2288 // the payload types (<fmt>s) on the m= line.
2289 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2290 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002291 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002292 EXPECT_EQ(ref_codecs, audio->codecs());
2293}
2294
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002295TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2296 static const char kSdpNoRtpmapString[] =
2297 "v=0\r\n"
2298 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2299 "s=-\r\n"
2300 "t=0 0\r\n"
2301 "m=audio 49232 RTP/AVP 18 103\r\n"
2302 "a=fmtp:18 annexb=yes\r\n"
2303 "a=rtpmap:103 ISAC/16000\r\n";
2304
Steve Antona3a92c22017-12-07 10:27:41 -08002305 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002306 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2307 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002308 jdesc.description()
2309 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2310 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002311
2312 cricket::AudioCodec g729 = audio->codecs()[0];
2313 EXPECT_EQ("G729", g729.name);
2314 EXPECT_EQ(8000, g729.clockrate);
2315 EXPECT_EQ(18, g729.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002316 cricket::CodecParameterMap::iterator found = g729.params.find("annexb");
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002317 ASSERT_TRUE(found != g729.params.end());
2318 EXPECT_EQ(found->second, "yes");
2319
2320 cricket::AudioCodec isac = audio->codecs()[1];
2321 EXPECT_EQ("ISAC", isac.name);
2322 EXPECT_EQ(103, isac.id);
2323 EXPECT_EQ(16000, isac.clockrate);
2324}
2325
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002326// Ensure that we can deserialize SDP with a=fingerprint properly.
2327TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2328 // Add a DTLS a=fingerprint attribute to our session description.
2329 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002330 JsepSessionDescription new_jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002331 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002332 jdesc_.session_version()));
2333
Steve Antona3a92c22017-12-07 10:27:41 -08002334 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002335 std::string sdp_with_fingerprint = kSdpString;
2336 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2337 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2338 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2339 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2340}
2341
2342TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 10:27:41 -08002343 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002344 std::string sdp_with_bundle = kSdpFullString;
2345 InjectAfter(kSessionTime,
2346 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2347 &sdp_with_bundle);
2348 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2349 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2350 group.AddContentName(kAudioContentName);
2351 group.AddContentName(kVideoContentName);
2352 desc_.AddGroup(group);
Yves Gerey665174f2018-06-19 15:03:05 +02002353 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002354 jdesc_.session_version()));
2355 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2356}
2357
2358TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002359 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002360 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002361 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002362 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002363 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002364 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002365 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 15:14:30 -08002366 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002367 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002368 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002369 acd->set_bandwidth(50 * 1000);
Yves Gerey665174f2018-06-19 15:03:05 +02002370 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002371 jdesc_.session_version()));
2372 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2373}
2374
2375TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 10:27:41 -08002376 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002377 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002378 InjectAfter(kSessionTime, "a=ice-options:iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002379 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002380 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002381 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002382 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002383 &sdp_with_ice_options);
2384 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2385 std::vector<std::string> transport_options;
2386 transport_options.push_back(kIceOption3);
2387 transport_options.push_back(kIceOption1);
2388 AddIceOptions(kAudioContentName, transport_options);
2389 transport_options.clear();
2390 transport_options.push_back(kIceOption3);
2391 transport_options.push_back(kIceOption2);
2392 AddIceOptions(kVideoContentName, transport_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002393 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002394 jdesc_.session_version()));
2395 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2396}
2397
2398TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2399 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 10:27:41 -08002400 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002401 std::string sdp_with_ufrag_pwd = kSdpFullString;
2402 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2403 // Add session level ufrag and pwd
2404 InjectAfter(kSessionTime,
Yves Gerey665174f2018-06-19 15:03:05 +02002405 "a=ice-pwd:session+level+icepwd\r\n"
2406 "a=ice-ufrag:session+level+iceufrag\r\n",
2407 &sdp_with_ufrag_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002408 // Add media level ufrag and pwd for audio
Yves Gerey665174f2018-06-19 15:03:05 +02002409 InjectAfter(
2410 "a=mid:audio_content_name\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002411 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2412 &sdp_with_ufrag_pwd);
2413 // Update the candidate ufrag and pwd to the expected ones.
Yves Gerey665174f2018-06-19 15:03:05 +02002414 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, "media+level+iceufrag",
2415 "media+level+icepwd"));
2416 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, "session+level+iceufrag",
2417 "session+level+icepwd"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002418 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2419 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2420}
2421
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002422TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002423 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002424}
2425
2426TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002427 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002428}
2429
2430TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002431 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002432}
2433
2434TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2435 EXPECT_TRUE(TestDeserializeRejected(true, false));
2436}
2437
2438TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2439 EXPECT_TRUE(TestDeserializeRejected(false, true));
2440}
2441
2442TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2443 EXPECT_TRUE(TestDeserializeRejected(true, true));
2444}
2445
2446// Tests that we can still handle the sdp uses mslabel and label instead of
2447// msid for backward compatibility.
2448TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07002449 jdesc_.description()->set_msid_supported(false);
Steve Antona3a92c22017-12-07 10:27:41 -08002450 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002451 std::string sdp_without_msid = kSdpFullString;
2452 Replace("msid", "xmsid", &sdp_without_msid);
2453 // Deserialize
2454 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2455 // Verify
2456 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2457}
2458
Johannes Kron0854eb62018-10-10 22:33:20 +02002459TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9ac3c912018-10-12 10:54:26 +02002460 jdesc_.description()->set_extmap_allow_mixed_headers(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002461 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2462 InjectAfter("t=0 0\r\n", kExtmapAllowMixed, &sdp_with_extmap_allow_mixed);
2463 // Deserialize
2464 JsepSessionDescription jdesc_deserialized(kDummyType);
2465 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2466 // Verify
2467 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2468}
2469
2470TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutExtmapAllowMixed) {
Johannes Kron9ac3c912018-10-12 10:54:26 +02002471 jdesc_.description()->set_extmap_allow_mixed_headers(false);
Johannes Kron0854eb62018-10-10 22:33:20 +02002472 std::string sdp_without_extmap_allow_mixed = kSdpFullString;
2473 // Deserialize
2474 JsepSessionDescription jdesc_deserialized(kDummyType);
2475 EXPECT_TRUE(
2476 SdpDeserialize(sdp_without_extmap_allow_mixed, &jdesc_deserialized));
2477 // Verify
2478 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2479}
2480
2481TEST_F(WebRtcSdpTest, DeserializeMediaContentDescriptionWithExtmapAllowMixed) {
2482 cricket::MediaContentDescription* video_desc =
2483 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2484 ASSERT_TRUE(video_desc);
2485 cricket::MediaContentDescription* audio_desc =
2486 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2487 ASSERT_TRUE(audio_desc);
Johannes Kron9ac3c912018-10-12 10:54:26 +02002488 video_desc->set_extmap_allow_mixed_headers(
Johannes Kron0854eb62018-10-10 22:33:20 +02002489 cricket::MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 10:54:26 +02002490 audio_desc->set_extmap_allow_mixed_headers(
Johannes Kron0854eb62018-10-10 22:33:20 +02002491 cricket::MediaContentDescription::kMedia);
2492
2493 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2494 InjectAfter("a=mid:audio_content_name\r\n", kExtmapAllowMixed,
2495 &sdp_with_extmap_allow_mixed);
2496 InjectAfter("a=mid:video_content_name\r\n", kExtmapAllowMixed,
2497 &sdp_with_extmap_allow_mixed);
2498
2499 // Deserialize
2500 JsepSessionDescription jdesc_deserialized(kDummyType);
2501 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2502 // Verify
2503 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2504}
2505
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002506TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2507 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2508
2509 std::string sdp = kSdpOneCandidate;
2510 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2511 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2512 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2513 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002514 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002515
2516 // Candidate line without generation extension.
2517 sdp = kSdpOneCandidate;
2518 Replace(" generation 2", "", &sdp);
2519 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2520 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2521 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2522 Candidate expected = jcandidate_->candidate();
2523 expected.set_generation(0);
2524 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2525
honghaiza0c44ea2016-03-23 16:07:48 -07002526 // Candidate with network id and/or cost.
2527 sdp = kSdpOneCandidate;
2528 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2529 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2530 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2531 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2532 expected = jcandidate_->candidate();
2533 expected.set_network_id(2);
2534 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2535 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2536 // Add network cost
2537 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2538 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2539 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2540 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2541
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002542 sdp = kSdpTcpActiveCandidate;
2543 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2544 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002545 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002546 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2547 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2548 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002549 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2550 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
Yves Gerey665174f2018-06-19 15:03:05 +02002551 EXPECT_TRUE(
2552 jcandidate.candidate().IsEquivalent(jcandidate_template->candidate()));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002553 sdp = kSdpTcpPassiveCandidate;
2554 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2555 sdp = kSdpTcpSOCandidate;
2556 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002557}
2558
2559// This test verifies the deserialization of candidate-attribute
2560// as per RFC 5245. Candiate-attribute will be of the format
2561// candidate:<blah>. This format will be used when candidates
2562// are trickled.
2563TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2564 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2565
2566 std::string candidate_attribute = kRawCandidate;
2567 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2568 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2569 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2570 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2571 EXPECT_EQ(2u, jcandidate.candidate().generation());
2572
2573 // Candidate line without generation extension.
2574 candidate_attribute = kRawCandidate;
2575 Replace(" generation 2", "", &candidate_attribute);
2576 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2577 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2578 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2579 Candidate expected = jcandidate_->candidate();
2580 expected.set_generation(0);
2581 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2582
2583 // Candidate line without candidate:
2584 candidate_attribute = kRawCandidate;
2585 Replace("candidate:", "", &candidate_attribute);
2586 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2587
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002588 // Candidate line with IPV6 address.
2589 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
Zach Steinb336c272018-08-09 01:16:13 -07002590
2591 // Candidate line with hostname address.
2592 EXPECT_TRUE(SdpDeserializeCandidate(kRawHostnameCandidate, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002593}
2594
2595// This test verifies that the deserialization of an invalid candidate string
2596// fails.
2597TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
Yves Gerey665174f2018-06-19 15:03:05 +02002598 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002599
2600 std::string candidate_attribute = kRawCandidate;
2601 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002602 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002603
2604 candidate_attribute = kSdpOneCandidate;
2605 candidate_attribute.replace(0, 1, "x");
2606 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2607
2608 candidate_attribute = kRawCandidate;
2609 candidate_attribute.append("\r\n");
2610 candidate_attribute.append(kRawCandidate);
2611 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2612
2613 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002614}
2615
2616TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2617 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002618 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002619 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2620
2621 std::string sdp_with_data = kSdpString;
2622 sdp_with_data.append(kSdpRtpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002623 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002624
2625 // Deserialize
2626 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2627 // Verify
2628 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2629}
2630
2631TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002632 bool use_sctpmap = true;
2633 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002634 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002635 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2636
2637 std::string sdp_with_data = kSdpString;
2638 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002639 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002640
lally@webrtc.org36300852015-02-24 20:19:35 +00002641 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2642 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2643 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2644
2645 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002646 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2647 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002648 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2649 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2650
2651 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002652 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2653 kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002654 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2655 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2656}
2657
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002658TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002659 bool use_sctpmap = false;
2660 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002661 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002662 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2663
2664 std::string sdp_with_data = kSdpString;
2665 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002666 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002667
lally@webrtc.org36300852015-02-24 20:19:35 +00002668 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002669 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2670 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002671
lally@webrtc.org36300852015-02-24 20:19:35 +00002672 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002673 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2674 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002675 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2676 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002677
lally@webrtc.org36300852015-02-24 20:19:35 +00002678 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002679 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2680 kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002681 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2682 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2683}
2684
lally69f57602015-10-08 10:15:04 -07002685TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002686 bool use_sctpmap = false;
2687 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002688 JsepSessionDescription jdesc(kDummyType);
lally69f57602015-10-08 10:15:04 -07002689 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2690
2691 std::string sdp_with_data = kSdpString;
2692 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002693 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 10:15:04 -07002694
2695 // Verify with DTLS/SCTP.
2696 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2697 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2698
2699 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002700 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2701 kUdpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002702 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2703 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2704
2705 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002706 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2707 kTcpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002708 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2709 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2710}
2711
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002712// Test to check the behaviour if sctp-port is specified
2713// on the m= line and in a=sctp-port.
2714TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002715 bool use_sctpmap = true;
2716 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002717 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002718 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2719
2720 std::string sdp_with_data = kSdpString;
2721 // Append m= attributes
2722 sdp_with_data.append(kSdpSctpDataChannelString);
2723 // Append a=sctp-port attribute
2724 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 10:27:41 -08002725 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002726
2727 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2728}
2729
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002730// For crbug/344475.
2731TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2732 std::string sdp_with_data = kSdpString;
2733 sdp_with_data.append(kSdpSctpDataChannelString);
2734 // Remove the "\n" at the end.
2735 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 10:27:41 -08002736 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002737
2738 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2739 // No crash is a pass.
2740}
2741
Steve Anton36b29d12017-10-30 09:57:42 -07002742void MutateJsepSctpPort(JsepSessionDescription* jdesc,
zstein4b2e0822017-02-17 19:48:38 -08002743 const SessionDescription& desc) {
wu@webrtc.org78187522013-10-07 23:32:02 +00002744 // take our pre-built session description and change the SCTP port.
zstein4b2e0822017-02-17 19:48:38 -08002745 cricket::SessionDescription* mutant = desc.Copy();
Steve Antonb1c1de12017-12-21 15:14:30 -08002746 DataContentDescription* dcdesc =
2747 mutant->GetContentDescriptionByName(kDataContentName)->as_data();
wu@webrtc.org78187522013-10-07 23:32:02 +00002748 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002749 EXPECT_EQ(1U, codecs.size());
solenberg9fa49752016-10-08 13:02:44 -07002750 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002751 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002752 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002753
2754 // note: mutant's owned by jdesc now.
Steve Anton36b29d12017-10-30 09:57:42 -07002755 ASSERT_TRUE(jdesc->Initialize(mutant, kSessionId, kSessionVersion));
wu@webrtc.org78187522013-10-07 23:32:02 +00002756 mutant = NULL;
zstein4b2e0822017-02-17 19:48:38 -08002757}
2758
2759TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
2760 bool use_sctpmap = true;
2761 AddSctpDataChannel(use_sctpmap);
2762
2763 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 10:27:41 -08002764 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002765 MutateJsepSctpPort(&jdesc, desc_);
wu@webrtc.org78187522013-10-07 23:32:02 +00002766
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002767 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002768 std::string sdp_with_data = kSdpString;
2769 sdp_with_data.append(kSdpSctpDataChannelString);
zstein4b2e0822017-02-17 19:48:38 -08002770 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2771 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2772 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002773 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:02 +00002774
2775 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2776 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08002777}
2778
2779TEST_F(WebRtcSdpTest,
2780 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
2781 bool use_sctpmap = false;
2782 AddSctpDataChannel(use_sctpmap);
2783
Steve Antona3a92c22017-12-07 10:27:41 -08002784 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002785 MutateJsepSctpPort(&jdesc, desc_);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002786
2787 // We need to test the deserialized JsepSessionDescription from
2788 // kSdpSctpDataChannelStringWithSctpPort for
2789 // draft-ietf-mmusic-sctp-sdp-07
2790 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08002791 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002792 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
zstein4b2e0822017-02-17 19:48:38 -08002793 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2794 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2795 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002796 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002797
2798 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2799 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002800}
2801
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002802TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002803 // We want to test that deserializing data content limits bandwidth
2804 // settings (it should never be greater than the default).
2805 // This should prevent someone from using unlimited data bandwidth through
2806 // JS and "breaking the Internet".
2807 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002808 std::string sdp_with_bandwidth = kSdpString;
2809 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02002810 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002811 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002812 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002813
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002814 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2815}
2816
2817TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08002818 bool use_sctpmap = true;
2819 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002820 JsepSessionDescription jdesc(kDummyType);
Steve Antonb1c1de12017-12-21 15:14:30 -08002821 DataContentDescription* dcd = GetFirstDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002822 dcd->set_bandwidth(100 * 1000);
2823 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2824
2825 std::string sdp_with_bandwidth = kSdpString;
2826 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02002827 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002828 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002829 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002830
2831 // SCTP has congestion control, so we shouldn't limit the bandwidth
2832 // as we do for RTP.
2833 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002834 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2835}
2836
Yves Gerey665174f2018-06-19 15:03:05 +02002837class WebRtcSdpExtmapTest : public WebRtcSdpTest,
2838 public testing::WithParamInterface<bool> {};
jbauch5869f502017-06-29 12:31:36 -07002839
2840TEST_P(WebRtcSdpExtmapTest,
Yves Gerey665174f2018-06-19 15:03:05 +02002841 DeserializeSessionDescriptionWithSessionLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002842 bool encrypted = GetParam();
2843 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002844}
2845
Yves Gerey665174f2018-06-19 15:03:05 +02002846TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002847 bool encrypted = GetParam();
2848 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002849}
2850
Yves Gerey665174f2018-06-19 15:03:05 +02002851TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithInvalidExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002852 bool encrypted = GetParam();
2853 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002854}
2855
jbauch5869f502017-06-29 12:31:36 -07002856INSTANTIATE_TEST_CASE_P(Encrypted,
2857 WebRtcSdpExtmapTest,
2858 ::testing::Values(false, true));
2859
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002860TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 10:27:41 -08002861 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002862 std::string sdp = kSdpFullString;
2863 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2864 // Deserialize
2865 SdpParseError error;
2866 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-16 17:54:10 -08002867 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002868 EXPECT_EQ(lastline, error.line);
2869 EXPECT_EQ("Invalid SDP line.", error.description);
2870}
2871
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002872TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2873 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2874 std::string new_sdp = kSdpOneCandidate;
2875 Replace("udp", "unsupported_transport", &new_sdp);
2876 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2877 new_sdp = kSdpOneCandidate;
2878 Replace("udp", "uDP", &new_sdp);
2879 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2880 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2881 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2882 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2883}
2884
honghaiza54a0802015-12-16 18:37:23 -08002885TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002886 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08002887 EXPECT_TRUE(
2888 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002889 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2890 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2891 Candidate ref_candidate = jcandidate_->candidate();
2892 ref_candidate.set_username("user_rtp");
2893 ref_candidate.set_password("password_rtp");
2894 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2895}
2896
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002897TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08002898 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002899
2900 // Deserialize
2901 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2902
2903 // Verify
2904 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002905 jdesc.description()
2906 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2907 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002908 EXPECT_TRUE(audio->conference_mode());
2909
2910 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 15:14:30 -08002911 jdesc.description()
2912 ->GetContentDescriptionByName(cricket::CN_VIDEO)
2913 ->as_video();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002914 EXPECT_TRUE(video->conference_mode());
2915}
2916
deadbeefd45aea82017-09-16 01:24:29 -07002917TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08002918 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 01:24:29 -07002919
2920 // We tested deserialization already above, so just test that if we serialize
2921 // and deserialize the flag doesn't disappear.
2922 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 12:22:16 -08002923 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 01:24:29 -07002924 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
2925
2926 // Verify.
2927 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002928 jdesc.description()
2929 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2930 ->as_audio();
deadbeefd45aea82017-09-16 01:24:29 -07002931 EXPECT_TRUE(audio->conference_mode());
2932
2933 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 15:14:30 -08002934 jdesc.description()
2935 ->GetContentDescriptionByName(cricket::CN_VIDEO)
2936 ->as_video();
deadbeefd45aea82017-09-16 01:24:29 -07002937 EXPECT_TRUE(video->conference_mode());
2938}
2939
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002940TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2941 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002942 const char kSdpEmptyType[] = " =candidate";
2943 const char kSdpEqualAsPlus[] = "a+candidate";
2944 const char kSdpSpaceAfterEqual[] = "a= candidate";
2945 const char kSdpUpperType[] = "A=candidate";
2946 const char kSdpEmptyLine[] = "";
2947 const char kSdpMissingValue[] = "a=";
2948
Yves Gerey665174f2018-06-19 15:03:05 +02002949 const char kSdpBrokenFingerprint[] =
2950 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002951 "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 +02002952 const char kSdpExtraField[] =
2953 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002954 "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 +02002955 const char kSdpMissingSpace[] =
2956 "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002957 "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 +00002958 // MD5 is not allowed in fingerprints.
Yves Gerey665174f2018-06-19 15:03:05 +02002959 const char kSdpMd5[] =
2960 "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002961 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002962
2963 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002964 ExpectParseFailure("v=", kSdpDestroyer);
2965 ExpectParseFailure("o=", kSdpDestroyer);
2966 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002967 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002968 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002969
2970 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002971 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2972 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002973
2974 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002975 ExpectParseFailure("a=candidate", kSdpEmptyType);
2976 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2977 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
2978 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002979
2980 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2981 // because it's orthogonal to what we are replacing and hence
2982 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002983 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
2984 ExpectParseFailure("a=sendrecv", kSdpExtraField);
2985 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
2986 ExpectParseFailure("a=sendrecv", kSdpMd5);
2987
2988 // Empty Line
2989 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
2990 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002991}
2992
2993TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2994 // ssrc
2995 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08002996 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002997 // crypto
2998 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
2999 // rtpmap
3000 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
3001 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
3002 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
3003 // candidate
3004 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
3005 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
3006 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
3007 ExpectParseFailure("rport 2346", "rport badvalue");
3008 ExpectParseFailure("rport 2346 generation 2",
3009 "rport 2346 generation badvalue");
3010 // m line
3011 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
3012 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
3013
3014 // bandwidth
3015 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003016 "b=AS:badvalue\r\n", "b=AS:badvalue");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003017 // rtcp-fb
3018 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3019 "a=rtcp-fb:badvalue nack\r\n",
3020 "a=rtcp-fb:badvalue nack");
3021 // extmap
3022 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3023 "a=extmap:badvalue http://example.com\r\n",
3024 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003025}
3026
3027TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 10:27:41 -08003028 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003029
3030 const char kSdpWithReorderedPlTypesString[] =
3031 "v=0\r\n"
3032 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3033 "s=-\r\n"
3034 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00003035 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
Yves Gerey665174f2018-06-19 15:03:05 +02003036 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
3037 // in the map.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003038 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003039 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003040
3041 // Deserialize
3042 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
3043
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003044 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003045 GetFirstAudioContentDescription(jdesc_output.description());
3046 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003047 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003048 EXPECT_EQ("ISAC", acd->codecs()[0].name);
3049 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003050 EXPECT_EQ(104, acd->codecs()[0].id);
3051}
3052
3053TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 10:27:41 -08003054 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003055 CodecParams params;
3056 params.max_ptime = 40;
3057 params.ptime = 30;
3058 params.min_ptime = 10;
3059 params.sprop_stereo = 1;
3060 params.stereo = 1;
3061 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003062 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003063 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 12:22:16 -08003064 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003065}
3066
3067TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
3068 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 10:27:41 -08003069 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003070 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003071 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003072}
3073
3074TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
3075 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 10:27:41 -08003076 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003077 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003078 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003079}
3080
3081TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 10:27:41 -08003082 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003083
3084 const char kSdpWithFmtpString[] =
3085 "v=0\r\n"
3086 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3087 "s=-\r\n"
3088 "t=0 0\r\n"
3089 "m=video 3457 RTP/SAVPF 120\r\n"
3090 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07003091 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3092
3093 // Deserialize
3094 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07003095 EXPECT_TRUE(
3096 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07003097
Donald Curtis0e07f922015-05-15 09:21:23 -07003098 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003099 GetFirstVideoContentDescription(jdesc_output.description());
3100 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 09:21:23 -07003101 ASSERT_FALSE(vcd->codecs().empty());
3102 cricket::VideoCodec vp8 = vcd->codecs()[0];
3103 EXPECT_EQ("VP8", vp8.name);
3104 EXPECT_EQ(120, vp8.id);
3105 cricket::CodecParameterMap::iterator found =
3106 vp8.params.find("x-google-min-bitrate");
3107 ASSERT_TRUE(found != vp8.params.end());
3108 EXPECT_EQ(found->second, "10");
3109 found = vp8.params.find("x-google-max-quantization");
3110 ASSERT_TRUE(found != vp8.params.end());
3111 EXPECT_EQ(found->second, "40");
3112}
3113
johan2d8d23e2016-06-03 01:22:42 -07003114TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 10:27:41 -08003115 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 01:22:42 -07003116
3117 const char kSdpWithFmtpString[] =
3118 "v=0\r\n"
3119 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3120 "s=-\r\n"
3121 "t=0 0\r\n"
3122 "m=video 49170 RTP/AVP 98\r\n"
3123 "a=rtpmap:98 H264/90000\r\n"
3124 "a=fmtp:98 profile-level-id=42A01E; "
3125 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3126
3127 // Deserialize.
3128 SdpParseError error;
3129 EXPECT_TRUE(
3130 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3131
johan2d8d23e2016-06-03 01:22:42 -07003132 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003133 GetFirstVideoContentDescription(jdesc_output.description());
3134 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 01:22:42 -07003135 ASSERT_FALSE(vcd->codecs().empty());
3136 cricket::VideoCodec h264 = vcd->codecs()[0];
3137 EXPECT_EQ("H264", h264.name);
3138 EXPECT_EQ(98, h264.id);
3139 cricket::CodecParameterMap::const_iterator found =
3140 h264.params.find("profile-level-id");
3141 ASSERT_TRUE(found != h264.params.end());
3142 EXPECT_EQ(found->second, "42A01E");
3143 found = h264.params.find("sprop-parameter-sets");
3144 ASSERT_TRUE(found != h264.params.end());
3145 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3146}
3147
Donald Curtis0e07f922015-05-15 09:21:23 -07003148TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 10:27:41 -08003149 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 09:21:23 -07003150
3151 const char kSdpWithFmtpString[] =
3152 "v=0\r\n"
3153 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3154 "s=-\r\n"
3155 "t=0 0\r\n"
3156 "m=video 3457 RTP/SAVPF 120\r\n"
3157 "a=rtpmap:120 VP8/90000\r\n"
3158 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003159
3160 // Deserialize
3161 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02003162 EXPECT_TRUE(
3163 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003164
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003165 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003166 GetFirstVideoContentDescription(jdesc_output.description());
3167 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003168 ASSERT_FALSE(vcd->codecs().empty());
3169 cricket::VideoCodec vp8 = vcd->codecs()[0];
3170 EXPECT_EQ("VP8", vp8.name);
3171 EXPECT_EQ(120, vp8.id);
3172 cricket::CodecParameterMap::iterator found =
3173 vp8.params.find("x-google-min-bitrate");
3174 ASSERT_TRUE(found != vp8.params.end());
3175 EXPECT_EQ(found->second, "10");
3176 found = vp8.params.find("x-google-max-quantization");
3177 ASSERT_TRUE(found != vp8.params.end());
3178 EXPECT_EQ(found->second, "40");
3179}
3180
ossuaa4b0772017-01-30 07:41:18 -08003181TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003182 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003183
3184 cricket::AudioCodecs codecs = acd->codecs();
3185 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3186 acd->set_codecs(codecs);
3187
Yves Gerey665174f2018-06-19 15:03:05 +02003188 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003189 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003190 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003191 std::string sdp_with_fmtp = kSdpFullString;
3192 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3193 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3194 &sdp_with_fmtp);
3195 EXPECT_EQ(sdp_with_fmtp, message);
3196}
3197
3198TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003199 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003200
3201 cricket::AudioCodecs codecs = acd->codecs();
3202 codecs[0].params["stereo"] = "1";
3203 acd->set_codecs(codecs);
3204
Yves Gerey665174f2018-06-19 15:03:05 +02003205 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003206 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003207 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003208 std::string sdp_with_fmtp = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003209 InjectAfter("a=rtpmap:111 opus/48000/2\r\n", "a=fmtp:111 stereo=1\r\n",
ossuaa4b0772017-01-30 07:41:18 -08003210 &sdp_with_fmtp);
3211 EXPECT_EQ(sdp_with_fmtp, message);
3212}
3213
3214TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003215 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003216
3217 cricket::AudioCodecs codecs = acd->codecs();
3218 codecs[0].params["ptime"] = "20";
3219 codecs[0].params["maxptime"] = "120";
3220 acd->set_codecs(codecs);
3221
Yves Gerey665174f2018-06-19 15:03:05 +02003222 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003223 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003224 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003225 std::string sdp_with_fmtp = kSdpFullString;
3226 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3227 "a=maxptime:120\r\n" // No comma here. String merging!
3228 "a=ptime:20\r\n",
3229 &sdp_with_fmtp);
3230 EXPECT_EQ(sdp_with_fmtp, message);
3231}
3232
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003233TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003234 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003235
3236 cricket::VideoCodecs codecs = vcd->codecs();
3237 codecs[0].params["x-google-min-bitrate"] = "10";
3238 vcd->set_codecs(codecs);
3239
Yves Gerey665174f2018-06-19 15:03:05 +02003240 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003241 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003242 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003243 std::string sdp_with_fmtp = kSdpFullString;
3244 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003245 "a=fmtp:120 x-google-min-bitrate=10\r\n", &sdp_with_fmtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003246 EXPECT_EQ(sdp_with_fmtp, message);
3247}
3248
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003249TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) {
3250 // Deserialize the baseline description, making sure it's ICE full.
Steve Antona3a92c22017-12-07 10:27:41 -08003251 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003252 std::string sdp_with_icelite = kSdpFullString;
3253 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3254 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3255 const cricket::TransportInfo* tinfo1 =
3256 desc->GetTransportInfoByName("audio_content_name");
3257 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3258 const cricket::TransportInfo* tinfo2 =
3259 desc->GetTransportInfoByName("video_content_name");
3260 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003261
3262 // Add "a=ice-lite" and deserialize, making sure it's ICE lite.
Yves Gerey665174f2018-06-19 15:03:05 +02003263 InjectAfter(kSessionTime, "a=ice-lite\r\n", &sdp_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003264 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3265 desc = jdesc_with_icelite.description();
3266 const cricket::TransportInfo* atinfo =
3267 desc->GetTransportInfoByName("audio_content_name");
3268 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3269 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003270 desc->GetTransportInfoByName("video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003271 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003272
3273 // Now that we know deserialization works, we can use TestSerialize to test
3274 // serialization.
3275 TestSerialize(jdesc_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003276}
3277
3278// Verifies that the candidates in the input SDP are parsed and serialized
3279// correctly in the output SDP.
3280TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3281 std::string sdp_with_data = kSdpString;
3282 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 10:27:41 -08003283 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003284
3285 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 12:22:16 -08003286 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003287}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003288
3289TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3290 AddFingerprint();
3291 TransportInfo audio_transport_info =
3292 *(desc_.GetTransportInfoByName(kAudioContentName));
3293 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3294 audio_transport_info.description.connection_role);
3295 audio_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003296 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003297
3298 TransportInfo video_transport_info =
3299 *(desc_.GetTransportInfoByName(kVideoContentName));
3300 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3301 video_transport_info.description.connection_role);
3302 video_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003303 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003304
3305 desc_.RemoveTransportInfoByName(kAudioContentName);
3306 desc_.RemoveTransportInfoByName(kVideoContentName);
3307
3308 desc_.AddTransportInfo(audio_transport_info);
3309 desc_.AddTransportInfo(video_transport_info);
3310
Yves Gerey665174f2018-06-19 15:03:05 +02003311 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003312 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003313 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003314 std::string sdp_with_dtlssetup = kSdpFullString;
3315
3316 // Fingerprint attribute is necessary to add DTLS setup attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003317 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_dtlssetup);
3318 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003319 // Now adding |setup| attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003320 InjectAfter(kFingerprint, "a=setup:active\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003321 EXPECT_EQ(sdp_with_dtlssetup, message);
3322}
3323
3324TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
Steve Antona3a92c22017-12-07 10:27:41 -08003325 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003326 std::string sdp_with_dtlssetup = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003327 InjectAfter(kSessionTime, "a=setup:actpass\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003328 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3329 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3330 const cricket::TransportInfo* atinfo =
3331 desc->GetTransportInfoByName("audio_content_name");
3332 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3333 atinfo->description.connection_role);
3334 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003335 desc->GetTransportInfoByName("video_content_name");
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003336 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3337 vtinfo->description.connection_role);
3338}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003339
3340// Verifies that the order of the serialized m-lines follows the order of the
3341// ContentInfo in SessionDescription, and vise versa for deserialization.
3342TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 10:27:41 -08003343 JsepSessionDescription jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02003344 const std::string media_content_sdps[3] = {kSdpAudioString, kSdpVideoString,
3345 kSdpSctpDataChannelString};
3346 const cricket::MediaType media_types[3] = {cricket::MEDIA_TYPE_AUDIO,
3347 cricket::MEDIA_TYPE_VIDEO,
3348 cricket::MEDIA_TYPE_DATA};
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003349
3350 // Verifies all 6 permutations.
3351 for (size_t i = 0; i < 6; ++i) {
3352 size_t media_content_in_sdp[3];
3353 // The index of the first media content.
3354 media_content_in_sdp[0] = i / 2;
3355 // The index of the second media content.
3356 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3357 // The index of the third media content.
3358 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3359
3360 std::string sdp_string = kSdpSessionString;
3361 for (size_t i = 0; i < 3; ++i)
3362 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3363
3364 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3365 cricket::SessionDescription* desc = jdesc.description();
3366 EXPECT_EQ(3u, desc->contents().size());
3367
3368 for (size_t i = 0; i < 3; ++i) {
3369 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 15:14:30 -08003370 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003371 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3372 }
3373
Steve Antone831b8c2018-02-01 12:22:16 -08003374 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003375 EXPECT_EQ(sdp_string, serialized_sdp);
3376 }
3377}
deadbeef9d3584c2016-02-16 17:54:10 -08003378
deadbeef25ed4352016-12-12 18:37:36 -08003379TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3380 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 10:27:41 -08003381 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003382 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003383 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3384 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3385}
3386
deadbeef12771a12017-01-03 13:53:47 -08003387// The semantics of "a=bundle-only" are only defined when it's used in
3388// combination with a 0 port on the m= line. We should ignore it if used with a
3389// nonzero port.
3390TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3391 // Make the base bundle-only description but unset the bundle-only flag.
3392 MakeBundleOnlyDescription();
3393 jdesc_.description()->contents()[1].bundle_only = false;
3394
3395 std::string modified_sdp = kBundleOnlySdpFullString;
3396 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08003397 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003398 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3399 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003400}
3401
3402TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3403 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003404 TestSerialize(jdesc_);
deadbeef25ed4352016-12-12 18:37:36 -08003405}
3406
deadbeef9d3584c2016-02-16 17:54:10 -08003407TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3408 MakePlanBDescription();
3409
Steve Antona3a92c22017-12-07 10:27:41 -08003410 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003411 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3412
3413 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3414}
3415
3416TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3417 MakePlanBDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003418 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-16 17:54:10 -08003419}
3420
3421TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3422 MakeUnifiedPlanDescription();
3423
Steve Antona3a92c22017-12-07 10:27:41 -08003424 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003425 EXPECT_TRUE(
3426 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3427
3428 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3429}
3430
3431TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3432 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003433 TestSerialize(jdesc_);
3434}
3435
Seth Hampson5b4f0752018-04-02 16:31:36 -07003436// This tests deserializing a Unified Plan SDP that is compatible with both
3437// Unified Plan and Plan B style SDP. It tests the case for audio/video tracks
3438// with no stream ids and multiple stream ids. For parsing this, the Unified
3439// Plan a=msid lines should take priority, because the Plan B style a=ssrc msid
3440// lines do not support multiple stream ids and no stream ids.
3441TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionSpecialMsid) {
3442 MakeUnifiedPlanDescriptionMultipleStreamIds();
3443
3444 JsepSessionDescription deserialized_description(kDummyType);
3445 EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid,
3446 &deserialized_description));
3447
3448 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3449}
3450
3451TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionSpecialMsid) {
3452 MakeUnifiedPlanDescriptionMultipleStreamIds();
3453 TestSerialize(jdesc_);
3454}
3455
Seth Hampson5897a6e2018-04-03 11:16:33 -07003456// This tests that a Unified Plan SDP with no a=ssrc lines is
3457// serialized/deserialized appropriately. In this case the
3458// MediaContentDescription will contain a StreamParams object that doesn't have
3459// any SSRCs. Vice versa, this will be created upon deserializing an SDP with no
3460// SSRC lines.
3461TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3462 MakeUnifiedPlanDescription();
3463 RemoveSsrcSignalingFromStreamParams();
3464 std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString;
3465 RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string);
3466
3467 JsepSessionDescription deserialized_description(kDummyType);
3468 EXPECT_TRUE(
3469 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3470 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3471}
3472
3473TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3474 MakeUnifiedPlanDescription();
3475 RemoveSsrcSignalingFromStreamParams();
3476
3477 TestSerialize(jdesc_);
3478}
3479
Steve Antone831b8c2018-02-01 12:22:16 -08003480TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
3481 JsepSessionDescription jsep_desc(kDummyType);
3482 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
3483 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3484}
3485
3486TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
3487 JsepSessionDescription jsep_desc(kDummyType);
3488 std::string sdp = kSdpSessionString;
3489 sdp += kSdpSctpDataChannelString;
3490 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3491 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3492}
3493
3494TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
3495 JsepSessionDescription jsep_desc(kDummyType);
3496 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
3497 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
3498 jsep_desc.description()->msid_signaling());
3499}
3500
3501TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
3502 JsepSessionDescription jsep_desc(kDummyType);
3503 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
3504 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
3505 jsep_desc.description()->msid_signaling());
3506}
3507
3508const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
3509const char kSsrcAttributeMsidLine[] =
3510 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
3511
3512TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
3513 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
3514 std::string sdp = webrtc::SdpSerialize(jdesc_);
3515
3516 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3517 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3518}
3519
3520TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
3521 jdesc_.description()->set_msid_signaling(
3522 cricket::kMsidSignalingSsrcAttribute);
3523 std::string sdp = webrtc::SdpSerialize(jdesc_);
3524
3525 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
3526 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3527}
3528
3529TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
3530 jdesc_.description()->set_msid_signaling(
3531 cricket::kMsidSignalingMediaSection |
3532 cricket::kMsidSignalingSsrcAttribute);
3533 std::string sdp = webrtc::SdpSerialize(jdesc_);
3534
3535 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3536 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-16 17:54:10 -08003537}
deadbeef7e146cb2016-09-28 10:04:34 -07003538
3539// Regression test for heap overflow bug:
3540// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3541TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 10:04:34 -07003542 // The issue occurs when the sctp-port attribute is found in a video
3543 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 12:43:58 -08003544 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 10:04:34 -07003545 "v=0\r\n"
3546 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3547 "s=-\r\n"
3548 "t=0 0\r\n"
3549 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3550 "a=sctp-port 5000\r\n"
3551 "a=fmtp:108 foo=10\r\n";
3552
3553 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3554 "sctp-port");
3555}
deadbeefb2362572016-12-13 16:37:06 -08003556
3557// Regression test for integer overflow bug:
3558// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3559TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003560 // Bandwidth attribute is the max signed 32-bit int, which will get
3561 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003562 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003563 "v=0\r\n"
3564 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3565 "s=-\r\n"
3566 "t=0 0\r\n"
3567 "m=video 3457 RTP/SAVPF 120\r\n"
3568 "b=AS:2147483647\r\n"
3569 "foo=fail\r\n";
3570
3571 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3572}
deadbeef7bcdb692017-01-20 12:43:58 -08003573
deadbeefbc88c6b2017-08-02 11:26:34 -07003574// Similar to the above, except that negative values are illegal, not just
3575// error-prone as large values are.
3576// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3577TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3578 static const char kSdpWithNegativeBandwidth[] =
3579 "v=0\r\n"
3580 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3581 "s=-\r\n"
3582 "t=0 0\r\n"
3583 "m=video 3457 RTP/SAVPF 120\r\n"
3584 "b=AS:-1000\r\n";
3585
3586 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3587}
3588
deadbeef3e8016e2017-08-03 17:49:30 -07003589// An exception to the above rule: a value of -1 for b=AS should just be
3590// ignored, resulting in "kAutoBandwidth" in the deserialized object.
3591// Applications historically may be using "b=AS:-1" to mean "no bandwidth
3592// limit", but this is now what ommitting the attribute entirely will do, so
3593// ignoring it will have the intended effect.
3594TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
3595 static const char kSdpWithBandwidthOfNegativeOne[] =
3596 "v=0\r\n"
3597 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3598 "s=-\r\n"
3599 "t=0 0\r\n"
3600 "m=video 3457 RTP/SAVPF 120\r\n"
3601 "b=AS:-1\r\n";
3602
Steve Antona3a92c22017-12-07 10:27:41 -08003603 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-03 17:49:30 -07003604 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-03 17:49:30 -07003605 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003606 GetFirstVideoContentDescription(jdesc_output.description());
3607 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-03 17:49:30 -07003608 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
3609}
3610
deadbeef7bcdb692017-01-20 12:43:58 -08003611// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3612// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3613// Regression test for:
3614// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3615TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3616 // Important piece is "ufrag foo pwd bar".
3617 static const char kSdpWithIceCredentialsInCandidateString[] =
3618 "v=0\r\n"
3619 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3620 "s=-\r\n"
3621 "t=0 0\r\n"
3622 "m=audio 9 RTP/SAVPF 111\r\n"
3623 "c=IN IP4 0.0.0.0\r\n"
3624 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3625 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3626 "a=rtpmap:111 opus/48000/2\r\n"
3627 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3628 "generation 2 ufrag foo pwd bar\r\n";
3629
Steve Antona3a92c22017-12-07 10:27:41 -08003630 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 12:43:58 -08003631 EXPECT_TRUE(
3632 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
3633 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3634 ASSERT_NE(nullptr, candidates);
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003635 ASSERT_EQ(1U, candidates->count());
deadbeef7bcdb692017-01-20 12:43:58 -08003636 cricket::Candidate c = candidates->at(0)->candidate();
3637 EXPECT_EQ("ufrag_voice", c.username());
3638 EXPECT_EQ("pwd_voice", c.password());
3639}
deadbeef90f1e1e2017-02-10 12:35:05 -08003640
Johannes Kron211856b2018-09-06 12:12:28 +02003641// Test that attribute lines "a=ice-ufrag-something"/"a=ice-pwd-something" are
3642// ignored, and only the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3643// Regression test for:
3644// https://bugs.chromium.org/p/webrtc/issues/detail?id=9712
3645TEST_F(WebRtcSdpTest, AttributeWithPartialMatchingNameIsIgnored) {
3646 static const char kSdpWithFooIceCredentials[] =
3647 "v=0\r\n"
3648 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3649 "s=-\r\n"
3650 "t=0 0\r\n"
3651 "m=audio 9 RTP/SAVPF 111\r\n"
3652 "c=IN IP4 0.0.0.0\r\n"
3653 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3654 "a=ice-ufrag-something:foo\r\na=ice-pwd-something:bar\r\n"
3655 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3656 "a=rtpmap:111 opus/48000/2\r\n"
3657 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3658 "generation 2\r\n";
3659
3660 JsepSessionDescription jdesc_output(kDummyType);
3661 EXPECT_TRUE(SdpDeserialize(kSdpWithFooIceCredentials, &jdesc_output));
3662 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3663 ASSERT_NE(nullptr, candidates);
3664 ASSERT_EQ(1U, candidates->count());
3665 cricket::Candidate c = candidates->at(0)->candidate();
3666 EXPECT_EQ("ufrag_voice", c.username());
3667 EXPECT_EQ("pwd_voice", c.password());
3668}
3669
deadbeef90f1e1e2017-02-10 12:35:05 -08003670// Test that SDP with an invalid port number in "a=candidate" lines is
3671// rejected, without crashing.
3672// Regression test for:
3673// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
3674TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
3675 static const char kSdpWithInvalidCandidatePort[] =
3676 "v=0\r\n"
3677 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3678 "s=-\r\n"
3679 "t=0 0\r\n"
3680 "m=audio 9 RTP/SAVPF 111\r\n"
3681 "c=IN IP4 0.0.0.0\r\n"
3682 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3683 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3684 "a=rtpmap:111 opus/48000/2\r\n"
3685 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
3686 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
3687
Steve Antona3a92c22017-12-07 10:27:41 -08003688 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 12:35:05 -08003689 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
3690}
deadbeefa4549d62017-02-10 17:26:22 -08003691
3692// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
3693// Regression test for:
3694// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
3695TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
3696 static const char kSdpWithMissingTrackId[] =
3697 "v=0\r\n"
3698 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3699 "s=-\r\n"
3700 "t=0 0\r\n"
3701 "m=audio 9 RTP/SAVPF 111\r\n"
3702 "c=IN IP4 0.0.0.0\r\n"
3703 "a=rtpmap:111 opus/48000/2\r\n"
3704 "a=msid:stream_id \r\n";
3705
Steve Antona3a92c22017-12-07 10:27:41 -08003706 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003707 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
3708}
3709
3710TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
3711 static const char kSdpWithMissingStreamId[] =
3712 "v=0\r\n"
3713 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3714 "s=-\r\n"
3715 "t=0 0\r\n"
3716 "m=audio 9 RTP/SAVPF 111\r\n"
3717 "c=IN IP4 0.0.0.0\r\n"
3718 "a=rtpmap:111 opus/48000/2\r\n"
3719 "a=msid: track_id\r\n";
3720
Steve Antona3a92c22017-12-07 10:27:41 -08003721 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003722 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
3723}
zhihuang38989e52017-03-21 11:04:53 -07003724
3725// Tests that if both session-level address and media-level address exist, use
3726// the media-level address.
3727TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 10:27:41 -08003728 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003729
3730 // Sesssion-level address.
3731 std::string sdp = kSdpFullString;
3732 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3733 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3734
3735 const auto& content1 = jsep_desc.description()->contents()[0];
3736 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 15:14:30 -08003737 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003738 const auto& content2 = jsep_desc.description()->contents()[1];
3739 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 15:14:30 -08003740 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003741}
3742
3743// Tests that the session-level connection address will be used if the media
3744// level-addresses are not specified.
3745TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 10:27:41 -08003746 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003747
3748 // Sesssion-level address.
3749 std::string sdp = kSdpString;
3750 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3751 // Remove the media level addresses.
3752 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3753 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3754 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3755
3756 const auto& content1 = jsep_desc.description()->contents()[0];
3757 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003758 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003759 const auto& content2 = jsep_desc.description()->contents()[1];
3760 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003761 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003762}
3763
3764TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 10:27:41 -08003765 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003766
3767 std::string sdp = kSdpString;
3768 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3769 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
3770 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
3771 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
3772 &sdp);
3773 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
3774 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
3775 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
3776 &sdp);
3777 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3778 const auto& content1 = jsep_desc.description()->contents()[0];
3779 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003780 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003781 const auto& content2 = jsep_desc.description()->contents()[1];
3782 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003783 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003784}
3785
3786// Test that the invalid or unsupprted connection data cannot be parsed.
3787TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 10:27:41 -08003788 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003789 std::string sdp = kSdpString;
3790 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3791
3792 // Unsupported multicast IPv4 address.
3793 sdp = kSdpFullString;
3794 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
3795 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3796
3797 // Unsupported multicast IPv6 address.
3798 sdp = kSdpFullString;
3799 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
3800 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3801
3802 // Mismatched address type.
3803 sdp = kSdpFullString;
3804 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
3805 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3806
3807 sdp = kSdpFullString;
3808 Replace("c=IN IP4 74.125.224.39\r\n",
3809 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
3810 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3811}
3812
3813TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 10:27:41 -08003814 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003815 MakeDescriptionWithoutCandidates(&expected_jsep);
3816 // Serialization.
Steve Antone831b8c2018-02-01 12:22:16 -08003817 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 11:04:53 -07003818 // Deserialization.
Steve Antona3a92c22017-12-07 10:27:41 -08003819 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003820 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 15:14:30 -08003821 auto audio_desc = jdesc.description()
3822 ->GetContentByName(kAudioContentName)
3823 ->media_description();
3824 auto video_desc = jdesc.description()
3825 ->GetContentByName(kVideoContentName)
3826 ->media_description();
zhihuang38989e52017-03-21 11:04:53 -07003827 EXPECT_EQ(audio_desc_->connection_address().ToString(),
3828 audio_desc->connection_address().ToString());
3829 EXPECT_EQ(video_desc_->connection_address().ToString(),
3830 video_desc->connection_address().ToString());
3831}
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07003832
3833// RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be
3834// used (i.e., a single space as the session name)." So we should accept that.
3835TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) {
3836 JsepSessionDescription jsep_desc(kDummyType);
3837 std::string sdp = kSdpString;
3838 Replace("s=-\r\n", "s= \r\n", &sdp);
3839 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3840}