blob: 2c88c33cf4a769d5f55fb6b4148d7e64ce53dfd3 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2011 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
kwibergd1fe2812016-04-27 06:47:29 -070011#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000012#include <set>
13#include <string>
14#include <vector>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "api/jsepsessiondescription.h"
17#include "media/base/mediaconstants.h"
18#include "media/engine/webrtcvideoengine.h"
Patrik Höglundaba85d12017-11-28 15:46:08 +010019#include "p2p/base/port.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "p2p/base/p2pconstants.h"
21#include "pc/mediasession.h"
22#include "rtc_base/checks.h"
23#include "rtc_base/gunit.h"
24#include "rtc_base/logging.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020025#include "rtc_base/stringencode.h"
26#include "rtc_base/stringutils.h"
Patrik Höglund563934e2017-09-15 09:04:28 +020027
ossu7bb87ee2017-01-23 04:56:25 -080028#ifdef WEBRTC_ANDROID
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020029#include "pc/test/androidtestinitializer.h"
ossu7bb87ee2017-01-23 04:56:25 -080030#endif
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020031#include "pc/webrtcsdp.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000032
33using cricket::AudioCodec;
34using cricket::AudioContentDescription;
35using cricket::Candidate;
36using cricket::ContentInfo;
37using cricket::CryptoParams;
38using cricket::ContentGroup;
39using cricket::DataCodec;
40using cricket::DataContentDescription;
41using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
42using cricket::ICE_CANDIDATE_COMPONENT_RTP;
43using cricket::kFecSsrcGroupSemantics;
44using cricket::LOCAL_PORT_TYPE;
45using cricket::NS_JINGLE_DRAFT_SCTP;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000046using cricket::NS_JINGLE_RTP;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047using cricket::RELAY_PORT_TYPE;
48using cricket::SessionDescription;
49using cricket::StreamParams;
50using cricket::STUN_PORT_TYPE;
51using cricket::TransportDescription;
52using cricket::TransportInfo;
53using cricket::VideoCodec;
54using cricket::VideoContentDescription;
55using webrtc::IceCandidateCollection;
56using webrtc::IceCandidateInterface;
57using webrtc::JsepIceCandidate;
58using webrtc::JsepSessionDescription;
isheriff6f8d6862016-05-26 11:24:55 -070059using webrtc::RtpExtension;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060using webrtc::SdpParseError;
61using webrtc::SessionDescriptionInterface;
62
63typedef std::vector<AudioCodec> AudioCodecs;
64typedef std::vector<Candidate> Candidates;
65
Peter Boström0c4e06b2015-10-07 12:23:21 +020066static const uint32_t kDefaultSctpPort = 5000;
zstein4b2e0822017-02-17 19:48:38 -080067static const char kDefaultSctpPortStr[] = "5000";
68static const uint16_t kUnusualSctpPort = 9556;
69static const char kUnusualSctpPortStr[] = "9556";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020071static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 15:17:14 -080072static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 15:17:14 -080074static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020076static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077static const char kCandidateFoundation1[] = "a0+B/1";
78static const char kCandidateFoundation2[] = "a0+B/2";
79static const char kCandidateFoundation3[] = "a0+B/3";
80static const char kCandidateFoundation4[] = "a0+B/4";
81static const char kAttributeCryptoVoice[] =
82 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
83 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
84 "dummy_session_params\r\n";
85static const char kAttributeCryptoVideo[] =
86 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
87 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
88static const char kFingerprint[] = "a=fingerprint:sha-1 "
89 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n";
90static const int kExtmapId = 1;
91static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
92static const char kExtmap[] =
93 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
94static const char kExtmapWithDirectionAndAttribute[] =
95 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
jbauch5869f502017-06-29 12:31:36 -070096static const char kExtmapWithDirectionAndAttributeEncrypted[] =
97 "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt "
98 "http://example.com/082005/ext.htm#ttime a1 a2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099
Peter Boström0c4e06b2015-10-07 12:23:21 +0200100static const uint8_t kIdentityDigest[] = {
101 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
102 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103
lally@webrtc.org34807282015-02-24 20:19:39 +0000104static const char kDtlsSctp[] = "DTLS/SCTP";
105static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
106static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +0000107
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000108struct CodecParams {
109 int max_ptime;
110 int ptime;
111 int min_ptime;
112 int sprop_stereo;
113 int stereo;
114 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000115 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116};
117
deadbeef9d3584c2016-02-16 17:54:10 -0800118// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
119// instead of "a=crypto", and have an explicit test for adding "a=crypto".
120// Currently it's the other way around.
121
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000122// Reference sdp string
123static const char kSdpFullString[] =
124 "v=0\r\n"
125 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
126 "s=-\r\n"
127 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800128 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000129 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
130 "c=IN IP4 74.125.127.126\r\n"
131 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
132 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
133 "generation 2\r\n"
134 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
135 "generation 2\r\n"
136 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
137 "generation 2\r\n"
138 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
139 "generation 2\r\n"
140 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
141 "raddr 192.168.1.5 rport 2346 "
142 "generation 2\r\n"
143 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
144 "raddr 192.168.1.5 rport 2348 "
145 "generation 2\r\n"
146 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
147 "a=mid:audio_content_name\r\n"
148 "a=sendrecv\r\n"
149 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800150 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000151 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
152 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
153 "dummy_session_params\r\n"
154 "a=rtpmap:111 opus/48000/2\r\n"
155 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000156 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000157 "a=ssrc:1 cname:stream_1_cname\r\n"
158 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
159 "a=ssrc:1 mslabel:local_stream_1\r\n"
160 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000161 "m=video 3457 RTP/SAVPF 120\r\n"
162 "c=IN IP4 74.125.224.39\r\n"
163 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
164 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
165 "generation 2\r\n"
166 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
167 "generation 2\r\n"
168 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
169 "generation 2\r\n"
170 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
171 "generation 2\r\n"
172 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
173 "generation 2\r\n"
174 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
175 "generation 2\r\n"
176 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
177 "a=mid:video_content_name\r\n"
178 "a=sendrecv\r\n"
179 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
180 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
181 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800182 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000183 "a=ssrc:2 cname:stream_1_cname\r\n"
184 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
185 "a=ssrc:2 mslabel:local_stream_1\r\n"
186 "a=ssrc:2 label:video_track_id_1\r\n"
187 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800188 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000189 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800190 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000191
192// SDP reference string without the candidates.
193static const char kSdpString[] =
194 "v=0\r\n"
195 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
196 "s=-\r\n"
197 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800198 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000199 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000200 "c=IN IP4 0.0.0.0\r\n"
201 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000202 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
203 "a=mid:audio_content_name\r\n"
204 "a=sendrecv\r\n"
205 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800206 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000207 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
208 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
209 "dummy_session_params\r\n"
210 "a=rtpmap:111 opus/48000/2\r\n"
211 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000212 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213 "a=ssrc:1 cname:stream_1_cname\r\n"
214 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
215 "a=ssrc:1 mslabel:local_stream_1\r\n"
216 "a=ssrc:1 label:audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000217 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000218 "c=IN IP4 0.0.0.0\r\n"
219 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000220 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
221 "a=mid:video_content_name\r\n"
222 "a=sendrecv\r\n"
223 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
224 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
225 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800226 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000227 "a=ssrc:2 cname:stream_1_cname\r\n"
228 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
229 "a=ssrc:2 mslabel:local_stream_1\r\n"
230 "a=ssrc:2 label:video_track_id_1\r\n"
231 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800232 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000233 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800234 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000235
236static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000237 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000238 "c=IN IP4 0.0.0.0\r\n"
239 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000240 "a=ice-ufrag:ufrag_data\r\n"
241 "a=ice-pwd:pwd_data\r\n"
242 "a=mid:data_content_name\r\n"
243 "a=sendrecv\r\n"
244 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
245 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
246 "a=rtpmap:101 google-data/90000\r\n"
247 "a=ssrc:10 cname:data_channel_cname\r\n"
248 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
249 "a=ssrc:10 mslabel:data_channel\r\n"
250 "a=ssrc:10 label:data_channeld0\r\n";
251
252static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000253 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000254 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000255 "a=ice-ufrag:ufrag_data\r\n"
256 "a=ice-pwd:pwd_data\r\n"
257 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000258 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000259
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000260// draft-ietf-mmusic-sctp-sdp-12
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000261static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000262 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
263 "a=max-message-size=100000\r\n"
264 "a=sctp-port 5000\r\n"
265 "c=IN IP4 0.0.0.0\r\n"
266 "a=ice-ufrag:ufrag_data\r\n"
267 "a=ice-pwd:pwd_data\r\n"
268 "a=mid:data_content_name\r\n";
269
lally69f57602015-10-08 10:15:04 -0700270static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
271 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
272 "a=max-message-size=100000\r\n"
273 "a=sctp-port:5000\r\n"
274 "c=IN IP4 0.0.0.0\r\n"
275 "a=ice-ufrag:ufrag_data\r\n"
276 "a=ice-pwd:pwd_data\r\n"
277 "a=mid:data_content_name\r\n";
278
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000279static const char kSdpSctpDataChannelWithCandidatesString[] =
280 "m=application 2345 DTLS/SCTP 5000\r\n"
281 "c=IN IP4 74.125.127.126\r\n"
282 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
283 "generation 2\r\n"
284 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
285 "generation 2\r\n"
286 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
287 "raddr 192.168.1.5 rport 2346 "
288 "generation 2\r\n"
289 "a=ice-ufrag:ufrag_data\r\n"
290 "a=ice-pwd:pwd_data\r\n"
291 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000292 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000293
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000294static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000295 "v=0\r\n"
296 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
297 "s=-\r\n"
298 "t=0 0\r\n"
299 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000300 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000301 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000302 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000303 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000304 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000305 "a=x-google-flag:conference\r\n";
306
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000307static const char kSdpSessionString[] =
308 "v=0\r\n"
309 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
310 "s=-\r\n"
311 "t=0 0\r\n"
312 "a=msid-semantic: WMS local_stream\r\n";
313
314static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000315 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000316 "c=IN IP4 0.0.0.0\r\n"
317 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000318 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
319 "a=mid:audio_content_name\r\n"
320 "a=sendrecv\r\n"
321 "a=rtpmap:111 opus/48000/2\r\n"
322 "a=ssrc:1 cname:stream_1_cname\r\n"
323 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
324 "a=ssrc:1 mslabel:local_stream\r\n"
325 "a=ssrc:1 label:audio_track_id_1\r\n";
326
327static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000328 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000329 "c=IN IP4 0.0.0.0\r\n"
330 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000331 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
332 "a=mid:video_content_name\r\n"
333 "a=sendrecv\r\n"
334 "a=rtpmap:120 VP8/90000\r\n"
335 "a=ssrc:2 cname:stream_1_cname\r\n"
336 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
337 "a=ssrc:2 mslabel:local_stream\r\n"
338 "a=ssrc:2 label:video_track_id_1\r\n";
339
deadbeef25ed4352016-12-12 18:37:36 -0800340// Reference sdp string using bundle-only.
341static const char kBundleOnlySdpFullString[] =
342 "v=0\r\n"
343 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
344 "s=-\r\n"
345 "t=0 0\r\n"
346 "a=group:BUNDLE audio_content_name video_content_name\r\n"
347 "a=msid-semantic: WMS local_stream_1\r\n"
348 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
349 "c=IN IP4 74.125.127.126\r\n"
350 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
351 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
352 "generation 2\r\n"
353 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
354 "generation 2\r\n"
355 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
356 "generation 2\r\n"
357 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
358 "generation 2\r\n"
359 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
360 "raddr 192.168.1.5 rport 2346 "
361 "generation 2\r\n"
362 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
363 "raddr 192.168.1.5 rport 2348 "
364 "generation 2\r\n"
365 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
366 "a=mid:audio_content_name\r\n"
367 "a=sendrecv\r\n"
368 "a=rtcp-mux\r\n"
369 "a=rtcp-rsize\r\n"
370 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
371 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
372 "dummy_session_params\r\n"
373 "a=rtpmap:111 opus/48000/2\r\n"
374 "a=rtpmap:103 ISAC/16000\r\n"
375 "a=rtpmap:104 ISAC/32000\r\n"
376 "a=ssrc:1 cname:stream_1_cname\r\n"
377 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
378 "a=ssrc:1 mslabel:local_stream_1\r\n"
379 "a=ssrc:1 label:audio_track_id_1\r\n"
380 "m=video 0 RTP/SAVPF 120\r\n"
381 "c=IN IP4 0.0.0.0\r\n"
382 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
383 "a=bundle-only\r\n"
384 "a=mid:video_content_name\r\n"
385 "a=sendrecv\r\n"
386 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
387 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
388 "a=rtpmap:120 VP8/90000\r\n"
389 "a=ssrc-group:FEC 2 3\r\n"
390 "a=ssrc:2 cname:stream_1_cname\r\n"
391 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
392 "a=ssrc:2 mslabel:local_stream_1\r\n"
393 "a=ssrc:2 label:video_track_id_1\r\n"
394 "a=ssrc:3 cname:stream_1_cname\r\n"
395 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
396 "a=ssrc:3 mslabel:local_stream_1\r\n"
397 "a=ssrc:3 label:video_track_id_1\r\n";
398
deadbeef9d3584c2016-02-16 17:54:10 -0800399// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
400// tracks.
401static const char kPlanBSdpFullString[] =
402 "v=0\r\n"
403 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
404 "s=-\r\n"
405 "t=0 0\r\n"
406 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
407 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
408 "c=IN IP4 74.125.127.126\r\n"
409 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
410 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
411 "generation 2\r\n"
412 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
413 "generation 2\r\n"
414 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
415 "generation 2\r\n"
416 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
417 "generation 2\r\n"
418 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
419 "raddr 192.168.1.5 rport 2346 "
420 "generation 2\r\n"
421 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
422 "raddr 192.168.1.5 rport 2348 "
423 "generation 2\r\n"
424 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
425 "a=mid:audio_content_name\r\n"
426 "a=sendrecv\r\n"
427 "a=rtcp-mux\r\n"
428 "a=rtcp-rsize\r\n"
429 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
430 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
431 "dummy_session_params\r\n"
432 "a=rtpmap:111 opus/48000/2\r\n"
433 "a=rtpmap:103 ISAC/16000\r\n"
434 "a=rtpmap:104 ISAC/32000\r\n"
435 "a=ssrc:1 cname:stream_1_cname\r\n"
436 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
437 "a=ssrc:1 mslabel:local_stream_1\r\n"
438 "a=ssrc:1 label:audio_track_id_1\r\n"
439 "a=ssrc:4 cname:stream_2_cname\r\n"
440 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
441 "a=ssrc:4 mslabel:local_stream_2\r\n"
442 "a=ssrc:4 label:audio_track_id_2\r\n"
443 "m=video 3457 RTP/SAVPF 120\r\n"
444 "c=IN IP4 74.125.224.39\r\n"
445 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
446 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
447 "generation 2\r\n"
448 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
449 "generation 2\r\n"
450 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
451 "generation 2\r\n"
452 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
453 "generation 2\r\n"
454 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
455 "generation 2\r\n"
456 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
457 "generation 2\r\n"
458 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
459 "a=mid:video_content_name\r\n"
460 "a=sendrecv\r\n"
461 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
462 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
463 "a=rtpmap:120 VP8/90000\r\n"
464 "a=ssrc-group:FEC 2 3\r\n"
465 "a=ssrc:2 cname:stream_1_cname\r\n"
466 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
467 "a=ssrc:2 mslabel:local_stream_1\r\n"
468 "a=ssrc:2 label:video_track_id_1\r\n"
469 "a=ssrc:3 cname:stream_1_cname\r\n"
470 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
471 "a=ssrc:3 mslabel:local_stream_1\r\n"
472 "a=ssrc:3 label:video_track_id_1\r\n"
473 "a=ssrc:5 cname:stream_2_cname\r\n"
474 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
475 "a=ssrc:5 mslabel:local_stream_2\r\n"
476 "a=ssrc:5 label:video_track_id_2\r\n"
477 "a=ssrc:6 cname:stream_2_cname\r\n"
478 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
479 "a=ssrc:6 mslabel:local_stream_2\r\n"
480 "a=ssrc:6 label:video_track_id_3\r\n";
481
Taylor Brandstetter5de6b752016-03-09 17:02:30 -0800482// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
483// tracks, but with the unified plan "a=msid" attribute.
484static const char kPlanBSdpFullStringWithMsid[] =
485 "v=0\r\n"
486 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
487 "s=-\r\n"
488 "t=0 0\r\n"
489 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
490 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
491 "c=IN IP4 74.125.127.126\r\n"
492 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
493 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
494 "generation 2\r\n"
495 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
496 "generation 2\r\n"
497 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
498 "generation 2\r\n"
499 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
500 "generation 2\r\n"
501 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
502 "raddr 192.168.1.5 rport 2346 "
503 "generation 2\r\n"
504 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
505 "raddr 192.168.1.5 rport 2348 "
506 "generation 2\r\n"
507 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
508 "a=mid:audio_content_name\r\n"
509 "a=msid:local_stream_1 audio_track_id_1\r\n"
510 "a=sendrecv\r\n"
511 "a=rtcp-mux\r\n"
512 "a=rtcp-rsize\r\n"
513 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
514 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
515 "dummy_session_params\r\n"
516 "a=rtpmap:111 opus/48000/2\r\n"
517 "a=rtpmap:103 ISAC/16000\r\n"
518 "a=rtpmap:104 ISAC/32000\r\n"
519 "a=ssrc:1 cname:stream_1_cname\r\n"
520 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
521 "a=ssrc:1 mslabel:local_stream_1\r\n"
522 "a=ssrc:1 label:audio_track_id_1\r\n"
523 "a=ssrc:4 cname:stream_2_cname\r\n"
524 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
525 "a=ssrc:4 mslabel:local_stream_2\r\n"
526 "a=ssrc:4 label:audio_track_id_2\r\n"
527 "m=video 3457 RTP/SAVPF 120\r\n"
528 "c=IN IP4 74.125.224.39\r\n"
529 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
530 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
531 "generation 2\r\n"
532 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
533 "generation 2\r\n"
534 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
535 "generation 2\r\n"
536 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
537 "generation 2\r\n"
538 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
539 "generation 2\r\n"
540 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
541 "generation 2\r\n"
542 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
543 "a=mid:video_content_name\r\n"
544 "a=msid:local_stream_1 video_track_id_1\r\n"
545 "a=sendrecv\r\n"
546 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
547 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
548 "a=rtpmap:120 VP8/90000\r\n"
549 "a=ssrc-group:FEC 2 3\r\n"
550 "a=ssrc:2 cname:stream_1_cname\r\n"
551 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
552 "a=ssrc:2 mslabel:local_stream_1\r\n"
553 "a=ssrc:2 label:video_track_id_1\r\n"
554 "a=ssrc:3 cname:stream_1_cname\r\n"
555 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
556 "a=ssrc:3 mslabel:local_stream_1\r\n"
557 "a=ssrc:3 label:video_track_id_1\r\n"
558 "a=ssrc:5 cname:stream_2_cname\r\n"
559 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
560 "a=ssrc:5 mslabel:local_stream_2\r\n"
561 "a=ssrc:5 label:video_track_id_2\r\n"
562 "a=ssrc:6 cname:stream_2_cname\r\n"
563 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
564 "a=ssrc:6 mslabel:local_stream_2\r\n"
565 "a=ssrc:6 label:video_track_id_3\r\n";
566
deadbeef9d3584c2016-02-16 17:54:10 -0800567// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
568// tracks.
569static const char kUnifiedPlanSdpFullString[] =
570 "v=0\r\n"
571 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
572 "s=-\r\n"
573 "t=0 0\r\n"
574 "a=msid-semantic: WMS local_stream_1\r\n"
575 // Audio track 1, stream 1 (with candidates).
576 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
577 "c=IN IP4 74.125.127.126\r\n"
578 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
579 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
580 "generation 2\r\n"
581 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
582 "generation 2\r\n"
583 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
584 "generation 2\r\n"
585 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
586 "generation 2\r\n"
587 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
588 "raddr 192.168.1.5 rport 2346 "
589 "generation 2\r\n"
590 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
591 "raddr 192.168.1.5 rport 2348 "
592 "generation 2\r\n"
593 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
594 "a=mid:audio_content_name\r\n"
595 "a=msid:local_stream_1 audio_track_id_1\r\n"
596 "a=sendrecv\r\n"
597 "a=rtcp-mux\r\n"
598 "a=rtcp-rsize\r\n"
599 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
600 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
601 "dummy_session_params\r\n"
602 "a=rtpmap:111 opus/48000/2\r\n"
603 "a=rtpmap:103 ISAC/16000\r\n"
604 "a=rtpmap:104 ISAC/32000\r\n"
605 "a=ssrc:1 cname:stream_1_cname\r\n"
606 // Video track 1, stream 1 (with candidates).
607 "m=video 3457 RTP/SAVPF 120\r\n"
608 "c=IN IP4 74.125.224.39\r\n"
609 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
610 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
611 "generation 2\r\n"
612 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
613 "generation 2\r\n"
614 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
615 "generation 2\r\n"
616 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
617 "generation 2\r\n"
618 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
619 "generation 2\r\n"
620 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
621 "generation 2\r\n"
622 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
623 "a=mid:video_content_name\r\n"
624 "a=msid:local_stream_1 video_track_id_1\r\n"
625 "a=sendrecv\r\n"
626 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
627 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
628 "a=rtpmap:120 VP8/90000\r\n"
629 "a=ssrc-group:FEC 2 3\r\n"
630 "a=ssrc:2 cname:stream_1_cname\r\n"
631 "a=ssrc:3 cname:stream_1_cname\r\n"
632 // Audio track 2, stream 2.
633 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
634 "c=IN IP4 0.0.0.0\r\n"
635 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
636 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
637 "a=mid:audio_content_name_2\r\n"
638 "a=msid:local_stream_2 audio_track_id_2\r\n"
639 "a=sendrecv\r\n"
640 "a=rtcp-mux\r\n"
641 "a=rtcp-rsize\r\n"
642 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
643 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
644 "dummy_session_params\r\n"
645 "a=rtpmap:111 opus/48000/2\r\n"
646 "a=rtpmap:103 ISAC/16000\r\n"
647 "a=rtpmap:104 ISAC/32000\r\n"
648 "a=ssrc:4 cname:stream_2_cname\r\n"
649 // Video track 2, stream 2.
650 "m=video 9 RTP/SAVPF 120\r\n"
651 "c=IN IP4 0.0.0.0\r\n"
652 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
653 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
654 "a=mid:video_content_name_2\r\n"
655 "a=msid:local_stream_2 video_track_id_2\r\n"
656 "a=sendrecv\r\n"
657 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
658 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
659 "a=rtpmap:120 VP8/90000\r\n"
660 "a=ssrc:5 cname:stream_2_cname\r\n"
661 // Video track 3, stream 2.
662 "m=video 9 RTP/SAVPF 120\r\n"
663 "c=IN IP4 0.0.0.0\r\n"
664 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
665 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
666 "a=mid:video_content_name_3\r\n"
667 "a=msid:local_stream_2 video_track_id_3\r\n"
668 "a=sendrecv\r\n"
669 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
670 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
671 "a=rtpmap:120 VP8/90000\r\n"
672 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000673
674// One candidate reference string as per W3c spec.
675// candidate:<blah> not a=candidate:<blah>CRLF
676static const char kRawCandidate[] =
677 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
678// One candidate reference string.
679static const char kSdpOneCandidate[] =
680 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
681 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000682
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000683static const char kSdpTcpActiveCandidate[] =
684 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
685 "tcptype active generation 2";
686static const char kSdpTcpPassiveCandidate[] =
687 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
688 "tcptype passive generation 2";
689static const char kSdpTcpSOCandidate[] =
690 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
691 "tcptype so generation 2";
692static const char kSdpTcpInvalidCandidate[] =
693 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
694 "tcptype invalid generation 2";
695
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000696// One candidate reference string with IPV6 address.
697static const char kRawIPV6Candidate[] =
698 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 12:04:36 -0700699 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000700
701// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800702static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000703 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800704 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000705
706// Session id and version
707static const char kSessionId[] = "18446744069414584320";
708static const char kSessionVersion[] = "18446462598732840960";
709
deadbeef9d3584c2016-02-16 17:54:10 -0800710// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000711static const char kIceOption1[] = "iceoption1";
712static const char kIceOption2[] = "iceoption2";
713static const char kIceOption3[] = "iceoption3";
714
deadbeef9d3584c2016-02-16 17:54:10 -0800715// ICE ufrags/passwords.
716static const char kUfragVoice[] = "ufrag_voice";
717static const char kPwdVoice[] = "pwd_voice";
718static const char kUfragVideo[] = "ufrag_video";
719static const char kPwdVideo[] = "pwd_video";
720static const char kUfragData[] = "ufrag_data";
721static const char kPwdData[] = "pwd_data";
722
723// Extra ufrags/passwords for extra unified plan m= sections.
724static const char kUfragVoice2[] = "ufrag_voice_2";
725static const char kPwdVoice2[] = "pwd_voice_2";
726static const char kUfragVideo2[] = "ufrag_video_2";
727static const char kPwdVideo2[] = "pwd_video_2";
728static const char kUfragVideo3[] = "ufrag_video_3";
729static const char kPwdVideo3[] = "pwd_video_3";
730
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000731// Content name
732static const char kAudioContentName[] = "audio_content_name";
733static const char kVideoContentName[] = "video_content_name";
734static const char kDataContentName[] = "data_content_name";
735
deadbeef9d3584c2016-02-16 17:54:10 -0800736// Extra content names for extra unified plan m= sections.
737static const char kAudioContentName2[] = "audio_content_name_2";
738static const char kVideoContentName2[] = "video_content_name_2";
739static const char kVideoContentName3[] = "video_content_name_3";
740
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000741// MediaStream 1
742static const char kStreamLabel1[] = "local_stream_1";
743static const char kStream1Cname[] = "stream_1_cname";
744static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200745static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000746static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800747static const uint32_t kVideoTrack1Ssrc1 = 2;
748static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000749
750// MediaStream 2
751static const char kStreamLabel2[] = "local_stream_2";
752static const char kStream2Cname[] = "stream_2_cname";
753static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200754static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800755static const char kVideoTrackId2[] = "video_track_id_2";
756static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000757static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800758static const uint32_t kVideoTrack3Ssrc = 6;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000759
760// DataChannel
761static const char kDataChannelLabel[] = "data_channel";
762static const char kDataChannelMsid[] = "data_channeld0";
763static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200764static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000765
766// Candidate
767static const char kDummyMid[] = "dummy_mid";
768static const int kDummyIndex = 123;
769
770// Misc
771static const char kDummyString[] = "dummy";
772
773// Helper functions
774
775static bool SdpDeserialize(const std::string& message,
776 JsepSessionDescription* jdesc) {
777 return webrtc::SdpDeserialize(message, jdesc, NULL);
778}
779
780static bool SdpDeserializeCandidate(const std::string& message,
781 JsepIceCandidate* candidate) {
782 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
783}
784
785// Add some extra |newlines| to the |message| after |line|.
786static void InjectAfter(const std::string& line,
787 const std::string& newlines,
788 std::string* message) {
789 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000790 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000791 tmp.c_str(), tmp.length(), message);
792}
793
794static void Replace(const std::string& line,
795 const std::string& newlines,
796 std::string* message) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000797 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000798 newlines.c_str(), newlines.length(), message);
799}
800
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000801// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
802// message.
803static void ExpectParseFailure(const std::string& bad_sdp,
804 const std::string& bad_part) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000805 JsepSessionDescription desc(kDummyString);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000806 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000807 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000808 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000809 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
810}
811
812// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
813static void ExpectParseFailure(const char* good_part, const char* bad_part) {
814 std::string bad_sdp = kSdpFullString;
815 Replace(good_part, bad_part, &bad_sdp);
816 ExpectParseFailure(bad_sdp, bad_part);
817}
818
819// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
820static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
821 const std::string& newlines,
822 const std::string& bad_part) {
823 std::string bad_sdp = kSdpFullString;
824 InjectAfter(injectpoint, newlines, &bad_sdp);
825 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000826}
827
828static void ReplaceDirection(cricket::MediaContentDirection direction,
829 std::string* message) {
830 std::string new_direction;
831 switch (direction) {
832 case cricket::MD_INACTIVE:
833 new_direction = "a=inactive";
834 break;
835 case cricket::MD_SENDONLY:
836 new_direction = "a=sendonly";
837 break;
838 case cricket::MD_RECVONLY:
839 new_direction = "a=recvonly";
840 break;
841 case cricket::MD_SENDRECV:
842 default:
843 new_direction = "a=sendrecv";
844 break;
845 }
846 Replace("a=sendrecv", new_direction, message);
847}
848
849static void ReplaceRejected(bool audio_rejected, bool video_rejected,
850 std::string* message) {
851 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800852 Replace("m=audio 9", "m=audio 0", message);
853 Replace(kAttributeIceUfragVoice, "", message);
854 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000855 }
856 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800857 Replace("m=video 9", "m=video 0", message);
858 Replace(kAttributeIceUfragVideo, "", message);
859 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000860 }
861}
862
863// WebRtcSdpTest
864
865class WebRtcSdpTest : public testing::Test {
866 public:
867 WebRtcSdpTest()
868 : jdesc_(kDummyString) {
phoglund37ebcf02016-01-08 05:04:57 -0800869#ifdef WEBRTC_ANDROID
870 webrtc::InitializeAndroidObjects();
871#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000872 // AudioContentDescription
873 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -0800874 StreamParams audio_stream;
875 audio_stream.id = kAudioTrackId1;
876 audio_stream.cname = kStream1Cname;
877 audio_stream.sync_label = kStreamLabel1;
878 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
879 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 11:04:53 -0700880 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
881 audio_desc_->set_connection_address(audio_addr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000882 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
883
884 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -0800885 video_desc_ = CreateVideoContentDescription();
886 StreamParams video_stream;
887 video_stream.id = kVideoTrackId1;
888 video_stream.cname = kStream1Cname;
889 video_stream.sync_label = kStreamLabel1;
890 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
891 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
892 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
893 video_stream.ssrc_groups.push_back(ssrc_group);
894 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 11:04:53 -0700895 rtc::SocketAddress video_addr("74.125.224.39", 3457);
896 video_desc_->set_connection_address(video_addr);
deadbeef9d3584c2016-02-16 17:54:10 -0800897 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000898
899 // TransportInfo
deadbeef9d3584c2016-02-16 17:54:10 -0800900 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
901 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice))));
902 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
903 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000904
905 // v4 host
906 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000907 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000908 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000909 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
910 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000911 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000912 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000913 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
914 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000916 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000917 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
918 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000920 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000921 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
922 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000923
924 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000925 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000926 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
927 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000928 cricket::LOCAL_PORT_TYPE,
929 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000930 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000931 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
932 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000933 cricket::LOCAL_PORT_TYPE,
934 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000935 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000936 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
937 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000938 cricket::LOCAL_PORT_TYPE,
939 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000940 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000941 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
942 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000943 cricket::LOCAL_PORT_TYPE,
944 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945
946 // stun
947 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000948 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
949 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000950 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
951 address_stun, kCandidatePriority, "", "",
952 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000953 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000954 candidate9.set_related_address(rel_address_stun);
955
956 address_stun.SetPort(port_stun++);
957 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000958 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
959 address_stun, kCandidatePriority, "", "",
960 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000961 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000962 candidate10.set_related_address(rel_address_stun);
963
964 // relay
965 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000966 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000967 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
968 address_relay, kCandidatePriority, "", "",
969 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000970 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000971 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000972 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
973 address_relay, kCandidatePriority, "", "",
974 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000975 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000976
977 // voice
978 candidates_.push_back(candidate1);
979 candidates_.push_back(candidate2);
980 candidates_.push_back(candidate5);
981 candidates_.push_back(candidate6);
982 candidates_.push_back(candidate9);
983 candidates_.push_back(candidate10);
984
985 // video
986 candidates_.push_back(candidate3);
987 candidates_.push_back(candidate4);
988 candidates_.push_back(candidate7);
989 candidates_.push_back(candidate8);
990 candidates_.push_back(candidate11);
991 candidates_.push_back(candidate12);
992
993 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"),
994 0, candidate1));
995
996 // Set up JsepSessionDescription.
997 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
998 std::string mline_id;
999 int mline_index = 0;
1000 for (size_t i = 0; i< candidates_.size(); ++i) {
1001 // In this test, the audio m line index will be 0, and the video m line
1002 // will be 1.
1003 bool is_video = (i > 5);
1004 mline_id = is_video ? "video_content_name" : "audio_content_name";
1005 mline_index = is_video ? 1 : 0;
1006 JsepIceCandidate jice(mline_id,
1007 mline_index,
1008 candidates_.at(i));
1009 jdesc_.AddCandidate(&jice);
1010 }
1011 }
1012
deadbeef25ed4352016-12-12 18:37:36 -08001013 // Turns the existing reference description into a description using
1014 // a=bundle-only. This means no transport attributes and a 0 port value on
1015 // the m= sections not associated with the BUNDLE-tag.
1016 void MakeBundleOnlyDescription() {
1017 // Remove video candidates. JsepSessionDescription doesn't make it
1018 // simple.
1019 const IceCandidateCollection* video_candidates_collection =
1020 jdesc_.candidates(1);
1021 ASSERT_NE(nullptr, video_candidates_collection);
1022 std::vector<cricket::Candidate> video_candidates;
1023 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1024 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1025 c.set_transport_name("video_content_name");
1026 video_candidates.push_back(c);
1027 }
1028 jdesc_.RemoveCandidates(video_candidates);
1029
1030 // And the rest of the transport attributes.
1031 desc_.transport_infos()[1].description.ice_ufrag.clear();
1032 desc_.transport_infos()[1].description.ice_pwd.clear();
1033 desc_.transport_infos()[1].description.connection_role =
1034 cricket::CONNECTIONROLE_NONE;
1035
1036 // Set bundle-only flag.
1037 desc_.contents()[1].bundle_only = true;
1038
1039 // Add BUNDLE group.
1040 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1041 group.AddContentName(kAudioContentName);
1042 group.AddContentName(kVideoContentName);
1043 desc_.AddGroup(group);
1044
1045 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1046 jdesc_.session_version()));
1047 }
1048
deadbeef9d3584c2016-02-16 17:54:10 -08001049 // Turns the existing reference description into a plan B description,
1050 // with 2 audio tracks and 3 video tracks.
1051 void MakePlanBDescription() {
1052 audio_desc_ = static_cast<AudioContentDescription*>(audio_desc_->Copy());
1053 video_desc_ = static_cast<VideoContentDescription*>(video_desc_->Copy());
1054
1055 StreamParams audio_track_2;
1056 audio_track_2.id = kAudioTrackId2;
1057 audio_track_2.cname = kStream2Cname;
1058 audio_track_2.sync_label = kStreamLabel2;
1059 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1060 audio_desc_->AddStream(audio_track_2);
1061
1062 StreamParams video_track_2;
1063 video_track_2.id = kVideoTrackId2;
1064 video_track_2.cname = kStream2Cname;
1065 video_track_2.sync_label = kStreamLabel2;
1066 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1067 video_desc_->AddStream(video_track_2);
1068
1069 StreamParams video_track_3;
1070 video_track_3.id = kVideoTrackId3;
1071 video_track_3.cname = kStream2Cname;
1072 video_track_3.sync_label = kStreamLabel2;
1073 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1074 video_desc_->AddStream(video_track_3);
1075
1076 desc_.RemoveContentByName(kAudioContentName);
1077 desc_.RemoveContentByName(kVideoContentName);
1078 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1079 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1080
1081 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1082 jdesc_.session_version()));
1083 }
1084
1085 // Turns the existing reference description into a unified plan description,
1086 // with 2 audio tracks and 3 video tracks.
1087 void MakeUnifiedPlanDescription() {
1088 // Audio track 2.
1089 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1090 StreamParams audio_track_2;
1091 audio_track_2.id = kAudioTrackId2;
1092 audio_track_2.cname = kStream2Cname;
1093 audio_track_2.sync_label = kStreamLabel2;
1094 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1095 audio_desc_2->AddStream(audio_track_2);
1096 desc_.AddContent(kAudioContentName2, NS_JINGLE_RTP, audio_desc_2);
1097 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1098 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
deadbeef9d3584c2016-02-16 17:54:10 -08001099 // Video track 2, in stream 2.
1100 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1101 StreamParams video_track_2;
1102 video_track_2.id = kVideoTrackId2;
1103 video_track_2.cname = kStream2Cname;
1104 video_track_2.sync_label = kStreamLabel2;
1105 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1106 video_desc_2->AddStream(video_track_2);
1107 desc_.AddContent(kVideoContentName2, NS_JINGLE_RTP, video_desc_2);
1108 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1109 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2))));
1110
1111 // Video track 3, in stream 2.
1112 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1113 StreamParams video_track_3;
1114 video_track_3.id = kVideoTrackId3;
1115 video_track_3.cname = kStream2Cname;
1116 video_track_3.sync_label = kStreamLabel2;
1117 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1118 video_desc_3->AddStream(video_track_3);
1119 desc_.AddContent(kVideoContentName3, NS_JINGLE_RTP, video_desc_3);
1120 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1121 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3))));
1122
1123 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1124 jdesc_.session_version()));
1125 }
1126
1127 // Creates an audio content description with no streams, and some default
1128 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001129 AudioContentDescription* CreateAudioContentDescription() {
1130 AudioContentDescription* audio = new AudioContentDescription();
1131 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -08001132 audio->set_rtcp_reduced_size(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001133 audio->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_32",
1134 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1135 "dummy_session_params"));
1136 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef67cf2c12016-04-13 10:07:16 -07001137 AudioCodec opus(111, "opus", 48000, 0, 2);
deadbeef9d3584c2016-02-16 17:54:10 -08001138 audio->AddCodec(opus);
ossue1405ad2017-01-23 08:55:48 -08001139 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1140 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001141 return audio;
1142 }
1143
deadbeef9d3584c2016-02-16 17:54:10 -08001144 // Creates a video content description with no streams, and some default
1145 // configuration.
1146 VideoContentDescription* CreateVideoContentDescription() {
1147 VideoContentDescription* video = new VideoContentDescription();
1148 video->AddCrypto(CryptoParams(
1149 1, "AES_CM_128_HMAC_SHA1_80",
1150 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1151 video->set_protocol(cricket::kMediaProtocolSavpf);
1152 video->AddCodec(
perkj26752742016-10-24 01:21:16 -07001153 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-16 17:54:10 -08001154 return video;
1155 }
1156
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001157 template <class MCD>
1158 void CompareMediaContentDescription(const MCD* cd1,
1159 const MCD* cd2) {
1160 // type
1161 EXPECT_EQ(cd1->type(), cd1->type());
1162
1163 // content direction
1164 EXPECT_EQ(cd1->direction(), cd2->direction());
1165
1166 // rtcp_mux
1167 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1168
deadbeef13871492015-12-09 12:37:51 -08001169 // rtcp_reduced_size
1170 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1171
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001172 // cryptos
1173 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1174 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1175 ADD_FAILURE();
1176 return;
1177 }
1178 for (size_t i = 0; i< cd1->cryptos().size(); ++i) {
1179 const CryptoParams c1 = cd1->cryptos().at(i);
1180 const CryptoParams c2 = cd2->cryptos().at(i);
1181 EXPECT_TRUE(c1.Matches(c2));
1182 EXPECT_EQ(c1.key_params, c2.key_params);
1183 EXPECT_EQ(c1.session_params, c2.session_params);
1184 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001185
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001186 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001187 // Use an equivalence class here, for old and new versions of the
1188 // protocol description.
1189 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:35 +00001190 || cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp
1191 || cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
1192 const bool cd2_is_also_dtls_sctp =
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001193 cd2->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:35 +00001194 || cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp
1195 || cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
1196 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001197 } else {
1198 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1199 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001200
1201 // codecs
1202 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1203
1204 // bandwidth
1205 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1206
1207 // streams
1208 EXPECT_EQ(cd1->streams(), cd2->streams());
1209
1210 // extmap
1211 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1212 cd2->rtp_header_extensions().size());
1213 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 11:24:55 -07001214 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1215 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001216 EXPECT_EQ(ext1.uri, ext2.uri);
1217 EXPECT_EQ(ext1.id, ext2.id);
jbauch5869f502017-06-29 12:31:36 -07001218 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001219 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001220 }
1221
zstein4b2e0822017-02-17 19:48:38 -08001222 void CompareDataContentDescription(const DataContentDescription* dcd1,
1223 const DataContentDescription* dcd2) {
1224 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
1225 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
1226 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001227
1228 void CompareSessionDescription(const SessionDescription& desc1,
1229 const SessionDescription& desc2) {
1230 // Compare content descriptions.
1231 if (desc1.contents().size() != desc2.contents().size()) {
1232 ADD_FAILURE();
1233 return;
1234 }
1235 for (size_t i = 0 ; i < desc1.contents().size(); ++i) {
1236 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1237 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-12 18:37:36 -08001238 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001239 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-12 18:37:36 -08001240 EXPECT_EQ(c1.type, c2.type);
1241 EXPECT_EQ(c1.rejected, c2.rejected);
1242 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001243
1244 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1245 if (IsAudioContent(&c1)) {
1246 const AudioContentDescription* acd1 =
1247 static_cast<const AudioContentDescription*>(c1.description);
1248 const AudioContentDescription* acd2 =
1249 static_cast<const AudioContentDescription*>(c2.description);
1250 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1251 }
1252
1253 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1254 if (IsVideoContent(&c1)) {
1255 const VideoContentDescription* vcd1 =
1256 static_cast<const VideoContentDescription*>(c1.description);
1257 const VideoContentDescription* vcd2 =
1258 static_cast<const VideoContentDescription*>(c2.description);
1259 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1260 }
1261
1262 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
1263 if (IsDataContent(&c1)) {
1264 const DataContentDescription* dcd1 =
1265 static_cast<const DataContentDescription*>(c1.description);
1266 const DataContentDescription* dcd2 =
1267 static_cast<const DataContentDescription*>(c2.description);
zstein4b2e0822017-02-17 19:48:38 -08001268 CompareDataContentDescription(dcd1, dcd2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001269 }
1270 }
1271
1272 // group
1273 const cricket::ContentGroups groups1 = desc1.groups();
1274 const cricket::ContentGroups groups2 = desc2.groups();
1275 EXPECT_EQ(groups1.size(), groups1.size());
1276 if (groups1.size() != groups2.size()) {
1277 ADD_FAILURE();
1278 return;
1279 }
1280 for (size_t i = 0; i < groups1.size(); ++i) {
1281 const cricket::ContentGroup group1 = groups1.at(i);
1282 const cricket::ContentGroup group2 = groups2.at(i);
1283 EXPECT_EQ(group1.semantics(), group2.semantics());
1284 const cricket::ContentNames names1 = group1.content_names();
1285 const cricket::ContentNames names2 = group2.content_names();
1286 EXPECT_EQ(names1.size(), names2.size());
1287 if (names1.size() != names2.size()) {
1288 ADD_FAILURE();
1289 return;
1290 }
1291 cricket::ContentNames::const_iterator iter1 = names1.begin();
1292 cricket::ContentNames::const_iterator iter2 = names2.begin();
1293 while (iter1 != names1.end()) {
1294 EXPECT_EQ(*iter1++, *iter2++);
1295 }
1296 }
1297
1298 // transport info
1299 const cricket::TransportInfos transports1 = desc1.transport_infos();
1300 const cricket::TransportInfos transports2 = desc2.transport_infos();
1301 EXPECT_EQ(transports1.size(), transports2.size());
1302 if (transports1.size() != transports2.size()) {
1303 ADD_FAILURE();
1304 return;
1305 }
1306 for (size_t i = 0; i < transports1.size(); ++i) {
1307 const cricket::TransportInfo transport1 = transports1.at(i);
1308 const cricket::TransportInfo transport2 = transports2.at(i);
1309 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001310 EXPECT_EQ(transport1.description.ice_ufrag,
1311 transport2.description.ice_ufrag);
1312 EXPECT_EQ(transport1.description.ice_pwd,
1313 transport2.description.ice_pwd);
1314 if (transport1.description.identity_fingerprint) {
1315 EXPECT_EQ(*transport1.description.identity_fingerprint,
1316 *transport2.description.identity_fingerprint);
1317 } else {
1318 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1319 transport2.description.identity_fingerprint.get());
1320 }
1321 EXPECT_EQ(transport1.description.transport_options,
1322 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001323 }
deadbeefc80741f2015-10-22 13:14:45 -07001324
1325 // global attributes
1326 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001327 }
1328
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001329 bool CompareSessionDescription(
1330 const JsepSessionDescription& desc1,
1331 const JsepSessionDescription& desc2) {
1332 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1333 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1334 CompareSessionDescription(*desc1.description(), *desc2.description());
1335 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1336 return false;
1337 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1338 const IceCandidateCollection* cc1 = desc1.candidates(i);
1339 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-12 18:37:36 -08001340 if (cc1->count() != cc2->count()) {
1341 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001342 return false;
deadbeef25ed4352016-12-12 18:37:36 -08001343 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001344 for (size_t j = 0; j < cc1->count(); ++j) {
1345 const IceCandidateInterface* c1 = cc1->at(j);
1346 const IceCandidateInterface* c2 = cc2->at(j);
1347 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1348 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1349 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1350 }
1351 }
1352 return true;
1353 }
1354
1355 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1356 // them with invalid keywords so that the parser will just ignore them.
1357 bool RemoveCandidateUfragPwd(std::string* sdp) {
1358 const char ice_ufrag[] = "a=ice-ufrag";
1359 const char ice_ufragx[] = "a=xice-ufrag";
1360 const char ice_pwd[] = "a=ice-pwd";
1361 const char ice_pwdx[] = "a=xice-pwd";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001362 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001363 ice_ufragx, strlen(ice_ufragx), sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001364 rtc::replace_substrs(ice_pwd, strlen(ice_pwd),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001365 ice_pwdx, strlen(ice_pwdx), sdp);
1366 return true;
1367 }
1368
1369 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
1370 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, int mline_index,
1371 const std::string& ufrag, const std::string& pwd) {
1372 std::string content_name;
1373 if (mline_index == 0) {
1374 content_name = kAudioContentName;
1375 } else if (mline_index == 1) {
1376 content_name = kVideoContentName;
1377 } else {
nissec80e7412017-01-11 05:56:46 -08001378 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001379 }
1380 TransportInfo transport_info(
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001381 content_name, TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001382 SessionDescription* desc =
1383 const_cast<SessionDescription*>(jdesc->description());
1384 desc->RemoveTransportInfoByName(content_name);
1385 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
1386 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1387 const IceCandidateCollection* cc = jdesc_.candidates(i);
1388 for (size_t j = 0; j < cc->count(); ++j) {
1389 if (cc->at(j)->sdp_mline_index() == mline_index) {
1390 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(
1391 ufrag);
1392 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(
1393 pwd);
1394 }
1395 }
1396 }
1397 return true;
1398 }
1399
1400 void AddIceOptions(const std::string& content_name,
1401 const std::vector<std::string>& transport_options) {
1402 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1403 cricket::TransportInfo transport_info =
1404 *(desc_.GetTransportInfoByName(content_name));
1405 desc_.RemoveTransportInfoByName(content_name);
1406 transport_info.description.transport_options = transport_options;
1407 desc_.AddTransportInfo(transport_info);
1408 }
1409
deadbeef3f7219b2015-12-28 15:17:14 -08001410 void SetIceUfragPwd(const std::string& content_name,
1411 const std::string& ice_ufrag,
1412 const std::string& ice_pwd) {
1413 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1414 cricket::TransportInfo transport_info =
1415 *(desc_.GetTransportInfoByName(content_name));
1416 desc_.RemoveTransportInfoByName(content_name);
1417 transport_info.description.ice_ufrag = ice_ufrag;
1418 transport_info.description.ice_pwd = ice_pwd;
1419 desc_.AddTransportInfo(transport_info);
1420 }
1421
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001422 void AddFingerprint() {
1423 desc_.RemoveTransportInfoByName(kAudioContentName);
1424 desc_.RemoveTransportInfoByName(kVideoContentName);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001425 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001426 kIdentityDigest,
1427 sizeof(kIdentityDigest));
deadbeef46eed762016-01-28 13:24:37 -08001428 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1429 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001430 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1431 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001432 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1433 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1434 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001435 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1436 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001437 cricket::CONNECTIONROLE_NONE, &fingerprint))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001438 }
1439
jbauch5869f502017-06-29 12:31:36 -07001440 void AddExtmap(bool encrypted) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001441 audio_desc_ = static_cast<AudioContentDescription*>(
1442 audio_desc_->Copy());
1443 video_desc_ = static_cast<VideoContentDescription*>(
1444 video_desc_->Copy());
jbauch5869f502017-06-29 12:31:36 -07001445 audio_desc_->AddRtpHeaderExtension(
1446 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1447 video_desc_->AddRtpHeaderExtension(
1448 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001449 desc_.RemoveContentByName(kAudioContentName);
1450 desc_.RemoveContentByName(kVideoContentName);
1451 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1452 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1453 }
1454
1455 void RemoveCryptos() {
1456 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1457 video_desc_->set_cryptos(std::vector<CryptoParams>());
1458 }
1459
1460 bool TestSerializeDirection(cricket::MediaContentDirection direction) {
1461 audio_desc_->set_direction(direction);
1462 video_desc_->set_direction(direction);
1463 std::string new_sdp = kSdpFullString;
1464 ReplaceDirection(direction, &new_sdp);
1465
1466 if (!jdesc_.Initialize(desc_.Copy(),
1467 jdesc_.session_id(),
1468 jdesc_.session_version())) {
1469 return false;
1470 }
deadbeef9d3584c2016-02-16 17:54:10 -08001471 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001472 EXPECT_EQ(new_sdp, message);
1473 return true;
1474 }
1475
1476 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
1477 audio_desc_ = static_cast<AudioContentDescription*>(
1478 audio_desc_->Copy());
1479 video_desc_ = static_cast<VideoContentDescription*>(
1480 video_desc_->Copy());
zhihuang38989e52017-03-21 11:04:53 -07001481
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001482 desc_.RemoveContentByName(kAudioContentName);
1483 desc_.RemoveContentByName(kVideoContentName);
1484 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1485 audio_desc_);
1486 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1487 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001488 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1489 audio_rejected ? "" : kPwdVoice);
1490 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1491 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001492
1493 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001494 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1495
deadbeef3f7219b2015-12-28 15:17:14 -08001496 JsepSessionDescription jdesc_no_candidates(kDummyString);
zhihuang38989e52017-03-21 11:04:53 -07001497 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
deadbeef9d3584c2016-02-16 17:54:10 -08001498 std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001499 EXPECT_EQ(new_sdp, message);
1500 return true;
1501 }
1502
zstein4b2e0822017-02-17 19:48:38 -08001503 void AddSctpDataChannel(bool use_sctpmap) {
kwibergd1fe2812016-04-27 06:47:29 -07001504 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001505 data_desc_ = data.get();
zstein4b2e0822017-02-17 19:48:38 -08001506 data_desc_->set_use_sctpmap(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001507 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
solenberg9fa49752016-10-08 13:02:44 -07001508 DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07001509 cricket::kGoogleSctpDataCodecName);
wu@webrtc.org78187522013-10-07 23:32:02 +00001510 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1511 data_desc_->AddCodec(codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001512 desc_.AddContent(kDataContentName, NS_JINGLE_DRAFT_SCTP, data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001513 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1514 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001515 }
1516
1517 void AddRtpDataChannel() {
kwibergd1fe2812016-04-27 06:47:29 -07001518 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001519 data_desc_ = data.get();
1520
deadbeef67cf2c12016-04-13 10:07:16 -07001521 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001522 StreamParams data_stream;
1523 data_stream.id = kDataChannelMsid;
1524 data_stream.cname = kDataChannelCname;
1525 data_stream.sync_label = kDataChannelLabel;
1526 data_stream.ssrcs.push_back(kDataChannelSsrc);
1527 data_desc_->AddStream(data_stream);
1528 data_desc_->AddCrypto(CryptoParams(
1529 1, "AES_CM_128_HMAC_SHA1_80",
1530 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
1531 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
1532 desc_.AddContent(kDataContentName, NS_JINGLE_RTP, data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001533 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1534 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001535 }
1536
1537 bool TestDeserializeDirection(cricket::MediaContentDirection direction) {
1538 std::string new_sdp = kSdpFullString;
1539 ReplaceDirection(direction, &new_sdp);
1540 JsepSessionDescription new_jdesc(kDummyString);
1541
1542 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1543
1544 audio_desc_->set_direction(direction);
1545 video_desc_->set_direction(direction);
1546 if (!jdesc_.Initialize(desc_.Copy(),
1547 jdesc_.session_id(),
1548 jdesc_.session_version())) {
1549 return false;
1550 }
1551 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1552 return true;
1553 }
1554
1555 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001556 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001557 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1558 JsepSessionDescription new_jdesc(JsepSessionDescription::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001559 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001560
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001561 audio_desc_ = static_cast<AudioContentDescription*>(
1562 audio_desc_->Copy());
1563 video_desc_ = static_cast<VideoContentDescription*>(
1564 video_desc_->Copy());
1565 desc_.RemoveContentByName(kAudioContentName);
1566 desc_.RemoveContentByName(kVideoContentName);
1567 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1568 audio_desc_);
1569 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1570 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001571 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1572 audio_rejected ? "" : kPwdVoice);
1573 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1574 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001575 JsepSessionDescription jdesc_no_candidates(kDummyString);
1576 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1577 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001578 return false;
1579 }
deadbeef3f7219b2015-12-28 15:17:14 -08001580 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001581 return true;
1582 }
1583
jbauch5869f502017-06-29 12:31:36 -07001584 void TestDeserializeExtmap(bool session_level, bool media_level,
1585 bool encrypted) {
1586 AddExtmap(encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001587 JsepSessionDescription new_jdesc("dummy");
1588 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1589 jdesc_.session_id(),
1590 jdesc_.session_version()));
1591 JsepSessionDescription jdesc_with_extmap("dummy");
1592 std::string sdp_with_extmap = kSdpString;
1593 if (session_level) {
jbauch5869f502017-06-29 12:31:36 -07001594 InjectAfter(kSessionTime,
1595 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1596 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001597 &sdp_with_extmap);
1598 }
1599 if (media_level) {
jbauch5869f502017-06-29 12:31:36 -07001600 InjectAfter(kAttributeIcePwdVoice,
1601 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1602 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001603 &sdp_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07001604 InjectAfter(kAttributeIcePwdVideo,
1605 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1606 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001607 &sdp_with_extmap);
1608 }
1609 // The extmap can't be present at the same time in both session level and
1610 // media level.
1611 if (session_level && media_level) {
1612 SdpParseError error;
1613 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap,
1614 &jdesc_with_extmap, &error));
1615 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1616 } else {
1617 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1618 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1619 }
1620 }
1621
1622 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
1623 const std::string& name, int expected_value) {
1624 cricket::CodecParameterMap::const_iterator found = params.find(name);
1625 ASSERT_TRUE(found != params.end());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001626 EXPECT_EQ(found->second, rtc::ToString<int>(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001627 }
1628
1629 void TestDeserializeCodecParams(const CodecParams& params,
1630 JsepSessionDescription* jdesc_output) {
1631 std::string sdp =
1632 "v=0\r\n"
1633 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1634 "s=-\r\n"
1635 "t=0 0\r\n"
1636 // Include semantics for WebRTC Media Streams since it is supported by
1637 // this parser, and will be added to the SDP when serializing a session
1638 // description.
1639 "a=msid-semantic: WMS\r\n"
1640 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001641 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001642 // Pltype 111 listed before 103 and 104 in the map.
1643 "a=rtpmap:111 opus/48000/2\r\n"
1644 // Pltype 103 listed before 104.
1645 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001646 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001647 "a=fmtp:111 0-15,66,70\r\n"
1648 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001649 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001650 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001651 << "; sprop-stereo=" << params.sprop_stereo
1652 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001653 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001654 << "a=ptime:" << params.ptime << "\r\n"
1655 << "a=maxptime:" << params.max_ptime << "\r\n";
1656 sdp += os.str();
1657
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001658 os.clear();
1659 os.str("");
1660 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001661 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001662 << "a=rtpmap:99 VP8/90000\r\n"
1663 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001664 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001665 sdp += os.str();
1666
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001667 // Deserialize
1668 SdpParseError error;
1669 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1670
1671 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1672 ASSERT_TRUE(ac != NULL);
1673 const AudioContentDescription* acd =
1674 static_cast<const AudioContentDescription*>(ac->description);
1675 ASSERT_FALSE(acd->codecs().empty());
1676 cricket::AudioCodec opus = acd->codecs()[0];
1677 EXPECT_EQ("opus", opus.name);
1678 EXPECT_EQ(111, opus.id);
1679 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1680 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1681 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1682 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001683 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1684 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001685 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1686 cricket::AudioCodec codec = acd->codecs()[i];
1687 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1688 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001689 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001690
1691 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1692 ASSERT_TRUE(vc != NULL);
1693 const VideoContentDescription* vcd =
1694 static_cast<const VideoContentDescription*>(vc->description);
1695 ASSERT_FALSE(vcd->codecs().empty());
1696 cricket::VideoCodec vp8 = vcd->codecs()[0];
1697 EXPECT_EQ("VP8", vp8.name);
1698 EXPECT_EQ(99, vp8.id);
1699 cricket::VideoCodec rtx = vcd->codecs()[1];
1700 EXPECT_EQ("RTX", rtx.name);
1701 EXPECT_EQ(95, rtx.id);
1702 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001703 }
1704
1705 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1706 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001707 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001708 "v=0\r\n"
1709 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1710 "s=-\r\n"
1711 "t=0 0\r\n"
1712 // Include semantics for WebRTC Media Streams since it is supported by
1713 // this parser, and will be added to the SDP when serializing a session
1714 // description.
1715 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001716 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001717 "a=rtpmap:111 opus/48000/2\r\n";
1718 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001719 "m=video 3457 RTP/SAVPF 101\r\n"
1720 "a=rtpmap:101 VP8/90000\r\n"
1721 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001722 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001723 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001724 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001725 os << sdp_session_and_audio;
1726 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
1727 os << sdp_video;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001728 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001729 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001730 // Deserialize
1731 SdpParseError error;
1732 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1733 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1734 ASSERT_TRUE(ac != NULL);
1735 const AudioContentDescription* acd =
1736 static_cast<const AudioContentDescription*>(ac->description);
1737 ASSERT_FALSE(acd->codecs().empty());
1738 cricket::AudioCodec opus = acd->codecs()[0];
1739 EXPECT_EQ(111, opus.id);
1740 EXPECT_TRUE(opus.HasFeedbackParam(
1741 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1742 cricket::kParamValueEmpty)));
1743
1744 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1745 ASSERT_TRUE(vc != NULL);
1746 const VideoContentDescription* vcd =
1747 static_cast<const VideoContentDescription*>(vc->description);
1748 ASSERT_FALSE(vcd->codecs().empty());
1749 cricket::VideoCodec vp8 = vcd->codecs()[0];
1750 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1751 vp8.name.c_str());
1752 EXPECT_EQ(101, vp8.id);
1753 EXPECT_TRUE(vp8.HasFeedbackParam(
1754 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1755 cricket::kParamValueEmpty)));
1756 EXPECT_TRUE(vp8.HasFeedbackParam(
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001757 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1758 cricket::kRtcpFbNackParamPli)));
1759 EXPECT_TRUE(vp8.HasFeedbackParam(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001760 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
1761 cricket::kParamValueEmpty)));
1762 EXPECT_TRUE(vp8.HasFeedbackParam(
1763 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
1764 cricket::kRtcpFbCcmParamFir)));
1765 }
1766
1767 // Two SDP messages can mean the same thing but be different strings, e.g.
1768 // some of the lines can be serialized in different order.
1769 // However, a deserialized description can be compared field by field and has
1770 // no order. If deserializer has already been tested, serializing then
1771 // deserializing and comparing JsepSessionDescription will test
1772 // the serializer sufficiently.
deadbeef9d3584c2016-02-16 17:54:10 -08001773 void TestSerialize(const JsepSessionDescription& jdesc,
1774 bool unified_plan_sdp) {
1775 std::string message = webrtc::SdpSerialize(jdesc, unified_plan_sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001776 JsepSessionDescription jdesc_output_des(kDummyString);
1777 SdpParseError error;
1778 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1779 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1780 }
1781
zhihuang38989e52017-03-21 11:04:53 -07001782 // Calling 'Initialize' with a copy of the inner SessionDescription will
1783 // create a copy of the JsepSessionDescription without candidates. The
1784 // 'connection address' field, previously set from the candidates, must also
1785 // be reset.
1786 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
1787 rtc::SocketAddress audio_addr("0.0.0.0", 9);
1788 rtc::SocketAddress video_addr("0.0.0.0", 9);
1789 audio_desc_->set_connection_address(audio_addr);
1790 video_desc_->set_connection_address(video_addr);
1791 ASSERT_TRUE(jdesc->Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1792 }
1793
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001794 protected:
1795 SessionDescription desc_;
1796 AudioContentDescription* audio_desc_;
1797 VideoContentDescription* video_desc_;
1798 DataContentDescription* data_desc_;
1799 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07001800 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001801 JsepSessionDescription jdesc_;
1802};
1803
1804void TestMismatch(const std::string& string1, const std::string& string2) {
1805 int position = 0;
1806 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1807 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001808 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001809 break;
1810 }
1811 }
1812 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1813 << " character\n"
1814 << " 1: " << string1.substr(position, 20) << "\n"
1815 << " 2: " << string2.substr(position, 20) << "\n";
1816}
1817
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001818TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1819 // SessionDescription with desc and candidates.
deadbeef9d3584c2016-02-16 17:54:10 -08001820 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001821 TestMismatch(std::string(kSdpFullString), message);
1822}
1823
1824TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
1825 JsepSessionDescription jdesc_empty(kDummyString);
deadbeef9d3584c2016-02-16 17:54:10 -08001826 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty, false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001827}
1828
1829// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1830// the case in a DTLS offer.
1831TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1832 AddFingerprint();
1833 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
zhihuang38989e52017-03-21 11:04:53 -07001834 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
deadbeef9d3584c2016-02-16 17:54:10 -08001835 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001836
1837 std::string sdp_with_fingerprint = kSdpString;
1838 InjectAfter(kAttributeIcePwdVoice,
1839 kFingerprint, &sdp_with_fingerprint);
1840 InjectAfter(kAttributeIcePwdVideo,
1841 kFingerprint, &sdp_with_fingerprint);
1842
1843 EXPECT_EQ(sdp_with_fingerprint, message);
1844}
1845
1846// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1847// be the case in a DTLS answer.
1848TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1849 AddFingerprint();
1850 RemoveCryptos();
1851 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
zhihuang38989e52017-03-21 11:04:53 -07001852 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
deadbeef9d3584c2016-02-16 17:54:10 -08001853 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001854
1855 std::string sdp_with_fingerprint = kSdpString;
1856 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1857 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
1858 InjectAfter(kAttributeIcePwdVoice,
1859 kFingerprint, &sdp_with_fingerprint);
1860 InjectAfter(kAttributeIcePwdVideo,
1861 kFingerprint, &sdp_with_fingerprint);
1862
1863 EXPECT_EQ(sdp_with_fingerprint, message);
1864}
1865
1866TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1867 // JsepSessionDescription with desc but without candidates.
1868 JsepSessionDescription jdesc_no_candidates(kDummyString);
zhihuang38989e52017-03-21 11:04:53 -07001869 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
deadbeef9d3584c2016-02-16 17:54:10 -08001870 std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001871 EXPECT_EQ(std::string(kSdpString), message);
1872}
1873
1874TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1875 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1876 group.AddContentName(kAudioContentName);
1877 group.AddContentName(kVideoContentName);
1878 desc_.AddGroup(group);
1879 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1880 jdesc_.session_id(),
1881 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08001882 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001883 std::string sdp_with_bundle = kSdpFullString;
1884 InjectAfter(kSessionTime,
1885 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1886 &sdp_with_bundle);
1887 EXPECT_EQ(sdp_with_bundle, message);
1888}
1889
1890TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
1891 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1892 GetFirstVideoContent(&desc_)->description);
1893 vcd->set_bandwidth(100 * 1000);
1894 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1895 GetFirstAudioContent(&desc_)->description);
1896 acd->set_bandwidth(50 * 1000);
1897 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1898 jdesc_.session_id(),
1899 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08001900 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001901 std::string sdp_with_bandwidth = kSdpFullString;
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001902 InjectAfter("c=IN IP4 74.125.224.39\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001903 "b=AS:100\r\n",
1904 &sdp_with_bandwidth);
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001905 InjectAfter("c=IN IP4 74.125.127.126\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001906 "b=AS:50\r\n",
1907 &sdp_with_bandwidth);
1908 EXPECT_EQ(sdp_with_bandwidth, message);
1909}
1910
1911TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1912 std::vector<std::string> transport_options;
1913 transport_options.push_back(kIceOption1);
1914 transport_options.push_back(kIceOption3);
1915 AddIceOptions(kAudioContentName, transport_options);
1916 transport_options.clear();
1917 transport_options.push_back(kIceOption2);
1918 transport_options.push_back(kIceOption3);
1919 AddIceOptions(kVideoContentName, transport_options);
1920 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1921 jdesc_.session_id(),
1922 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08001923 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001924 std::string sdp_with_ice_options = kSdpFullString;
1925 InjectAfter(kAttributeIcePwdVoice,
1926 "a=ice-options:iceoption1 iceoption3\r\n",
1927 &sdp_with_ice_options);
1928 InjectAfter(kAttributeIcePwdVideo,
1929 "a=ice-options:iceoption2 iceoption3\r\n",
1930 &sdp_with_ice_options);
1931 EXPECT_EQ(sdp_with_ice_options, message);
1932}
1933
1934TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
1935 EXPECT_TRUE(TestSerializeDirection(cricket::MD_RECVONLY));
1936}
1937
1938TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
1939 EXPECT_TRUE(TestSerializeDirection(cricket::MD_SENDONLY));
1940}
1941
1942TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
1943 EXPECT_TRUE(TestSerializeDirection(cricket::MD_INACTIVE));
1944}
1945
1946TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
1947 EXPECT_TRUE(TestSerializeRejected(true, false));
1948}
1949
1950TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
1951 EXPECT_TRUE(TestSerializeRejected(false, true));
1952}
1953
1954TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
1955 EXPECT_TRUE(TestSerializeRejected(true, true));
1956}
1957
1958TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
1959 AddRtpDataChannel();
1960 JsepSessionDescription jsep_desc(kDummyString);
1961
zhihuang38989e52017-03-21 11:04:53 -07001962 MakeDescriptionWithoutCandidates(&jsep_desc);
deadbeef9d3584c2016-02-16 17:54:10 -08001963 std::string message = webrtc::SdpSerialize(jsep_desc, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001964
1965 std::string expected_sdp = kSdpString;
1966 expected_sdp.append(kSdpRtpDataChannelString);
1967 EXPECT_EQ(expected_sdp, message);
1968}
1969
1970TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08001971 bool use_sctpmap = true;
1972 AddSctpDataChannel(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001973 JsepSessionDescription jsep_desc(kDummyString);
1974
zhihuang38989e52017-03-21 11:04:53 -07001975 MakeDescriptionWithoutCandidates(&jsep_desc);
deadbeef9d3584c2016-02-16 17:54:10 -08001976 std::string message = webrtc::SdpSerialize(jsep_desc, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001977
1978 std::string expected_sdp = kSdpString;
1979 expected_sdp.append(kSdpSctpDataChannelString);
1980 EXPECT_EQ(message, expected_sdp);
1981}
1982
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001983TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08001984 bool use_sctpmap = true;
1985 AddSctpDataChannel(use_sctpmap);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001986 JsepSessionDescription jsep_desc(kDummyString);
zhihuang38989e52017-03-21 11:04:53 -07001987 MakeDescriptionWithoutCandidates(&jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001988 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
1989 jsep_desc.description()->GetContentDescriptionByName(kDataContentName));
1990
1991 const int kNewPort = 1234;
solenberg9fa49752016-10-08 13:02:44 -07001992 cricket::DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07001993 cricket::kGoogleSctpDataCodecName);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001994 codec.SetParam(cricket::kCodecParamPort, kNewPort);
1995 dcdesc->AddOrReplaceCodec(codec);
1996
deadbeef9d3584c2016-02-16 17:54:10 -08001997 std::string message = webrtc::SdpSerialize(jsep_desc, false);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001998
1999 std::string expected_sdp = kSdpString;
2000 expected_sdp.append(kSdpSctpDataChannelString);
2001
2002 char default_portstr[16];
2003 char new_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002004 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002005 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002006 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
2007 rtc::replace_substrs(default_portstr, strlen(default_portstr),
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002008 new_portstr, strlen(new_portstr),
2009 &expected_sdp);
2010
2011 EXPECT_EQ(expected_sdp, message);
2012}
2013
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002014TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
zhihuang38989e52017-03-21 11:04:53 -07002015 JsepSessionDescription jsep_desc(kDummyString);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002016 AddRtpDataChannel();
2017 data_desc_->set_bandwidth(100*1000);
zhihuang38989e52017-03-21 11:04:53 -07002018 MakeDescriptionWithoutCandidates(&jsep_desc);
deadbeef9d3584c2016-02-16 17:54:10 -08002019 std::string message = webrtc::SdpSerialize(jsep_desc, false);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002020
2021 std::string expected_sdp = kSdpString;
2022 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002023 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00002024 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 +00002025 "b=AS:100\r\n",
2026 &expected_sdp);
2027 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002028}
2029
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002030TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002031 bool encrypted = false;
2032 AddExtmap(encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002033 JsepSessionDescription desc_with_extmap("dummy");
zhihuang38989e52017-03-21 11:04:53 -07002034 MakeDescriptionWithoutCandidates(&desc_with_extmap);
deadbeef9d3584c2016-02-16 17:54:10 -08002035 std::string message = webrtc::SdpSerialize(desc_with_extmap, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002036
2037 std::string sdp_with_extmap = kSdpString;
2038 InjectAfter("a=mid:audio_content_name\r\n",
2039 kExtmap, &sdp_with_extmap);
2040 InjectAfter("a=mid:video_content_name\r\n",
2041 kExtmap, &sdp_with_extmap);
2042
2043 EXPECT_EQ(sdp_with_extmap, message);
2044}
2045
jbauch5869f502017-06-29 12:31:36 -07002046TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2047 bool encrypted = true;
2048 AddExtmap(encrypted);
2049 JsepSessionDescription desc_with_extmap("dummy");
2050 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(),
2051 kSessionId, kSessionVersion));
2052 TestSerialize(desc_with_extmap, false);
2053}
2054
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002055TEST_F(WebRtcSdpTest, SerializeCandidates) {
2056 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002057 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002058
2059 Candidate candidate_with_ufrag(candidates_.front());
2060 candidate_with_ufrag.set_username("ABC");
2061 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2062 candidate_with_ufrag));
2063 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2064 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002065
2066 Candidate candidate_with_network_info(candidates_.front());
2067 candidate_with_network_info.set_network_id(1);
2068 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2069 candidate_with_network_info));
2070 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2071 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2072 candidate_with_network_info.set_network_cost(999);
2073 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2074 candidate_with_network_info));
2075 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2076 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2077 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002078}
2079
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002080// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2081// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002082TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002083 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002084 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2085 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2086 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002087 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002088 std::unique_ptr<IceCandidateInterface> jcandidate(
2089 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002090
2091 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2092 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2093}
2094
htaa6b99442016-04-12 10:29:17 -07002095TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002096 cricket::VideoCodec h264_codec("H264");
2097 h264_codec.SetParam("profile-level-id", "42e01f");
2098 h264_codec.SetParam("level-asymmetry-allowed", "1");
2099 h264_codec.SetParam("packetization-mode", "1");
2100 video_desc_->AddCodec(h264_codec);
2101
htaa6b99442016-04-12 10:29:17 -07002102 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
2103
2104 std::string message = webrtc::SdpSerialize(jdesc_, false);
2105 size_t after_pt = message.find(" H264/90000");
2106 ASSERT_NE(after_pt, std::string::npos);
2107 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2108 ASSERT_NE(before_pt, std::string::npos);
2109 before_pt += strlen("a=rtpmap:");
2110 std::string pt = message.substr(before_pt, after_pt - before_pt);
2111 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2112 std::string to_find = "a=fmtp:" + pt + " ";
2113 size_t fmtp_pos = message.find(to_find);
2114 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
2115 size_t fmtp_endpos = message.find("\n", fmtp_pos);
2116 ASSERT_NE(std::string::npos, fmtp_endpos);
2117 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2118 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2119 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2120 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002121 // Check that there are no spaces after semicolons.
2122 // https://bugs.webrtc.org/5793
2123 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002124}
2125
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002126TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
2127 JsepSessionDescription jdesc(kDummyString);
2128 // Deserialize
2129 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2130 // Verify
2131 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2132}
2133
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002134TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
2135 JsepSessionDescription jdesc(kDummyString);
2136 const char kSdpWithoutMline[] =
2137 "v=0\r\n"
2138 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2139 "s=-\r\n"
2140 "t=0 0\r\n"
2141 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
2142 // Deserialize
2143 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2144 EXPECT_EQ(0u, jdesc.description()->contents().size());
2145}
2146
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002147TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
2148 JsepSessionDescription jdesc(kDummyString);
2149 std::string sdp_without_carriage_return = kSdpFullString;
2150 Replace("\r\n", "\n", &sdp_without_carriage_return);
2151 // Deserialize
2152 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2153 // Verify
2154 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2155}
2156
2157TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2158 // SessionDescription with desc but without candidates.
2159 JsepSessionDescription jdesc_no_candidates(kDummyString);
2160 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
2161 kSessionId, kSessionVersion));
2162 JsepSessionDescription new_jdesc(kDummyString);
2163 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2164 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2165}
2166
2167TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2168 static const char kSdpNoRtpmapString[] =
2169 "v=0\r\n"
2170 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2171 "s=-\r\n"
2172 "t=0 0\r\n"
2173 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2174 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002175 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002176 // The rtpmap line for static payload codec is optional.
2177 "a=rtpmap:18 G729/16000\r\n"
2178 "a=rtpmap:103 ISAC/16000\r\n";
2179
2180 JsepSessionDescription jdesc(kDummyString);
2181 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2182 cricket::AudioContentDescription* audio =
2183 static_cast<AudioContentDescription*>(
2184 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2185 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002186 // The codecs in the AudioContentDescription should be in the same order as
2187 // the payload types (<fmt>s) on the m= line.
2188 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2189 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002190 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002191 EXPECT_EQ(ref_codecs, audio->codecs());
2192}
2193
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002194TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2195 static const char kSdpNoRtpmapString[] =
2196 "v=0\r\n"
2197 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2198 "s=-\r\n"
2199 "t=0 0\r\n"
2200 "m=audio 49232 RTP/AVP 18 103\r\n"
2201 "a=fmtp:18 annexb=yes\r\n"
2202 "a=rtpmap:103 ISAC/16000\r\n";
2203
2204 JsepSessionDescription jdesc(kDummyString);
2205 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2206 cricket::AudioContentDescription* audio =
2207 static_cast<AudioContentDescription*>(
2208 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2209
2210 cricket::AudioCodec g729 = audio->codecs()[0];
2211 EXPECT_EQ("G729", g729.name);
2212 EXPECT_EQ(8000, g729.clockrate);
2213 EXPECT_EQ(18, g729.id);
2214 cricket::CodecParameterMap::iterator found =
2215 g729.params.find("annexb");
2216 ASSERT_TRUE(found != g729.params.end());
2217 EXPECT_EQ(found->second, "yes");
2218
2219 cricket::AudioCodec isac = audio->codecs()[1];
2220 EXPECT_EQ("ISAC", isac.name);
2221 EXPECT_EQ(103, isac.id);
2222 EXPECT_EQ(16000, isac.clockrate);
2223}
2224
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002225// Ensure that we can deserialize SDP with a=fingerprint properly.
2226TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2227 // Add a DTLS a=fingerprint attribute to our session description.
2228 AddFingerprint();
2229 JsepSessionDescription new_jdesc(kDummyString);
2230 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
2231 jdesc_.session_id(),
2232 jdesc_.session_version()));
2233
2234 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
2235 std::string sdp_with_fingerprint = kSdpString;
2236 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2237 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2238 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2239 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2240}
2241
2242TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
2243 JsepSessionDescription jdesc_with_bundle(kDummyString);
2244 std::string sdp_with_bundle = kSdpFullString;
2245 InjectAfter(kSessionTime,
2246 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2247 &sdp_with_bundle);
2248 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2249 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2250 group.AddContentName(kAudioContentName);
2251 group.AddContentName(kVideoContentName);
2252 desc_.AddGroup(group);
2253 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2254 jdesc_.session_id(),
2255 jdesc_.session_version()));
2256 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2257}
2258
2259TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
2260 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2261 std::string sdp_with_bandwidth = kSdpFullString;
2262 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
2263 "b=AS:100\r\n",
2264 &sdp_with_bandwidth);
2265 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
2266 "b=AS:50\r\n",
2267 &sdp_with_bandwidth);
2268 EXPECT_TRUE(
2269 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2270 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
2271 GetFirstVideoContent(&desc_)->description);
2272 vcd->set_bandwidth(100 * 1000);
2273 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
2274 GetFirstAudioContent(&desc_)->description);
2275 acd->set_bandwidth(50 * 1000);
2276 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2277 jdesc_.session_id(),
2278 jdesc_.session_version()));
2279 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2280}
2281
2282TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
2283 JsepSessionDescription jdesc_with_ice_options(kDummyString);
2284 std::string sdp_with_ice_options = kSdpFullString;
2285 InjectAfter(kSessionTime,
2286 "a=ice-options:iceoption3\r\n",
2287 &sdp_with_ice_options);
2288 InjectAfter(kAttributeIcePwdVoice,
2289 "a=ice-options:iceoption1\r\n",
2290 &sdp_with_ice_options);
2291 InjectAfter(kAttributeIcePwdVideo,
2292 "a=ice-options:iceoption2\r\n",
2293 &sdp_with_ice_options);
2294 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2295 std::vector<std::string> transport_options;
2296 transport_options.push_back(kIceOption3);
2297 transport_options.push_back(kIceOption1);
2298 AddIceOptions(kAudioContentName, transport_options);
2299 transport_options.clear();
2300 transport_options.push_back(kIceOption3);
2301 transport_options.push_back(kIceOption2);
2302 AddIceOptions(kVideoContentName, transport_options);
2303 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2304 jdesc_.session_id(),
2305 jdesc_.session_version()));
2306 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2307}
2308
2309TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2310 // Remove the original ice-ufrag and ice-pwd
2311 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyString);
2312 std::string sdp_with_ufrag_pwd = kSdpFullString;
2313 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2314 // Add session level ufrag and pwd
2315 InjectAfter(kSessionTime,
2316 "a=ice-pwd:session+level+icepwd\r\n"
2317 "a=ice-ufrag:session+level+iceufrag\r\n",
2318 &sdp_with_ufrag_pwd);
2319 // Add media level ufrag and pwd for audio
2320 InjectAfter("a=mid:audio_content_name\r\n",
2321 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2322 &sdp_with_ufrag_pwd);
2323 // Update the candidate ufrag and pwd to the expected ones.
2324 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0,
2325 "media+level+iceufrag", "media+level+icepwd"));
2326 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1,
2327 "session+level+iceufrag", "session+level+icepwd"));
2328 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2329 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2330}
2331
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002332TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
2333 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_RECVONLY));
2334}
2335
2336TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
2337 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_SENDONLY));
2338}
2339
2340TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
2341 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_INACTIVE));
2342}
2343
2344TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2345 EXPECT_TRUE(TestDeserializeRejected(true, false));
2346}
2347
2348TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2349 EXPECT_TRUE(TestDeserializeRejected(false, true));
2350}
2351
2352TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2353 EXPECT_TRUE(TestDeserializeRejected(true, true));
2354}
2355
2356// Tests that we can still handle the sdp uses mslabel and label instead of
2357// msid for backward compatibility.
2358TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07002359 jdesc_.description()->set_msid_supported(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002360 JsepSessionDescription jdesc(kDummyString);
2361 std::string sdp_without_msid = kSdpFullString;
2362 Replace("msid", "xmsid", &sdp_without_msid);
2363 // Deserialize
2364 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2365 // Verify
2366 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2367}
2368
2369TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2370 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2371
2372 std::string sdp = kSdpOneCandidate;
2373 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2374 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2375 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2376 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002377 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002378
2379 // Candidate line without generation extension.
2380 sdp = kSdpOneCandidate;
2381 Replace(" generation 2", "", &sdp);
2382 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2383 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2384 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2385 Candidate expected = jcandidate_->candidate();
2386 expected.set_generation(0);
2387 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2388
honghaiza0c44ea2016-03-23 16:07:48 -07002389 // Candidate with network id and/or cost.
2390 sdp = kSdpOneCandidate;
2391 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2392 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2393 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2394 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2395 expected = jcandidate_->candidate();
2396 expected.set_network_id(2);
2397 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2398 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2399 // Add network cost
2400 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2401 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2402 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2403 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2404
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002405 sdp = kSdpTcpActiveCandidate;
2406 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2407 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002408 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002409 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2410 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2411 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002412 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2413 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002414 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(
2415 jcandidate_template->candidate()));
2416 sdp = kSdpTcpPassiveCandidate;
2417 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2418 sdp = kSdpTcpSOCandidate;
2419 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002420}
2421
2422// This test verifies the deserialization of candidate-attribute
2423// as per RFC 5245. Candiate-attribute will be of the format
2424// candidate:<blah>. This format will be used when candidates
2425// are trickled.
2426TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2427 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2428
2429 std::string candidate_attribute = kRawCandidate;
2430 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2431 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2432 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2433 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2434 EXPECT_EQ(2u, jcandidate.candidate().generation());
2435
2436 // Candidate line without generation extension.
2437 candidate_attribute = kRawCandidate;
2438 Replace(" generation 2", "", &candidate_attribute);
2439 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2440 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2441 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2442 Candidate expected = jcandidate_->candidate();
2443 expected.set_generation(0);
2444 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2445
2446 // Candidate line without candidate:
2447 candidate_attribute = kRawCandidate;
2448 Replace("candidate:", "", &candidate_attribute);
2449 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2450
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002451 // Candidate line with IPV6 address.
2452 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
2453}
2454
2455// This test verifies that the deserialization of an invalid candidate string
2456// fails.
2457TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
2458 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2459
2460 std::string candidate_attribute = kRawCandidate;
2461 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002462 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002463
2464 candidate_attribute = kSdpOneCandidate;
2465 candidate_attribute.replace(0, 1, "x");
2466 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2467
2468 candidate_attribute = kRawCandidate;
2469 candidate_attribute.append("\r\n");
2470 candidate_attribute.append(kRawCandidate);
2471 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2472
2473 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002474}
2475
2476TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2477 AddRtpDataChannel();
2478 JsepSessionDescription jdesc(kDummyString);
2479 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2480
2481 std::string sdp_with_data = kSdpString;
2482 sdp_with_data.append(kSdpRtpDataChannelString);
2483 JsepSessionDescription jdesc_output(kDummyString);
2484
2485 // Deserialize
2486 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2487 // Verify
2488 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2489}
2490
2491TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002492 bool use_sctpmap = true;
2493 AddSctpDataChannel(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002494 JsepSessionDescription jdesc(kDummyString);
2495 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2496
2497 std::string sdp_with_data = kSdpString;
2498 sdp_with_data.append(kSdpSctpDataChannelString);
2499 JsepSessionDescription jdesc_output(kDummyString);
2500
lally@webrtc.org36300852015-02-24 20:19:35 +00002501 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2502 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2503 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2504
2505 // Verify with UDP/DTLS/SCTP.
2506 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2507 strlen(kDtlsSctp), kUdpDtlsSctp);
2508 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2509 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2510
2511 // Verify with TCP/DTLS/SCTP.
2512 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2513 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002514 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2515 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2516}
2517
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002518TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002519 bool use_sctpmap = false;
2520 AddSctpDataChannel(use_sctpmap);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002521 JsepSessionDescription jdesc(kDummyString);
2522 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2523
2524 std::string sdp_with_data = kSdpString;
2525 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2526 JsepSessionDescription jdesc_output(kDummyString);
2527
lally@webrtc.org36300852015-02-24 20:19:35 +00002528 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002529 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2530 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002531
lally@webrtc.org36300852015-02-24 20:19:35 +00002532 // Verify with UDP/DTLS/SCTP.
2533 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2534 strlen(kDtlsSctp), kUdpDtlsSctp);
2535 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2536 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002537
lally@webrtc.org36300852015-02-24 20:19:35 +00002538 // Verify with TCP/DTLS/SCTP.
2539 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2540 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002541 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2542 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2543}
2544
lally69f57602015-10-08 10:15:04 -07002545TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002546 bool use_sctpmap = false;
2547 AddSctpDataChannel(use_sctpmap);
lally69f57602015-10-08 10:15:04 -07002548 JsepSessionDescription jdesc(kDummyString);
2549 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2550
2551 std::string sdp_with_data = kSdpString;
2552 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
2553 JsepSessionDescription jdesc_output(kDummyString);
2554
2555 // Verify with DTLS/SCTP.
2556 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2557 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2558
2559 // Verify with UDP/DTLS/SCTP.
2560 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2561 strlen(kDtlsSctp), kUdpDtlsSctp);
2562 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2563 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2564
2565 // Verify with TCP/DTLS/SCTP.
2566 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2567 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
2568 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2569 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2570}
2571
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002572// Test to check the behaviour if sctp-port is specified
2573// on the m= line and in a=sctp-port.
2574TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002575 bool use_sctpmap = true;
2576 AddSctpDataChannel(use_sctpmap);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002577 JsepSessionDescription jdesc(kDummyString);
2578 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2579
2580 std::string sdp_with_data = kSdpString;
2581 // Append m= attributes
2582 sdp_with_data.append(kSdpSctpDataChannelString);
2583 // Append a=sctp-port attribute
2584 sdp_with_data.append("a=sctp-port 5000\r\n");
2585 JsepSessionDescription jdesc_output(kDummyString);
2586
2587 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2588}
2589
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002590// For crbug/344475.
2591TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2592 std::string sdp_with_data = kSdpString;
2593 sdp_with_data.append(kSdpSctpDataChannelString);
2594 // Remove the "\n" at the end.
2595 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
2596 JsepSessionDescription jdesc_output(kDummyString);
2597
2598 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2599 // No crash is a pass.
2600}
2601
Steve Anton36b29d12017-10-30 09:57:42 -07002602void MutateJsepSctpPort(JsepSessionDescription* jdesc,
zstein4b2e0822017-02-17 19:48:38 -08002603 const SessionDescription& desc) {
wu@webrtc.org78187522013-10-07 23:32:02 +00002604 // take our pre-built session description and change the SCTP port.
zstein4b2e0822017-02-17 19:48:38 -08002605 cricket::SessionDescription* mutant = desc.Copy();
wu@webrtc.org78187522013-10-07 23:32:02 +00002606 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
2607 mutant->GetContentDescriptionByName(kDataContentName));
2608 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002609 EXPECT_EQ(1U, codecs.size());
solenberg9fa49752016-10-08 13:02:44 -07002610 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002611 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002612 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002613
2614 // note: mutant's owned by jdesc now.
Steve Anton36b29d12017-10-30 09:57:42 -07002615 ASSERT_TRUE(jdesc->Initialize(mutant, kSessionId, kSessionVersion));
wu@webrtc.org78187522013-10-07 23:32:02 +00002616 mutant = NULL;
zstein4b2e0822017-02-17 19:48:38 -08002617}
2618
2619TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
2620 bool use_sctpmap = true;
2621 AddSctpDataChannel(use_sctpmap);
2622
2623 // First setup the expected JsepSessionDescription.
2624 JsepSessionDescription jdesc(kDummyString);
Steve Anton36b29d12017-10-30 09:57:42 -07002625 MutateJsepSctpPort(&jdesc, desc_);
wu@webrtc.org78187522013-10-07 23:32:02 +00002626
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002627 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002628 std::string sdp_with_data = kSdpString;
2629 sdp_with_data.append(kSdpSctpDataChannelString);
zstein4b2e0822017-02-17 19:48:38 -08002630 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2631 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2632 &sdp_with_data);
wu@webrtc.org78187522013-10-07 23:32:02 +00002633 JsepSessionDescription jdesc_output(kDummyString);
2634
2635 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2636 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08002637}
2638
2639TEST_F(WebRtcSdpTest,
2640 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
2641 bool use_sctpmap = false;
2642 AddSctpDataChannel(use_sctpmap);
2643
2644 JsepSessionDescription jdesc(kDummyString);
Steve Anton36b29d12017-10-30 09:57:42 -07002645 MutateJsepSctpPort(&jdesc, desc_);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002646
2647 // We need to test the deserialized JsepSessionDescription from
2648 // kSdpSctpDataChannelStringWithSctpPort for
2649 // draft-ietf-mmusic-sctp-sdp-07
2650 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08002651 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002652 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
zstein4b2e0822017-02-17 19:48:38 -08002653 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2654 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2655 &sdp_with_data);
2656 JsepSessionDescription jdesc_output(kDummyString);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002657
2658 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2659 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002660}
2661
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002662TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002663 // We want to test that deserializing data content limits bandwidth
2664 // settings (it should never be greater than the default).
2665 // This should prevent someone from using unlimited data bandwidth through
2666 // JS and "breaking the Internet".
2667 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002668 std::string sdp_with_bandwidth = kSdpString;
2669 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
2670 InjectAfter("a=mid:data_content_name\r\n",
2671 "b=AS:100\r\n",
2672 &sdp_with_bandwidth);
2673 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2674
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002675 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2676}
2677
2678TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08002679 bool use_sctpmap = true;
2680 AddSctpDataChannel(use_sctpmap);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002681 JsepSessionDescription jdesc(kDummyString);
2682 DataContentDescription* dcd = static_cast<DataContentDescription*>(
2683 GetFirstDataContent(&desc_)->description);
2684 dcd->set_bandwidth(100 * 1000);
2685 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2686
2687 std::string sdp_with_bandwidth = kSdpString;
2688 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
2689 InjectAfter("a=mid:data_content_name\r\n",
2690 "b=AS:100\r\n",
2691 &sdp_with_bandwidth);
2692 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2693
2694 // SCTP has congestion control, so we shouldn't limit the bandwidth
2695 // as we do for RTP.
2696 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002697 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2698}
2699
jbauch5869f502017-06-29 12:31:36 -07002700class WebRtcSdpExtmapTest
2701 : public WebRtcSdpTest, public testing::WithParamInterface<bool> {
2702};
2703
2704TEST_P(WebRtcSdpExtmapTest,
2705 DeserializeSessionDescriptionWithSessionLevelExtmap) {
2706 bool encrypted = GetParam();
2707 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002708}
2709
jbauch5869f502017-06-29 12:31:36 -07002710TEST_P(WebRtcSdpExtmapTest,
2711 DeserializeSessionDescriptionWithMediaLevelExtmap) {
2712 bool encrypted = GetParam();
2713 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002714}
2715
jbauch5869f502017-06-29 12:31:36 -07002716TEST_P(WebRtcSdpExtmapTest,
2717 DeserializeSessionDescriptionWithInvalidExtmap) {
2718 bool encrypted = GetParam();
2719 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002720}
2721
jbauch5869f502017-06-29 12:31:36 -07002722INSTANTIATE_TEST_CASE_P(Encrypted,
2723 WebRtcSdpExtmapTest,
2724 ::testing::Values(false, true));
2725
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002726TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
2727 JsepSessionDescription jdesc(kDummyString);
2728 std::string sdp = kSdpFullString;
2729 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2730 // Deserialize
2731 SdpParseError error;
2732 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-16 17:54:10 -08002733 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002734 EXPECT_EQ(lastline, error.line);
2735 EXPECT_EQ("Invalid SDP line.", error.description);
2736}
2737
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002738TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2739 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2740 std::string new_sdp = kSdpOneCandidate;
2741 Replace("udp", "unsupported_transport", &new_sdp);
2742 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2743 new_sdp = kSdpOneCandidate;
2744 Replace("udp", "uDP", &new_sdp);
2745 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2746 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2747 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2748 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2749}
2750
honghaiza54a0802015-12-16 18:37:23 -08002751TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002752 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08002753 EXPECT_TRUE(
2754 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002755 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2756 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2757 Candidate ref_candidate = jcandidate_->candidate();
2758 ref_candidate.set_username("user_rtp");
2759 ref_candidate.set_password("password_rtp");
2760 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2761}
2762
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002763TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
2764 JsepSessionDescription jdesc(kDummyString);
2765
2766 // Deserialize
2767 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2768
2769 // Verify
2770 cricket::AudioContentDescription* audio =
2771 static_cast<AudioContentDescription*>(
2772 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2773 EXPECT_TRUE(audio->conference_mode());
2774
2775 cricket::VideoContentDescription* video =
2776 static_cast<VideoContentDescription*>(
2777 jdesc.description()->GetContentDescriptionByName(cricket::CN_VIDEO));
2778 EXPECT_TRUE(video->conference_mode());
2779}
2780
deadbeefd45aea82017-09-16 01:24:29 -07002781TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
2782 JsepSessionDescription jdesc(kDummyString);
2783
2784 // We tested deserialization already above, so just test that if we serialize
2785 // and deserialize the flag doesn't disappear.
2786 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2787 std::string reserialized = webrtc::SdpSerialize(jdesc, false);
2788 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
2789
2790 // Verify.
2791 cricket::AudioContentDescription* audio =
2792 static_cast<AudioContentDescription*>(
2793 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2794 EXPECT_TRUE(audio->conference_mode());
2795
2796 cricket::VideoContentDescription* video =
2797 static_cast<VideoContentDescription*>(
2798 jdesc.description()->GetContentDescriptionByName(cricket::CN_VIDEO));
2799 EXPECT_TRUE(video->conference_mode());
2800}
2801
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002802TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2803 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002804 const char kSdpEmptyType[] = " =candidate";
2805 const char kSdpEqualAsPlus[] = "a+candidate";
2806 const char kSdpSpaceAfterEqual[] = "a= candidate";
2807 const char kSdpUpperType[] = "A=candidate";
2808 const char kSdpEmptyLine[] = "";
2809 const char kSdpMissingValue[] = "a=";
2810
2811 const char kSdpBrokenFingerprint[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002812 "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 +00002813 const char kSdpExtraField[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002814 "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 +00002815 const char kSdpMissingSpace[] = "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002816 "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 +00002817 // MD5 is not allowed in fingerprints.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002818 const char kSdpMd5[] = "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002819 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002820
2821 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002822 ExpectParseFailure("v=", kSdpDestroyer);
2823 ExpectParseFailure("o=", kSdpDestroyer);
2824 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002825 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002826 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002827
2828 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002829 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2830 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002831
2832 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002833 ExpectParseFailure("a=candidate", kSdpEmptyType);
2834 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2835 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
2836 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002837
2838 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2839 // because it's orthogonal to what we are replacing and hence
2840 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002841 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
2842 ExpectParseFailure("a=sendrecv", kSdpExtraField);
2843 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
2844 ExpectParseFailure("a=sendrecv", kSdpMd5);
2845
2846 // Empty Line
2847 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
2848 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002849}
2850
2851TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2852 // ssrc
2853 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08002854 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002855 // crypto
2856 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
2857 // rtpmap
2858 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
2859 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
2860 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
2861 // candidate
2862 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
2863 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
2864 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
2865 ExpectParseFailure("rport 2346", "rport badvalue");
2866 ExpectParseFailure("rport 2346 generation 2",
2867 "rport 2346 generation badvalue");
2868 // m line
2869 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
2870 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
2871
2872 // bandwidth
2873 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2874 "b=AS:badvalue\r\n",
2875 "b=AS:badvalue");
2876 // rtcp-fb
2877 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2878 "a=rtcp-fb:badvalue nack\r\n",
2879 "a=rtcp-fb:badvalue nack");
2880 // extmap
2881 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2882 "a=extmap:badvalue http://example.com\r\n",
2883 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002884}
2885
2886TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
2887 JsepSessionDescription jdesc_output(kDummyString);
2888
2889 const char kSdpWithReorderedPlTypesString[] =
2890 "v=0\r\n"
2891 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2892 "s=-\r\n"
2893 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00002894 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002895 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
2896 // in the map.
2897 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002898 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002899
2900 // Deserialize
2901 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
2902
2903 const ContentInfo* ac = GetFirstAudioContent(jdesc_output.description());
2904 ASSERT_TRUE(ac != NULL);
2905 const AudioContentDescription* acd =
2906 static_cast<const AudioContentDescription*>(ac->description);
2907 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002908 EXPECT_EQ("ISAC", acd->codecs()[0].name);
2909 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002910 EXPECT_EQ(104, acd->codecs()[0].id);
2911}
2912
2913TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
2914 JsepSessionDescription jdesc_output(kDummyString);
2915 CodecParams params;
2916 params.max_ptime = 40;
2917 params.ptime = 30;
2918 params.min_ptime = 10;
2919 params.sprop_stereo = 1;
2920 params.stereo = 1;
2921 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002922 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002923 TestDeserializeCodecParams(params, &jdesc_output);
deadbeef9d3584c2016-02-16 17:54:10 -08002924 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002925}
2926
2927TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
2928 const bool kUseWildcard = false;
2929 JsepSessionDescription jdesc_output(kDummyString);
2930 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
deadbeef9d3584c2016-02-16 17:54:10 -08002931 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002932}
2933
2934TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
2935 const bool kUseWildcard = true;
2936 JsepSessionDescription jdesc_output(kDummyString);
2937 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
deadbeef9d3584c2016-02-16 17:54:10 -08002938 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002939}
2940
2941TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
2942 JsepSessionDescription jdesc_output(kDummyString);
2943
2944 const char kSdpWithFmtpString[] =
2945 "v=0\r\n"
2946 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2947 "s=-\r\n"
2948 "t=0 0\r\n"
2949 "m=video 3457 RTP/SAVPF 120\r\n"
2950 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07002951 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
2952
2953 // Deserialize
2954 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07002955 EXPECT_TRUE(
2956 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07002957
2958 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2959 ASSERT_TRUE(vc != NULL);
2960 const VideoContentDescription* vcd =
2961 static_cast<const VideoContentDescription*>(vc->description);
2962 ASSERT_FALSE(vcd->codecs().empty());
2963 cricket::VideoCodec vp8 = vcd->codecs()[0];
2964 EXPECT_EQ("VP8", vp8.name);
2965 EXPECT_EQ(120, vp8.id);
2966 cricket::CodecParameterMap::iterator found =
2967 vp8.params.find("x-google-min-bitrate");
2968 ASSERT_TRUE(found != vp8.params.end());
2969 EXPECT_EQ(found->second, "10");
2970 found = vp8.params.find("x-google-max-quantization");
2971 ASSERT_TRUE(found != vp8.params.end());
2972 EXPECT_EQ(found->second, "40");
2973}
2974
johan2d8d23e2016-06-03 01:22:42 -07002975TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
2976 JsepSessionDescription jdesc_output(kDummyString);
2977
2978 const char kSdpWithFmtpString[] =
2979 "v=0\r\n"
2980 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2981 "s=-\r\n"
2982 "t=0 0\r\n"
2983 "m=video 49170 RTP/AVP 98\r\n"
2984 "a=rtpmap:98 H264/90000\r\n"
2985 "a=fmtp:98 profile-level-id=42A01E; "
2986 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
2987
2988 // Deserialize.
2989 SdpParseError error;
2990 EXPECT_TRUE(
2991 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
2992
2993 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2994 ASSERT_TRUE(vc != NULL);
2995 const VideoContentDescription* vcd =
2996 static_cast<const VideoContentDescription*>(vc->description);
2997 ASSERT_TRUE(vcd != NULL);
2998 ASSERT_FALSE(vcd->codecs().empty());
2999 cricket::VideoCodec h264 = vcd->codecs()[0];
3000 EXPECT_EQ("H264", h264.name);
3001 EXPECT_EQ(98, h264.id);
3002 cricket::CodecParameterMap::const_iterator found =
3003 h264.params.find("profile-level-id");
3004 ASSERT_TRUE(found != h264.params.end());
3005 EXPECT_EQ(found->second, "42A01E");
3006 found = h264.params.find("sprop-parameter-sets");
3007 ASSERT_TRUE(found != h264.params.end());
3008 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3009}
3010
Donald Curtis0e07f922015-05-15 09:21:23 -07003011TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
3012 JsepSessionDescription jdesc_output(kDummyString);
3013
3014 const char kSdpWithFmtpString[] =
3015 "v=0\r\n"
3016 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3017 "s=-\r\n"
3018 "t=0 0\r\n"
3019 "m=video 3457 RTP/SAVPF 120\r\n"
3020 "a=rtpmap:120 VP8/90000\r\n"
3021 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003022
3023 // Deserialize
3024 SdpParseError error;
3025 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output,
3026 &error));
3027
3028 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
3029 ASSERT_TRUE(vc != NULL);
3030 const VideoContentDescription* vcd =
3031 static_cast<const VideoContentDescription*>(vc->description);
3032 ASSERT_FALSE(vcd->codecs().empty());
3033 cricket::VideoCodec vp8 = vcd->codecs()[0];
3034 EXPECT_EQ("VP8", vp8.name);
3035 EXPECT_EQ(120, vp8.id);
3036 cricket::CodecParameterMap::iterator found =
3037 vp8.params.find("x-google-min-bitrate");
3038 ASSERT_TRUE(found != vp8.params.end());
3039 EXPECT_EQ(found->second, "10");
3040 found = vp8.params.find("x-google-max-quantization");
3041 ASSERT_TRUE(found != vp8.params.end());
3042 EXPECT_EQ(found->second, "40");
3043}
3044
ossuaa4b0772017-01-30 07:41:18 -08003045TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
3046 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
3047 GetFirstAudioContent(&desc_)->description);
3048
3049 cricket::AudioCodecs codecs = acd->codecs();
3050 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3051 acd->set_codecs(codecs);
3052
3053 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3054 jdesc_.session_id(),
3055 jdesc_.session_version()));
3056 std::string message = webrtc::SdpSerialize(jdesc_, false);
3057 std::string sdp_with_fmtp = kSdpFullString;
3058 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3059 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3060 &sdp_with_fmtp);
3061 EXPECT_EQ(sdp_with_fmtp, message);
3062}
3063
3064TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
3065 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
3066 GetFirstAudioContent(&desc_)->description);
3067
3068 cricket::AudioCodecs codecs = acd->codecs();
3069 codecs[0].params["stereo"] = "1";
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:111 opus/48000/2\r\n",
3078 "a=fmtp:111 stereo=1\r\n",
3079 &sdp_with_fmtp);
3080 EXPECT_EQ(sdp_with_fmtp, message);
3081}
3082
3083TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
3084 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
3085 GetFirstAudioContent(&desc_)->description);
3086
3087 cricket::AudioCodecs codecs = acd->codecs();
3088 codecs[0].params["ptime"] = "20";
3089 codecs[0].params["maxptime"] = "120";
3090 acd->set_codecs(codecs);
3091
3092 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3093 jdesc_.session_id(),
3094 jdesc_.session_version()));
3095 std::string message = webrtc::SdpSerialize(jdesc_, false);
3096 std::string sdp_with_fmtp = kSdpFullString;
3097 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3098 "a=maxptime:120\r\n" // No comma here. String merging!
3099 "a=ptime:20\r\n",
3100 &sdp_with_fmtp);
3101 EXPECT_EQ(sdp_with_fmtp, message);
3102}
3103
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003104TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
3105 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
3106 GetFirstVideoContent(&desc_)->description);
3107
3108 cricket::VideoCodecs codecs = vcd->codecs();
3109 codecs[0].params["x-google-min-bitrate"] = "10";
3110 vcd->set_codecs(codecs);
3111
3112 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3113 jdesc_.session_id(),
3114 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08003115 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003116 std::string sdp_with_fmtp = kSdpFullString;
3117 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
3118 "a=fmtp:120 x-google-min-bitrate=10\r\n",
3119 &sdp_with_fmtp);
3120 EXPECT_EQ(sdp_with_fmtp, message);
3121}
3122
3123TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) {
3124 JsepSessionDescription jdesc_with_icelite(kDummyString);
3125 std::string sdp_with_icelite = kSdpFullString;
3126 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3127 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3128 const cricket::TransportInfo* tinfo1 =
3129 desc->GetTransportInfoByName("audio_content_name");
3130 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3131 const cricket::TransportInfo* tinfo2 =
3132 desc->GetTransportInfoByName("video_content_name");
3133 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
3134 InjectAfter(kSessionTime,
3135 "a=ice-lite\r\n",
3136 &sdp_with_icelite);
3137 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3138 desc = jdesc_with_icelite.description();
3139 const cricket::TransportInfo* atinfo =
3140 desc->GetTransportInfoByName("audio_content_name");
3141 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3142 const cricket::TransportInfo* vtinfo =
3143 desc->GetTransportInfoByName("video_content_name");
3144 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
3145}
3146
3147// Verifies that the candidates in the input SDP are parsed and serialized
3148// correctly in the output SDP.
3149TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3150 std::string sdp_with_data = kSdpString;
3151 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
3152 JsepSessionDescription jdesc_output(kDummyString);
3153
3154 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
deadbeef9d3584c2016-02-16 17:54:10 -08003155 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output, false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003156}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003157
3158TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3159 AddFingerprint();
3160 TransportInfo audio_transport_info =
3161 *(desc_.GetTransportInfoByName(kAudioContentName));
3162 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3163 audio_transport_info.description.connection_role);
3164 audio_transport_info.description.connection_role =
3165 cricket::CONNECTIONROLE_ACTIVE;
3166
3167 TransportInfo video_transport_info =
3168 *(desc_.GetTransportInfoByName(kVideoContentName));
3169 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3170 video_transport_info.description.connection_role);
3171 video_transport_info.description.connection_role =
3172 cricket::CONNECTIONROLE_ACTIVE;
3173
3174 desc_.RemoveTransportInfoByName(kAudioContentName);
3175 desc_.RemoveTransportInfoByName(kVideoContentName);
3176
3177 desc_.AddTransportInfo(audio_transport_info);
3178 desc_.AddTransportInfo(video_transport_info);
3179
3180 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3181 jdesc_.session_id(),
3182 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08003183 std::string message = webrtc::SdpSerialize(jdesc_, false);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003184 std::string sdp_with_dtlssetup = kSdpFullString;
3185
3186 // Fingerprint attribute is necessary to add DTLS setup attribute.
3187 InjectAfter(kAttributeIcePwdVoice,
3188 kFingerprint, &sdp_with_dtlssetup);
3189 InjectAfter(kAttributeIcePwdVideo,
3190 kFingerprint, &sdp_with_dtlssetup);
3191 // Now adding |setup| attribute.
3192 InjectAfter(kFingerprint,
3193 "a=setup:active\r\n", &sdp_with_dtlssetup);
3194 EXPECT_EQ(sdp_with_dtlssetup, message);
3195}
3196
3197TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
3198 JsepSessionDescription jdesc_with_dtlssetup(kDummyString);
3199 std::string sdp_with_dtlssetup = kSdpFullString;
3200 InjectAfter(kSessionTime,
3201 "a=setup:actpass\r\n",
3202 &sdp_with_dtlssetup);
3203 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3204 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3205 const cricket::TransportInfo* atinfo =
3206 desc->GetTransportInfoByName("audio_content_name");
3207 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3208 atinfo->description.connection_role);
3209 const cricket::TransportInfo* vtinfo =
3210 desc->GetTransportInfoByName("video_content_name");
3211 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3212 vtinfo->description.connection_role);
3213}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003214
3215// Verifies that the order of the serialized m-lines follows the order of the
3216// ContentInfo in SessionDescription, and vise versa for deserialization.
3217TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
3218 JsepSessionDescription jdesc(kDummyString);
3219 const std::string media_content_sdps[3] = {
3220 kSdpAudioString,
3221 kSdpVideoString,
3222 kSdpSctpDataChannelString
3223 };
3224 const cricket::MediaType media_types[3] = {
3225 cricket::MEDIA_TYPE_AUDIO,
3226 cricket::MEDIA_TYPE_VIDEO,
3227 cricket::MEDIA_TYPE_DATA
3228 };
3229
3230 // Verifies all 6 permutations.
3231 for (size_t i = 0; i < 6; ++i) {
3232 size_t media_content_in_sdp[3];
3233 // The index of the first media content.
3234 media_content_in_sdp[0] = i / 2;
3235 // The index of the second media content.
3236 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3237 // The index of the third media content.
3238 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3239
3240 std::string sdp_string = kSdpSessionString;
3241 for (size_t i = 0; i < 3; ++i)
3242 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3243
3244 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3245 cricket::SessionDescription* desc = jdesc.description();
3246 EXPECT_EQ(3u, desc->contents().size());
3247
3248 for (size_t i = 0; i < 3; ++i) {
3249 const cricket::MediaContentDescription* mdesc =
3250 static_cast<const cricket::MediaContentDescription*>(
3251 desc->contents()[i].description);
3252 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3253 }
3254
deadbeef9d3584c2016-02-16 17:54:10 -08003255 std::string serialized_sdp = webrtc::SdpSerialize(jdesc, false);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003256 EXPECT_EQ(sdp_string, serialized_sdp);
3257 }
3258}
deadbeef9d3584c2016-02-16 17:54:10 -08003259
deadbeef25ed4352016-12-12 18:37:36 -08003260TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3261 MakeBundleOnlyDescription();
3262 JsepSessionDescription deserialized_description(kDummyString);
deadbeef12771a12017-01-03 13:53:47 -08003263 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003264 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3265 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3266}
3267
deadbeef12771a12017-01-03 13:53:47 -08003268// The semantics of "a=bundle-only" are only defined when it's used in
3269// combination with a 0 port on the m= line. We should ignore it if used with a
3270// nonzero port.
3271TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3272 // Make the base bundle-only description but unset the bundle-only flag.
3273 MakeBundleOnlyDescription();
3274 jdesc_.description()->contents()[1].bundle_only = false;
3275
3276 std::string modified_sdp = kBundleOnlySdpFullString;
3277 Replace("m=video 0", "m=video 9", &modified_sdp);
3278 JsepSessionDescription deserialized_description(kDummyString);
3279 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3280 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003281}
3282
3283TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3284 MakeBundleOnlyDescription();
3285 TestSerialize(jdesc_, false);
3286}
3287
deadbeef9d3584c2016-02-16 17:54:10 -08003288TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3289 MakePlanBDescription();
3290
3291 JsepSessionDescription deserialized_description(kDummyString);
3292 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3293
3294 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3295}
3296
3297TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3298 MakePlanBDescription();
3299 TestSerialize(jdesc_, false);
3300}
3301
Taylor Brandstetter5de6b752016-03-09 17:02:30 -08003302// Some WebRTC endpoints include the msid in both the Plan B and Unified Plan
3303// ways, to make SDP that's compatible with both Plan B and Unified Plan (to
3304// some extent). If we parse this, the Plan B msid attribute (which is more
3305// specific, since it's at the SSRC level) should take priority.
3306TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescriptionWithMsid) {
3307 MakePlanBDescription();
3308
3309 JsepSessionDescription deserialized_description(kDummyString);
3310 EXPECT_TRUE(
3311 SdpDeserialize(kPlanBSdpFullStringWithMsid, &deserialized_description));
3312
3313 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3314}
3315
deadbeef9d3584c2016-02-16 17:54:10 -08003316TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3317 MakeUnifiedPlanDescription();
3318
3319 JsepSessionDescription deserialized_description(kDummyString);
3320 EXPECT_TRUE(
3321 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3322
3323 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3324}
3325
3326TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3327 MakeUnifiedPlanDescription();
3328 TestSerialize(jdesc_, true);
3329}
deadbeef7e146cb2016-09-28 10:04:34 -07003330
3331// Regression test for heap overflow bug:
3332// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3333TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 10:04:34 -07003334 // The issue occurs when the sctp-port attribute is found in a video
3335 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 12:43:58 -08003336 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 10:04:34 -07003337 "v=0\r\n"
3338 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3339 "s=-\r\n"
3340 "t=0 0\r\n"
3341 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3342 "a=sctp-port 5000\r\n"
3343 "a=fmtp:108 foo=10\r\n";
3344
3345 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3346 "sctp-port");
3347}
deadbeefb2362572016-12-13 16:37:06 -08003348
3349// Regression test for integer overflow bug:
3350// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3351TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003352 // Bandwidth attribute is the max signed 32-bit int, which will get
3353 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003354 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003355 "v=0\r\n"
3356 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3357 "s=-\r\n"
3358 "t=0 0\r\n"
3359 "m=video 3457 RTP/SAVPF 120\r\n"
3360 "b=AS:2147483647\r\n"
3361 "foo=fail\r\n";
3362
3363 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3364}
deadbeef7bcdb692017-01-20 12:43:58 -08003365
deadbeefbc88c6b2017-08-02 11:26:34 -07003366// Similar to the above, except that negative values are illegal, not just
3367// error-prone as large values are.
3368// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3369TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3370 static const char kSdpWithNegativeBandwidth[] =
3371 "v=0\r\n"
3372 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3373 "s=-\r\n"
3374 "t=0 0\r\n"
3375 "m=video 3457 RTP/SAVPF 120\r\n"
3376 "b=AS:-1000\r\n";
3377
3378 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3379}
3380
deadbeef3e8016e2017-08-03 17:49:30 -07003381// An exception to the above rule: a value of -1 for b=AS should just be
3382// ignored, resulting in "kAutoBandwidth" in the deserialized object.
3383// Applications historically may be using "b=AS:-1" to mean "no bandwidth
3384// limit", but this is now what ommitting the attribute entirely will do, so
3385// ignoring it will have the intended effect.
3386TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
3387 static const char kSdpWithBandwidthOfNegativeOne[] =
3388 "v=0\r\n"
3389 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3390 "s=-\r\n"
3391 "t=0 0\r\n"
3392 "m=video 3457 RTP/SAVPF 120\r\n"
3393 "b=AS:-1\r\n";
3394
3395 JsepSessionDescription jdesc_output(kDummyString);
3396 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
3397 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
3398 ASSERT_NE(nullptr, vc);
3399 const VideoContentDescription* vcd =
3400 static_cast<const VideoContentDescription*>(vc->description);
3401 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
3402}
3403
deadbeef7bcdb692017-01-20 12:43:58 -08003404// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3405// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3406// Regression test for:
3407// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3408TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3409 // Important piece is "ufrag foo pwd bar".
3410 static const char kSdpWithIceCredentialsInCandidateString[] =
3411 "v=0\r\n"
3412 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3413 "s=-\r\n"
3414 "t=0 0\r\n"
3415 "m=audio 9 RTP/SAVPF 111\r\n"
3416 "c=IN IP4 0.0.0.0\r\n"
3417 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3418 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3419 "a=rtpmap:111 opus/48000/2\r\n"
3420 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3421 "generation 2 ufrag foo pwd bar\r\n";
3422
3423 JsepSessionDescription jdesc_output(kDummyString);
3424 EXPECT_TRUE(
3425 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
3426 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3427 ASSERT_NE(nullptr, candidates);
3428 ASSERT_EQ(1, candidates->count());
3429 cricket::Candidate c = candidates->at(0)->candidate();
3430 EXPECT_EQ("ufrag_voice", c.username());
3431 EXPECT_EQ("pwd_voice", c.password());
3432}
deadbeef90f1e1e2017-02-10 12:35:05 -08003433
3434// Test that SDP with an invalid port number in "a=candidate" lines is
3435// rejected, without crashing.
3436// Regression test for:
3437// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
3438TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
3439 static const char kSdpWithInvalidCandidatePort[] =
3440 "v=0\r\n"
3441 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3442 "s=-\r\n"
3443 "t=0 0\r\n"
3444 "m=audio 9 RTP/SAVPF 111\r\n"
3445 "c=IN IP4 0.0.0.0\r\n"
3446 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3447 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3448 "a=rtpmap:111 opus/48000/2\r\n"
3449 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
3450 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
3451
3452 JsepSessionDescription jdesc_output(kDummyString);
3453 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
3454}
deadbeefa4549d62017-02-10 17:26:22 -08003455
3456// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
3457// Regression test for:
3458// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
3459TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
3460 static const char kSdpWithMissingTrackId[] =
3461 "v=0\r\n"
3462 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3463 "s=-\r\n"
3464 "t=0 0\r\n"
3465 "m=audio 9 RTP/SAVPF 111\r\n"
3466 "c=IN IP4 0.0.0.0\r\n"
3467 "a=rtpmap:111 opus/48000/2\r\n"
3468 "a=msid:stream_id \r\n";
3469
3470 JsepSessionDescription jdesc_output(kDummyString);
3471 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
3472}
3473
3474TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
3475 static const char kSdpWithMissingStreamId[] =
3476 "v=0\r\n"
3477 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3478 "s=-\r\n"
3479 "t=0 0\r\n"
3480 "m=audio 9 RTP/SAVPF 111\r\n"
3481 "c=IN IP4 0.0.0.0\r\n"
3482 "a=rtpmap:111 opus/48000/2\r\n"
3483 "a=msid: track_id\r\n";
3484
3485 JsepSessionDescription jdesc_output(kDummyString);
3486 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
3487}
zhihuang38989e52017-03-21 11:04:53 -07003488
3489// Tests that if both session-level address and media-level address exist, use
3490// the media-level address.
3491TEST_F(WebRtcSdpTest, ParseConnectionData) {
3492 JsepSessionDescription jsep_desc(kDummyString);
3493
3494 // Sesssion-level address.
3495 std::string sdp = kSdpFullString;
3496 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3497 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3498
3499 const auto& content1 = jsep_desc.description()->contents()[0];
3500 EXPECT_EQ("74.125.127.126:2345",
3501 static_cast<cricket::MediaContentDescription*>(content1.description)
3502 ->connection_address()
3503 .ToString());
3504 const auto& content2 = jsep_desc.description()->contents()[1];
3505 EXPECT_EQ("74.125.224.39:3457",
3506 static_cast<cricket::MediaContentDescription*>(content2.description)
3507 ->connection_address()
3508 .ToString());
3509}
3510
3511// Tests that the session-level connection address will be used if the media
3512// level-addresses are not specified.
3513TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
3514 JsepSessionDescription jsep_desc(kDummyString);
3515
3516 // Sesssion-level address.
3517 std::string sdp = kSdpString;
3518 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3519 // Remove the media level addresses.
3520 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3521 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3522 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3523
3524 const auto& content1 = jsep_desc.description()->contents()[0];
3525 EXPECT_EQ("192.168.0.3:9",
3526 static_cast<cricket::MediaContentDescription*>(content1.description)
3527 ->connection_address()
3528 .ToString());
3529 const auto& content2 = jsep_desc.description()->contents()[1];
3530 EXPECT_EQ("192.168.0.3:9",
3531 static_cast<cricket::MediaContentDescription*>(content2.description)
3532 ->connection_address()
3533 .ToString());
3534}
3535
3536TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
3537 JsepSessionDescription jsep_desc(kDummyString);
3538
3539 std::string sdp = kSdpString;
3540 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3541 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
3542 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
3543 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
3544 &sdp);
3545 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
3546 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
3547 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
3548 &sdp);
3549 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3550 const auto& content1 = jsep_desc.description()->contents()[0];
3551 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
3552 static_cast<cricket::MediaContentDescription*>(content1.description)
3553 ->connection_address()
3554 .ToString());
3555 const auto& content2 = jsep_desc.description()->contents()[1];
3556 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
3557 static_cast<cricket::MediaContentDescription*>(content2.description)
3558 ->connection_address()
3559 .ToString());
3560}
3561
3562// Test that the invalid or unsupprted connection data cannot be parsed.
3563TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
3564 JsepSessionDescription jsep_desc(kDummyString);
3565 std::string sdp = kSdpString;
3566 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3567
3568 // Unsupported multicast IPv4 address.
3569 sdp = kSdpFullString;
3570 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
3571 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3572
3573 // Unsupported multicast IPv6 address.
3574 sdp = kSdpFullString;
3575 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
3576 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3577
3578 // Mismatched address type.
3579 sdp = kSdpFullString;
3580 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
3581 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3582
3583 sdp = kSdpFullString;
3584 Replace("c=IN IP4 74.125.224.39\r\n",
3585 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
3586 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3587}
3588
3589TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
3590 JsepSessionDescription expected_jsep(kDummyString);
3591 MakeDescriptionWithoutCandidates(&expected_jsep);
3592 // Serialization.
3593 std::string message = webrtc::SdpSerialize(expected_jsep, false);
3594 // Deserialization.
3595 JsepSessionDescription jdesc(kDummyString);
3596 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
3597 auto audio_desc = static_cast<cricket::MediaContentDescription*>(
3598 jdesc.description()->GetContentByName(kAudioContentName)->description);
3599 auto video_desc = static_cast<cricket::MediaContentDescription*>(
3600 jdesc.description()->GetContentByName(kVideoContentName)->description);
3601 EXPECT_EQ(audio_desc_->connection_address().ToString(),
3602 audio_desc->connection_address().ToString());
3603 EXPECT_EQ(video_desc_->connection_address().ToString(),
3604 video_desc->connection_address().ToString());
3605}