blob: 24b196f50e00c3ec7ba97a775ce3a389cad0b6a9 [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
Henrik Kjellander15583c12016-02-10 10:53:12 +010016#include "webrtc/api/jsepsessiondescription.h"
kjellanderf4752772016-03-02 05:42:30 -080017#include "webrtc/media/base/mediaconstants.h"
eladalonf1841382017-06-12 01:16:46 -070018#include "webrtc/media/engine/webrtcvideoengine.h"
htaa6b99442016-04-12 10:29:17 -070019#include "webrtc/modules/video_coding/codecs/h264/include/h264.h"
kjellanderf4752772016-03-02 05:42:30 -080020#include "webrtc/p2p/base/p2pconstants.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010021#include "webrtc/pc/mediasession.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020022#include "webrtc/rtc_base/checks.h"
23#include "webrtc/rtc_base/gunit.h"
24#include "webrtc/rtc_base/logging.h"
25#include "webrtc/rtc_base/messagedigest.h"
26#include "webrtc/rtc_base/sslfingerprint.h"
27#include "webrtc/rtc_base/stringencode.h"
28#include "webrtc/rtc_base/stringutils.h"
ossu7bb87ee2017-01-23 04:56:25 -080029#ifdef WEBRTC_ANDROID
30#include "webrtc/pc/test/androidtestinitializer.h"
31#endif
32#include "webrtc/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;
46using cricket::NS_JINGLE_DRAFT_SCTP;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047using cricket::NS_JINGLE_RTP;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000048using cricket::RELAY_PORT_TYPE;
49using cricket::SessionDescription;
50using cricket::StreamParams;
51using cricket::STUN_PORT_TYPE;
52using cricket::TransportDescription;
53using cricket::TransportInfo;
54using cricket::VideoCodec;
55using cricket::VideoContentDescription;
56using webrtc::IceCandidateCollection;
57using webrtc::IceCandidateInterface;
58using webrtc::JsepIceCandidate;
59using webrtc::JsepSessionDescription;
isheriff6f8d6862016-05-26 11:24:55 -070060using webrtc::RtpExtension;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061using webrtc::SdpParseError;
62using webrtc::SessionDescriptionInterface;
63
64typedef std::vector<AudioCodec> AudioCodecs;
65typedef std::vector<Candidate> Candidates;
66
Peter Boström0c4e06b2015-10-07 12:23:21 +020067static const uint32_t kDefaultSctpPort = 5000;
zstein4b2e0822017-02-17 19:48:38 -080068static const char kDefaultSctpPortStr[] = "5000";
69static const uint16_t kUnusualSctpPort = 9556;
70static const char kUnusualSctpPortStr[] = "9556";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020072static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 15:17:14 -080073static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 15:17:14 -080075static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020077static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078static const char kCandidateFoundation1[] = "a0+B/1";
79static const char kCandidateFoundation2[] = "a0+B/2";
80static const char kCandidateFoundation3[] = "a0+B/3";
81static const char kCandidateFoundation4[] = "a0+B/4";
82static const char kAttributeCryptoVoice[] =
83 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
84 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
85 "dummy_session_params\r\n";
86static const char kAttributeCryptoVideo[] =
87 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
88 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
89static const char kFingerprint[] = "a=fingerprint:sha-1 "
90 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n";
91static const int kExtmapId = 1;
92static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
93static const char kExtmap[] =
94 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
95static const char kExtmapWithDirectionAndAttribute[] =
96 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
jbauch5869f502017-06-29 12:31:36 -070097static const char kExtmapWithDirectionAndAttributeEncrypted[] =
98 "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt "
99 "http://example.com/082005/ext.htm#ttime a1 a2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100
Peter Boström0c4e06b2015-10-07 12:23:21 +0200101static const uint8_t kIdentityDigest[] = {
102 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
103 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000104
lally@webrtc.org34807282015-02-24 20:19:39 +0000105static const char kDtlsSctp[] = "DTLS/SCTP";
106static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
107static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +0000108
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000109struct CodecParams {
110 int max_ptime;
111 int ptime;
112 int min_ptime;
113 int sprop_stereo;
114 int stereo;
115 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000116 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000117};
118
deadbeef9d3584c2016-02-16 17:54:10 -0800119// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
120// instead of "a=crypto", and have an explicit test for adding "a=crypto".
121// Currently it's the other way around.
122
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000123// Reference sdp string
124static const char kSdpFullString[] =
125 "v=0\r\n"
126 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
127 "s=-\r\n"
128 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800129 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000130 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
131 "c=IN IP4 74.125.127.126\r\n"
132 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
133 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
134 "generation 2\r\n"
135 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
136 "generation 2\r\n"
137 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
138 "generation 2\r\n"
139 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
140 "generation 2\r\n"
141 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
142 "raddr 192.168.1.5 rport 2346 "
143 "generation 2\r\n"
144 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
145 "raddr 192.168.1.5 rport 2348 "
146 "generation 2\r\n"
147 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
148 "a=mid:audio_content_name\r\n"
149 "a=sendrecv\r\n"
150 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800151 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000152 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
153 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
154 "dummy_session_params\r\n"
155 "a=rtpmap:111 opus/48000/2\r\n"
156 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000157 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000158 "a=ssrc:1 cname:stream_1_cname\r\n"
159 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
160 "a=ssrc:1 mslabel:local_stream_1\r\n"
161 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000162 "m=video 3457 RTP/SAVPF 120\r\n"
163 "c=IN IP4 74.125.224.39\r\n"
164 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
165 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
166 "generation 2\r\n"
167 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
168 "generation 2\r\n"
169 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
170 "generation 2\r\n"
171 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
172 "generation 2\r\n"
173 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
174 "generation 2\r\n"
175 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
176 "generation 2\r\n"
177 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
178 "a=mid:video_content_name\r\n"
179 "a=sendrecv\r\n"
180 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
181 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
182 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800183 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000184 "a=ssrc:2 cname:stream_1_cname\r\n"
185 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
186 "a=ssrc:2 mslabel:local_stream_1\r\n"
187 "a=ssrc:2 label:video_track_id_1\r\n"
188 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800189 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000190 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800191 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000192
193// SDP reference string without the candidates.
194static const char kSdpString[] =
195 "v=0\r\n"
196 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
197 "s=-\r\n"
198 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800199 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000200 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000201 "c=IN IP4 0.0.0.0\r\n"
202 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000203 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
204 "a=mid:audio_content_name\r\n"
205 "a=sendrecv\r\n"
206 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800207 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000208 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
209 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
210 "dummy_session_params\r\n"
211 "a=rtpmap:111 opus/48000/2\r\n"
212 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000213 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000214 "a=ssrc:1 cname:stream_1_cname\r\n"
215 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
216 "a=ssrc:1 mslabel:local_stream_1\r\n"
217 "a=ssrc:1 label:audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000218 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000219 "c=IN IP4 0.0.0.0\r\n"
220 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000221 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
222 "a=mid:video_content_name\r\n"
223 "a=sendrecv\r\n"
224 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
225 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
226 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800227 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000228 "a=ssrc:2 cname:stream_1_cname\r\n"
229 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
230 "a=ssrc:2 mslabel:local_stream_1\r\n"
231 "a=ssrc:2 label:video_track_id_1\r\n"
232 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800233 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000234 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800235 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000236
237static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000238 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000239 "c=IN IP4 0.0.0.0\r\n"
240 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000241 "a=ice-ufrag:ufrag_data\r\n"
242 "a=ice-pwd:pwd_data\r\n"
243 "a=mid:data_content_name\r\n"
244 "a=sendrecv\r\n"
245 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
246 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
247 "a=rtpmap:101 google-data/90000\r\n"
248 "a=ssrc:10 cname:data_channel_cname\r\n"
249 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
250 "a=ssrc:10 mslabel:data_channel\r\n"
251 "a=ssrc:10 label:data_channeld0\r\n";
252
253static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000254 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000255 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000256 "a=ice-ufrag:ufrag_data\r\n"
257 "a=ice-pwd:pwd_data\r\n"
258 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000259 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000260
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000261// draft-ietf-mmusic-sctp-sdp-12
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000262static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000263 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
264 "a=max-message-size=100000\r\n"
265 "a=sctp-port 5000\r\n"
266 "c=IN IP4 0.0.0.0\r\n"
267 "a=ice-ufrag:ufrag_data\r\n"
268 "a=ice-pwd:pwd_data\r\n"
269 "a=mid:data_content_name\r\n";
270
lally69f57602015-10-08 10:15:04 -0700271static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
272 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
273 "a=max-message-size=100000\r\n"
274 "a=sctp-port:5000\r\n"
275 "c=IN IP4 0.0.0.0\r\n"
276 "a=ice-ufrag:ufrag_data\r\n"
277 "a=ice-pwd:pwd_data\r\n"
278 "a=mid:data_content_name\r\n";
279
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000280static const char kSdpSctpDataChannelWithCandidatesString[] =
281 "m=application 2345 DTLS/SCTP 5000\r\n"
282 "c=IN IP4 74.125.127.126\r\n"
283 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
284 "generation 2\r\n"
285 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
286 "generation 2\r\n"
287 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
288 "raddr 192.168.1.5 rport 2346 "
289 "generation 2\r\n"
290 "a=ice-ufrag:ufrag_data\r\n"
291 "a=ice-pwd:pwd_data\r\n"
292 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000293 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000294
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000295static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000296 "v=0\r\n"
297 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
298 "s=-\r\n"
299 "t=0 0\r\n"
300 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000301 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000302 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000303 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000304 "m=video 9 RTP/SAVPF 120\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";
307
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000308static const char kSdpSessionString[] =
309 "v=0\r\n"
310 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
311 "s=-\r\n"
312 "t=0 0\r\n"
313 "a=msid-semantic: WMS local_stream\r\n";
314
315static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000316 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000317 "c=IN IP4 0.0.0.0\r\n"
318 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000319 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
320 "a=mid:audio_content_name\r\n"
321 "a=sendrecv\r\n"
322 "a=rtpmap:111 opus/48000/2\r\n"
323 "a=ssrc:1 cname:stream_1_cname\r\n"
324 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
325 "a=ssrc:1 mslabel:local_stream\r\n"
326 "a=ssrc:1 label:audio_track_id_1\r\n";
327
328static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000329 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000330 "c=IN IP4 0.0.0.0\r\n"
331 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000332 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
333 "a=mid:video_content_name\r\n"
334 "a=sendrecv\r\n"
335 "a=rtpmap:120 VP8/90000\r\n"
336 "a=ssrc:2 cname:stream_1_cname\r\n"
337 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
338 "a=ssrc:2 mslabel:local_stream\r\n"
339 "a=ssrc:2 label:video_track_id_1\r\n";
340
deadbeef25ed4352016-12-12 18:37:36 -0800341// Reference sdp string using bundle-only.
342static const char kBundleOnlySdpFullString[] =
343 "v=0\r\n"
344 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
345 "s=-\r\n"
346 "t=0 0\r\n"
347 "a=group:BUNDLE audio_content_name video_content_name\r\n"
348 "a=msid-semantic: WMS local_stream_1\r\n"
349 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
350 "c=IN IP4 74.125.127.126\r\n"
351 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
352 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
353 "generation 2\r\n"
354 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
355 "generation 2\r\n"
356 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
357 "generation 2\r\n"
358 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
359 "generation 2\r\n"
360 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
361 "raddr 192.168.1.5 rport 2346 "
362 "generation 2\r\n"
363 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
364 "raddr 192.168.1.5 rport 2348 "
365 "generation 2\r\n"
366 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
367 "a=mid:audio_content_name\r\n"
368 "a=sendrecv\r\n"
369 "a=rtcp-mux\r\n"
370 "a=rtcp-rsize\r\n"
371 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
372 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
373 "dummy_session_params\r\n"
374 "a=rtpmap:111 opus/48000/2\r\n"
375 "a=rtpmap:103 ISAC/16000\r\n"
376 "a=rtpmap:104 ISAC/32000\r\n"
377 "a=ssrc:1 cname:stream_1_cname\r\n"
378 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
379 "a=ssrc:1 mslabel:local_stream_1\r\n"
380 "a=ssrc:1 label:audio_track_id_1\r\n"
381 "m=video 0 RTP/SAVPF 120\r\n"
382 "c=IN IP4 0.0.0.0\r\n"
383 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
384 "a=bundle-only\r\n"
385 "a=mid:video_content_name\r\n"
386 "a=sendrecv\r\n"
387 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
388 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
389 "a=rtpmap:120 VP8/90000\r\n"
390 "a=ssrc-group:FEC 2 3\r\n"
391 "a=ssrc:2 cname:stream_1_cname\r\n"
392 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
393 "a=ssrc:2 mslabel:local_stream_1\r\n"
394 "a=ssrc:2 label:video_track_id_1\r\n"
395 "a=ssrc:3 cname:stream_1_cname\r\n"
396 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
397 "a=ssrc:3 mslabel:local_stream_1\r\n"
398 "a=ssrc:3 label:video_track_id_1\r\n";
399
deadbeef9d3584c2016-02-16 17:54:10 -0800400// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
401// tracks.
402static const char kPlanBSdpFullString[] =
403 "v=0\r\n"
404 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
405 "s=-\r\n"
406 "t=0 0\r\n"
407 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
408 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
409 "c=IN IP4 74.125.127.126\r\n"
410 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
411 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
412 "generation 2\r\n"
413 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
414 "generation 2\r\n"
415 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
416 "generation 2\r\n"
417 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
418 "generation 2\r\n"
419 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
420 "raddr 192.168.1.5 rport 2346 "
421 "generation 2\r\n"
422 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
423 "raddr 192.168.1.5 rport 2348 "
424 "generation 2\r\n"
425 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
426 "a=mid:audio_content_name\r\n"
427 "a=sendrecv\r\n"
428 "a=rtcp-mux\r\n"
429 "a=rtcp-rsize\r\n"
430 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
431 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
432 "dummy_session_params\r\n"
433 "a=rtpmap:111 opus/48000/2\r\n"
434 "a=rtpmap:103 ISAC/16000\r\n"
435 "a=rtpmap:104 ISAC/32000\r\n"
436 "a=ssrc:1 cname:stream_1_cname\r\n"
437 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
438 "a=ssrc:1 mslabel:local_stream_1\r\n"
439 "a=ssrc:1 label:audio_track_id_1\r\n"
440 "a=ssrc:4 cname:stream_2_cname\r\n"
441 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
442 "a=ssrc:4 mslabel:local_stream_2\r\n"
443 "a=ssrc:4 label:audio_track_id_2\r\n"
444 "m=video 3457 RTP/SAVPF 120\r\n"
445 "c=IN IP4 74.125.224.39\r\n"
446 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
447 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
448 "generation 2\r\n"
449 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
450 "generation 2\r\n"
451 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
452 "generation 2\r\n"
453 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
454 "generation 2\r\n"
455 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
456 "generation 2\r\n"
457 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
458 "generation 2\r\n"
459 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
460 "a=mid:video_content_name\r\n"
461 "a=sendrecv\r\n"
462 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
463 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
464 "a=rtpmap:120 VP8/90000\r\n"
465 "a=ssrc-group:FEC 2 3\r\n"
466 "a=ssrc:2 cname:stream_1_cname\r\n"
467 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
468 "a=ssrc:2 mslabel:local_stream_1\r\n"
469 "a=ssrc:2 label:video_track_id_1\r\n"
470 "a=ssrc:3 cname:stream_1_cname\r\n"
471 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
472 "a=ssrc:3 mslabel:local_stream_1\r\n"
473 "a=ssrc:3 label:video_track_id_1\r\n"
474 "a=ssrc:5 cname:stream_2_cname\r\n"
475 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
476 "a=ssrc:5 mslabel:local_stream_2\r\n"
477 "a=ssrc:5 label:video_track_id_2\r\n"
478 "a=ssrc:6 cname:stream_2_cname\r\n"
479 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
480 "a=ssrc:6 mslabel:local_stream_2\r\n"
481 "a=ssrc:6 label:video_track_id_3\r\n";
482
Taylor Brandstetter5de6b752016-03-09 17:02:30 -0800483// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
484// tracks, but with the unified plan "a=msid" attribute.
485static const char kPlanBSdpFullStringWithMsid[] =
486 "v=0\r\n"
487 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
488 "s=-\r\n"
489 "t=0 0\r\n"
490 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
491 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
492 "c=IN IP4 74.125.127.126\r\n"
493 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
494 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
495 "generation 2\r\n"
496 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
497 "generation 2\r\n"
498 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
499 "generation 2\r\n"
500 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
501 "generation 2\r\n"
502 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
503 "raddr 192.168.1.5 rport 2346 "
504 "generation 2\r\n"
505 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
506 "raddr 192.168.1.5 rport 2348 "
507 "generation 2\r\n"
508 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
509 "a=mid:audio_content_name\r\n"
510 "a=msid:local_stream_1 audio_track_id_1\r\n"
511 "a=sendrecv\r\n"
512 "a=rtcp-mux\r\n"
513 "a=rtcp-rsize\r\n"
514 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
515 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
516 "dummy_session_params\r\n"
517 "a=rtpmap:111 opus/48000/2\r\n"
518 "a=rtpmap:103 ISAC/16000\r\n"
519 "a=rtpmap:104 ISAC/32000\r\n"
520 "a=ssrc:1 cname:stream_1_cname\r\n"
521 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
522 "a=ssrc:1 mslabel:local_stream_1\r\n"
523 "a=ssrc:1 label:audio_track_id_1\r\n"
524 "a=ssrc:4 cname:stream_2_cname\r\n"
525 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
526 "a=ssrc:4 mslabel:local_stream_2\r\n"
527 "a=ssrc:4 label:audio_track_id_2\r\n"
528 "m=video 3457 RTP/SAVPF 120\r\n"
529 "c=IN IP4 74.125.224.39\r\n"
530 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
531 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
532 "generation 2\r\n"
533 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
534 "generation 2\r\n"
535 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
536 "generation 2\r\n"
537 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
538 "generation 2\r\n"
539 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
540 "generation 2\r\n"
541 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
542 "generation 2\r\n"
543 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
544 "a=mid:video_content_name\r\n"
545 "a=msid:local_stream_1 video_track_id_1\r\n"
546 "a=sendrecv\r\n"
547 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
548 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
549 "a=rtpmap:120 VP8/90000\r\n"
550 "a=ssrc-group:FEC 2 3\r\n"
551 "a=ssrc:2 cname:stream_1_cname\r\n"
552 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
553 "a=ssrc:2 mslabel:local_stream_1\r\n"
554 "a=ssrc:2 label:video_track_id_1\r\n"
555 "a=ssrc:3 cname:stream_1_cname\r\n"
556 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
557 "a=ssrc:3 mslabel:local_stream_1\r\n"
558 "a=ssrc:3 label:video_track_id_1\r\n"
559 "a=ssrc:5 cname:stream_2_cname\r\n"
560 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
561 "a=ssrc:5 mslabel:local_stream_2\r\n"
562 "a=ssrc:5 label:video_track_id_2\r\n"
563 "a=ssrc:6 cname:stream_2_cname\r\n"
564 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
565 "a=ssrc:6 mslabel:local_stream_2\r\n"
566 "a=ssrc:6 label:video_track_id_3\r\n";
567
deadbeef9d3584c2016-02-16 17:54:10 -0800568// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
569// tracks.
570static const char kUnifiedPlanSdpFullString[] =
571 "v=0\r\n"
572 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
573 "s=-\r\n"
574 "t=0 0\r\n"
575 "a=msid-semantic: WMS local_stream_1\r\n"
576 // Audio track 1, stream 1 (with candidates).
577 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
578 "c=IN IP4 74.125.127.126\r\n"
579 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
580 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
581 "generation 2\r\n"
582 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
583 "generation 2\r\n"
584 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
585 "generation 2\r\n"
586 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
587 "generation 2\r\n"
588 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
589 "raddr 192.168.1.5 rport 2346 "
590 "generation 2\r\n"
591 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
592 "raddr 192.168.1.5 rport 2348 "
593 "generation 2\r\n"
594 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
595 "a=mid:audio_content_name\r\n"
596 "a=msid:local_stream_1 audio_track_id_1\r\n"
597 "a=sendrecv\r\n"
598 "a=rtcp-mux\r\n"
599 "a=rtcp-rsize\r\n"
600 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
601 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
602 "dummy_session_params\r\n"
603 "a=rtpmap:111 opus/48000/2\r\n"
604 "a=rtpmap:103 ISAC/16000\r\n"
605 "a=rtpmap:104 ISAC/32000\r\n"
606 "a=ssrc:1 cname:stream_1_cname\r\n"
607 // Video track 1, stream 1 (with candidates).
608 "m=video 3457 RTP/SAVPF 120\r\n"
609 "c=IN IP4 74.125.224.39\r\n"
610 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
611 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
612 "generation 2\r\n"
613 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
614 "generation 2\r\n"
615 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
616 "generation 2\r\n"
617 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
618 "generation 2\r\n"
619 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
620 "generation 2\r\n"
621 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
622 "generation 2\r\n"
623 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
624 "a=mid:video_content_name\r\n"
625 "a=msid:local_stream_1 video_track_id_1\r\n"
626 "a=sendrecv\r\n"
627 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
628 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
629 "a=rtpmap:120 VP8/90000\r\n"
630 "a=ssrc-group:FEC 2 3\r\n"
631 "a=ssrc:2 cname:stream_1_cname\r\n"
632 "a=ssrc:3 cname:stream_1_cname\r\n"
633 // Audio track 2, stream 2.
634 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
635 "c=IN IP4 0.0.0.0\r\n"
636 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
637 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
638 "a=mid:audio_content_name_2\r\n"
639 "a=msid:local_stream_2 audio_track_id_2\r\n"
640 "a=sendrecv\r\n"
641 "a=rtcp-mux\r\n"
642 "a=rtcp-rsize\r\n"
643 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
644 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
645 "dummy_session_params\r\n"
646 "a=rtpmap:111 opus/48000/2\r\n"
647 "a=rtpmap:103 ISAC/16000\r\n"
648 "a=rtpmap:104 ISAC/32000\r\n"
649 "a=ssrc:4 cname:stream_2_cname\r\n"
650 // Video track 2, stream 2.
651 "m=video 9 RTP/SAVPF 120\r\n"
652 "c=IN IP4 0.0.0.0\r\n"
653 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
654 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
655 "a=mid:video_content_name_2\r\n"
656 "a=msid:local_stream_2 video_track_id_2\r\n"
657 "a=sendrecv\r\n"
658 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
659 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
660 "a=rtpmap:120 VP8/90000\r\n"
661 "a=ssrc:5 cname:stream_2_cname\r\n"
662 // Video track 3, stream 2.
663 "m=video 9 RTP/SAVPF 120\r\n"
664 "c=IN IP4 0.0.0.0\r\n"
665 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
666 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
667 "a=mid:video_content_name_3\r\n"
668 "a=msid:local_stream_2 video_track_id_3\r\n"
669 "a=sendrecv\r\n"
670 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
671 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
672 "a=rtpmap:120 VP8/90000\r\n"
673 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000674
675// One candidate reference string as per W3c spec.
676// candidate:<blah> not a=candidate:<blah>CRLF
677static const char kRawCandidate[] =
678 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
679// One candidate reference string.
680static const char kSdpOneCandidate[] =
681 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
682 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000683
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000684static const char kSdpTcpActiveCandidate[] =
685 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
686 "tcptype active generation 2";
687static const char kSdpTcpPassiveCandidate[] =
688 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
689 "tcptype passive generation 2";
690static const char kSdpTcpSOCandidate[] =
691 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
692 "tcptype so generation 2";
693static const char kSdpTcpInvalidCandidate[] =
694 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
695 "tcptype invalid generation 2";
696
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000697// One candidate reference string with IPV6 address.
698static const char kRawIPV6Candidate[] =
699 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 12:04:36 -0700700 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000701
702// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800703static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000704 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800705 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000706
707// Session id and version
708static const char kSessionId[] = "18446744069414584320";
709static const char kSessionVersion[] = "18446462598732840960";
710
deadbeef9d3584c2016-02-16 17:54:10 -0800711// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712static const char kIceOption1[] = "iceoption1";
713static const char kIceOption2[] = "iceoption2";
714static const char kIceOption3[] = "iceoption3";
715
deadbeef9d3584c2016-02-16 17:54:10 -0800716// ICE ufrags/passwords.
717static const char kUfragVoice[] = "ufrag_voice";
718static const char kPwdVoice[] = "pwd_voice";
719static const char kUfragVideo[] = "ufrag_video";
720static const char kPwdVideo[] = "pwd_video";
721static const char kUfragData[] = "ufrag_data";
722static const char kPwdData[] = "pwd_data";
723
724// Extra ufrags/passwords for extra unified plan m= sections.
725static const char kUfragVoice2[] = "ufrag_voice_2";
726static const char kPwdVoice2[] = "pwd_voice_2";
727static const char kUfragVideo2[] = "ufrag_video_2";
728static const char kPwdVideo2[] = "pwd_video_2";
729static const char kUfragVideo3[] = "ufrag_video_3";
730static const char kPwdVideo3[] = "pwd_video_3";
731
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000732// Content name
733static const char kAudioContentName[] = "audio_content_name";
734static const char kVideoContentName[] = "video_content_name";
735static const char kDataContentName[] = "data_content_name";
736
deadbeef9d3584c2016-02-16 17:54:10 -0800737// Extra content names for extra unified plan m= sections.
738static const char kAudioContentName2[] = "audio_content_name_2";
739static const char kVideoContentName2[] = "video_content_name_2";
740static const char kVideoContentName3[] = "video_content_name_3";
741
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000742// MediaStream 1
743static const char kStreamLabel1[] = "local_stream_1";
744static const char kStream1Cname[] = "stream_1_cname";
745static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200746static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000747static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800748static const uint32_t kVideoTrack1Ssrc1 = 2;
749static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000750
751// MediaStream 2
752static const char kStreamLabel2[] = "local_stream_2";
753static const char kStream2Cname[] = "stream_2_cname";
754static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200755static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800756static const char kVideoTrackId2[] = "video_track_id_2";
757static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000758static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800759static const uint32_t kVideoTrack3Ssrc = 6;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000760
761// DataChannel
762static const char kDataChannelLabel[] = "data_channel";
763static const char kDataChannelMsid[] = "data_channeld0";
764static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200765static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000766
767// Candidate
768static const char kDummyMid[] = "dummy_mid";
769static const int kDummyIndex = 123;
770
771// Misc
772static const char kDummyString[] = "dummy";
773
774// Helper functions
775
776static bool SdpDeserialize(const std::string& message,
777 JsepSessionDescription* jdesc) {
778 return webrtc::SdpDeserialize(message, jdesc, NULL);
779}
780
781static bool SdpDeserializeCandidate(const std::string& message,
782 JsepIceCandidate* candidate) {
783 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
784}
785
786// Add some extra |newlines| to the |message| after |line|.
787static void InjectAfter(const std::string& line,
788 const std::string& newlines,
789 std::string* message) {
790 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000791 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000792 tmp.c_str(), tmp.length(), message);
793}
794
795static void Replace(const std::string& line,
796 const std::string& newlines,
797 std::string* message) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000798 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799 newlines.c_str(), newlines.length(), message);
800}
801
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000802// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
803// message.
804static void ExpectParseFailure(const std::string& bad_sdp,
805 const std::string& bad_part) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000806 JsepSessionDescription desc(kDummyString);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000807 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000808 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000809 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000810 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
811}
812
813// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
814static void ExpectParseFailure(const char* good_part, const char* bad_part) {
815 std::string bad_sdp = kSdpFullString;
816 Replace(good_part, bad_part, &bad_sdp);
817 ExpectParseFailure(bad_sdp, bad_part);
818}
819
820// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
821static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
822 const std::string& newlines,
823 const std::string& bad_part) {
824 std::string bad_sdp = kSdpFullString;
825 InjectAfter(injectpoint, newlines, &bad_sdp);
826 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000827}
828
829static void ReplaceDirection(cricket::MediaContentDirection direction,
830 std::string* message) {
831 std::string new_direction;
832 switch (direction) {
833 case cricket::MD_INACTIVE:
834 new_direction = "a=inactive";
835 break;
836 case cricket::MD_SENDONLY:
837 new_direction = "a=sendonly";
838 break;
839 case cricket::MD_RECVONLY:
840 new_direction = "a=recvonly";
841 break;
842 case cricket::MD_SENDRECV:
843 default:
844 new_direction = "a=sendrecv";
845 break;
846 }
847 Replace("a=sendrecv", new_direction, message);
848}
849
850static void ReplaceRejected(bool audio_rejected, bool video_rejected,
851 std::string* message) {
852 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800853 Replace("m=audio 9", "m=audio 0", message);
854 Replace(kAttributeIceUfragVoice, "", message);
855 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000856 }
857 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800858 Replace("m=video 9", "m=video 0", message);
859 Replace(kAttributeIceUfragVideo, "", message);
860 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000861 }
862}
863
864// WebRtcSdpTest
865
866class WebRtcSdpTest : public testing::Test {
867 public:
868 WebRtcSdpTest()
869 : jdesc_(kDummyString) {
phoglund37ebcf02016-01-08 05:04:57 -0800870#ifdef WEBRTC_ANDROID
871 webrtc::InitializeAndroidObjects();
872#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000873 // AudioContentDescription
874 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -0800875 StreamParams audio_stream;
876 audio_stream.id = kAudioTrackId1;
877 audio_stream.cname = kStream1Cname;
878 audio_stream.sync_label = kStreamLabel1;
879 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
880 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 11:04:53 -0700881 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
882 audio_desc_->set_connection_address(audio_addr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
884
885 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -0800886 video_desc_ = CreateVideoContentDescription();
887 StreamParams video_stream;
888 video_stream.id = kVideoTrackId1;
889 video_stream.cname = kStream1Cname;
890 video_stream.sync_label = kStreamLabel1;
891 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
892 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
893 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
894 video_stream.ssrc_groups.push_back(ssrc_group);
895 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 11:04:53 -0700896 rtc::SocketAddress video_addr("74.125.224.39", 3457);
897 video_desc_->set_connection_address(video_addr);
deadbeef9d3584c2016-02-16 17:54:10 -0800898 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000899
900 // TransportInfo
deadbeef9d3584c2016-02-16 17:54:10 -0800901 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
902 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice))));
903 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
904 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000905
906 // v4 host
907 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000908 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000909 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000910 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
911 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000912 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000913 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000914 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
915 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000916 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000917 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000918 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
919 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000920 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000921 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000922 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
923 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000924
925 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000926 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000927 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
928 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000929 cricket::LOCAL_PORT_TYPE,
930 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000931 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000932 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
933 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000934 cricket::LOCAL_PORT_TYPE,
935 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000936 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000937 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
938 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000939 cricket::LOCAL_PORT_TYPE,
940 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000941 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000942 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
943 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000944 cricket::LOCAL_PORT_TYPE,
945 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000946
947 // stun
948 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000949 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
950 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000951 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
952 address_stun, kCandidatePriority, "", "",
953 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000954 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000955 candidate9.set_related_address(rel_address_stun);
956
957 address_stun.SetPort(port_stun++);
958 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000959 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
960 address_stun, kCandidatePriority, "", "",
961 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000962 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000963 candidate10.set_related_address(rel_address_stun);
964
965 // relay
966 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000967 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000968 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
969 address_relay, kCandidatePriority, "", "",
970 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000971 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000972 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000973 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
974 address_relay, kCandidatePriority, "", "",
975 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000976 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000977
978 // voice
979 candidates_.push_back(candidate1);
980 candidates_.push_back(candidate2);
981 candidates_.push_back(candidate5);
982 candidates_.push_back(candidate6);
983 candidates_.push_back(candidate9);
984 candidates_.push_back(candidate10);
985
986 // video
987 candidates_.push_back(candidate3);
988 candidates_.push_back(candidate4);
989 candidates_.push_back(candidate7);
990 candidates_.push_back(candidate8);
991 candidates_.push_back(candidate11);
992 candidates_.push_back(candidate12);
993
994 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"),
995 0, candidate1));
996
997 // Set up JsepSessionDescription.
998 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
999 std::string mline_id;
1000 int mline_index = 0;
1001 for (size_t i = 0; i< candidates_.size(); ++i) {
1002 // In this test, the audio m line index will be 0, and the video m line
1003 // will be 1.
1004 bool is_video = (i > 5);
1005 mline_id = is_video ? "video_content_name" : "audio_content_name";
1006 mline_index = is_video ? 1 : 0;
1007 JsepIceCandidate jice(mline_id,
1008 mline_index,
1009 candidates_.at(i));
1010 jdesc_.AddCandidate(&jice);
1011 }
1012 }
1013
deadbeef25ed4352016-12-12 18:37:36 -08001014 // Turns the existing reference description into a description using
1015 // a=bundle-only. This means no transport attributes and a 0 port value on
1016 // the m= sections not associated with the BUNDLE-tag.
1017 void MakeBundleOnlyDescription() {
1018 // Remove video candidates. JsepSessionDescription doesn't make it
1019 // simple.
1020 const IceCandidateCollection* video_candidates_collection =
1021 jdesc_.candidates(1);
1022 ASSERT_NE(nullptr, video_candidates_collection);
1023 std::vector<cricket::Candidate> video_candidates;
1024 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1025 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1026 c.set_transport_name("video_content_name");
1027 video_candidates.push_back(c);
1028 }
1029 jdesc_.RemoveCandidates(video_candidates);
1030
1031 // And the rest of the transport attributes.
1032 desc_.transport_infos()[1].description.ice_ufrag.clear();
1033 desc_.transport_infos()[1].description.ice_pwd.clear();
1034 desc_.transport_infos()[1].description.connection_role =
1035 cricket::CONNECTIONROLE_NONE;
1036
1037 // Set bundle-only flag.
1038 desc_.contents()[1].bundle_only = true;
1039
1040 // Add BUNDLE group.
1041 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1042 group.AddContentName(kAudioContentName);
1043 group.AddContentName(kVideoContentName);
1044 desc_.AddGroup(group);
1045
1046 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1047 jdesc_.session_version()));
1048 }
1049
deadbeef9d3584c2016-02-16 17:54:10 -08001050 // Turns the existing reference description into a plan B description,
1051 // with 2 audio tracks and 3 video tracks.
1052 void MakePlanBDescription() {
1053 audio_desc_ = static_cast<AudioContentDescription*>(audio_desc_->Copy());
1054 video_desc_ = static_cast<VideoContentDescription*>(video_desc_->Copy());
1055
1056 StreamParams audio_track_2;
1057 audio_track_2.id = kAudioTrackId2;
1058 audio_track_2.cname = kStream2Cname;
1059 audio_track_2.sync_label = kStreamLabel2;
1060 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1061 audio_desc_->AddStream(audio_track_2);
1062
1063 StreamParams video_track_2;
1064 video_track_2.id = kVideoTrackId2;
1065 video_track_2.cname = kStream2Cname;
1066 video_track_2.sync_label = kStreamLabel2;
1067 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1068 video_desc_->AddStream(video_track_2);
1069
1070 StreamParams video_track_3;
1071 video_track_3.id = kVideoTrackId3;
1072 video_track_3.cname = kStream2Cname;
1073 video_track_3.sync_label = kStreamLabel2;
1074 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1075 video_desc_->AddStream(video_track_3);
1076
1077 desc_.RemoveContentByName(kAudioContentName);
1078 desc_.RemoveContentByName(kVideoContentName);
1079 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1080 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1081
1082 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1083 jdesc_.session_version()));
1084 }
1085
1086 // Turns the existing reference description into a unified plan description,
1087 // with 2 audio tracks and 3 video tracks.
1088 void MakeUnifiedPlanDescription() {
1089 // Audio track 2.
1090 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1091 StreamParams audio_track_2;
1092 audio_track_2.id = kAudioTrackId2;
1093 audio_track_2.cname = kStream2Cname;
1094 audio_track_2.sync_label = kStreamLabel2;
1095 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1096 audio_desc_2->AddStream(audio_track_2);
1097 desc_.AddContent(kAudioContentName2, NS_JINGLE_RTP, audio_desc_2);
1098 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1099 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
deadbeef9d3584c2016-02-16 17:54:10 -08001100 // Video track 2, in stream 2.
1101 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1102 StreamParams video_track_2;
1103 video_track_2.id = kVideoTrackId2;
1104 video_track_2.cname = kStream2Cname;
1105 video_track_2.sync_label = kStreamLabel2;
1106 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1107 video_desc_2->AddStream(video_track_2);
1108 desc_.AddContent(kVideoContentName2, NS_JINGLE_RTP, video_desc_2);
1109 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1110 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2))));
1111
1112 // Video track 3, in stream 2.
1113 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1114 StreamParams video_track_3;
1115 video_track_3.id = kVideoTrackId3;
1116 video_track_3.cname = kStream2Cname;
1117 video_track_3.sync_label = kStreamLabel2;
1118 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1119 video_desc_3->AddStream(video_track_3);
1120 desc_.AddContent(kVideoContentName3, NS_JINGLE_RTP, video_desc_3);
1121 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1122 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3))));
1123
1124 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1125 jdesc_.session_version()));
1126 }
1127
1128 // Creates an audio content description with no streams, and some default
1129 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001130 AudioContentDescription* CreateAudioContentDescription() {
1131 AudioContentDescription* audio = new AudioContentDescription();
1132 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -08001133 audio->set_rtcp_reduced_size(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001134 audio->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_32",
1135 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1136 "dummy_session_params"));
1137 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef67cf2c12016-04-13 10:07:16 -07001138 AudioCodec opus(111, "opus", 48000, 0, 2);
deadbeef9d3584c2016-02-16 17:54:10 -08001139 audio->AddCodec(opus);
ossue1405ad2017-01-23 08:55:48 -08001140 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1141 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001142 return audio;
1143 }
1144
deadbeef9d3584c2016-02-16 17:54:10 -08001145 // Creates a video content description with no streams, and some default
1146 // configuration.
1147 VideoContentDescription* CreateVideoContentDescription() {
1148 VideoContentDescription* video = new VideoContentDescription();
1149 video->AddCrypto(CryptoParams(
1150 1, "AES_CM_128_HMAC_SHA1_80",
1151 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1152 video->set_protocol(cricket::kMediaProtocolSavpf);
1153 video->AddCodec(
perkj26752742016-10-24 01:21:16 -07001154 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-16 17:54:10 -08001155 return video;
1156 }
1157
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001158 template <class MCD>
1159 void CompareMediaContentDescription(const MCD* cd1,
1160 const MCD* cd2) {
1161 // type
1162 EXPECT_EQ(cd1->type(), cd1->type());
1163
1164 // content direction
1165 EXPECT_EQ(cd1->direction(), cd2->direction());
1166
1167 // rtcp_mux
1168 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1169
deadbeef13871492015-12-09 12:37:51 -08001170 // rtcp_reduced_size
1171 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1172
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001173 // cryptos
1174 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1175 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1176 ADD_FAILURE();
1177 return;
1178 }
1179 for (size_t i = 0; i< cd1->cryptos().size(); ++i) {
1180 const CryptoParams c1 = cd1->cryptos().at(i);
1181 const CryptoParams c2 = cd2->cryptos().at(i);
1182 EXPECT_TRUE(c1.Matches(c2));
1183 EXPECT_EQ(c1.key_params, c2.key_params);
1184 EXPECT_EQ(c1.session_params, c2.session_params);
1185 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001186
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001187 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001188 // Use an equivalence class here, for old and new versions of the
1189 // protocol description.
1190 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:35 +00001191 || cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp
1192 || cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
1193 const bool cd2_is_also_dtls_sctp =
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001194 cd2->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:35 +00001195 || cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp
1196 || cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
1197 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001198 } else {
1199 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1200 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001201
1202 // codecs
1203 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1204
1205 // bandwidth
1206 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1207
1208 // streams
1209 EXPECT_EQ(cd1->streams(), cd2->streams());
1210
1211 // extmap
1212 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1213 cd2->rtp_header_extensions().size());
1214 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 11:24:55 -07001215 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1216 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001217 EXPECT_EQ(ext1.uri, ext2.uri);
1218 EXPECT_EQ(ext1.id, ext2.id);
jbauch5869f502017-06-29 12:31:36 -07001219 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001220 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001221 }
1222
zstein4b2e0822017-02-17 19:48:38 -08001223 void CompareDataContentDescription(const DataContentDescription* dcd1,
1224 const DataContentDescription* dcd2) {
1225 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
1226 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
1227 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001228
1229 void CompareSessionDescription(const SessionDescription& desc1,
1230 const SessionDescription& desc2) {
1231 // Compare content descriptions.
1232 if (desc1.contents().size() != desc2.contents().size()) {
1233 ADD_FAILURE();
1234 return;
1235 }
1236 for (size_t i = 0 ; i < desc1.contents().size(); ++i) {
1237 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1238 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-12 18:37:36 -08001239 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001240 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-12 18:37:36 -08001241 EXPECT_EQ(c1.type, c2.type);
1242 EXPECT_EQ(c1.rejected, c2.rejected);
1243 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001244
1245 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1246 if (IsAudioContent(&c1)) {
1247 const AudioContentDescription* acd1 =
1248 static_cast<const AudioContentDescription*>(c1.description);
1249 const AudioContentDescription* acd2 =
1250 static_cast<const AudioContentDescription*>(c2.description);
1251 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1252 }
1253
1254 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1255 if (IsVideoContent(&c1)) {
1256 const VideoContentDescription* vcd1 =
1257 static_cast<const VideoContentDescription*>(c1.description);
1258 const VideoContentDescription* vcd2 =
1259 static_cast<const VideoContentDescription*>(c2.description);
1260 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1261 }
1262
1263 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
1264 if (IsDataContent(&c1)) {
1265 const DataContentDescription* dcd1 =
1266 static_cast<const DataContentDescription*>(c1.description);
1267 const DataContentDescription* dcd2 =
1268 static_cast<const DataContentDescription*>(c2.description);
zstein4b2e0822017-02-17 19:48:38 -08001269 CompareDataContentDescription(dcd1, dcd2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001270 }
1271 }
1272
1273 // group
1274 const cricket::ContentGroups groups1 = desc1.groups();
1275 const cricket::ContentGroups groups2 = desc2.groups();
1276 EXPECT_EQ(groups1.size(), groups1.size());
1277 if (groups1.size() != groups2.size()) {
1278 ADD_FAILURE();
1279 return;
1280 }
1281 for (size_t i = 0; i < groups1.size(); ++i) {
1282 const cricket::ContentGroup group1 = groups1.at(i);
1283 const cricket::ContentGroup group2 = groups2.at(i);
1284 EXPECT_EQ(group1.semantics(), group2.semantics());
1285 const cricket::ContentNames names1 = group1.content_names();
1286 const cricket::ContentNames names2 = group2.content_names();
1287 EXPECT_EQ(names1.size(), names2.size());
1288 if (names1.size() != names2.size()) {
1289 ADD_FAILURE();
1290 return;
1291 }
1292 cricket::ContentNames::const_iterator iter1 = names1.begin();
1293 cricket::ContentNames::const_iterator iter2 = names2.begin();
1294 while (iter1 != names1.end()) {
1295 EXPECT_EQ(*iter1++, *iter2++);
1296 }
1297 }
1298
1299 // transport info
1300 const cricket::TransportInfos transports1 = desc1.transport_infos();
1301 const cricket::TransportInfos transports2 = desc2.transport_infos();
1302 EXPECT_EQ(transports1.size(), transports2.size());
1303 if (transports1.size() != transports2.size()) {
1304 ADD_FAILURE();
1305 return;
1306 }
1307 for (size_t i = 0; i < transports1.size(); ++i) {
1308 const cricket::TransportInfo transport1 = transports1.at(i);
1309 const cricket::TransportInfo transport2 = transports2.at(i);
1310 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001311 EXPECT_EQ(transport1.description.ice_ufrag,
1312 transport2.description.ice_ufrag);
1313 EXPECT_EQ(transport1.description.ice_pwd,
1314 transport2.description.ice_pwd);
1315 if (transport1.description.identity_fingerprint) {
1316 EXPECT_EQ(*transport1.description.identity_fingerprint,
1317 *transport2.description.identity_fingerprint);
1318 } else {
1319 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1320 transport2.description.identity_fingerprint.get());
1321 }
1322 EXPECT_EQ(transport1.description.transport_options,
1323 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001324 }
deadbeefc80741f2015-10-22 13:14:45 -07001325
1326 // global attributes
1327 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001328 }
1329
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001330 bool CompareSessionDescription(
1331 const JsepSessionDescription& desc1,
1332 const JsepSessionDescription& desc2) {
1333 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1334 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1335 CompareSessionDescription(*desc1.description(), *desc2.description());
1336 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1337 return false;
1338 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1339 const IceCandidateCollection* cc1 = desc1.candidates(i);
1340 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-12 18:37:36 -08001341 if (cc1->count() != cc2->count()) {
1342 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001343 return false;
deadbeef25ed4352016-12-12 18:37:36 -08001344 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001345 for (size_t j = 0; j < cc1->count(); ++j) {
1346 const IceCandidateInterface* c1 = cc1->at(j);
1347 const IceCandidateInterface* c2 = cc2->at(j);
1348 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1349 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1350 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1351 }
1352 }
1353 return true;
1354 }
1355
1356 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1357 // them with invalid keywords so that the parser will just ignore them.
1358 bool RemoveCandidateUfragPwd(std::string* sdp) {
1359 const char ice_ufrag[] = "a=ice-ufrag";
1360 const char ice_ufragx[] = "a=xice-ufrag";
1361 const char ice_pwd[] = "a=ice-pwd";
1362 const char ice_pwdx[] = "a=xice-pwd";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001363 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001364 ice_ufragx, strlen(ice_ufragx), sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001365 rtc::replace_substrs(ice_pwd, strlen(ice_pwd),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001366 ice_pwdx, strlen(ice_pwdx), sdp);
1367 return true;
1368 }
1369
1370 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
1371 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, int mline_index,
1372 const std::string& ufrag, const std::string& pwd) {
1373 std::string content_name;
1374 if (mline_index == 0) {
1375 content_name = kAudioContentName;
1376 } else if (mline_index == 1) {
1377 content_name = kVideoContentName;
1378 } else {
nissec80e7412017-01-11 05:56:46 -08001379 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001380 }
1381 TransportInfo transport_info(
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001382 content_name, TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001383 SessionDescription* desc =
1384 const_cast<SessionDescription*>(jdesc->description());
1385 desc->RemoveTransportInfoByName(content_name);
1386 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
1387 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1388 const IceCandidateCollection* cc = jdesc_.candidates(i);
1389 for (size_t j = 0; j < cc->count(); ++j) {
1390 if (cc->at(j)->sdp_mline_index() == mline_index) {
1391 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(
1392 ufrag);
1393 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(
1394 pwd);
1395 }
1396 }
1397 }
1398 return true;
1399 }
1400
1401 void AddIceOptions(const std::string& content_name,
1402 const std::vector<std::string>& transport_options) {
1403 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1404 cricket::TransportInfo transport_info =
1405 *(desc_.GetTransportInfoByName(content_name));
1406 desc_.RemoveTransportInfoByName(content_name);
1407 transport_info.description.transport_options = transport_options;
1408 desc_.AddTransportInfo(transport_info);
1409 }
1410
deadbeef3f7219b2015-12-28 15:17:14 -08001411 void SetIceUfragPwd(const std::string& content_name,
1412 const std::string& ice_ufrag,
1413 const std::string& ice_pwd) {
1414 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1415 cricket::TransportInfo transport_info =
1416 *(desc_.GetTransportInfoByName(content_name));
1417 desc_.RemoveTransportInfoByName(content_name);
1418 transport_info.description.ice_ufrag = ice_ufrag;
1419 transport_info.description.ice_pwd = ice_pwd;
1420 desc_.AddTransportInfo(transport_info);
1421 }
1422
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001423 void AddFingerprint() {
1424 desc_.RemoveTransportInfoByName(kAudioContentName);
1425 desc_.RemoveTransportInfoByName(kVideoContentName);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001426 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001427 kIdentityDigest,
1428 sizeof(kIdentityDigest));
deadbeef46eed762016-01-28 13:24:37 -08001429 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1430 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001431 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1432 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001433 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1434 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1435 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001436 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1437 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001438 cricket::CONNECTIONROLE_NONE, &fingerprint))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001439 }
1440
jbauch5869f502017-06-29 12:31:36 -07001441 void AddExtmap(bool encrypted) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001442 audio_desc_ = static_cast<AudioContentDescription*>(
1443 audio_desc_->Copy());
1444 video_desc_ = static_cast<VideoContentDescription*>(
1445 video_desc_->Copy());
jbauch5869f502017-06-29 12:31:36 -07001446 audio_desc_->AddRtpHeaderExtension(
1447 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1448 video_desc_->AddRtpHeaderExtension(
1449 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001450 desc_.RemoveContentByName(kAudioContentName);
1451 desc_.RemoveContentByName(kVideoContentName);
1452 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1453 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1454 }
1455
1456 void RemoveCryptos() {
1457 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1458 video_desc_->set_cryptos(std::vector<CryptoParams>());
1459 }
1460
1461 bool TestSerializeDirection(cricket::MediaContentDirection direction) {
1462 audio_desc_->set_direction(direction);
1463 video_desc_->set_direction(direction);
1464 std::string new_sdp = kSdpFullString;
1465 ReplaceDirection(direction, &new_sdp);
1466
1467 if (!jdesc_.Initialize(desc_.Copy(),
1468 jdesc_.session_id(),
1469 jdesc_.session_version())) {
1470 return false;
1471 }
deadbeef9d3584c2016-02-16 17:54:10 -08001472 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001473 EXPECT_EQ(new_sdp, message);
1474 return true;
1475 }
1476
1477 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
1478 audio_desc_ = static_cast<AudioContentDescription*>(
1479 audio_desc_->Copy());
1480 video_desc_ = static_cast<VideoContentDescription*>(
1481 video_desc_->Copy());
zhihuang38989e52017-03-21 11:04:53 -07001482
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001483 desc_.RemoveContentByName(kAudioContentName);
1484 desc_.RemoveContentByName(kVideoContentName);
1485 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1486 audio_desc_);
1487 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1488 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001489 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1490 audio_rejected ? "" : kPwdVoice);
1491 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1492 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001493
1494 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001495 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1496
deadbeef3f7219b2015-12-28 15:17:14 -08001497 JsepSessionDescription jdesc_no_candidates(kDummyString);
zhihuang38989e52017-03-21 11:04:53 -07001498 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
deadbeef9d3584c2016-02-16 17:54:10 -08001499 std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001500 EXPECT_EQ(new_sdp, message);
1501 return true;
1502 }
1503
zstein4b2e0822017-02-17 19:48:38 -08001504 void AddSctpDataChannel(bool use_sctpmap) {
kwibergd1fe2812016-04-27 06:47:29 -07001505 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001506 data_desc_ = data.get();
zstein4b2e0822017-02-17 19:48:38 -08001507 data_desc_->set_use_sctpmap(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001508 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
solenberg9fa49752016-10-08 13:02:44 -07001509 DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07001510 cricket::kGoogleSctpDataCodecName);
wu@webrtc.org78187522013-10-07 23:32:02 +00001511 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1512 data_desc_->AddCodec(codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001513 desc_.AddContent(kDataContentName, NS_JINGLE_DRAFT_SCTP, data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001514 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1515 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001516 }
1517
1518 void AddRtpDataChannel() {
kwibergd1fe2812016-04-27 06:47:29 -07001519 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001520 data_desc_ = data.get();
1521
deadbeef67cf2c12016-04-13 10:07:16 -07001522 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001523 StreamParams data_stream;
1524 data_stream.id = kDataChannelMsid;
1525 data_stream.cname = kDataChannelCname;
1526 data_stream.sync_label = kDataChannelLabel;
1527 data_stream.ssrcs.push_back(kDataChannelSsrc);
1528 data_desc_->AddStream(data_stream);
1529 data_desc_->AddCrypto(CryptoParams(
1530 1, "AES_CM_128_HMAC_SHA1_80",
1531 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
1532 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
1533 desc_.AddContent(kDataContentName, NS_JINGLE_RTP, data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001534 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1535 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001536 }
1537
1538 bool TestDeserializeDirection(cricket::MediaContentDirection direction) {
1539 std::string new_sdp = kSdpFullString;
1540 ReplaceDirection(direction, &new_sdp);
1541 JsepSessionDescription new_jdesc(kDummyString);
1542
1543 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1544
1545 audio_desc_->set_direction(direction);
1546 video_desc_->set_direction(direction);
1547 if (!jdesc_.Initialize(desc_.Copy(),
1548 jdesc_.session_id(),
1549 jdesc_.session_version())) {
1550 return false;
1551 }
1552 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1553 return true;
1554 }
1555
1556 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001557 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001558 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1559 JsepSessionDescription new_jdesc(JsepSessionDescription::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001560 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001561
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001562 audio_desc_ = static_cast<AudioContentDescription*>(
1563 audio_desc_->Copy());
1564 video_desc_ = static_cast<VideoContentDescription*>(
1565 video_desc_->Copy());
1566 desc_.RemoveContentByName(kAudioContentName);
1567 desc_.RemoveContentByName(kVideoContentName);
1568 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1569 audio_desc_);
1570 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1571 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001572 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1573 audio_rejected ? "" : kPwdVoice);
1574 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1575 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001576 JsepSessionDescription jdesc_no_candidates(kDummyString);
1577 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1578 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001579 return false;
1580 }
deadbeef3f7219b2015-12-28 15:17:14 -08001581 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001582 return true;
1583 }
1584
jbauch5869f502017-06-29 12:31:36 -07001585 void TestDeserializeExtmap(bool session_level, bool media_level,
1586 bool encrypted) {
1587 AddExtmap(encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001588 JsepSessionDescription new_jdesc("dummy");
1589 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1590 jdesc_.session_id(),
1591 jdesc_.session_version()));
1592 JsepSessionDescription jdesc_with_extmap("dummy");
1593 std::string sdp_with_extmap = kSdpString;
1594 if (session_level) {
jbauch5869f502017-06-29 12:31:36 -07001595 InjectAfter(kSessionTime,
1596 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1597 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001598 &sdp_with_extmap);
1599 }
1600 if (media_level) {
jbauch5869f502017-06-29 12:31:36 -07001601 InjectAfter(kAttributeIcePwdVoice,
1602 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1603 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001604 &sdp_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07001605 InjectAfter(kAttributeIcePwdVideo,
1606 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1607 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001608 &sdp_with_extmap);
1609 }
1610 // The extmap can't be present at the same time in both session level and
1611 // media level.
1612 if (session_level && media_level) {
1613 SdpParseError error;
1614 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap,
1615 &jdesc_with_extmap, &error));
1616 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1617 } else {
1618 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1619 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1620 }
1621 }
1622
1623 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
1624 const std::string& name, int expected_value) {
1625 cricket::CodecParameterMap::const_iterator found = params.find(name);
1626 ASSERT_TRUE(found != params.end());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001627 EXPECT_EQ(found->second, rtc::ToString<int>(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001628 }
1629
1630 void TestDeserializeCodecParams(const CodecParams& params,
1631 JsepSessionDescription* jdesc_output) {
1632 std::string sdp =
1633 "v=0\r\n"
1634 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1635 "s=-\r\n"
1636 "t=0 0\r\n"
1637 // Include semantics for WebRTC Media Streams since it is supported by
1638 // this parser, and will be added to the SDP when serializing a session
1639 // description.
1640 "a=msid-semantic: WMS\r\n"
1641 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001642 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001643 // Pltype 111 listed before 103 and 104 in the map.
1644 "a=rtpmap:111 opus/48000/2\r\n"
1645 // Pltype 103 listed before 104.
1646 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001647 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001648 "a=fmtp:111 0-15,66,70\r\n"
1649 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001650 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001651 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001652 << "; sprop-stereo=" << params.sprop_stereo
1653 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001654 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001655 << "a=ptime:" << params.ptime << "\r\n"
1656 << "a=maxptime:" << params.max_ptime << "\r\n";
1657 sdp += os.str();
1658
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001659 os.clear();
1660 os.str("");
1661 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001662 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001663 << "a=rtpmap:99 VP8/90000\r\n"
1664 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001665 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001666 sdp += os.str();
1667
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001668 // Deserialize
1669 SdpParseError error;
1670 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1671
1672 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1673 ASSERT_TRUE(ac != NULL);
1674 const AudioContentDescription* acd =
1675 static_cast<const AudioContentDescription*>(ac->description);
1676 ASSERT_FALSE(acd->codecs().empty());
1677 cricket::AudioCodec opus = acd->codecs()[0];
1678 EXPECT_EQ("opus", opus.name);
1679 EXPECT_EQ(111, opus.id);
1680 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1681 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1682 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1683 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001684 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1685 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001686 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1687 cricket::AudioCodec codec = acd->codecs()[i];
1688 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1689 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001690 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001691
1692 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1693 ASSERT_TRUE(vc != NULL);
1694 const VideoContentDescription* vcd =
1695 static_cast<const VideoContentDescription*>(vc->description);
1696 ASSERT_FALSE(vcd->codecs().empty());
1697 cricket::VideoCodec vp8 = vcd->codecs()[0];
1698 EXPECT_EQ("VP8", vp8.name);
1699 EXPECT_EQ(99, vp8.id);
1700 cricket::VideoCodec rtx = vcd->codecs()[1];
1701 EXPECT_EQ("RTX", rtx.name);
1702 EXPECT_EQ(95, rtx.id);
1703 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001704 }
1705
1706 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1707 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001708 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001709 "v=0\r\n"
1710 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1711 "s=-\r\n"
1712 "t=0 0\r\n"
1713 // Include semantics for WebRTC Media Streams since it is supported by
1714 // this parser, and will be added to the SDP when serializing a session
1715 // description.
1716 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001717 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001718 "a=rtpmap:111 opus/48000/2\r\n";
1719 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001720 "m=video 3457 RTP/SAVPF 101\r\n"
1721 "a=rtpmap:101 VP8/90000\r\n"
1722 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001723 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001724 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001725 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001726 os << sdp_session_and_audio;
1727 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
1728 os << sdp_video;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001729 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001730 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001731 // Deserialize
1732 SdpParseError error;
1733 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1734 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1735 ASSERT_TRUE(ac != NULL);
1736 const AudioContentDescription* acd =
1737 static_cast<const AudioContentDescription*>(ac->description);
1738 ASSERT_FALSE(acd->codecs().empty());
1739 cricket::AudioCodec opus = acd->codecs()[0];
1740 EXPECT_EQ(111, opus.id);
1741 EXPECT_TRUE(opus.HasFeedbackParam(
1742 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1743 cricket::kParamValueEmpty)));
1744
1745 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1746 ASSERT_TRUE(vc != NULL);
1747 const VideoContentDescription* vcd =
1748 static_cast<const VideoContentDescription*>(vc->description);
1749 ASSERT_FALSE(vcd->codecs().empty());
1750 cricket::VideoCodec vp8 = vcd->codecs()[0];
1751 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1752 vp8.name.c_str());
1753 EXPECT_EQ(101, vp8.id);
1754 EXPECT_TRUE(vp8.HasFeedbackParam(
1755 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1756 cricket::kParamValueEmpty)));
1757 EXPECT_TRUE(vp8.HasFeedbackParam(
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001758 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1759 cricket::kRtcpFbNackParamPli)));
1760 EXPECT_TRUE(vp8.HasFeedbackParam(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
1762 cricket::kParamValueEmpty)));
1763 EXPECT_TRUE(vp8.HasFeedbackParam(
1764 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
1765 cricket::kRtcpFbCcmParamFir)));
1766 }
1767
1768 // Two SDP messages can mean the same thing but be different strings, e.g.
1769 // some of the lines can be serialized in different order.
1770 // However, a deserialized description can be compared field by field and has
1771 // no order. If deserializer has already been tested, serializing then
1772 // deserializing and comparing JsepSessionDescription will test
1773 // the serializer sufficiently.
deadbeef9d3584c2016-02-16 17:54:10 -08001774 void TestSerialize(const JsepSessionDescription& jdesc,
1775 bool unified_plan_sdp) {
1776 std::string message = webrtc::SdpSerialize(jdesc, unified_plan_sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001777 JsepSessionDescription jdesc_output_des(kDummyString);
1778 SdpParseError error;
1779 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1780 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1781 }
1782
zhihuang38989e52017-03-21 11:04:53 -07001783 // Calling 'Initialize' with a copy of the inner SessionDescription will
1784 // create a copy of the JsepSessionDescription without candidates. The
1785 // 'connection address' field, previously set from the candidates, must also
1786 // be reset.
1787 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
1788 rtc::SocketAddress audio_addr("0.0.0.0", 9);
1789 rtc::SocketAddress video_addr("0.0.0.0", 9);
1790 audio_desc_->set_connection_address(audio_addr);
1791 video_desc_->set_connection_address(video_addr);
1792 ASSERT_TRUE(jdesc->Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1793 }
1794
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001795 protected:
1796 SessionDescription desc_;
1797 AudioContentDescription* audio_desc_;
1798 VideoContentDescription* video_desc_;
1799 DataContentDescription* data_desc_;
1800 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07001801 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001802 JsepSessionDescription jdesc_;
1803};
1804
1805void TestMismatch(const std::string& string1, const std::string& string2) {
1806 int position = 0;
1807 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1808 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001809 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001810 break;
1811 }
1812 }
1813 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1814 << " character\n"
1815 << " 1: " << string1.substr(position, 20) << "\n"
1816 << " 2: " << string2.substr(position, 20) << "\n";
1817}
1818
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001819TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1820 // SessionDescription with desc and candidates.
deadbeef9d3584c2016-02-16 17:54:10 -08001821 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001822 TestMismatch(std::string(kSdpFullString), message);
1823}
1824
1825TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
1826 JsepSessionDescription jdesc_empty(kDummyString);
deadbeef9d3584c2016-02-16 17:54:10 -08001827 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty, false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001828}
1829
1830// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1831// the case in a DTLS offer.
1832TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1833 AddFingerprint();
1834 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
zhihuang38989e52017-03-21 11:04:53 -07001835 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
deadbeef9d3584c2016-02-16 17:54:10 -08001836 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001837
1838 std::string sdp_with_fingerprint = kSdpString;
1839 InjectAfter(kAttributeIcePwdVoice,
1840 kFingerprint, &sdp_with_fingerprint);
1841 InjectAfter(kAttributeIcePwdVideo,
1842 kFingerprint, &sdp_with_fingerprint);
1843
1844 EXPECT_EQ(sdp_with_fingerprint, message);
1845}
1846
1847// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1848// be the case in a DTLS answer.
1849TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1850 AddFingerprint();
1851 RemoveCryptos();
1852 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
zhihuang38989e52017-03-21 11:04:53 -07001853 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
deadbeef9d3584c2016-02-16 17:54:10 -08001854 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001855
1856 std::string sdp_with_fingerprint = kSdpString;
1857 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1858 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
1859 InjectAfter(kAttributeIcePwdVoice,
1860 kFingerprint, &sdp_with_fingerprint);
1861 InjectAfter(kAttributeIcePwdVideo,
1862 kFingerprint, &sdp_with_fingerprint);
1863
1864 EXPECT_EQ(sdp_with_fingerprint, message);
1865}
1866
1867TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1868 // JsepSessionDescription with desc but without candidates.
1869 JsepSessionDescription jdesc_no_candidates(kDummyString);
zhihuang38989e52017-03-21 11:04:53 -07001870 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
deadbeef9d3584c2016-02-16 17:54:10 -08001871 std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001872 EXPECT_EQ(std::string(kSdpString), message);
1873}
1874
1875TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1876 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1877 group.AddContentName(kAudioContentName);
1878 group.AddContentName(kVideoContentName);
1879 desc_.AddGroup(group);
1880 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1881 jdesc_.session_id(),
1882 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08001883 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001884 std::string sdp_with_bundle = kSdpFullString;
1885 InjectAfter(kSessionTime,
1886 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1887 &sdp_with_bundle);
1888 EXPECT_EQ(sdp_with_bundle, message);
1889}
1890
1891TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
1892 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1893 GetFirstVideoContent(&desc_)->description);
1894 vcd->set_bandwidth(100 * 1000);
1895 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1896 GetFirstAudioContent(&desc_)->description);
1897 acd->set_bandwidth(50 * 1000);
1898 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1899 jdesc_.session_id(),
1900 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08001901 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001902 std::string sdp_with_bandwidth = kSdpFullString;
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001903 InjectAfter("c=IN IP4 74.125.224.39\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001904 "b=AS:100\r\n",
1905 &sdp_with_bandwidth);
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001906 InjectAfter("c=IN IP4 74.125.127.126\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001907 "b=AS:50\r\n",
1908 &sdp_with_bandwidth);
1909 EXPECT_EQ(sdp_with_bandwidth, message);
1910}
1911
1912TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1913 std::vector<std::string> transport_options;
1914 transport_options.push_back(kIceOption1);
1915 transport_options.push_back(kIceOption3);
1916 AddIceOptions(kAudioContentName, transport_options);
1917 transport_options.clear();
1918 transport_options.push_back(kIceOption2);
1919 transport_options.push_back(kIceOption3);
1920 AddIceOptions(kVideoContentName, transport_options);
1921 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1922 jdesc_.session_id(),
1923 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08001924 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001925 std::string sdp_with_ice_options = kSdpFullString;
1926 InjectAfter(kAttributeIcePwdVoice,
1927 "a=ice-options:iceoption1 iceoption3\r\n",
1928 &sdp_with_ice_options);
1929 InjectAfter(kAttributeIcePwdVideo,
1930 "a=ice-options:iceoption2 iceoption3\r\n",
1931 &sdp_with_ice_options);
1932 EXPECT_EQ(sdp_with_ice_options, message);
1933}
1934
1935TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
1936 EXPECT_TRUE(TestSerializeDirection(cricket::MD_RECVONLY));
1937}
1938
1939TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
1940 EXPECT_TRUE(TestSerializeDirection(cricket::MD_SENDONLY));
1941}
1942
1943TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
1944 EXPECT_TRUE(TestSerializeDirection(cricket::MD_INACTIVE));
1945}
1946
1947TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
1948 EXPECT_TRUE(TestSerializeRejected(true, false));
1949}
1950
1951TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
1952 EXPECT_TRUE(TestSerializeRejected(false, true));
1953}
1954
1955TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
1956 EXPECT_TRUE(TestSerializeRejected(true, true));
1957}
1958
1959TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
1960 AddRtpDataChannel();
1961 JsepSessionDescription jsep_desc(kDummyString);
1962
zhihuang38989e52017-03-21 11:04:53 -07001963 MakeDescriptionWithoutCandidates(&jsep_desc);
deadbeef9d3584c2016-02-16 17:54:10 -08001964 std::string message = webrtc::SdpSerialize(jsep_desc, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001965
1966 std::string expected_sdp = kSdpString;
1967 expected_sdp.append(kSdpRtpDataChannelString);
1968 EXPECT_EQ(expected_sdp, message);
1969}
1970
1971TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08001972 bool use_sctpmap = true;
1973 AddSctpDataChannel(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001974 JsepSessionDescription jsep_desc(kDummyString);
1975
zhihuang38989e52017-03-21 11:04:53 -07001976 MakeDescriptionWithoutCandidates(&jsep_desc);
deadbeef9d3584c2016-02-16 17:54:10 -08001977 std::string message = webrtc::SdpSerialize(jsep_desc, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001978
1979 std::string expected_sdp = kSdpString;
1980 expected_sdp.append(kSdpSctpDataChannelString);
1981 EXPECT_EQ(message, expected_sdp);
1982}
1983
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001984TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08001985 bool use_sctpmap = true;
1986 AddSctpDataChannel(use_sctpmap);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001987 JsepSessionDescription jsep_desc(kDummyString);
zhihuang38989e52017-03-21 11:04:53 -07001988 MakeDescriptionWithoutCandidates(&jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001989 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
1990 jsep_desc.description()->GetContentDescriptionByName(kDataContentName));
1991
1992 const int kNewPort = 1234;
solenberg9fa49752016-10-08 13:02:44 -07001993 cricket::DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07001994 cricket::kGoogleSctpDataCodecName);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001995 codec.SetParam(cricket::kCodecParamPort, kNewPort);
1996 dcdesc->AddOrReplaceCodec(codec);
1997
deadbeef9d3584c2016-02-16 17:54:10 -08001998 std::string message = webrtc::SdpSerialize(jsep_desc, false);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001999
2000 std::string expected_sdp = kSdpString;
2001 expected_sdp.append(kSdpSctpDataChannelString);
2002
2003 char default_portstr[16];
2004 char new_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002005 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002006 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002007 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
2008 rtc::replace_substrs(default_portstr, strlen(default_portstr),
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002009 new_portstr, strlen(new_portstr),
2010 &expected_sdp);
2011
2012 EXPECT_EQ(expected_sdp, message);
2013}
2014
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002015TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
zhihuang38989e52017-03-21 11:04:53 -07002016 JsepSessionDescription jsep_desc(kDummyString);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002017 AddRtpDataChannel();
2018 data_desc_->set_bandwidth(100*1000);
zhihuang38989e52017-03-21 11:04:53 -07002019 MakeDescriptionWithoutCandidates(&jsep_desc);
deadbeef9d3584c2016-02-16 17:54:10 -08002020 std::string message = webrtc::SdpSerialize(jsep_desc, false);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002021
2022 std::string expected_sdp = kSdpString;
2023 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002024 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00002025 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002026 "b=AS:100\r\n",
2027 &expected_sdp);
2028 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002029}
2030
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002031TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002032 bool encrypted = false;
2033 AddExtmap(encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002034 JsepSessionDescription desc_with_extmap("dummy");
zhihuang38989e52017-03-21 11:04:53 -07002035 MakeDescriptionWithoutCandidates(&desc_with_extmap);
deadbeef9d3584c2016-02-16 17:54:10 -08002036 std::string message = webrtc::SdpSerialize(desc_with_extmap, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002037
2038 std::string sdp_with_extmap = kSdpString;
2039 InjectAfter("a=mid:audio_content_name\r\n",
2040 kExtmap, &sdp_with_extmap);
2041 InjectAfter("a=mid:video_content_name\r\n",
2042 kExtmap, &sdp_with_extmap);
2043
2044 EXPECT_EQ(sdp_with_extmap, message);
2045}
2046
jbauch5869f502017-06-29 12:31:36 -07002047TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2048 bool encrypted = true;
2049 AddExtmap(encrypted);
2050 JsepSessionDescription desc_with_extmap("dummy");
2051 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(),
2052 kSessionId, kSessionVersion));
2053 TestSerialize(desc_with_extmap, false);
2054}
2055
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002056TEST_F(WebRtcSdpTest, SerializeCandidates) {
2057 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002058 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002059
2060 Candidate candidate_with_ufrag(candidates_.front());
2061 candidate_with_ufrag.set_username("ABC");
2062 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2063 candidate_with_ufrag));
2064 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2065 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002066
2067 Candidate candidate_with_network_info(candidates_.front());
2068 candidate_with_network_info.set_network_id(1);
2069 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2070 candidate_with_network_info));
2071 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2072 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2073 candidate_with_network_info.set_network_cost(999);
2074 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2075 candidate_with_network_info));
2076 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2077 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2078 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002079}
2080
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002081// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2082// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002083TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002084 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002085 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2086 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2087 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002088 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002089 std::unique_ptr<IceCandidateInterface> jcandidate(
2090 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002091
2092 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2093 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2094}
2095
htaa6b99442016-04-12 10:29:17 -07002096TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002097 cricket::VideoCodec h264_codec("H264");
2098 h264_codec.SetParam("profile-level-id", "42e01f");
2099 h264_codec.SetParam("level-asymmetry-allowed", "1");
2100 h264_codec.SetParam("packetization-mode", "1");
2101 video_desc_->AddCodec(h264_codec);
2102
htaa6b99442016-04-12 10:29:17 -07002103 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
2104
2105 std::string message = webrtc::SdpSerialize(jdesc_, false);
2106 size_t after_pt = message.find(" H264/90000");
2107 ASSERT_NE(after_pt, std::string::npos);
2108 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2109 ASSERT_NE(before_pt, std::string::npos);
2110 before_pt += strlen("a=rtpmap:");
2111 std::string pt = message.substr(before_pt, after_pt - before_pt);
2112 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2113 std::string to_find = "a=fmtp:" + pt + " ";
2114 size_t fmtp_pos = message.find(to_find);
2115 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
2116 size_t fmtp_endpos = message.find("\n", fmtp_pos);
2117 ASSERT_NE(std::string::npos, fmtp_endpos);
2118 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2119 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2120 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2121 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002122 // Check that there are no spaces after semicolons.
2123 // https://bugs.webrtc.org/5793
2124 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002125}
2126
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002127TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
2128 JsepSessionDescription jdesc(kDummyString);
2129 // Deserialize
2130 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2131 // Verify
2132 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2133}
2134
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002135TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
2136 JsepSessionDescription jdesc(kDummyString);
2137 const char kSdpWithoutMline[] =
2138 "v=0\r\n"
2139 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2140 "s=-\r\n"
2141 "t=0 0\r\n"
2142 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
2143 // Deserialize
2144 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2145 EXPECT_EQ(0u, jdesc.description()->contents().size());
2146}
2147
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002148TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
2149 JsepSessionDescription jdesc(kDummyString);
2150 std::string sdp_without_carriage_return = kSdpFullString;
2151 Replace("\r\n", "\n", &sdp_without_carriage_return);
2152 // Deserialize
2153 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2154 // Verify
2155 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2156}
2157
2158TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2159 // SessionDescription with desc but without candidates.
2160 JsepSessionDescription jdesc_no_candidates(kDummyString);
2161 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
2162 kSessionId, kSessionVersion));
2163 JsepSessionDescription new_jdesc(kDummyString);
2164 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2165 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2166}
2167
2168TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2169 static const char kSdpNoRtpmapString[] =
2170 "v=0\r\n"
2171 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2172 "s=-\r\n"
2173 "t=0 0\r\n"
2174 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2175 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002176 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002177 // The rtpmap line for static payload codec is optional.
2178 "a=rtpmap:18 G729/16000\r\n"
2179 "a=rtpmap:103 ISAC/16000\r\n";
2180
2181 JsepSessionDescription jdesc(kDummyString);
2182 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2183 cricket::AudioContentDescription* audio =
2184 static_cast<AudioContentDescription*>(
2185 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2186 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002187 // The codecs in the AudioContentDescription should be in the same order as
2188 // the payload types (<fmt>s) on the m= line.
2189 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2190 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002191 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002192 EXPECT_EQ(ref_codecs, audio->codecs());
2193}
2194
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002195TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2196 static const char kSdpNoRtpmapString[] =
2197 "v=0\r\n"
2198 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2199 "s=-\r\n"
2200 "t=0 0\r\n"
2201 "m=audio 49232 RTP/AVP 18 103\r\n"
2202 "a=fmtp:18 annexb=yes\r\n"
2203 "a=rtpmap:103 ISAC/16000\r\n";
2204
2205 JsepSessionDescription jdesc(kDummyString);
2206 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2207 cricket::AudioContentDescription* audio =
2208 static_cast<AudioContentDescription*>(
2209 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2210
2211 cricket::AudioCodec g729 = audio->codecs()[0];
2212 EXPECT_EQ("G729", g729.name);
2213 EXPECT_EQ(8000, g729.clockrate);
2214 EXPECT_EQ(18, g729.id);
2215 cricket::CodecParameterMap::iterator found =
2216 g729.params.find("annexb");
2217 ASSERT_TRUE(found != g729.params.end());
2218 EXPECT_EQ(found->second, "yes");
2219
2220 cricket::AudioCodec isac = audio->codecs()[1];
2221 EXPECT_EQ("ISAC", isac.name);
2222 EXPECT_EQ(103, isac.id);
2223 EXPECT_EQ(16000, isac.clockrate);
2224}
2225
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002226// Ensure that we can deserialize SDP with a=fingerprint properly.
2227TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2228 // Add a DTLS a=fingerprint attribute to our session description.
2229 AddFingerprint();
2230 JsepSessionDescription new_jdesc(kDummyString);
2231 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
2232 jdesc_.session_id(),
2233 jdesc_.session_version()));
2234
2235 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
2236 std::string sdp_with_fingerprint = kSdpString;
2237 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2238 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2239 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2240 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2241}
2242
2243TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
2244 JsepSessionDescription jdesc_with_bundle(kDummyString);
2245 std::string sdp_with_bundle = kSdpFullString;
2246 InjectAfter(kSessionTime,
2247 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2248 &sdp_with_bundle);
2249 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2250 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2251 group.AddContentName(kAudioContentName);
2252 group.AddContentName(kVideoContentName);
2253 desc_.AddGroup(group);
2254 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2255 jdesc_.session_id(),
2256 jdesc_.session_version()));
2257 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2258}
2259
2260TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
2261 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2262 std::string sdp_with_bandwidth = kSdpFullString;
2263 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
2264 "b=AS:100\r\n",
2265 &sdp_with_bandwidth);
2266 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
2267 "b=AS:50\r\n",
2268 &sdp_with_bandwidth);
2269 EXPECT_TRUE(
2270 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2271 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
2272 GetFirstVideoContent(&desc_)->description);
2273 vcd->set_bandwidth(100 * 1000);
2274 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
2275 GetFirstAudioContent(&desc_)->description);
2276 acd->set_bandwidth(50 * 1000);
2277 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2278 jdesc_.session_id(),
2279 jdesc_.session_version()));
2280 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2281}
2282
2283TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
2284 JsepSessionDescription jdesc_with_ice_options(kDummyString);
2285 std::string sdp_with_ice_options = kSdpFullString;
2286 InjectAfter(kSessionTime,
2287 "a=ice-options:iceoption3\r\n",
2288 &sdp_with_ice_options);
2289 InjectAfter(kAttributeIcePwdVoice,
2290 "a=ice-options:iceoption1\r\n",
2291 &sdp_with_ice_options);
2292 InjectAfter(kAttributeIcePwdVideo,
2293 "a=ice-options:iceoption2\r\n",
2294 &sdp_with_ice_options);
2295 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2296 std::vector<std::string> transport_options;
2297 transport_options.push_back(kIceOption3);
2298 transport_options.push_back(kIceOption1);
2299 AddIceOptions(kAudioContentName, transport_options);
2300 transport_options.clear();
2301 transport_options.push_back(kIceOption3);
2302 transport_options.push_back(kIceOption2);
2303 AddIceOptions(kVideoContentName, transport_options);
2304 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2305 jdesc_.session_id(),
2306 jdesc_.session_version()));
2307 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2308}
2309
2310TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2311 // Remove the original ice-ufrag and ice-pwd
2312 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyString);
2313 std::string sdp_with_ufrag_pwd = kSdpFullString;
2314 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2315 // Add session level ufrag and pwd
2316 InjectAfter(kSessionTime,
2317 "a=ice-pwd:session+level+icepwd\r\n"
2318 "a=ice-ufrag:session+level+iceufrag\r\n",
2319 &sdp_with_ufrag_pwd);
2320 // Add media level ufrag and pwd for audio
2321 InjectAfter("a=mid:audio_content_name\r\n",
2322 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2323 &sdp_with_ufrag_pwd);
2324 // Update the candidate ufrag and pwd to the expected ones.
2325 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0,
2326 "media+level+iceufrag", "media+level+icepwd"));
2327 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1,
2328 "session+level+iceufrag", "session+level+icepwd"));
2329 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2330 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2331}
2332
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002333TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
2334 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_RECVONLY));
2335}
2336
2337TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
2338 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_SENDONLY));
2339}
2340
2341TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
2342 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_INACTIVE));
2343}
2344
2345TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2346 EXPECT_TRUE(TestDeserializeRejected(true, false));
2347}
2348
2349TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2350 EXPECT_TRUE(TestDeserializeRejected(false, true));
2351}
2352
2353TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2354 EXPECT_TRUE(TestDeserializeRejected(true, true));
2355}
2356
2357// Tests that we can still handle the sdp uses mslabel and label instead of
2358// msid for backward compatibility.
2359TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07002360 jdesc_.description()->set_msid_supported(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002361 JsepSessionDescription jdesc(kDummyString);
2362 std::string sdp_without_msid = kSdpFullString;
2363 Replace("msid", "xmsid", &sdp_without_msid);
2364 // Deserialize
2365 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2366 // Verify
2367 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2368}
2369
2370TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2371 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2372
2373 std::string sdp = kSdpOneCandidate;
2374 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2375 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2376 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2377 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002378 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002379
2380 // Candidate line without generation extension.
2381 sdp = kSdpOneCandidate;
2382 Replace(" generation 2", "", &sdp);
2383 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2384 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2385 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2386 Candidate expected = jcandidate_->candidate();
2387 expected.set_generation(0);
2388 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2389
honghaiza0c44ea2016-03-23 16:07:48 -07002390 // Candidate with network id and/or cost.
2391 sdp = kSdpOneCandidate;
2392 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2393 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2394 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2395 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2396 expected = jcandidate_->candidate();
2397 expected.set_network_id(2);
2398 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2399 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2400 // Add network cost
2401 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2402 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2403 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2404 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2405
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002406 sdp = kSdpTcpActiveCandidate;
2407 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2408 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002409 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002410 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2411 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2412 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002413 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2414 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002415 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(
2416 jcandidate_template->candidate()));
2417 sdp = kSdpTcpPassiveCandidate;
2418 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2419 sdp = kSdpTcpSOCandidate;
2420 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002421}
2422
2423// This test verifies the deserialization of candidate-attribute
2424// as per RFC 5245. Candiate-attribute will be of the format
2425// candidate:<blah>. This format will be used when candidates
2426// are trickled.
2427TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2428 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2429
2430 std::string candidate_attribute = kRawCandidate;
2431 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2432 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2433 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2434 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2435 EXPECT_EQ(2u, jcandidate.candidate().generation());
2436
2437 // Candidate line without generation extension.
2438 candidate_attribute = kRawCandidate;
2439 Replace(" generation 2", "", &candidate_attribute);
2440 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2441 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2442 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2443 Candidate expected = jcandidate_->candidate();
2444 expected.set_generation(0);
2445 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2446
2447 // Candidate line without candidate:
2448 candidate_attribute = kRawCandidate;
2449 Replace("candidate:", "", &candidate_attribute);
2450 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2451
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002452 // Candidate line with IPV6 address.
2453 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
2454}
2455
2456// This test verifies that the deserialization of an invalid candidate string
2457// fails.
2458TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
2459 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2460
2461 std::string candidate_attribute = kRawCandidate;
2462 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002463 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002464
2465 candidate_attribute = kSdpOneCandidate;
2466 candidate_attribute.replace(0, 1, "x");
2467 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2468
2469 candidate_attribute = kRawCandidate;
2470 candidate_attribute.append("\r\n");
2471 candidate_attribute.append(kRawCandidate);
2472 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2473
2474 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002475}
2476
2477TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2478 AddRtpDataChannel();
2479 JsepSessionDescription jdesc(kDummyString);
2480 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2481
2482 std::string sdp_with_data = kSdpString;
2483 sdp_with_data.append(kSdpRtpDataChannelString);
2484 JsepSessionDescription jdesc_output(kDummyString);
2485
2486 // Deserialize
2487 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2488 // Verify
2489 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2490}
2491
2492TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002493 bool use_sctpmap = true;
2494 AddSctpDataChannel(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002495 JsepSessionDescription jdesc(kDummyString);
2496 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2497
2498 std::string sdp_with_data = kSdpString;
2499 sdp_with_data.append(kSdpSctpDataChannelString);
2500 JsepSessionDescription jdesc_output(kDummyString);
2501
lally@webrtc.org36300852015-02-24 20:19:35 +00002502 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2503 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2504 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2505
2506 // Verify with UDP/DTLS/SCTP.
2507 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2508 strlen(kDtlsSctp), kUdpDtlsSctp);
2509 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2510 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2511
2512 // Verify with TCP/DTLS/SCTP.
2513 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2514 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002515 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2516 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2517}
2518
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002519TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002520 bool use_sctpmap = false;
2521 AddSctpDataChannel(use_sctpmap);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002522 JsepSessionDescription jdesc(kDummyString);
2523 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2524
2525 std::string sdp_with_data = kSdpString;
2526 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2527 JsepSessionDescription jdesc_output(kDummyString);
2528
lally@webrtc.org36300852015-02-24 20:19:35 +00002529 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002530 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2531 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002532
lally@webrtc.org36300852015-02-24 20:19:35 +00002533 // Verify with UDP/DTLS/SCTP.
2534 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2535 strlen(kDtlsSctp), kUdpDtlsSctp);
2536 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2537 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002538
lally@webrtc.org36300852015-02-24 20:19:35 +00002539 // Verify with TCP/DTLS/SCTP.
2540 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2541 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002542 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2543 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2544}
2545
lally69f57602015-10-08 10:15:04 -07002546TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002547 bool use_sctpmap = false;
2548 AddSctpDataChannel(use_sctpmap);
lally69f57602015-10-08 10:15:04 -07002549 JsepSessionDescription jdesc(kDummyString);
2550 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2551
2552 std::string sdp_with_data = kSdpString;
2553 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
2554 JsepSessionDescription jdesc_output(kDummyString);
2555
2556 // Verify with DTLS/SCTP.
2557 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2558 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2559
2560 // Verify with UDP/DTLS/SCTP.
2561 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2562 strlen(kDtlsSctp), kUdpDtlsSctp);
2563 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2564 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2565
2566 // Verify with TCP/DTLS/SCTP.
2567 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2568 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
2569 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2570 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2571}
2572
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002573// Test to check the behaviour if sctp-port is specified
2574// on the m= line and in a=sctp-port.
2575TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002576 bool use_sctpmap = true;
2577 AddSctpDataChannel(use_sctpmap);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002578 JsepSessionDescription jdesc(kDummyString);
2579 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2580
2581 std::string sdp_with_data = kSdpString;
2582 // Append m= attributes
2583 sdp_with_data.append(kSdpSctpDataChannelString);
2584 // Append a=sctp-port attribute
2585 sdp_with_data.append("a=sctp-port 5000\r\n");
2586 JsepSessionDescription jdesc_output(kDummyString);
2587
2588 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2589}
2590
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002591// For crbug/344475.
2592TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2593 std::string sdp_with_data = kSdpString;
2594 sdp_with_data.append(kSdpSctpDataChannelString);
2595 // Remove the "\n" at the end.
2596 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
2597 JsepSessionDescription jdesc_output(kDummyString);
2598
2599 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2600 // No crash is a pass.
2601}
2602
zstein4b2e0822017-02-17 19:48:38 -08002603void MutateJsepSctpPort(JsepSessionDescription& jdesc,
2604 const SessionDescription& desc) {
wu@webrtc.org78187522013-10-07 23:32:02 +00002605 // take our pre-built session description and change the SCTP port.
zstein4b2e0822017-02-17 19:48:38 -08002606 cricket::SessionDescription* mutant = desc.Copy();
wu@webrtc.org78187522013-10-07 23:32:02 +00002607 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
2608 mutant->GetContentDescriptionByName(kDataContentName));
2609 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002610 EXPECT_EQ(1U, codecs.size());
solenberg9fa49752016-10-08 13:02:44 -07002611 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002612 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002613 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002614
2615 // note: mutant's owned by jdesc now.
2616 ASSERT_TRUE(jdesc.Initialize(mutant, kSessionId, kSessionVersion));
2617 mutant = NULL;
zstein4b2e0822017-02-17 19:48:38 -08002618}
2619
2620TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
2621 bool use_sctpmap = true;
2622 AddSctpDataChannel(use_sctpmap);
2623
2624 // First setup the expected JsepSessionDescription.
2625 JsepSessionDescription jdesc(kDummyString);
2626 MutateJsepSctpPort(jdesc, desc_);
wu@webrtc.org78187522013-10-07 23:32:02 +00002627
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002628 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002629 std::string sdp_with_data = kSdpString;
2630 sdp_with_data.append(kSdpSctpDataChannelString);
zstein4b2e0822017-02-17 19:48:38 -08002631 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2632 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2633 &sdp_with_data);
wu@webrtc.org78187522013-10-07 23:32:02 +00002634 JsepSessionDescription jdesc_output(kDummyString);
2635
2636 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2637 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08002638}
2639
2640TEST_F(WebRtcSdpTest,
2641 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
2642 bool use_sctpmap = false;
2643 AddSctpDataChannel(use_sctpmap);
2644
2645 JsepSessionDescription jdesc(kDummyString);
2646 MutateJsepSctpPort(jdesc, desc_);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002647
2648 // We need to test the deserialized JsepSessionDescription from
2649 // kSdpSctpDataChannelStringWithSctpPort for
2650 // draft-ietf-mmusic-sctp-sdp-07
2651 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08002652 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002653 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
zstein4b2e0822017-02-17 19:48:38 -08002654 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2655 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2656 &sdp_with_data);
2657 JsepSessionDescription jdesc_output(kDummyString);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002658
2659 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2660 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002661}
2662
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002663TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002664 // We want to test that deserializing data content limits bandwidth
2665 // settings (it should never be greater than the default).
2666 // This should prevent someone from using unlimited data bandwidth through
2667 // JS and "breaking the Internet".
2668 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002669 std::string sdp_with_bandwidth = kSdpString;
2670 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
2671 InjectAfter("a=mid:data_content_name\r\n",
2672 "b=AS:100\r\n",
2673 &sdp_with_bandwidth);
2674 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2675
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002676 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2677}
2678
2679TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08002680 bool use_sctpmap = true;
2681 AddSctpDataChannel(use_sctpmap);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002682 JsepSessionDescription jdesc(kDummyString);
2683 DataContentDescription* dcd = static_cast<DataContentDescription*>(
2684 GetFirstDataContent(&desc_)->description);
2685 dcd->set_bandwidth(100 * 1000);
2686 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2687
2688 std::string sdp_with_bandwidth = kSdpString;
2689 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
2690 InjectAfter("a=mid:data_content_name\r\n",
2691 "b=AS:100\r\n",
2692 &sdp_with_bandwidth);
2693 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2694
2695 // SCTP has congestion control, so we shouldn't limit the bandwidth
2696 // as we do for RTP.
2697 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002698 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2699}
2700
jbauch5869f502017-06-29 12:31:36 -07002701class WebRtcSdpExtmapTest
2702 : public WebRtcSdpTest, public testing::WithParamInterface<bool> {
2703};
2704
2705TEST_P(WebRtcSdpExtmapTest,
2706 DeserializeSessionDescriptionWithSessionLevelExtmap) {
2707 bool encrypted = GetParam();
2708 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002709}
2710
jbauch5869f502017-06-29 12:31:36 -07002711TEST_P(WebRtcSdpExtmapTest,
2712 DeserializeSessionDescriptionWithMediaLevelExtmap) {
2713 bool encrypted = GetParam();
2714 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002715}
2716
jbauch5869f502017-06-29 12:31:36 -07002717TEST_P(WebRtcSdpExtmapTest,
2718 DeserializeSessionDescriptionWithInvalidExtmap) {
2719 bool encrypted = GetParam();
2720 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002721}
2722
jbauch5869f502017-06-29 12:31:36 -07002723INSTANTIATE_TEST_CASE_P(Encrypted,
2724 WebRtcSdpExtmapTest,
2725 ::testing::Values(false, true));
2726
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002727TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
2728 JsepSessionDescription jdesc(kDummyString);
2729 std::string sdp = kSdpFullString;
2730 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2731 // Deserialize
2732 SdpParseError error;
2733 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-16 17:54:10 -08002734 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002735 EXPECT_EQ(lastline, error.line);
2736 EXPECT_EQ("Invalid SDP line.", error.description);
2737}
2738
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002739TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2740 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2741 std::string new_sdp = kSdpOneCandidate;
2742 Replace("udp", "unsupported_transport", &new_sdp);
2743 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2744 new_sdp = kSdpOneCandidate;
2745 Replace("udp", "uDP", &new_sdp);
2746 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2747 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2748 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2749 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2750}
2751
honghaiza54a0802015-12-16 18:37:23 -08002752TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002753 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08002754 EXPECT_TRUE(
2755 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002756 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2757 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2758 Candidate ref_candidate = jcandidate_->candidate();
2759 ref_candidate.set_username("user_rtp");
2760 ref_candidate.set_password("password_rtp");
2761 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2762}
2763
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002764TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
2765 JsepSessionDescription jdesc(kDummyString);
2766
2767 // Deserialize
2768 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2769
2770 // Verify
2771 cricket::AudioContentDescription* audio =
2772 static_cast<AudioContentDescription*>(
2773 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2774 EXPECT_TRUE(audio->conference_mode());
2775
2776 cricket::VideoContentDescription* video =
2777 static_cast<VideoContentDescription*>(
2778 jdesc.description()->GetContentDescriptionByName(cricket::CN_VIDEO));
2779 EXPECT_TRUE(video->conference_mode());
2780}
2781
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002782TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2783 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002784 const char kSdpEmptyType[] = " =candidate";
2785 const char kSdpEqualAsPlus[] = "a+candidate";
2786 const char kSdpSpaceAfterEqual[] = "a= candidate";
2787 const char kSdpUpperType[] = "A=candidate";
2788 const char kSdpEmptyLine[] = "";
2789 const char kSdpMissingValue[] = "a=";
2790
2791 const char kSdpBrokenFingerprint[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002792 "4AAD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002793 const char kSdpExtraField[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002794 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB XXX";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002795 const char kSdpMissingSpace[] = "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002796 "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 +00002797 // MD5 is not allowed in fingerprints.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002798 const char kSdpMd5[] = "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002799 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002800
2801 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002802 ExpectParseFailure("v=", kSdpDestroyer);
2803 ExpectParseFailure("o=", kSdpDestroyer);
2804 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002805 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002806 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002807
2808 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002809 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2810 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002811
2812 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002813 ExpectParseFailure("a=candidate", kSdpEmptyType);
2814 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2815 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
2816 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002817
2818 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2819 // because it's orthogonal to what we are replacing and hence
2820 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002821 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
2822 ExpectParseFailure("a=sendrecv", kSdpExtraField);
2823 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
2824 ExpectParseFailure("a=sendrecv", kSdpMd5);
2825
2826 // Empty Line
2827 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
2828 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002829}
2830
2831TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2832 // ssrc
2833 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08002834 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002835 // crypto
2836 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
2837 // rtpmap
2838 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
2839 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
2840 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
2841 // candidate
2842 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
2843 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
2844 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
2845 ExpectParseFailure("rport 2346", "rport badvalue");
2846 ExpectParseFailure("rport 2346 generation 2",
2847 "rport 2346 generation badvalue");
2848 // m line
2849 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
2850 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
2851
2852 // bandwidth
2853 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2854 "b=AS:badvalue\r\n",
2855 "b=AS:badvalue");
2856 // rtcp-fb
2857 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2858 "a=rtcp-fb:badvalue nack\r\n",
2859 "a=rtcp-fb:badvalue nack");
2860 // extmap
2861 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2862 "a=extmap:badvalue http://example.com\r\n",
2863 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002864}
2865
2866TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
2867 JsepSessionDescription jdesc_output(kDummyString);
2868
2869 const char kSdpWithReorderedPlTypesString[] =
2870 "v=0\r\n"
2871 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2872 "s=-\r\n"
2873 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00002874 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002875 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
2876 // in the map.
2877 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002878 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002879
2880 // Deserialize
2881 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
2882
2883 const ContentInfo* ac = GetFirstAudioContent(jdesc_output.description());
2884 ASSERT_TRUE(ac != NULL);
2885 const AudioContentDescription* acd =
2886 static_cast<const AudioContentDescription*>(ac->description);
2887 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002888 EXPECT_EQ("ISAC", acd->codecs()[0].name);
2889 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002890 EXPECT_EQ(104, acd->codecs()[0].id);
2891}
2892
2893TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
2894 JsepSessionDescription jdesc_output(kDummyString);
2895 CodecParams params;
2896 params.max_ptime = 40;
2897 params.ptime = 30;
2898 params.min_ptime = 10;
2899 params.sprop_stereo = 1;
2900 params.stereo = 1;
2901 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002902 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002903 TestDeserializeCodecParams(params, &jdesc_output);
deadbeef9d3584c2016-02-16 17:54:10 -08002904 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002905}
2906
2907TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
2908 const bool kUseWildcard = false;
2909 JsepSessionDescription jdesc_output(kDummyString);
2910 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
deadbeef9d3584c2016-02-16 17:54:10 -08002911 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002912}
2913
2914TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
2915 const bool kUseWildcard = true;
2916 JsepSessionDescription jdesc_output(kDummyString);
2917 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
deadbeef9d3584c2016-02-16 17:54:10 -08002918 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002919}
2920
2921TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
2922 JsepSessionDescription jdesc_output(kDummyString);
2923
2924 const char kSdpWithFmtpString[] =
2925 "v=0\r\n"
2926 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2927 "s=-\r\n"
2928 "t=0 0\r\n"
2929 "m=video 3457 RTP/SAVPF 120\r\n"
2930 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07002931 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
2932
2933 // Deserialize
2934 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07002935 EXPECT_TRUE(
2936 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07002937
2938 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2939 ASSERT_TRUE(vc != NULL);
2940 const VideoContentDescription* vcd =
2941 static_cast<const VideoContentDescription*>(vc->description);
2942 ASSERT_FALSE(vcd->codecs().empty());
2943 cricket::VideoCodec vp8 = vcd->codecs()[0];
2944 EXPECT_EQ("VP8", vp8.name);
2945 EXPECT_EQ(120, vp8.id);
2946 cricket::CodecParameterMap::iterator found =
2947 vp8.params.find("x-google-min-bitrate");
2948 ASSERT_TRUE(found != vp8.params.end());
2949 EXPECT_EQ(found->second, "10");
2950 found = vp8.params.find("x-google-max-quantization");
2951 ASSERT_TRUE(found != vp8.params.end());
2952 EXPECT_EQ(found->second, "40");
2953}
2954
johan2d8d23e2016-06-03 01:22:42 -07002955TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
2956 JsepSessionDescription jdesc_output(kDummyString);
2957
2958 const char kSdpWithFmtpString[] =
2959 "v=0\r\n"
2960 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2961 "s=-\r\n"
2962 "t=0 0\r\n"
2963 "m=video 49170 RTP/AVP 98\r\n"
2964 "a=rtpmap:98 H264/90000\r\n"
2965 "a=fmtp:98 profile-level-id=42A01E; "
2966 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
2967
2968 // Deserialize.
2969 SdpParseError error;
2970 EXPECT_TRUE(
2971 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
2972
2973 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2974 ASSERT_TRUE(vc != NULL);
2975 const VideoContentDescription* vcd =
2976 static_cast<const VideoContentDescription*>(vc->description);
2977 ASSERT_TRUE(vcd != NULL);
2978 ASSERT_FALSE(vcd->codecs().empty());
2979 cricket::VideoCodec h264 = vcd->codecs()[0];
2980 EXPECT_EQ("H264", h264.name);
2981 EXPECT_EQ(98, h264.id);
2982 cricket::CodecParameterMap::const_iterator found =
2983 h264.params.find("profile-level-id");
2984 ASSERT_TRUE(found != h264.params.end());
2985 EXPECT_EQ(found->second, "42A01E");
2986 found = h264.params.find("sprop-parameter-sets");
2987 ASSERT_TRUE(found != h264.params.end());
2988 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
2989}
2990
Donald Curtis0e07f922015-05-15 09:21:23 -07002991TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
2992 JsepSessionDescription jdesc_output(kDummyString);
2993
2994 const char kSdpWithFmtpString[] =
2995 "v=0\r\n"
2996 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2997 "s=-\r\n"
2998 "t=0 0\r\n"
2999 "m=video 3457 RTP/SAVPF 120\r\n"
3000 "a=rtpmap:120 VP8/90000\r\n"
3001 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003002
3003 // Deserialize
3004 SdpParseError error;
3005 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output,
3006 &error));
3007
3008 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
3009 ASSERT_TRUE(vc != NULL);
3010 const VideoContentDescription* vcd =
3011 static_cast<const VideoContentDescription*>(vc->description);
3012 ASSERT_FALSE(vcd->codecs().empty());
3013 cricket::VideoCodec vp8 = vcd->codecs()[0];
3014 EXPECT_EQ("VP8", vp8.name);
3015 EXPECT_EQ(120, vp8.id);
3016 cricket::CodecParameterMap::iterator found =
3017 vp8.params.find("x-google-min-bitrate");
3018 ASSERT_TRUE(found != vp8.params.end());
3019 EXPECT_EQ(found->second, "10");
3020 found = vp8.params.find("x-google-max-quantization");
3021 ASSERT_TRUE(found != vp8.params.end());
3022 EXPECT_EQ(found->second, "40");
3023}
3024
ossuaa4b0772017-01-30 07:41:18 -08003025TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
3026 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
3027 GetFirstAudioContent(&desc_)->description);
3028
3029 cricket::AudioCodecs codecs = acd->codecs();
3030 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3031 acd->set_codecs(codecs);
3032
3033 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3034 jdesc_.session_id(),
3035 jdesc_.session_version()));
3036 std::string message = webrtc::SdpSerialize(jdesc_, false);
3037 std::string sdp_with_fmtp = kSdpFullString;
3038 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3039 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3040 &sdp_with_fmtp);
3041 EXPECT_EQ(sdp_with_fmtp, message);
3042}
3043
3044TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
3045 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
3046 GetFirstAudioContent(&desc_)->description);
3047
3048 cricket::AudioCodecs codecs = acd->codecs();
3049 codecs[0].params["stereo"] = "1";
3050 acd->set_codecs(codecs);
3051
3052 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3053 jdesc_.session_id(),
3054 jdesc_.session_version()));
3055 std::string message = webrtc::SdpSerialize(jdesc_, false);
3056 std::string sdp_with_fmtp = kSdpFullString;
3057 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3058 "a=fmtp:111 stereo=1\r\n",
3059 &sdp_with_fmtp);
3060 EXPECT_EQ(sdp_with_fmtp, message);
3061}
3062
3063TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
3064 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
3065 GetFirstAudioContent(&desc_)->description);
3066
3067 cricket::AudioCodecs codecs = acd->codecs();
3068 codecs[0].params["ptime"] = "20";
3069 codecs[0].params["maxptime"] = "120";
3070 acd->set_codecs(codecs);
3071
3072 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3073 jdesc_.session_id(),
3074 jdesc_.session_version()));
3075 std::string message = webrtc::SdpSerialize(jdesc_, false);
3076 std::string sdp_with_fmtp = kSdpFullString;
3077 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3078 "a=maxptime:120\r\n" // No comma here. String merging!
3079 "a=ptime:20\r\n",
3080 &sdp_with_fmtp);
3081 EXPECT_EQ(sdp_with_fmtp, message);
3082}
3083
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003084TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
3085 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
3086 GetFirstVideoContent(&desc_)->description);
3087
3088 cricket::VideoCodecs codecs = vcd->codecs();
3089 codecs[0].params["x-google-min-bitrate"] = "10";
3090 vcd->set_codecs(codecs);
3091
3092 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3093 jdesc_.session_id(),
3094 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08003095 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003096 std::string sdp_with_fmtp = kSdpFullString;
3097 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
3098 "a=fmtp:120 x-google-min-bitrate=10\r\n",
3099 &sdp_with_fmtp);
3100 EXPECT_EQ(sdp_with_fmtp, message);
3101}
3102
3103TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) {
3104 JsepSessionDescription jdesc_with_icelite(kDummyString);
3105 std::string sdp_with_icelite = kSdpFullString;
3106 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3107 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3108 const cricket::TransportInfo* tinfo1 =
3109 desc->GetTransportInfoByName("audio_content_name");
3110 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3111 const cricket::TransportInfo* tinfo2 =
3112 desc->GetTransportInfoByName("video_content_name");
3113 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
3114 InjectAfter(kSessionTime,
3115 "a=ice-lite\r\n",
3116 &sdp_with_icelite);
3117 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3118 desc = jdesc_with_icelite.description();
3119 const cricket::TransportInfo* atinfo =
3120 desc->GetTransportInfoByName("audio_content_name");
3121 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3122 const cricket::TransportInfo* vtinfo =
3123 desc->GetTransportInfoByName("video_content_name");
3124 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
3125}
3126
3127// Verifies that the candidates in the input SDP are parsed and serialized
3128// correctly in the output SDP.
3129TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3130 std::string sdp_with_data = kSdpString;
3131 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
3132 JsepSessionDescription jdesc_output(kDummyString);
3133
3134 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
deadbeef9d3584c2016-02-16 17:54:10 -08003135 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output, false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003136}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003137
3138TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3139 AddFingerprint();
3140 TransportInfo audio_transport_info =
3141 *(desc_.GetTransportInfoByName(kAudioContentName));
3142 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3143 audio_transport_info.description.connection_role);
3144 audio_transport_info.description.connection_role =
3145 cricket::CONNECTIONROLE_ACTIVE;
3146
3147 TransportInfo video_transport_info =
3148 *(desc_.GetTransportInfoByName(kVideoContentName));
3149 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3150 video_transport_info.description.connection_role);
3151 video_transport_info.description.connection_role =
3152 cricket::CONNECTIONROLE_ACTIVE;
3153
3154 desc_.RemoveTransportInfoByName(kAudioContentName);
3155 desc_.RemoveTransportInfoByName(kVideoContentName);
3156
3157 desc_.AddTransportInfo(audio_transport_info);
3158 desc_.AddTransportInfo(video_transport_info);
3159
3160 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3161 jdesc_.session_id(),
3162 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08003163 std::string message = webrtc::SdpSerialize(jdesc_, false);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003164 std::string sdp_with_dtlssetup = kSdpFullString;
3165
3166 // Fingerprint attribute is necessary to add DTLS setup attribute.
3167 InjectAfter(kAttributeIcePwdVoice,
3168 kFingerprint, &sdp_with_dtlssetup);
3169 InjectAfter(kAttributeIcePwdVideo,
3170 kFingerprint, &sdp_with_dtlssetup);
3171 // Now adding |setup| attribute.
3172 InjectAfter(kFingerprint,
3173 "a=setup:active\r\n", &sdp_with_dtlssetup);
3174 EXPECT_EQ(sdp_with_dtlssetup, message);
3175}
3176
3177TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
3178 JsepSessionDescription jdesc_with_dtlssetup(kDummyString);
3179 std::string sdp_with_dtlssetup = kSdpFullString;
3180 InjectAfter(kSessionTime,
3181 "a=setup:actpass\r\n",
3182 &sdp_with_dtlssetup);
3183 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3184 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3185 const cricket::TransportInfo* atinfo =
3186 desc->GetTransportInfoByName("audio_content_name");
3187 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3188 atinfo->description.connection_role);
3189 const cricket::TransportInfo* vtinfo =
3190 desc->GetTransportInfoByName("video_content_name");
3191 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3192 vtinfo->description.connection_role);
3193}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003194
3195// Verifies that the order of the serialized m-lines follows the order of the
3196// ContentInfo in SessionDescription, and vise versa for deserialization.
3197TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
3198 JsepSessionDescription jdesc(kDummyString);
3199 const std::string media_content_sdps[3] = {
3200 kSdpAudioString,
3201 kSdpVideoString,
3202 kSdpSctpDataChannelString
3203 };
3204 const cricket::MediaType media_types[3] = {
3205 cricket::MEDIA_TYPE_AUDIO,
3206 cricket::MEDIA_TYPE_VIDEO,
3207 cricket::MEDIA_TYPE_DATA
3208 };
3209
3210 // Verifies all 6 permutations.
3211 for (size_t i = 0; i < 6; ++i) {
3212 size_t media_content_in_sdp[3];
3213 // The index of the first media content.
3214 media_content_in_sdp[0] = i / 2;
3215 // The index of the second media content.
3216 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3217 // The index of the third media content.
3218 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3219
3220 std::string sdp_string = kSdpSessionString;
3221 for (size_t i = 0; i < 3; ++i)
3222 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3223
3224 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3225 cricket::SessionDescription* desc = jdesc.description();
3226 EXPECT_EQ(3u, desc->contents().size());
3227
3228 for (size_t i = 0; i < 3; ++i) {
3229 const cricket::MediaContentDescription* mdesc =
3230 static_cast<const cricket::MediaContentDescription*>(
3231 desc->contents()[i].description);
3232 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3233 }
3234
deadbeef9d3584c2016-02-16 17:54:10 -08003235 std::string serialized_sdp = webrtc::SdpSerialize(jdesc, false);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003236 EXPECT_EQ(sdp_string, serialized_sdp);
3237 }
3238}
deadbeef9d3584c2016-02-16 17:54:10 -08003239
deadbeef25ed4352016-12-12 18:37:36 -08003240TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3241 MakeBundleOnlyDescription();
3242 JsepSessionDescription deserialized_description(kDummyString);
deadbeef12771a12017-01-03 13:53:47 -08003243 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003244 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3245 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3246}
3247
deadbeef12771a12017-01-03 13:53:47 -08003248// The semantics of "a=bundle-only" are only defined when it's used in
3249// combination with a 0 port on the m= line. We should ignore it if used with a
3250// nonzero port.
3251TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3252 // Make the base bundle-only description but unset the bundle-only flag.
3253 MakeBundleOnlyDescription();
3254 jdesc_.description()->contents()[1].bundle_only = false;
3255
3256 std::string modified_sdp = kBundleOnlySdpFullString;
3257 Replace("m=video 0", "m=video 9", &modified_sdp);
3258 JsepSessionDescription deserialized_description(kDummyString);
3259 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3260 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003261}
3262
3263TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3264 MakeBundleOnlyDescription();
3265 TestSerialize(jdesc_, false);
3266}
3267
deadbeef9d3584c2016-02-16 17:54:10 -08003268TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3269 MakePlanBDescription();
3270
3271 JsepSessionDescription deserialized_description(kDummyString);
3272 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3273
3274 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3275}
3276
3277TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3278 MakePlanBDescription();
3279 TestSerialize(jdesc_, false);
3280}
3281
Taylor Brandstetter5de6b752016-03-09 17:02:30 -08003282// Some WebRTC endpoints include the msid in both the Plan B and Unified Plan
3283// ways, to make SDP that's compatible with both Plan B and Unified Plan (to
3284// some extent). If we parse this, the Plan B msid attribute (which is more
3285// specific, since it's at the SSRC level) should take priority.
3286TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescriptionWithMsid) {
3287 MakePlanBDescription();
3288
3289 JsepSessionDescription deserialized_description(kDummyString);
3290 EXPECT_TRUE(
3291 SdpDeserialize(kPlanBSdpFullStringWithMsid, &deserialized_description));
3292
3293 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3294}
3295
deadbeef9d3584c2016-02-16 17:54:10 -08003296TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3297 MakeUnifiedPlanDescription();
3298
3299 JsepSessionDescription deserialized_description(kDummyString);
3300 EXPECT_TRUE(
3301 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3302
3303 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3304}
3305
3306TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3307 MakeUnifiedPlanDescription();
3308 TestSerialize(jdesc_, true);
3309}
deadbeef7e146cb2016-09-28 10:04:34 -07003310
3311// Regression test for heap overflow bug:
3312// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3313TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 10:04:34 -07003314 // The issue occurs when the sctp-port attribute is found in a video
3315 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 12:43:58 -08003316 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 10:04:34 -07003317 "v=0\r\n"
3318 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3319 "s=-\r\n"
3320 "t=0 0\r\n"
3321 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3322 "a=sctp-port 5000\r\n"
3323 "a=fmtp:108 foo=10\r\n";
3324
3325 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3326 "sctp-port");
3327}
deadbeefb2362572016-12-13 16:37:06 -08003328
3329// Regression test for integer overflow bug:
3330// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3331TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003332 // Bandwidth attribute is the max signed 32-bit int, which will get
3333 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003334 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003335 "v=0\r\n"
3336 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3337 "s=-\r\n"
3338 "t=0 0\r\n"
3339 "m=video 3457 RTP/SAVPF 120\r\n"
3340 "b=AS:2147483647\r\n"
3341 "foo=fail\r\n";
3342
3343 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3344}
deadbeef7bcdb692017-01-20 12:43:58 -08003345
deadbeefbc88c6b2017-08-02 11:26:34 -07003346// Similar to the above, except that negative values are illegal, not just
3347// error-prone as large values are.
3348// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3349TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3350 static const char kSdpWithNegativeBandwidth[] =
3351 "v=0\r\n"
3352 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3353 "s=-\r\n"
3354 "t=0 0\r\n"
3355 "m=video 3457 RTP/SAVPF 120\r\n"
3356 "b=AS:-1000\r\n";
3357
3358 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3359}
3360
deadbeef7bcdb692017-01-20 12:43:58 -08003361// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3362// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3363// Regression test for:
3364// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3365TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3366 // Important piece is "ufrag foo pwd bar".
3367 static const char kSdpWithIceCredentialsInCandidateString[] =
3368 "v=0\r\n"
3369 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3370 "s=-\r\n"
3371 "t=0 0\r\n"
3372 "m=audio 9 RTP/SAVPF 111\r\n"
3373 "c=IN IP4 0.0.0.0\r\n"
3374 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3375 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3376 "a=rtpmap:111 opus/48000/2\r\n"
3377 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3378 "generation 2 ufrag foo pwd bar\r\n";
3379
3380 JsepSessionDescription jdesc_output(kDummyString);
3381 EXPECT_TRUE(
3382 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
3383 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3384 ASSERT_NE(nullptr, candidates);
3385 ASSERT_EQ(1, candidates->count());
3386 cricket::Candidate c = candidates->at(0)->candidate();
3387 EXPECT_EQ("ufrag_voice", c.username());
3388 EXPECT_EQ("pwd_voice", c.password());
3389}
deadbeef90f1e1e2017-02-10 12:35:05 -08003390
3391// Test that SDP with an invalid port number in "a=candidate" lines is
3392// rejected, without crashing.
3393// Regression test for:
3394// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
3395TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
3396 static const char kSdpWithInvalidCandidatePort[] =
3397 "v=0\r\n"
3398 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3399 "s=-\r\n"
3400 "t=0 0\r\n"
3401 "m=audio 9 RTP/SAVPF 111\r\n"
3402 "c=IN IP4 0.0.0.0\r\n"
3403 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3404 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3405 "a=rtpmap:111 opus/48000/2\r\n"
3406 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
3407 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
3408
3409 JsepSessionDescription jdesc_output(kDummyString);
3410 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
3411}
deadbeefa4549d62017-02-10 17:26:22 -08003412
3413// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
3414// Regression test for:
3415// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
3416TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
3417 static const char kSdpWithMissingTrackId[] =
3418 "v=0\r\n"
3419 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3420 "s=-\r\n"
3421 "t=0 0\r\n"
3422 "m=audio 9 RTP/SAVPF 111\r\n"
3423 "c=IN IP4 0.0.0.0\r\n"
3424 "a=rtpmap:111 opus/48000/2\r\n"
3425 "a=msid:stream_id \r\n";
3426
3427 JsepSessionDescription jdesc_output(kDummyString);
3428 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
3429}
3430
3431TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
3432 static const char kSdpWithMissingStreamId[] =
3433 "v=0\r\n"
3434 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3435 "s=-\r\n"
3436 "t=0 0\r\n"
3437 "m=audio 9 RTP/SAVPF 111\r\n"
3438 "c=IN IP4 0.0.0.0\r\n"
3439 "a=rtpmap:111 opus/48000/2\r\n"
3440 "a=msid: track_id\r\n";
3441
3442 JsepSessionDescription jdesc_output(kDummyString);
3443 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
3444}
zhihuang38989e52017-03-21 11:04:53 -07003445
3446// Tests that if both session-level address and media-level address exist, use
3447// the media-level address.
3448TEST_F(WebRtcSdpTest, ParseConnectionData) {
3449 JsepSessionDescription jsep_desc(kDummyString);
3450
3451 // Sesssion-level address.
3452 std::string sdp = kSdpFullString;
3453 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3454 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3455
3456 const auto& content1 = jsep_desc.description()->contents()[0];
3457 EXPECT_EQ("74.125.127.126:2345",
3458 static_cast<cricket::MediaContentDescription*>(content1.description)
3459 ->connection_address()
3460 .ToString());
3461 const auto& content2 = jsep_desc.description()->contents()[1];
3462 EXPECT_EQ("74.125.224.39:3457",
3463 static_cast<cricket::MediaContentDescription*>(content2.description)
3464 ->connection_address()
3465 .ToString());
3466}
3467
3468// Tests that the session-level connection address will be used if the media
3469// level-addresses are not specified.
3470TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
3471 JsepSessionDescription jsep_desc(kDummyString);
3472
3473 // Sesssion-level address.
3474 std::string sdp = kSdpString;
3475 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3476 // Remove the media level addresses.
3477 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3478 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3479 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3480
3481 const auto& content1 = jsep_desc.description()->contents()[0];
3482 EXPECT_EQ("192.168.0.3:9",
3483 static_cast<cricket::MediaContentDescription*>(content1.description)
3484 ->connection_address()
3485 .ToString());
3486 const auto& content2 = jsep_desc.description()->contents()[1];
3487 EXPECT_EQ("192.168.0.3:9",
3488 static_cast<cricket::MediaContentDescription*>(content2.description)
3489 ->connection_address()
3490 .ToString());
3491}
3492
3493TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
3494 JsepSessionDescription jsep_desc(kDummyString);
3495
3496 std::string sdp = kSdpString;
3497 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3498 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
3499 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
3500 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
3501 &sdp);
3502 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
3503 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
3504 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
3505 &sdp);
3506 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3507 const auto& content1 = jsep_desc.description()->contents()[0];
3508 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
3509 static_cast<cricket::MediaContentDescription*>(content1.description)
3510 ->connection_address()
3511 .ToString());
3512 const auto& content2 = jsep_desc.description()->contents()[1];
3513 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
3514 static_cast<cricket::MediaContentDescription*>(content2.description)
3515 ->connection_address()
3516 .ToString());
3517}
3518
3519// Test that the invalid or unsupprted connection data cannot be parsed.
3520TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
3521 JsepSessionDescription jsep_desc(kDummyString);
3522 std::string sdp = kSdpString;
3523 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3524
3525 // Unsupported multicast IPv4 address.
3526 sdp = kSdpFullString;
3527 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
3528 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3529
3530 // Unsupported multicast IPv6 address.
3531 sdp = kSdpFullString;
3532 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
3533 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3534
3535 // Mismatched address type.
3536 sdp = kSdpFullString;
3537 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
3538 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3539
3540 sdp = kSdpFullString;
3541 Replace("c=IN IP4 74.125.224.39\r\n",
3542 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
3543 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3544}
3545
3546TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
3547 JsepSessionDescription expected_jsep(kDummyString);
3548 MakeDescriptionWithoutCandidates(&expected_jsep);
3549 // Serialization.
3550 std::string message = webrtc::SdpSerialize(expected_jsep, false);
3551 // Deserialization.
3552 JsepSessionDescription jdesc(kDummyString);
3553 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
3554 auto audio_desc = static_cast<cricket::MediaContentDescription*>(
3555 jdesc.description()->GetContentByName(kAudioContentName)->description);
3556 auto video_desc = static_cast<cricket::MediaContentDescription*>(
3557 jdesc.description()->GetContentByName(kVideoContentName)->description);
3558 EXPECT_EQ(audio_desc_->connection_address().ToString(),
3559 audio_desc->connection_address().ToString());
3560 EXPECT_EQ(video_desc_->connection_address().ToString(),
3561 video_desc->connection_address().ToString());
3562}