blob: fb55e31c9ce7cdf7cfdc9ad7a575c5c998fcd648 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 * Copyright 2011 Google Inc.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <set>
29#include <string>
30#include <vector>
31
32#include "talk/app/webrtc/jsepsessiondescription.h"
33#include "talk/app/webrtc/webrtcsdp.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000034#include "talk/media/base/constants.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000035#include "webrtc/p2p/base/constants.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000036#include "talk/session/media/mediasession.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000037#include "webrtc/base/gunit.h"
38#include "webrtc/base/logging.h"
39#include "webrtc/base/messagedigest.h"
40#include "webrtc/base/scoped_ptr.h"
41#include "webrtc/base/sslfingerprint.h"
42#include "webrtc/base/stringencode.h"
43#include "webrtc/base/stringutils.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044
45using cricket::AudioCodec;
46using cricket::AudioContentDescription;
47using cricket::Candidate;
48using cricket::ContentInfo;
49using cricket::CryptoParams;
50using cricket::ContentGroup;
51using cricket::DataCodec;
52using cricket::DataContentDescription;
53using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
54using cricket::ICE_CANDIDATE_COMPONENT_RTP;
55using cricket::kFecSsrcGroupSemantics;
56using cricket::LOCAL_PORT_TYPE;
57using cricket::NS_JINGLE_DRAFT_SCTP;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058using cricket::NS_JINGLE_RTP;
59using cricket::RtpHeaderExtension;
60using cricket::RELAY_PORT_TYPE;
61using cricket::SessionDescription;
62using cricket::StreamParams;
63using cricket::STUN_PORT_TYPE;
64using cricket::TransportDescription;
65using cricket::TransportInfo;
66using cricket::VideoCodec;
67using cricket::VideoContentDescription;
68using webrtc::IceCandidateCollection;
69using webrtc::IceCandidateInterface;
70using webrtc::JsepIceCandidate;
71using webrtc::JsepSessionDescription;
72using webrtc::SdpParseError;
73using webrtc::SessionDescriptionInterface;
74
75typedef std::vector<AudioCodec> AudioCodecs;
76typedef std::vector<Candidate> Candidates;
77
Peter Boström0c4e06b2015-10-07 12:23:21 +020078static const uint32_t kDefaultSctpPort = 5000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020080static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
henrike@webrtc.org28e20752013-07-10 00:45:36 +000081static const char kCandidateUfragVoice[] = "ufrag_voice";
82static const char kCandidatePwdVoice[] = "pwd_voice";
83static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
84static const char kCandidateUfragVideo[] = "ufrag_video";
85static const char kCandidatePwdVideo[] = "pwd_video";
86static const char kCandidateUfragData[] = "ufrag_data";
87static const char kCandidatePwdData[] = "pwd_data";
88static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020089static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090static const char kCandidateFoundation1[] = "a0+B/1";
91static const char kCandidateFoundation2[] = "a0+B/2";
92static const char kCandidateFoundation3[] = "a0+B/3";
93static const char kCandidateFoundation4[] = "a0+B/4";
94static const char kAttributeCryptoVoice[] =
95 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
96 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
97 "dummy_session_params\r\n";
98static const char kAttributeCryptoVideo[] =
99 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
100 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
101static const char kFingerprint[] = "a=fingerprint:sha-1 "
102 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n";
103static const int kExtmapId = 1;
104static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
105static const char kExtmap[] =
106 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
107static const char kExtmapWithDirectionAndAttribute[] =
108 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
109
Peter Boström0c4e06b2015-10-07 12:23:21 +0200110static const uint8_t kIdentityDigest[] = {
111 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
112 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000113
lally@webrtc.org34807282015-02-24 20:19:39 +0000114static const char kDtlsSctp[] = "DTLS/SCTP";
115static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
116static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +0000117
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000118struct CodecParams {
119 int max_ptime;
120 int ptime;
121 int min_ptime;
122 int sprop_stereo;
123 int stereo;
124 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000125 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000126};
127
128// Reference sdp string
129static const char kSdpFullString[] =
130 "v=0\r\n"
131 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
132 "s=-\r\n"
133 "t=0 0\r\n"
134 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
135 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
136 "c=IN IP4 74.125.127.126\r\n"
137 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
138 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
139 "generation 2\r\n"
140 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
141 "generation 2\r\n"
142 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
143 "generation 2\r\n"
144 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
145 "generation 2\r\n"
146 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
147 "raddr 192.168.1.5 rport 2346 "
148 "generation 2\r\n"
149 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
150 "raddr 192.168.1.5 rport 2348 "
151 "generation 2\r\n"
152 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
153 "a=mid:audio_content_name\r\n"
154 "a=sendrecv\r\n"
155 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800156 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000157 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
158 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
159 "dummy_session_params\r\n"
160 "a=rtpmap:111 opus/48000/2\r\n"
161 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000162 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000163 "a=ssrc:1 cname:stream_1_cname\r\n"
164 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
165 "a=ssrc:1 mslabel:local_stream_1\r\n"
166 "a=ssrc:1 label:audio_track_id_1\r\n"
167 "a=ssrc:4 cname:stream_2_cname\r\n"
168 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
169 "a=ssrc:4 mslabel:local_stream_2\r\n"
170 "a=ssrc:4 label:audio_track_id_2\r\n"
171 "m=video 3457 RTP/SAVPF 120\r\n"
172 "c=IN IP4 74.125.224.39\r\n"
173 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
174 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
175 "generation 2\r\n"
176 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
177 "generation 2\r\n"
178 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
179 "generation 2\r\n"
180 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
181 "generation 2\r\n"
182 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
183 "generation 2\r\n"
184 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
185 "generation 2\r\n"
186 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
187 "a=mid:video_content_name\r\n"
188 "a=sendrecv\r\n"
189 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
190 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
191 "a=rtpmap:120 VP8/90000\r\n"
192 "a=ssrc:2 cname:stream_1_cname\r\n"
193 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
194 "a=ssrc:2 mslabel:local_stream_1\r\n"
195 "a=ssrc:2 label:video_track_id_1\r\n"
196 "a=ssrc:3 cname:stream_1_cname\r\n"
197 "a=ssrc:3 msid:local_stream_1 video_track_id_2\r\n"
198 "a=ssrc:3 mslabel:local_stream_1\r\n"
199 "a=ssrc:3 label:video_track_id_2\r\n"
200 "a=ssrc-group:FEC 5 6\r\n"
201 "a=ssrc:5 cname:stream_2_cname\r\n"
202 "a=ssrc:5 msid:local_stream_2 video_track_id_3\r\n"
203 "a=ssrc:5 mslabel:local_stream_2\r\n"
204 "a=ssrc:5 label:video_track_id_3\r\n"
205 "a=ssrc:6 cname:stream_2_cname\r\n"
206 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
207 "a=ssrc:6 mslabel:local_stream_2\r\n"
208 "a=ssrc:6 label:video_track_id_3\r\n";
209
210// SDP reference string without the candidates.
211static const char kSdpString[] =
212 "v=0\r\n"
213 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
214 "s=-\r\n"
215 "t=0 0\r\n"
216 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000217 "m=audio 9 RTP/SAVPF 111 103 104\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_voice\r\na=ice-pwd:pwd_voice\r\n"
221 "a=mid:audio_content_name\r\n"
222 "a=sendrecv\r\n"
223 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800224 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000225 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
226 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
227 "dummy_session_params\r\n"
228 "a=rtpmap:111 opus/48000/2\r\n"
229 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000230 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000231 "a=ssrc:1 cname:stream_1_cname\r\n"
232 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
233 "a=ssrc:1 mslabel:local_stream_1\r\n"
234 "a=ssrc:1 label:audio_track_id_1\r\n"
235 "a=ssrc:4 cname:stream_2_cname\r\n"
236 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
237 "a=ssrc:4 mslabel:local_stream_2\r\n"
238 "a=ssrc:4 label:audio_track_id_2\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000239 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000240 "c=IN IP4 0.0.0.0\r\n"
241 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000242 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
243 "a=mid:video_content_name\r\n"
244 "a=sendrecv\r\n"
245 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
246 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
247 "a=rtpmap:120 VP8/90000\r\n"
248 "a=ssrc:2 cname:stream_1_cname\r\n"
249 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
250 "a=ssrc:2 mslabel:local_stream_1\r\n"
251 "a=ssrc:2 label:video_track_id_1\r\n"
252 "a=ssrc:3 cname:stream_1_cname\r\n"
253 "a=ssrc:3 msid:local_stream_1 video_track_id_2\r\n"
254 "a=ssrc:3 mslabel:local_stream_1\r\n"
255 "a=ssrc:3 label:video_track_id_2\r\n"
256 "a=ssrc-group:FEC 5 6\r\n"
257 "a=ssrc:5 cname:stream_2_cname\r\n"
258 "a=ssrc:5 msid:local_stream_2 video_track_id_3\r\n"
259 "a=ssrc:5 mslabel:local_stream_2\r\n"
260 "a=ssrc:5 label:video_track_id_3\r\n"
261 "a=ssrc:6 cname:stream_2_cname\r\n"
262 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
263 "a=ssrc:6 mslabel:local_stream_2\r\n"
264 "a=ssrc:6 label:video_track_id_3\r\n";
265
266static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000267 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000268 "c=IN IP4 0.0.0.0\r\n"
269 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000270 "a=ice-ufrag:ufrag_data\r\n"
271 "a=ice-pwd:pwd_data\r\n"
272 "a=mid:data_content_name\r\n"
273 "a=sendrecv\r\n"
274 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
275 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
276 "a=rtpmap:101 google-data/90000\r\n"
277 "a=ssrc:10 cname:data_channel_cname\r\n"
278 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
279 "a=ssrc:10 mslabel:data_channel\r\n"
280 "a=ssrc:10 label:data_channeld0\r\n";
281
282static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000283 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000284 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000285 "a=ice-ufrag:ufrag_data\r\n"
286 "a=ice-pwd:pwd_data\r\n"
287 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000288 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000289
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000290// draft-ietf-mmusic-sctp-sdp-12
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000291static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000292 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
293 "a=max-message-size=100000\r\n"
294 "a=sctp-port 5000\r\n"
295 "c=IN IP4 0.0.0.0\r\n"
296 "a=ice-ufrag:ufrag_data\r\n"
297 "a=ice-pwd:pwd_data\r\n"
298 "a=mid:data_content_name\r\n";
299
lally69f57602015-10-08 10:15:04 -0700300static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
301 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
302 "a=max-message-size=100000\r\n"
303 "a=sctp-port:5000\r\n"
304 "c=IN IP4 0.0.0.0\r\n"
305 "a=ice-ufrag:ufrag_data\r\n"
306 "a=ice-pwd:pwd_data\r\n"
307 "a=mid:data_content_name\r\n";
308
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000309static const char kSdpSctpDataChannelWithCandidatesString[] =
310 "m=application 2345 DTLS/SCTP 5000\r\n"
311 "c=IN IP4 74.125.127.126\r\n"
312 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
313 "generation 2\r\n"
314 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
315 "generation 2\r\n"
316 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
317 "raddr 192.168.1.5 rport 2346 "
318 "generation 2\r\n"
319 "a=ice-ufrag:ufrag_data\r\n"
320 "a=ice-pwd:pwd_data\r\n"
321 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000322 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000323
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000324static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000325 "v=0\r\n"
326 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
327 "s=-\r\n"
328 "t=0 0\r\n"
329 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000330 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000331 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000332 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000333 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000334 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000335 "a=x-google-flag:conference\r\n";
336
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000337static const char kSdpSessionString[] =
338 "v=0\r\n"
339 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
340 "s=-\r\n"
341 "t=0 0\r\n"
342 "a=msid-semantic: WMS local_stream\r\n";
343
344static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000345 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000346 "c=IN IP4 0.0.0.0\r\n"
347 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000348 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
349 "a=mid:audio_content_name\r\n"
350 "a=sendrecv\r\n"
351 "a=rtpmap:111 opus/48000/2\r\n"
352 "a=ssrc:1 cname:stream_1_cname\r\n"
353 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
354 "a=ssrc:1 mslabel:local_stream\r\n"
355 "a=ssrc:1 label:audio_track_id_1\r\n";
356
357static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000358 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000359 "c=IN IP4 0.0.0.0\r\n"
360 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000361 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
362 "a=mid:video_content_name\r\n"
363 "a=sendrecv\r\n"
364 "a=rtpmap:120 VP8/90000\r\n"
365 "a=ssrc:2 cname:stream_1_cname\r\n"
366 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
367 "a=ssrc:2 mslabel:local_stream\r\n"
368 "a=ssrc:2 label:video_track_id_1\r\n";
369
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000370
371// One candidate reference string as per W3c spec.
372// candidate:<blah> not a=candidate:<blah>CRLF
373static const char kRawCandidate[] =
374 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
375// One candidate reference string.
376static const char kSdpOneCandidate[] =
377 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
378 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000379
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000380static const char kSdpTcpActiveCandidate[] =
381 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
382 "tcptype active generation 2";
383static const char kSdpTcpPassiveCandidate[] =
384 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
385 "tcptype passive generation 2";
386static const char kSdpTcpSOCandidate[] =
387 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
388 "tcptype so generation 2";
389static const char kSdpTcpInvalidCandidate[] =
390 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
391 "tcptype invalid generation 2";
392
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000393// One candidate reference string with IPV6 address.
394static const char kRawIPV6Candidate[] =
395 "candidate:a0+B/1 1 udp 2130706432 "
396 "abcd::abcd::abcd::abcd::abcd::abcd::abcd::abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000397
398// One candidate reference string.
399static const char kSdpOneCandidateOldFormat[] =
400 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
401 " eth0 username user_rtp password password_rtp generation 2\r\n";
402
403// Session id and version
404static const char kSessionId[] = "18446744069414584320";
405static const char kSessionVersion[] = "18446462598732840960";
406
407// Ice options
408static const char kIceOption1[] = "iceoption1";
409static const char kIceOption2[] = "iceoption2";
410static const char kIceOption3[] = "iceoption3";
411
412// Content name
413static const char kAudioContentName[] = "audio_content_name";
414static const char kVideoContentName[] = "video_content_name";
415static const char kDataContentName[] = "data_content_name";
416
417// MediaStream 1
418static const char kStreamLabel1[] = "local_stream_1";
419static const char kStream1Cname[] = "stream_1_cname";
420static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200421static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000422static const char kVideoTrackId1[] = "video_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200423static const uint32_t kVideoTrack1Ssrc = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000424static const char kVideoTrackId2[] = "video_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200425static const uint32_t kVideoTrack2Ssrc = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000426
427// MediaStream 2
428static const char kStreamLabel2[] = "local_stream_2";
429static const char kStream2Cname[] = "stream_2_cname";
430static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200431static const uint32_t kAudioTrack2Ssrc = 4;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000432static const char kVideoTrackId3[] = "video_track_id_3";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200433static const uint32_t kVideoTrack3Ssrc = 5;
434static const uint32_t kVideoTrack4Ssrc = 6;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000435
436// DataChannel
437static const char kDataChannelLabel[] = "data_channel";
438static const char kDataChannelMsid[] = "data_channeld0";
439static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200440static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000441
442// Candidate
443static const char kDummyMid[] = "dummy_mid";
444static const int kDummyIndex = 123;
445
446// Misc
447static const char kDummyString[] = "dummy";
448
449// Helper functions
450
451static bool SdpDeserialize(const std::string& message,
452 JsepSessionDescription* jdesc) {
453 return webrtc::SdpDeserialize(message, jdesc, NULL);
454}
455
456static bool SdpDeserializeCandidate(const std::string& message,
457 JsepIceCandidate* candidate) {
458 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
459}
460
461// Add some extra |newlines| to the |message| after |line|.
462static void InjectAfter(const std::string& line,
463 const std::string& newlines,
464 std::string* message) {
465 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000466 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000467 tmp.c_str(), tmp.length(), message);
468}
469
470static void Replace(const std::string& line,
471 const std::string& newlines,
472 std::string* message) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000473 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000474 newlines.c_str(), newlines.length(), message);
475}
476
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000477// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
478// message.
479static void ExpectParseFailure(const std::string& bad_sdp,
480 const std::string& bad_part) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000481 JsepSessionDescription desc(kDummyString);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000482 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000483 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000484 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000485 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
486}
487
488// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
489static void ExpectParseFailure(const char* good_part, const char* bad_part) {
490 std::string bad_sdp = kSdpFullString;
491 Replace(good_part, bad_part, &bad_sdp);
492 ExpectParseFailure(bad_sdp, bad_part);
493}
494
495// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
496static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
497 const std::string& newlines,
498 const std::string& bad_part) {
499 std::string bad_sdp = kSdpFullString;
500 InjectAfter(injectpoint, newlines, &bad_sdp);
501 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000502}
503
504static void ReplaceDirection(cricket::MediaContentDirection direction,
505 std::string* message) {
506 std::string new_direction;
507 switch (direction) {
508 case cricket::MD_INACTIVE:
509 new_direction = "a=inactive";
510 break;
511 case cricket::MD_SENDONLY:
512 new_direction = "a=sendonly";
513 break;
514 case cricket::MD_RECVONLY:
515 new_direction = "a=recvonly";
516 break;
517 case cricket::MD_SENDRECV:
518 default:
519 new_direction = "a=sendrecv";
520 break;
521 }
522 Replace("a=sendrecv", new_direction, message);
523}
524
525static void ReplaceRejected(bool audio_rejected, bool video_rejected,
526 std::string* message) {
527 if (audio_rejected) {
528 Replace("m=audio 2345", "m=audio 0", message);
529 }
530 if (video_rejected) {
531 Replace("m=video 3457", "m=video 0", message);
532 }
533}
534
535// WebRtcSdpTest
536
537class WebRtcSdpTest : public testing::Test {
538 public:
539 WebRtcSdpTest()
540 : jdesc_(kDummyString) {
541 // AudioContentDescription
542 audio_desc_ = CreateAudioContentDescription();
543 AudioCodec opus(111, "opus", 48000, 0, 2, 3);
544 audio_desc_->AddCodec(opus);
545 audio_desc_->AddCodec(AudioCodec(103, "ISAC", 16000, 32000, 1, 2));
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000546 audio_desc_->AddCodec(AudioCodec(104, "ISAC", 32000, 56000, 1, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000547 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
548
549 // VideoContentDescription
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000550 rtc::scoped_ptr<VideoContentDescription> video(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000551 new VideoContentDescription());
552 video_desc_ = video.get();
553 StreamParams video_stream1;
554 video_stream1.id = kVideoTrackId1;
555 video_stream1.cname = kStream1Cname;
556 video_stream1.sync_label = kStreamLabel1;
557 video_stream1.ssrcs.push_back(kVideoTrack1Ssrc);
558 video->AddStream(video_stream1);
559 StreamParams video_stream2;
560 video_stream2.id = kVideoTrackId2;
561 video_stream2.cname = kStream1Cname;
562 video_stream2.sync_label = kStreamLabel1;
563 video_stream2.ssrcs.push_back(kVideoTrack2Ssrc);
564 video->AddStream(video_stream2);
565 StreamParams video_stream3;
566 video_stream3.id = kVideoTrackId3;
567 video_stream3.cname = kStream2Cname;
568 video_stream3.sync_label = kStreamLabel2;
569 video_stream3.ssrcs.push_back(kVideoTrack3Ssrc);
570 video_stream3.ssrcs.push_back(kVideoTrack4Ssrc);
571 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream3.ssrcs);
572 video_stream3.ssrc_groups.push_back(ssrc_group);
573 video->AddStream(video_stream3);
574 video->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
575 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
576 video->set_protocol(cricket::kMediaProtocolSavpf);
577 video->AddCodec(VideoCodec(
578 120,
579 JsepSessionDescription::kDefaultVideoCodecName,
580 JsepSessionDescription::kMaxVideoCodecWidth,
581 JsepSessionDescription::kMaxVideoCodecHeight,
582 JsepSessionDescription::kDefaultVideoCodecFramerate,
583 JsepSessionDescription::kDefaultVideoCodecPreference));
584
585 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP,
586 video.release());
587
588 // TransportInfo
589 EXPECT_TRUE(desc_.AddTransportInfo(
590 TransportInfo(kAudioContentName,
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700591 TransportDescription(kCandidateUfragVoice,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000592 kCandidatePwdVoice))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000593 EXPECT_TRUE(desc_.AddTransportInfo(
594 TransportInfo(kVideoContentName,
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700595 TransportDescription(kCandidateUfragVideo,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000596 kCandidatePwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000597
598 // v4 host
599 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000600 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000601 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000602 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
603 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000604 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000605 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000606 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
607 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000608 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000609 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000610 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
611 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000612 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000613 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000614 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
615 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000616
617 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000618 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000619 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
620 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000621 cricket::LOCAL_PORT_TYPE,
622 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000623 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000624 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
625 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000626 cricket::LOCAL_PORT_TYPE,
627 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000628 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000629 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
630 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000631 cricket::LOCAL_PORT_TYPE,
632 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000633 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000634 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
635 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000636 cricket::LOCAL_PORT_TYPE,
637 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000638
639 // stun
640 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000641 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
642 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000643 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
644 address_stun, kCandidatePriority, "", "",
645 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000646 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000647 candidate9.set_related_address(rel_address_stun);
648
649 address_stun.SetPort(port_stun++);
650 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000651 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
652 address_stun, kCandidatePriority, "", "",
653 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000654 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000655 candidate10.set_related_address(rel_address_stun);
656
657 // relay
658 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000659 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000660 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
661 address_relay, kCandidatePriority, "", "",
662 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000663 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000664 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000665 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
666 address_relay, kCandidatePriority, "", "",
667 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000668 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000669
670 // voice
671 candidates_.push_back(candidate1);
672 candidates_.push_back(candidate2);
673 candidates_.push_back(candidate5);
674 candidates_.push_back(candidate6);
675 candidates_.push_back(candidate9);
676 candidates_.push_back(candidate10);
677
678 // video
679 candidates_.push_back(candidate3);
680 candidates_.push_back(candidate4);
681 candidates_.push_back(candidate7);
682 candidates_.push_back(candidate8);
683 candidates_.push_back(candidate11);
684 candidates_.push_back(candidate12);
685
686 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"),
687 0, candidate1));
688
689 // Set up JsepSessionDescription.
690 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
691 std::string mline_id;
692 int mline_index = 0;
693 for (size_t i = 0; i< candidates_.size(); ++i) {
694 // In this test, the audio m line index will be 0, and the video m line
695 // will be 1.
696 bool is_video = (i > 5);
697 mline_id = is_video ? "video_content_name" : "audio_content_name";
698 mline_index = is_video ? 1 : 0;
699 JsepIceCandidate jice(mline_id,
700 mline_index,
701 candidates_.at(i));
702 jdesc_.AddCandidate(&jice);
703 }
704 }
705
706 AudioContentDescription* CreateAudioContentDescription() {
707 AudioContentDescription* audio = new AudioContentDescription();
708 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -0800709 audio->set_rtcp_reduced_size(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000710 StreamParams audio_stream1;
711 audio_stream1.id = kAudioTrackId1;
712 audio_stream1.cname = kStream1Cname;
713 audio_stream1.sync_label = kStreamLabel1;
714 audio_stream1.ssrcs.push_back(kAudioTrack1Ssrc);
715 audio->AddStream(audio_stream1);
716 StreamParams audio_stream2;
717 audio_stream2.id = kAudioTrackId2;
718 audio_stream2.cname = kStream2Cname;
719 audio_stream2.sync_label = kStreamLabel2;
720 audio_stream2.ssrcs.push_back(kAudioTrack2Ssrc);
721 audio->AddStream(audio_stream2);
722 audio->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_32",
723 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
724 "dummy_session_params"));
725 audio->set_protocol(cricket::kMediaProtocolSavpf);
726 return audio;
727 }
728
729 template <class MCD>
730 void CompareMediaContentDescription(const MCD* cd1,
731 const MCD* cd2) {
732 // type
733 EXPECT_EQ(cd1->type(), cd1->type());
734
735 // content direction
736 EXPECT_EQ(cd1->direction(), cd2->direction());
737
738 // rtcp_mux
739 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
740
deadbeef13871492015-12-09 12:37:51 -0800741 // rtcp_reduced_size
742 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
743
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000744 // cryptos
745 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
746 if (cd1->cryptos().size() != cd2->cryptos().size()) {
747 ADD_FAILURE();
748 return;
749 }
750 for (size_t i = 0; i< cd1->cryptos().size(); ++i) {
751 const CryptoParams c1 = cd1->cryptos().at(i);
752 const CryptoParams c2 = cd2->cryptos().at(i);
753 EXPECT_TRUE(c1.Matches(c2));
754 EXPECT_EQ(c1.key_params, c2.key_params);
755 EXPECT_EQ(c1.session_params, c2.session_params);
756 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +0000757
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000758 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +0000759 // Use an equivalence class here, for old and new versions of the
760 // protocol description.
761 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:35 +0000762 || cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp
763 || cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
764 const bool cd2_is_also_dtls_sctp =
lally@webrtc.orgd7b61652015-02-24 20:18:55 +0000765 cd2->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:35 +0000766 || cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp
767 || cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
768 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +0000769 } else {
770 EXPECT_EQ(cd1->protocol(), cd2->protocol());
771 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000772
773 // codecs
774 EXPECT_EQ(cd1->codecs(), cd2->codecs());
775
776 // bandwidth
777 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
778
779 // streams
780 EXPECT_EQ(cd1->streams(), cd2->streams());
781
782 // extmap
783 ASSERT_EQ(cd1->rtp_header_extensions().size(),
784 cd2->rtp_header_extensions().size());
785 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) {
786 const RtpHeaderExtension ext1 = cd1->rtp_header_extensions().at(i);
787 const RtpHeaderExtension ext2 = cd2->rtp_header_extensions().at(i);
788 EXPECT_EQ(ext1.uri, ext2.uri);
789 EXPECT_EQ(ext1.id, ext2.id);
790 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000791 }
792
793
794 void CompareSessionDescription(const SessionDescription& desc1,
795 const SessionDescription& desc2) {
796 // Compare content descriptions.
797 if (desc1.contents().size() != desc2.contents().size()) {
798 ADD_FAILURE();
799 return;
800 }
801 for (size_t i = 0 ; i < desc1.contents().size(); ++i) {
802 const cricket::ContentInfo& c1 = desc1.contents().at(i);
803 const cricket::ContentInfo& c2 = desc2.contents().at(i);
804 // content name
805 EXPECT_EQ(c1.name, c2.name);
806 // content type
807 // Note, ASSERT will return from the function, but will not stop the test.
808 ASSERT_EQ(c1.type, c2.type);
809
810 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
811 if (IsAudioContent(&c1)) {
812 const AudioContentDescription* acd1 =
813 static_cast<const AudioContentDescription*>(c1.description);
814 const AudioContentDescription* acd2 =
815 static_cast<const AudioContentDescription*>(c2.description);
816 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
817 }
818
819 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
820 if (IsVideoContent(&c1)) {
821 const VideoContentDescription* vcd1 =
822 static_cast<const VideoContentDescription*>(c1.description);
823 const VideoContentDescription* vcd2 =
824 static_cast<const VideoContentDescription*>(c2.description);
825 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
826 }
827
828 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
829 if (IsDataContent(&c1)) {
830 const DataContentDescription* dcd1 =
831 static_cast<const DataContentDescription*>(c1.description);
832 const DataContentDescription* dcd2 =
833 static_cast<const DataContentDescription*>(c2.description);
834 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
835 }
836 }
837
838 // group
839 const cricket::ContentGroups groups1 = desc1.groups();
840 const cricket::ContentGroups groups2 = desc2.groups();
841 EXPECT_EQ(groups1.size(), groups1.size());
842 if (groups1.size() != groups2.size()) {
843 ADD_FAILURE();
844 return;
845 }
846 for (size_t i = 0; i < groups1.size(); ++i) {
847 const cricket::ContentGroup group1 = groups1.at(i);
848 const cricket::ContentGroup group2 = groups2.at(i);
849 EXPECT_EQ(group1.semantics(), group2.semantics());
850 const cricket::ContentNames names1 = group1.content_names();
851 const cricket::ContentNames names2 = group2.content_names();
852 EXPECT_EQ(names1.size(), names2.size());
853 if (names1.size() != names2.size()) {
854 ADD_FAILURE();
855 return;
856 }
857 cricket::ContentNames::const_iterator iter1 = names1.begin();
858 cricket::ContentNames::const_iterator iter2 = names2.begin();
859 while (iter1 != names1.end()) {
860 EXPECT_EQ(*iter1++, *iter2++);
861 }
862 }
863
864 // transport info
865 const cricket::TransportInfos transports1 = desc1.transport_infos();
866 const cricket::TransportInfos transports2 = desc2.transport_infos();
867 EXPECT_EQ(transports1.size(), transports2.size());
868 if (transports1.size() != transports2.size()) {
869 ADD_FAILURE();
870 return;
871 }
872 for (size_t i = 0; i < transports1.size(); ++i) {
873 const cricket::TransportInfo transport1 = transports1.at(i);
874 const cricket::TransportInfo transport2 = transports2.at(i);
875 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876 EXPECT_EQ(transport1.description.ice_ufrag,
877 transport2.description.ice_ufrag);
878 EXPECT_EQ(transport1.description.ice_pwd,
879 transport2.description.ice_pwd);
880 if (transport1.description.identity_fingerprint) {
881 EXPECT_EQ(*transport1.description.identity_fingerprint,
882 *transport2.description.identity_fingerprint);
883 } else {
884 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
885 transport2.description.identity_fingerprint.get());
886 }
887 EXPECT_EQ(transport1.description.transport_options,
888 transport2.description.transport_options);
889 EXPECT_TRUE(CompareCandidates(transport1.description.candidates,
890 transport2.description.candidates));
891 }
deadbeefc80741f2015-10-22 13:14:45 -0700892
893 // global attributes
894 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000895 }
896
897 bool CompareCandidates(const Candidates& cs1, const Candidates& cs2) {
898 EXPECT_EQ(cs1.size(), cs2.size());
899 if (cs1.size() != cs2.size())
900 return false;
901 for (size_t i = 0; i< cs1.size(); ++i) {
902 const Candidate c1 = cs1.at(i);
903 const Candidate c2 = cs2.at(i);
904 EXPECT_TRUE(c1.IsEquivalent(c2));
905 }
906 return true;
907 }
908
909 bool CompareSessionDescription(
910 const JsepSessionDescription& desc1,
911 const JsepSessionDescription& desc2) {
912 EXPECT_EQ(desc1.session_id(), desc2.session_id());
913 EXPECT_EQ(desc1.session_version(), desc2.session_version());
914 CompareSessionDescription(*desc1.description(), *desc2.description());
915 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
916 return false;
917 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
918 const IceCandidateCollection* cc1 = desc1.candidates(i);
919 const IceCandidateCollection* cc2 = desc2.candidates(i);
920 if (cc1->count() != cc2->count())
921 return false;
922 for (size_t j = 0; j < cc1->count(); ++j) {
923 const IceCandidateInterface* c1 = cc1->at(j);
924 const IceCandidateInterface* c2 = cc2->at(j);
925 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
926 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
927 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
928 }
929 }
930 return true;
931 }
932
933 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
934 // them with invalid keywords so that the parser will just ignore them.
935 bool RemoveCandidateUfragPwd(std::string* sdp) {
936 const char ice_ufrag[] = "a=ice-ufrag";
937 const char ice_ufragx[] = "a=xice-ufrag";
938 const char ice_pwd[] = "a=ice-pwd";
939 const char ice_pwdx[] = "a=xice-pwd";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000940 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000941 ice_ufragx, strlen(ice_ufragx), sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000942 rtc::replace_substrs(ice_pwd, strlen(ice_pwd),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000943 ice_pwdx, strlen(ice_pwdx), sdp);
944 return true;
945 }
946
947 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
948 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, int mline_index,
949 const std::string& ufrag, const std::string& pwd) {
950 std::string content_name;
951 if (mline_index == 0) {
952 content_name = kAudioContentName;
953 } else if (mline_index == 1) {
954 content_name = kVideoContentName;
955 } else {
956 ASSERT(false);
957 }
958 TransportInfo transport_info(
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700959 content_name, TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000960 SessionDescription* desc =
961 const_cast<SessionDescription*>(jdesc->description());
962 desc->RemoveTransportInfoByName(content_name);
963 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
964 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
965 const IceCandidateCollection* cc = jdesc_.candidates(i);
966 for (size_t j = 0; j < cc->count(); ++j) {
967 if (cc->at(j)->sdp_mline_index() == mline_index) {
968 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(
969 ufrag);
970 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(
971 pwd);
972 }
973 }
974 }
975 return true;
976 }
977
978 void AddIceOptions(const std::string& content_name,
979 const std::vector<std::string>& transport_options) {
980 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
981 cricket::TransportInfo transport_info =
982 *(desc_.GetTransportInfoByName(content_name));
983 desc_.RemoveTransportInfoByName(content_name);
984 transport_info.description.transport_options = transport_options;
985 desc_.AddTransportInfo(transport_info);
986 }
987
988 void AddFingerprint() {
989 desc_.RemoveTransportInfoByName(kAudioContentName);
990 desc_.RemoveTransportInfoByName(kVideoContentName);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000991 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000992 kIdentityDigest,
993 sizeof(kIdentityDigest));
994 EXPECT_TRUE(desc_.AddTransportInfo(
995 TransportInfo(kAudioContentName,
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700996 TransportDescription(std::vector<std::string>(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000997 kCandidateUfragVoice,
998 kCandidatePwdVoice,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000999 cricket::ICEMODE_FULL,
1000 cricket::CONNECTIONROLE_NONE,
1001 &fingerprint, Candidates()))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001002 EXPECT_TRUE(desc_.AddTransportInfo(
1003 TransportInfo(kVideoContentName,
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001004 TransportDescription(std::vector<std::string>(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001005 kCandidateUfragVideo,
1006 kCandidatePwdVideo,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001007 cricket::ICEMODE_FULL,
1008 cricket::CONNECTIONROLE_NONE,
1009 &fingerprint, Candidates()))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001010 }
1011
1012 void AddExtmap() {
1013 audio_desc_ = static_cast<AudioContentDescription*>(
1014 audio_desc_->Copy());
1015 video_desc_ = static_cast<VideoContentDescription*>(
1016 video_desc_->Copy());
1017 audio_desc_->AddRtpHeaderExtension(
1018 RtpHeaderExtension(kExtmapUri, kExtmapId));
1019 video_desc_->AddRtpHeaderExtension(
1020 RtpHeaderExtension(kExtmapUri, kExtmapId));
1021 desc_.RemoveContentByName(kAudioContentName);
1022 desc_.RemoveContentByName(kVideoContentName);
1023 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1024 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1025 }
1026
1027 void RemoveCryptos() {
1028 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1029 video_desc_->set_cryptos(std::vector<CryptoParams>());
1030 }
1031
1032 bool TestSerializeDirection(cricket::MediaContentDirection direction) {
1033 audio_desc_->set_direction(direction);
1034 video_desc_->set_direction(direction);
1035 std::string new_sdp = kSdpFullString;
1036 ReplaceDirection(direction, &new_sdp);
1037
1038 if (!jdesc_.Initialize(desc_.Copy(),
1039 jdesc_.session_id(),
1040 jdesc_.session_version())) {
1041 return false;
1042 }
1043 std::string message = webrtc::SdpSerialize(jdesc_);
1044 EXPECT_EQ(new_sdp, message);
1045 return true;
1046 }
1047
1048 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
1049 audio_desc_ = static_cast<AudioContentDescription*>(
1050 audio_desc_->Copy());
1051 video_desc_ = static_cast<VideoContentDescription*>(
1052 video_desc_->Copy());
1053 desc_.RemoveContentByName(kAudioContentName);
1054 desc_.RemoveContentByName(kVideoContentName);
1055 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1056 audio_desc_);
1057 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1058 video_desc_);
1059 std::string new_sdp = kSdpFullString;
1060 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1061
1062 if (!jdesc_.Initialize(desc_.Copy(),
1063 jdesc_.session_id(),
1064 jdesc_.session_version())) {
1065 return false;
1066 }
1067 std::string message = webrtc::SdpSerialize(jdesc_);
1068 EXPECT_EQ(new_sdp, message);
1069 return true;
1070 }
1071
1072 void AddSctpDataChannel() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001073 rtc::scoped_ptr<DataContentDescription> data(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001074 new DataContentDescription());
1075 data_desc_ = data.get();
1076 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
wu@webrtc.org78187522013-10-07 23:32:02 +00001077 DataCodec codec(cricket::kGoogleSctpDataCodecId,
1078 cricket::kGoogleSctpDataCodecName, 0);
1079 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1080 data_desc_->AddCodec(codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001081 desc_.AddContent(kDataContentName, NS_JINGLE_DRAFT_SCTP, data.release());
1082 EXPECT_TRUE(desc_.AddTransportInfo(
1083 TransportInfo(kDataContentName,
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001084 TransportDescription(kCandidateUfragData,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001085 kCandidatePwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001086 }
1087
1088 void AddRtpDataChannel() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001089 rtc::scoped_ptr<DataContentDescription> data(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001090 new DataContentDescription());
1091 data_desc_ = data.get();
1092
1093 data_desc_->AddCodec(DataCodec(101, "google-data", 1));
1094 StreamParams data_stream;
1095 data_stream.id = kDataChannelMsid;
1096 data_stream.cname = kDataChannelCname;
1097 data_stream.sync_label = kDataChannelLabel;
1098 data_stream.ssrcs.push_back(kDataChannelSsrc);
1099 data_desc_->AddStream(data_stream);
1100 data_desc_->AddCrypto(CryptoParams(
1101 1, "AES_CM_128_HMAC_SHA1_80",
1102 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
1103 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
1104 desc_.AddContent(kDataContentName, NS_JINGLE_RTP, data.release());
1105 EXPECT_TRUE(desc_.AddTransportInfo(
1106 TransportInfo(kDataContentName,
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001107 TransportDescription(kCandidateUfragData,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001108 kCandidatePwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001109 }
1110
1111 bool TestDeserializeDirection(cricket::MediaContentDirection direction) {
1112 std::string new_sdp = kSdpFullString;
1113 ReplaceDirection(direction, &new_sdp);
1114 JsepSessionDescription new_jdesc(kDummyString);
1115
1116 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1117
1118 audio_desc_->set_direction(direction);
1119 video_desc_->set_direction(direction);
1120 if (!jdesc_.Initialize(desc_.Copy(),
1121 jdesc_.session_id(),
1122 jdesc_.session_version())) {
1123 return false;
1124 }
1125 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1126 return true;
1127 }
1128
1129 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
1130 std::string new_sdp = kSdpFullString;
1131 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1132 JsepSessionDescription new_jdesc(JsepSessionDescription::kOffer);
1133
1134 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1135 audio_desc_ = static_cast<AudioContentDescription*>(
1136 audio_desc_->Copy());
1137 video_desc_ = static_cast<VideoContentDescription*>(
1138 video_desc_->Copy());
1139 desc_.RemoveContentByName(kAudioContentName);
1140 desc_.RemoveContentByName(kVideoContentName);
1141 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1142 audio_desc_);
1143 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1144 video_desc_);
1145 if (!jdesc_.Initialize(desc_.Copy(),
1146 jdesc_.session_id(),
1147 jdesc_.session_version())) {
1148 return false;
1149 }
1150 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1151 return true;
1152 }
1153
1154 void TestDeserializeExtmap(bool session_level, bool media_level) {
1155 AddExtmap();
1156 JsepSessionDescription new_jdesc("dummy");
1157 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1158 jdesc_.session_id(),
1159 jdesc_.session_version()));
1160 JsepSessionDescription jdesc_with_extmap("dummy");
1161 std::string sdp_with_extmap = kSdpString;
1162 if (session_level) {
1163 InjectAfter(kSessionTime, kExtmapWithDirectionAndAttribute,
1164 &sdp_with_extmap);
1165 }
1166 if (media_level) {
1167 InjectAfter(kAttributeIcePwdVoice, kExtmapWithDirectionAndAttribute,
1168 &sdp_with_extmap);
1169 InjectAfter(kAttributeIcePwdVideo, kExtmapWithDirectionAndAttribute,
1170 &sdp_with_extmap);
1171 }
1172 // The extmap can't be present at the same time in both session level and
1173 // media level.
1174 if (session_level && media_level) {
1175 SdpParseError error;
1176 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap,
1177 &jdesc_with_extmap, &error));
1178 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1179 } else {
1180 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1181 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1182 }
1183 }
1184
1185 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
1186 const std::string& name, int expected_value) {
1187 cricket::CodecParameterMap::const_iterator found = params.find(name);
1188 ASSERT_TRUE(found != params.end());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001189 EXPECT_EQ(found->second, rtc::ToString<int>(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001190 }
1191
1192 void TestDeserializeCodecParams(const CodecParams& params,
1193 JsepSessionDescription* jdesc_output) {
1194 std::string sdp =
1195 "v=0\r\n"
1196 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1197 "s=-\r\n"
1198 "t=0 0\r\n"
1199 // Include semantics for WebRTC Media Streams since it is supported by
1200 // this parser, and will be added to the SDP when serializing a session
1201 // description.
1202 "a=msid-semantic: WMS\r\n"
1203 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001204 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001205 // Pltype 111 listed before 103 and 104 in the map.
1206 "a=rtpmap:111 opus/48000/2\r\n"
1207 // Pltype 103 listed before 104.
1208 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001209 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001210 "a=fmtp:111 0-15,66,70\r\n"
1211 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001212 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001213 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001214 << "; sprop-stereo=" << params.sprop_stereo
1215 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001216 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001217 << "a=ptime:" << params.ptime << "\r\n"
1218 << "a=maxptime:" << params.max_ptime << "\r\n";
1219 sdp += os.str();
1220
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001221 os.clear();
1222 os.str("");
1223 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001224 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001225 << "a=rtpmap:99 VP8/90000\r\n"
1226 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001227 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001228 sdp += os.str();
1229
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001230 // Deserialize
1231 SdpParseError error;
1232 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1233
1234 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1235 ASSERT_TRUE(ac != NULL);
1236 const AudioContentDescription* acd =
1237 static_cast<const AudioContentDescription*>(ac->description);
1238 ASSERT_FALSE(acd->codecs().empty());
1239 cricket::AudioCodec opus = acd->codecs()[0];
1240 EXPECT_EQ("opus", opus.name);
1241 EXPECT_EQ(111, opus.id);
1242 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1243 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1244 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1245 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001246 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1247 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001248 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1249 cricket::AudioCodec codec = acd->codecs()[i];
1250 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1251 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
1252 if (codec.name == "ISAC") {
1253 if (codec.clockrate == 16000) {
1254 EXPECT_EQ(32000, codec.bitrate);
1255 } else {
1256 EXPECT_EQ(56000, codec.bitrate);
1257 }
1258 }
1259 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001260
1261 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1262 ASSERT_TRUE(vc != NULL);
1263 const VideoContentDescription* vcd =
1264 static_cast<const VideoContentDescription*>(vc->description);
1265 ASSERT_FALSE(vcd->codecs().empty());
1266 cricket::VideoCodec vp8 = vcd->codecs()[0];
1267 EXPECT_EQ("VP8", vp8.name);
1268 EXPECT_EQ(99, vp8.id);
1269 cricket::VideoCodec rtx = vcd->codecs()[1];
1270 EXPECT_EQ("RTX", rtx.name);
1271 EXPECT_EQ(95, rtx.id);
1272 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001273 }
1274
1275 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1276 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001277 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001278 "v=0\r\n"
1279 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1280 "s=-\r\n"
1281 "t=0 0\r\n"
1282 // Include semantics for WebRTC Media Streams since it is supported by
1283 // this parser, and will be added to the SDP when serializing a session
1284 // description.
1285 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001286 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001287 "a=rtpmap:111 opus/48000/2\r\n";
1288 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001289 "m=video 3457 RTP/SAVPF 101\r\n"
1290 "a=rtpmap:101 VP8/90000\r\n"
1291 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001292 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001293 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001294 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001295 os << sdp_session_and_audio;
1296 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
1297 os << sdp_video;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001298 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001299 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001300 // Deserialize
1301 SdpParseError error;
1302 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1303 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1304 ASSERT_TRUE(ac != NULL);
1305 const AudioContentDescription* acd =
1306 static_cast<const AudioContentDescription*>(ac->description);
1307 ASSERT_FALSE(acd->codecs().empty());
1308 cricket::AudioCodec opus = acd->codecs()[0];
1309 EXPECT_EQ(111, opus.id);
1310 EXPECT_TRUE(opus.HasFeedbackParam(
1311 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1312 cricket::kParamValueEmpty)));
1313
1314 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1315 ASSERT_TRUE(vc != NULL);
1316 const VideoContentDescription* vcd =
1317 static_cast<const VideoContentDescription*>(vc->description);
1318 ASSERT_FALSE(vcd->codecs().empty());
1319 cricket::VideoCodec vp8 = vcd->codecs()[0];
1320 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1321 vp8.name.c_str());
1322 EXPECT_EQ(101, vp8.id);
1323 EXPECT_TRUE(vp8.HasFeedbackParam(
1324 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1325 cricket::kParamValueEmpty)));
1326 EXPECT_TRUE(vp8.HasFeedbackParam(
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001327 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1328 cricket::kRtcpFbNackParamPli)));
1329 EXPECT_TRUE(vp8.HasFeedbackParam(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001330 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
1331 cricket::kParamValueEmpty)));
1332 EXPECT_TRUE(vp8.HasFeedbackParam(
1333 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
1334 cricket::kRtcpFbCcmParamFir)));
1335 }
1336
1337 // Two SDP messages can mean the same thing but be different strings, e.g.
1338 // some of the lines can be serialized in different order.
1339 // However, a deserialized description can be compared field by field and has
1340 // no order. If deserializer has already been tested, serializing then
1341 // deserializing and comparing JsepSessionDescription will test
1342 // the serializer sufficiently.
1343 void TestSerialize(const JsepSessionDescription& jdesc) {
1344 std::string message = webrtc::SdpSerialize(jdesc);
1345 JsepSessionDescription jdesc_output_des(kDummyString);
1346 SdpParseError error;
1347 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1348 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1349 }
1350
1351 protected:
1352 SessionDescription desc_;
1353 AudioContentDescription* audio_desc_;
1354 VideoContentDescription* video_desc_;
1355 DataContentDescription* data_desc_;
1356 Candidates candidates_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001357 rtc::scoped_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001358 JsepSessionDescription jdesc_;
1359};
1360
1361void TestMismatch(const std::string& string1, const std::string& string2) {
1362 int position = 0;
1363 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1364 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001365 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001366 break;
1367 }
1368 }
1369 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1370 << " character\n"
1371 << " 1: " << string1.substr(position, 20) << "\n"
1372 << " 2: " << string2.substr(position, 20) << "\n";
1373}
1374
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001375TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1376 // SessionDescription with desc and candidates.
1377 std::string message = webrtc::SdpSerialize(jdesc_);
1378 TestMismatch(std::string(kSdpFullString), message);
1379}
1380
1381TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
1382 JsepSessionDescription jdesc_empty(kDummyString);
1383 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
1384}
1385
guoweis@webrtc.org57ac2c82015-02-06 00:45:13 +00001386// This tests serialization of SDP with only IPv6 candidates and verifies that
1387// IPv6 is used as default address in c line according to preference.
1388TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIPv6Only) {
1389 // Only test 1 m line.
1390 desc_.RemoveContentByName("video_content_name");
1391 // Stun has a high preference than local host.
1392 cricket::Candidate candidate1(
1393 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1394 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1395 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1396 cricket::Candidate candidate2(
1397 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1398 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
1399 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1400 JsepSessionDescription jdesc(kDummyString);
1401 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1402
1403 // Only add the candidates to audio m line.
1404 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1405 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1406 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1407 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
1408 std::string message = webrtc::SdpSerialize(jdesc);
1409
1410 // Audio line should have a c line like this one.
1411 EXPECT_NE(message.find("c=IN IP6 ::1"), std::string::npos);
1412 // Shouldn't have a IP4 c line.
1413 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
1414}
1415
1416// This tests serialization of SDP with both IPv4 and IPv6 candidates and
1417// verifies that IPv4 is used as default address in c line even if the
1418// preference of IPv4 is lower.
1419TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothIPFamilies) {
1420 // Only test 1 m line.
1421 desc_.RemoveContentByName("video_content_name");
1422 cricket::Candidate candidate_v4(
1423 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1424 rtc::SocketAddress("192.168.1.5", 1234), kCandidatePriority, "", "",
1425 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1426 cricket::Candidate candidate_v6(
1427 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1428 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1429 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1430 JsepSessionDescription jdesc(kDummyString);
1431 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1432
1433 // Only add the candidates to audio m line.
1434 JsepIceCandidate jice_v4("audio_content_name", 0, candidate_v4);
1435 JsepIceCandidate jice_v6("audio_content_name", 0, candidate_v6);
1436 ASSERT_TRUE(jdesc.AddCandidate(&jice_v4));
1437 ASSERT_TRUE(jdesc.AddCandidate(&jice_v6));
1438 std::string message = webrtc::SdpSerialize(jdesc);
1439
1440 // Audio line should have a c line like this one.
1441 EXPECT_NE(message.find("c=IN IP4 192.168.1.5"), std::string::npos);
1442 // Shouldn't have a IP6 c line.
1443 EXPECT_EQ(message.find("c=IN IP6"), std::string::npos);
1444}
1445
1446// This tests serialization of SDP with both UDP and TCP candidates and
1447// verifies that UDP is used as default address in c line even if the
1448// preference of UDP is lower.
1449TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothProtocols) {
1450 // Only test 1 m line.
1451 desc_.RemoveContentByName("video_content_name");
1452 // Stun has a high preference than local host.
1453 cricket::Candidate candidate1(
1454 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1455 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1456 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1457 cricket::Candidate candidate2(
1458 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1459 rtc::SocketAddress("fe80::1234:5678:abcd:ef12", 1235), kCandidatePriority,
1460 "", "", cricket::LOCAL_PORT_TYPE, kCandidateGeneration,
1461 kCandidateFoundation1);
1462 JsepSessionDescription jdesc(kDummyString);
1463 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1464
1465 // Only add the candidates to audio m line.
1466 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1467 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1468 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1469 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
1470 std::string message = webrtc::SdpSerialize(jdesc);
1471
1472 // Audio line should have a c line like this one.
1473 EXPECT_NE(message.find("c=IN IP6 fe80::1234:5678:abcd:ef12"),
1474 std::string::npos);
1475 // Shouldn't have a IP4 c line.
1476 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
1477}
1478
1479// This tests serialization of SDP with only TCP candidates and verifies that
1480// null IPv4 is used as default address in c line.
1481TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithTCPOnly) {
1482 // Only test 1 m line.
1483 desc_.RemoveContentByName("video_content_name");
1484 // Stun has a high preference than local host.
1485 cricket::Candidate candidate1(
1486 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1487 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1488 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1489 cricket::Candidate candidate2(
1490 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1491 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
1492 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1493 JsepSessionDescription jdesc(kDummyString);
1494 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1495
1496 // Only add the candidates to audio m line.
1497 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1498 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1499 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1500 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
1501 std::string message = webrtc::SdpSerialize(jdesc);
1502
1503 // Audio line should have a c line like this one when no any default exists.
1504 EXPECT_NE(message.find("c=IN IP4 0.0.0.0"), std::string::npos);
1505}
1506
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001507// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1508// the case in a DTLS offer.
1509TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1510 AddFingerprint();
1511 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1512 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1513 kSessionId, kSessionVersion));
1514 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
1515
1516 std::string sdp_with_fingerprint = kSdpString;
1517 InjectAfter(kAttributeIcePwdVoice,
1518 kFingerprint, &sdp_with_fingerprint);
1519 InjectAfter(kAttributeIcePwdVideo,
1520 kFingerprint, &sdp_with_fingerprint);
1521
1522 EXPECT_EQ(sdp_with_fingerprint, message);
1523}
1524
1525// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1526// be the case in a DTLS answer.
1527TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1528 AddFingerprint();
1529 RemoveCryptos();
1530 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1531 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1532 kSessionId, kSessionVersion));
1533 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
1534
1535 std::string sdp_with_fingerprint = kSdpString;
1536 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1537 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
1538 InjectAfter(kAttributeIcePwdVoice,
1539 kFingerprint, &sdp_with_fingerprint);
1540 InjectAfter(kAttributeIcePwdVideo,
1541 kFingerprint, &sdp_with_fingerprint);
1542
1543 EXPECT_EQ(sdp_with_fingerprint, message);
1544}
1545
1546TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1547 // JsepSessionDescription with desc but without candidates.
1548 JsepSessionDescription jdesc_no_candidates(kDummyString);
1549 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
1550 kSessionId, kSessionVersion));
1551 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
1552 EXPECT_EQ(std::string(kSdpString), message);
1553}
1554
1555TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1556 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1557 group.AddContentName(kAudioContentName);
1558 group.AddContentName(kVideoContentName);
1559 desc_.AddGroup(group);
1560 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1561 jdesc_.session_id(),
1562 jdesc_.session_version()));
1563 std::string message = webrtc::SdpSerialize(jdesc_);
1564 std::string sdp_with_bundle = kSdpFullString;
1565 InjectAfter(kSessionTime,
1566 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1567 &sdp_with_bundle);
1568 EXPECT_EQ(sdp_with_bundle, message);
1569}
1570
1571TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
1572 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1573 GetFirstVideoContent(&desc_)->description);
1574 vcd->set_bandwidth(100 * 1000);
1575 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1576 GetFirstAudioContent(&desc_)->description);
1577 acd->set_bandwidth(50 * 1000);
1578 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1579 jdesc_.session_id(),
1580 jdesc_.session_version()));
1581 std::string message = webrtc::SdpSerialize(jdesc_);
1582 std::string sdp_with_bandwidth = kSdpFullString;
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001583 InjectAfter("c=IN IP4 74.125.224.39\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001584 "b=AS:100\r\n",
1585 &sdp_with_bandwidth);
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001586 InjectAfter("c=IN IP4 74.125.127.126\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001587 "b=AS:50\r\n",
1588 &sdp_with_bandwidth);
1589 EXPECT_EQ(sdp_with_bandwidth, message);
1590}
1591
1592TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1593 std::vector<std::string> transport_options;
1594 transport_options.push_back(kIceOption1);
1595 transport_options.push_back(kIceOption3);
1596 AddIceOptions(kAudioContentName, transport_options);
1597 transport_options.clear();
1598 transport_options.push_back(kIceOption2);
1599 transport_options.push_back(kIceOption3);
1600 AddIceOptions(kVideoContentName, transport_options);
1601 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1602 jdesc_.session_id(),
1603 jdesc_.session_version()));
1604 std::string message = webrtc::SdpSerialize(jdesc_);
1605 std::string sdp_with_ice_options = kSdpFullString;
1606 InjectAfter(kAttributeIcePwdVoice,
1607 "a=ice-options:iceoption1 iceoption3\r\n",
1608 &sdp_with_ice_options);
1609 InjectAfter(kAttributeIcePwdVideo,
1610 "a=ice-options:iceoption2 iceoption3\r\n",
1611 &sdp_with_ice_options);
1612 EXPECT_EQ(sdp_with_ice_options, message);
1613}
1614
1615TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
1616 EXPECT_TRUE(TestSerializeDirection(cricket::MD_RECVONLY));
1617}
1618
1619TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
1620 EXPECT_TRUE(TestSerializeDirection(cricket::MD_SENDONLY));
1621}
1622
1623TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
1624 EXPECT_TRUE(TestSerializeDirection(cricket::MD_INACTIVE));
1625}
1626
1627TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
1628 EXPECT_TRUE(TestSerializeRejected(true, false));
1629}
1630
1631TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
1632 EXPECT_TRUE(TestSerializeRejected(false, true));
1633}
1634
1635TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
1636 EXPECT_TRUE(TestSerializeRejected(true, true));
1637}
1638
1639TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
1640 AddRtpDataChannel();
1641 JsepSessionDescription jsep_desc(kDummyString);
1642
1643 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1644 std::string message = webrtc::SdpSerialize(jsep_desc);
1645
1646 std::string expected_sdp = kSdpString;
1647 expected_sdp.append(kSdpRtpDataChannelString);
1648 EXPECT_EQ(expected_sdp, message);
1649}
1650
1651TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
1652 AddSctpDataChannel();
1653 JsepSessionDescription jsep_desc(kDummyString);
1654
1655 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1656 std::string message = webrtc::SdpSerialize(jsep_desc);
1657
1658 std::string expected_sdp = kSdpString;
1659 expected_sdp.append(kSdpSctpDataChannelString);
1660 EXPECT_EQ(message, expected_sdp);
1661}
1662
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001663TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
1664 AddSctpDataChannel();
1665 JsepSessionDescription jsep_desc(kDummyString);
1666
1667 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1668 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
1669 jsep_desc.description()->GetContentDescriptionByName(kDataContentName));
1670
1671 const int kNewPort = 1234;
1672 cricket::DataCodec codec(
1673 cricket::kGoogleSctpDataCodecId, cricket::kGoogleSctpDataCodecName, 0);
1674 codec.SetParam(cricket::kCodecParamPort, kNewPort);
1675 dcdesc->AddOrReplaceCodec(codec);
1676
1677 std::string message = webrtc::SdpSerialize(jsep_desc);
1678
1679 std::string expected_sdp = kSdpString;
1680 expected_sdp.append(kSdpSctpDataChannelString);
1681
1682 char default_portstr[16];
1683 char new_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001684 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001685 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001686 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
1687 rtc::replace_substrs(default_portstr, strlen(default_portstr),
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001688 new_portstr, strlen(new_portstr),
1689 &expected_sdp);
1690
1691 EXPECT_EQ(expected_sdp, message);
1692}
1693
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001694TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
1695 AddRtpDataChannel();
1696 data_desc_->set_bandwidth(100*1000);
1697 JsepSessionDescription jsep_desc(kDummyString);
1698
1699 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1700 std::string message = webrtc::SdpSerialize(jsep_desc);
1701
1702 std::string expected_sdp = kSdpString;
1703 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07001704 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00001705 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 +00001706 "b=AS:100\r\n",
1707 &expected_sdp);
1708 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001709}
1710
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001711TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
1712 AddExtmap();
1713 JsepSessionDescription desc_with_extmap("dummy");
1714 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(),
1715 kSessionId, kSessionVersion));
1716 std::string message = webrtc::SdpSerialize(desc_with_extmap);
1717
1718 std::string sdp_with_extmap = kSdpString;
1719 InjectAfter("a=mid:audio_content_name\r\n",
1720 kExtmap, &sdp_with_extmap);
1721 InjectAfter("a=mid:video_content_name\r\n",
1722 kExtmap, &sdp_with_extmap);
1723
1724 EXPECT_EQ(sdp_with_extmap, message);
1725}
1726
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001727TEST_F(WebRtcSdpTest, SerializeCandidates) {
1728 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00001729 EXPECT_EQ(std::string(kRawCandidate), message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001730}
1731
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00001732// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
1733// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00001734TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001735 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001736 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
1737 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
1738 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00001739 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
1740 rtc::scoped_ptr<IceCandidateInterface> jcandidate(
1741 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
1742
1743 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
1744 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
1745}
1746
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001747TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
1748 JsepSessionDescription jdesc(kDummyString);
1749 // Deserialize
1750 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
1751 // Verify
1752 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1753}
1754
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001755TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
1756 JsepSessionDescription jdesc(kDummyString);
1757 const char kSdpWithoutMline[] =
1758 "v=0\r\n"
1759 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1760 "s=-\r\n"
1761 "t=0 0\r\n"
1762 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
1763 // Deserialize
1764 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
1765 EXPECT_EQ(0u, jdesc.description()->contents().size());
1766}
1767
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001768TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
1769 JsepSessionDescription jdesc(kDummyString);
1770 std::string sdp_without_carriage_return = kSdpFullString;
1771 Replace("\r\n", "\n", &sdp_without_carriage_return);
1772 // Deserialize
1773 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
1774 // Verify
1775 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1776}
1777
1778TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
1779 // SessionDescription with desc but without candidates.
1780 JsepSessionDescription jdesc_no_candidates(kDummyString);
1781 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
1782 kSessionId, kSessionVersion));
1783 JsepSessionDescription new_jdesc(kDummyString);
1784 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
1785 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
1786}
1787
1788TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
1789 static const char kSdpNoRtpmapString[] =
1790 "v=0\r\n"
1791 "o=- 11 22 IN IP4 127.0.0.1\r\n"
1792 "s=-\r\n"
1793 "t=0 0\r\n"
1794 "m=audio 49232 RTP/AVP 0 18 103\r\n"
1795 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001796 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001797 // The rtpmap line for static payload codec is optional.
1798 "a=rtpmap:18 G729/16000\r\n"
1799 "a=rtpmap:103 ISAC/16000\r\n";
1800
1801 JsepSessionDescription jdesc(kDummyString);
1802 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
1803 cricket::AudioContentDescription* audio =
1804 static_cast<AudioContentDescription*>(
1805 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
1806 AudioCodecs ref_codecs;
1807 // The codecs in the AudioContentDescription will be sorted by preference.
1808 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1, 3));
1809 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1, 2));
1810 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 32000, 1, 1));
1811 EXPECT_EQ(ref_codecs, audio->codecs());
1812}
1813
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001814TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
1815 static const char kSdpNoRtpmapString[] =
1816 "v=0\r\n"
1817 "o=- 11 22 IN IP4 127.0.0.1\r\n"
1818 "s=-\r\n"
1819 "t=0 0\r\n"
1820 "m=audio 49232 RTP/AVP 18 103\r\n"
1821 "a=fmtp:18 annexb=yes\r\n"
1822 "a=rtpmap:103 ISAC/16000\r\n";
1823
1824 JsepSessionDescription jdesc(kDummyString);
1825 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
1826 cricket::AudioContentDescription* audio =
1827 static_cast<AudioContentDescription*>(
1828 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
1829
1830 cricket::AudioCodec g729 = audio->codecs()[0];
1831 EXPECT_EQ("G729", g729.name);
1832 EXPECT_EQ(8000, g729.clockrate);
1833 EXPECT_EQ(18, g729.id);
1834 cricket::CodecParameterMap::iterator found =
1835 g729.params.find("annexb");
1836 ASSERT_TRUE(found != g729.params.end());
1837 EXPECT_EQ(found->second, "yes");
1838
1839 cricket::AudioCodec isac = audio->codecs()[1];
1840 EXPECT_EQ("ISAC", isac.name);
1841 EXPECT_EQ(103, isac.id);
1842 EXPECT_EQ(16000, isac.clockrate);
1843}
1844
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001845// Ensure that we can deserialize SDP with a=fingerprint properly.
1846TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
1847 // Add a DTLS a=fingerprint attribute to our session description.
1848 AddFingerprint();
1849 JsepSessionDescription new_jdesc(kDummyString);
1850 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1851 jdesc_.session_id(),
1852 jdesc_.session_version()));
1853
1854 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1855 std::string sdp_with_fingerprint = kSdpString;
1856 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1857 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
1858 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
1859 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
1860}
1861
1862TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
1863 JsepSessionDescription jdesc_with_bundle(kDummyString);
1864 std::string sdp_with_bundle = kSdpFullString;
1865 InjectAfter(kSessionTime,
1866 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1867 &sdp_with_bundle);
1868 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
1869 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1870 group.AddContentName(kAudioContentName);
1871 group.AddContentName(kVideoContentName);
1872 desc_.AddGroup(group);
1873 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1874 jdesc_.session_id(),
1875 jdesc_.session_version()));
1876 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
1877}
1878
1879TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
1880 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
1881 std::string sdp_with_bandwidth = kSdpFullString;
1882 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
1883 "b=AS:100\r\n",
1884 &sdp_with_bandwidth);
1885 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
1886 "b=AS:50\r\n",
1887 &sdp_with_bandwidth);
1888 EXPECT_TRUE(
1889 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
1890 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1891 GetFirstVideoContent(&desc_)->description);
1892 vcd->set_bandwidth(100 * 1000);
1893 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1894 GetFirstAudioContent(&desc_)->description);
1895 acd->set_bandwidth(50 * 1000);
1896 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1897 jdesc_.session_id(),
1898 jdesc_.session_version()));
1899 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
1900}
1901
1902TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
1903 JsepSessionDescription jdesc_with_ice_options(kDummyString);
1904 std::string sdp_with_ice_options = kSdpFullString;
1905 InjectAfter(kSessionTime,
1906 "a=ice-options:iceoption3\r\n",
1907 &sdp_with_ice_options);
1908 InjectAfter(kAttributeIcePwdVoice,
1909 "a=ice-options:iceoption1\r\n",
1910 &sdp_with_ice_options);
1911 InjectAfter(kAttributeIcePwdVideo,
1912 "a=ice-options:iceoption2\r\n",
1913 &sdp_with_ice_options);
1914 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
1915 std::vector<std::string> transport_options;
1916 transport_options.push_back(kIceOption3);
1917 transport_options.push_back(kIceOption1);
1918 AddIceOptions(kAudioContentName, transport_options);
1919 transport_options.clear();
1920 transport_options.push_back(kIceOption3);
1921 transport_options.push_back(kIceOption2);
1922 AddIceOptions(kVideoContentName, transport_options);
1923 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1924 jdesc_.session_id(),
1925 jdesc_.session_version()));
1926 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
1927}
1928
1929TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
1930 // Remove the original ice-ufrag and ice-pwd
1931 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyString);
1932 std::string sdp_with_ufrag_pwd = kSdpFullString;
1933 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
1934 // Add session level ufrag and pwd
1935 InjectAfter(kSessionTime,
1936 "a=ice-pwd:session+level+icepwd\r\n"
1937 "a=ice-ufrag:session+level+iceufrag\r\n",
1938 &sdp_with_ufrag_pwd);
1939 // Add media level ufrag and pwd for audio
1940 InjectAfter("a=mid:audio_content_name\r\n",
1941 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
1942 &sdp_with_ufrag_pwd);
1943 // Update the candidate ufrag and pwd to the expected ones.
1944 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0,
1945 "media+level+iceufrag", "media+level+icepwd"));
1946 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1,
1947 "session+level+iceufrag", "session+level+icepwd"));
1948 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
1949 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
1950}
1951
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001952TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
1953 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_RECVONLY));
1954}
1955
1956TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
1957 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_SENDONLY));
1958}
1959
1960TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
1961 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_INACTIVE));
1962}
1963
1964TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
1965 EXPECT_TRUE(TestDeserializeRejected(true, false));
1966}
1967
1968TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
1969 EXPECT_TRUE(TestDeserializeRejected(false, true));
1970}
1971
1972TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
1973 EXPECT_TRUE(TestDeserializeRejected(true, true));
1974}
1975
1976// Tests that we can still handle the sdp uses mslabel and label instead of
1977// msid for backward compatibility.
1978TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07001979 jdesc_.description()->set_msid_supported(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001980 JsepSessionDescription jdesc(kDummyString);
1981 std::string sdp_without_msid = kSdpFullString;
1982 Replace("msid", "xmsid", &sdp_without_msid);
1983 // Deserialize
1984 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
1985 // Verify
1986 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1987}
1988
1989TEST_F(WebRtcSdpTest, DeserializeCandidate) {
1990 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
1991
1992 std::string sdp = kSdpOneCandidate;
1993 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
1994 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
1995 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
1996 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
1997
1998 // Candidate line without generation extension.
1999 sdp = kSdpOneCandidate;
2000 Replace(" generation 2", "", &sdp);
2001 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2002 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2003 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2004 Candidate expected = jcandidate_->candidate();
2005 expected.set_generation(0);
2006 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2007
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002008 sdp = kSdpTcpActiveCandidate;
2009 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2010 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002011 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002012 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2013 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2014 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002015 rtc::scoped_ptr<IceCandidateInterface> jcandidate_template(
2016 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
2017 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(
2018 jcandidate_template->candidate()));
2019 sdp = kSdpTcpPassiveCandidate;
2020 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2021 sdp = kSdpTcpSOCandidate;
2022 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002023}
2024
2025// This test verifies the deserialization of candidate-attribute
2026// as per RFC 5245. Candiate-attribute will be of the format
2027// candidate:<blah>. This format will be used when candidates
2028// are trickled.
2029TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2030 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2031
2032 std::string candidate_attribute = kRawCandidate;
2033 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2034 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2035 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2036 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2037 EXPECT_EQ(2u, jcandidate.candidate().generation());
2038
2039 // Candidate line without generation extension.
2040 candidate_attribute = kRawCandidate;
2041 Replace(" generation 2", "", &candidate_attribute);
2042 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2043 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2044 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2045 Candidate expected = jcandidate_->candidate();
2046 expected.set_generation(0);
2047 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2048
2049 // Candidate line without candidate:
2050 candidate_attribute = kRawCandidate;
2051 Replace("candidate:", "", &candidate_attribute);
2052 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2053
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002054 // Candidate line with IPV6 address.
2055 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
2056}
2057
2058// This test verifies that the deserialization of an invalid candidate string
2059// fails.
2060TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
2061 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2062
2063 std::string candidate_attribute = kRawCandidate;
2064 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002065 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002066
2067 candidate_attribute = kSdpOneCandidate;
2068 candidate_attribute.replace(0, 1, "x");
2069 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2070
2071 candidate_attribute = kRawCandidate;
2072 candidate_attribute.append("\r\n");
2073 candidate_attribute.append(kRawCandidate);
2074 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2075
2076 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002077}
2078
2079TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2080 AddRtpDataChannel();
2081 JsepSessionDescription jdesc(kDummyString);
2082 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2083
2084 std::string sdp_with_data = kSdpString;
2085 sdp_with_data.append(kSdpRtpDataChannelString);
2086 JsepSessionDescription jdesc_output(kDummyString);
2087
2088 // Deserialize
2089 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2090 // Verify
2091 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2092}
2093
2094TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
2095 AddSctpDataChannel();
2096 JsepSessionDescription jdesc(kDummyString);
2097 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2098
2099 std::string sdp_with_data = kSdpString;
2100 sdp_with_data.append(kSdpSctpDataChannelString);
2101 JsepSessionDescription jdesc_output(kDummyString);
2102
lally@webrtc.org36300852015-02-24 20:19:35 +00002103 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2104 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2105 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2106
2107 // Verify with UDP/DTLS/SCTP.
2108 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2109 strlen(kDtlsSctp), kUdpDtlsSctp);
2110 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2111 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2112
2113 // Verify with TCP/DTLS/SCTP.
2114 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2115 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002116 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2117 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2118}
2119
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002120TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
2121 AddSctpDataChannel();
2122 JsepSessionDescription jdesc(kDummyString);
2123 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2124
2125 std::string sdp_with_data = kSdpString;
2126 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2127 JsepSessionDescription jdesc_output(kDummyString);
2128
lally@webrtc.org36300852015-02-24 20:19:35 +00002129 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002130 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2131 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002132
lally@webrtc.org36300852015-02-24 20:19:35 +00002133 // Verify with UDP/DTLS/SCTP.
2134 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2135 strlen(kDtlsSctp), kUdpDtlsSctp);
2136 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2137 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002138
lally@webrtc.org36300852015-02-24 20:19:35 +00002139 // Verify with TCP/DTLS/SCTP.
2140 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2141 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002142 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2143 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2144}
2145
lally69f57602015-10-08 10:15:04 -07002146TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
2147 AddSctpDataChannel();
2148 JsepSessionDescription jdesc(kDummyString);
2149 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2150
2151 std::string sdp_with_data = kSdpString;
2152 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
2153 JsepSessionDescription jdesc_output(kDummyString);
2154
2155 // Verify with DTLS/SCTP.
2156 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2157 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2158
2159 // Verify with UDP/DTLS/SCTP.
2160 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2161 strlen(kDtlsSctp), kUdpDtlsSctp);
2162 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2163 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2164
2165 // Verify with TCP/DTLS/SCTP.
2166 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2167 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
2168 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2169 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2170}
2171
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002172// Test to check the behaviour if sctp-port is specified
2173// on the m= line and in a=sctp-port.
2174TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
2175 AddSctpDataChannel();
2176 JsepSessionDescription jdesc(kDummyString);
2177 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2178
2179 std::string sdp_with_data = kSdpString;
2180 // Append m= attributes
2181 sdp_with_data.append(kSdpSctpDataChannelString);
2182 // Append a=sctp-port attribute
2183 sdp_with_data.append("a=sctp-port 5000\r\n");
2184 JsepSessionDescription jdesc_output(kDummyString);
2185
2186 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2187}
2188
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002189// For crbug/344475.
2190TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2191 std::string sdp_with_data = kSdpString;
2192 sdp_with_data.append(kSdpSctpDataChannelString);
2193 // Remove the "\n" at the end.
2194 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
2195 JsepSessionDescription jdesc_output(kDummyString);
2196
2197 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2198 // No crash is a pass.
2199}
2200
wu@webrtc.org78187522013-10-07 23:32:02 +00002201TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndNewPort) {
2202 AddSctpDataChannel();
Peter Boström0c4e06b2015-10-07 12:23:21 +02002203 const uint16_t kUnusualSctpPort = 9556;
wu@webrtc.org78187522013-10-07 23:32:02 +00002204 char default_portstr[16];
2205 char unusual_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002206 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
wu@webrtc.org78187522013-10-07 23:32:02 +00002207 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002208 rtc::sprintfn(unusual_portstr, sizeof(unusual_portstr), "%d",
wu@webrtc.org78187522013-10-07 23:32:02 +00002209 kUnusualSctpPort);
2210
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002211 // First setup the expected JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002212 JsepSessionDescription jdesc(kDummyString);
2213 // take our pre-built session description and change the SCTP port.
2214 cricket::SessionDescription* mutant = desc_.Copy();
2215 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
2216 mutant->GetContentDescriptionByName(kDataContentName));
2217 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002218 EXPECT_EQ(1U, codecs.size());
2219 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002220 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002221 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002222
2223 // note: mutant's owned by jdesc now.
2224 ASSERT_TRUE(jdesc.Initialize(mutant, kSessionId, kSessionVersion));
2225 mutant = NULL;
2226
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002227 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002228 std::string sdp_with_data = kSdpString;
2229 sdp_with_data.append(kSdpSctpDataChannelString);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002230 rtc::replace_substrs(default_portstr, strlen(default_portstr),
wu@webrtc.org78187522013-10-07 23:32:02 +00002231 unusual_portstr, strlen(unusual_portstr),
2232 &sdp_with_data);
2233 JsepSessionDescription jdesc_output(kDummyString);
2234
2235 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2236 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002237
2238 // We need to test the deserialized JsepSessionDescription from
2239 // kSdpSctpDataChannelStringWithSctpPort for
2240 // draft-ietf-mmusic-sctp-sdp-07
2241 // a=sctp-port
2242 sdp_with_data = kSdpString;
2243 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2244 rtc::replace_substrs(default_portstr, strlen(default_portstr),
2245 unusual_portstr, strlen(unusual_portstr),
2246 &sdp_with_data);
2247
2248 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2249 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002250}
2251
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002252TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002253 // We want to test that deserializing data content limits bandwidth
2254 // settings (it should never be greater than the default).
2255 // This should prevent someone from using unlimited data bandwidth through
2256 // JS and "breaking the Internet".
2257 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002258 std::string sdp_with_bandwidth = kSdpString;
2259 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
2260 InjectAfter("a=mid:data_content_name\r\n",
2261 "b=AS:100\r\n",
2262 &sdp_with_bandwidth);
2263 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2264
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002265 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2266}
2267
2268TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
2269 AddSctpDataChannel();
2270 JsepSessionDescription jdesc(kDummyString);
2271 DataContentDescription* dcd = static_cast<DataContentDescription*>(
2272 GetFirstDataContent(&desc_)->description);
2273 dcd->set_bandwidth(100 * 1000);
2274 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2275
2276 std::string sdp_with_bandwidth = kSdpString;
2277 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
2278 InjectAfter("a=mid:data_content_name\r\n",
2279 "b=AS:100\r\n",
2280 &sdp_with_bandwidth);
2281 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2282
2283 // SCTP has congestion control, so we shouldn't limit the bandwidth
2284 // as we do for RTP.
2285 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002286 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2287}
2288
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002289TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSessionLevelExtmap) {
2290 TestDeserializeExtmap(true, false);
2291}
2292
2293TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
2294 TestDeserializeExtmap(false, true);
2295}
2296
2297TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInvalidExtmap) {
2298 TestDeserializeExtmap(true, true);
2299}
2300
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002301TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
2302 JsepSessionDescription jdesc(kDummyString);
2303 std::string sdp = kSdpFullString;
2304 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2305 // Deserialize
2306 SdpParseError error;
2307 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
2308 const std::string lastline = "a=ssrc:6 label:video_track_id_3";
2309 EXPECT_EQ(lastline, error.line);
2310 EXPECT_EQ("Invalid SDP line.", error.description);
2311}
2312
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002313TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2314 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2315 std::string new_sdp = kSdpOneCandidate;
2316 Replace("udp", "unsupported_transport", &new_sdp);
2317 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2318 new_sdp = kSdpOneCandidate;
2319 Replace("udp", "uDP", &new_sdp);
2320 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2321 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2322 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2323 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2324}
2325
2326TEST_F(WebRtcSdpTest, DeserializeCandidateOldFormat) {
2327 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2328 EXPECT_TRUE(SdpDeserializeCandidate(kSdpOneCandidateOldFormat,&jcandidate));
2329 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2330 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2331 Candidate ref_candidate = jcandidate_->candidate();
2332 ref_candidate.set_username("user_rtp");
2333 ref_candidate.set_password("password_rtp");
2334 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2335}
2336
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002337TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
2338 JsepSessionDescription jdesc(kDummyString);
2339
2340 // Deserialize
2341 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2342
2343 // Verify
2344 cricket::AudioContentDescription* audio =
2345 static_cast<AudioContentDescription*>(
2346 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2347 EXPECT_TRUE(audio->conference_mode());
2348
2349 cricket::VideoContentDescription* video =
2350 static_cast<VideoContentDescription*>(
2351 jdesc.description()->GetContentDescriptionByName(cricket::CN_VIDEO));
2352 EXPECT_TRUE(video->conference_mode());
2353}
2354
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002355TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2356 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002357 const char kSdpEmptyType[] = " =candidate";
2358 const char kSdpEqualAsPlus[] = "a+candidate";
2359 const char kSdpSpaceAfterEqual[] = "a= candidate";
2360 const char kSdpUpperType[] = "A=candidate";
2361 const char kSdpEmptyLine[] = "";
2362 const char kSdpMissingValue[] = "a=";
2363
2364 const char kSdpBrokenFingerprint[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002365 "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 +00002366 const char kSdpExtraField[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002367 "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 +00002368 const char kSdpMissingSpace[] = "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002369 "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 +00002370 // MD5 is not allowed in fingerprints.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002371 const char kSdpMd5[] = "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002372 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002373
2374 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002375 ExpectParseFailure("v=", kSdpDestroyer);
2376 ExpectParseFailure("o=", kSdpDestroyer);
2377 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002378 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002379 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002380
2381 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002382 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2383 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002384
2385 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002386 ExpectParseFailure("a=candidate", kSdpEmptyType);
2387 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2388 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
2389 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002390
2391 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2392 // because it's orthogonal to what we are replacing and hence
2393 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002394 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
2395 ExpectParseFailure("a=sendrecv", kSdpExtraField);
2396 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
2397 ExpectParseFailure("a=sendrecv", kSdpMd5);
2398
2399 // Empty Line
2400 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
2401 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002402}
2403
2404TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2405 // ssrc
2406 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
2407 ExpectParseFailure("a=ssrc-group:FEC 5 6", "a=ssrc-group:FEC badvalue 6");
2408 // crypto
2409 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
2410 // rtpmap
2411 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
2412 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
2413 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
2414 // candidate
2415 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
2416 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
2417 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
2418 ExpectParseFailure("rport 2346", "rport badvalue");
2419 ExpectParseFailure("rport 2346 generation 2",
2420 "rport 2346 generation badvalue");
2421 // m line
2422 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
2423 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
2424
2425 // bandwidth
2426 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2427 "b=AS:badvalue\r\n",
2428 "b=AS:badvalue");
2429 // rtcp-fb
2430 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2431 "a=rtcp-fb:badvalue nack\r\n",
2432 "a=rtcp-fb:badvalue nack");
2433 // extmap
2434 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2435 "a=extmap:badvalue http://example.com\r\n",
2436 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002437}
2438
2439TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
2440 JsepSessionDescription jdesc_output(kDummyString);
2441
2442 const char kSdpWithReorderedPlTypesString[] =
2443 "v=0\r\n"
2444 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2445 "s=-\r\n"
2446 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00002447 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002448 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
2449 // in the map.
2450 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002451 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002452
2453 // Deserialize
2454 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
2455
2456 const ContentInfo* ac = GetFirstAudioContent(jdesc_output.description());
2457 ASSERT_TRUE(ac != NULL);
2458 const AudioContentDescription* acd =
2459 static_cast<const AudioContentDescription*>(ac->description);
2460 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002461 EXPECT_EQ("ISAC", acd->codecs()[0].name);
2462 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002463 EXPECT_EQ(104, acd->codecs()[0].id);
2464}
2465
2466TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
2467 JsepSessionDescription jdesc_output(kDummyString);
2468 CodecParams params;
2469 params.max_ptime = 40;
2470 params.ptime = 30;
2471 params.min_ptime = 10;
2472 params.sprop_stereo = 1;
2473 params.stereo = 1;
2474 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002475 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002476 TestDeserializeCodecParams(params, &jdesc_output);
2477 TestSerialize(jdesc_output);
2478}
2479
2480TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
2481 const bool kUseWildcard = false;
2482 JsepSessionDescription jdesc_output(kDummyString);
2483 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
2484 TestSerialize(jdesc_output);
2485}
2486
2487TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
2488 const bool kUseWildcard = true;
2489 JsepSessionDescription jdesc_output(kDummyString);
2490 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
2491 TestSerialize(jdesc_output);
2492}
2493
2494TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
2495 JsepSessionDescription jdesc_output(kDummyString);
2496
2497 const char kSdpWithFmtpString[] =
2498 "v=0\r\n"
2499 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2500 "s=-\r\n"
2501 "t=0 0\r\n"
2502 "m=video 3457 RTP/SAVPF 120\r\n"
2503 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07002504 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
2505
2506 // Deserialize
2507 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07002508 EXPECT_TRUE(
2509 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07002510
2511 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2512 ASSERT_TRUE(vc != NULL);
2513 const VideoContentDescription* vcd =
2514 static_cast<const VideoContentDescription*>(vc->description);
2515 ASSERT_FALSE(vcd->codecs().empty());
2516 cricket::VideoCodec vp8 = vcd->codecs()[0];
2517 EXPECT_EQ("VP8", vp8.name);
2518 EXPECT_EQ(120, vp8.id);
2519 cricket::CodecParameterMap::iterator found =
2520 vp8.params.find("x-google-min-bitrate");
2521 ASSERT_TRUE(found != vp8.params.end());
2522 EXPECT_EQ(found->second, "10");
2523 found = vp8.params.find("x-google-max-quantization");
2524 ASSERT_TRUE(found != vp8.params.end());
2525 EXPECT_EQ(found->second, "40");
2526}
2527
2528TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
2529 JsepSessionDescription jdesc_output(kDummyString);
2530
2531 const char kSdpWithFmtpString[] =
2532 "v=0\r\n"
2533 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2534 "s=-\r\n"
2535 "t=0 0\r\n"
2536 "m=video 3457 RTP/SAVPF 120\r\n"
2537 "a=rtpmap:120 VP8/90000\r\n"
2538 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002539
2540 // Deserialize
2541 SdpParseError error;
2542 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output,
2543 &error));
2544
2545 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2546 ASSERT_TRUE(vc != NULL);
2547 const VideoContentDescription* vcd =
2548 static_cast<const VideoContentDescription*>(vc->description);
2549 ASSERT_FALSE(vcd->codecs().empty());
2550 cricket::VideoCodec vp8 = vcd->codecs()[0];
2551 EXPECT_EQ("VP8", vp8.name);
2552 EXPECT_EQ(120, vp8.id);
2553 cricket::CodecParameterMap::iterator found =
2554 vp8.params.find("x-google-min-bitrate");
2555 ASSERT_TRUE(found != vp8.params.end());
2556 EXPECT_EQ(found->second, "10");
2557 found = vp8.params.find("x-google-max-quantization");
2558 ASSERT_TRUE(found != vp8.params.end());
2559 EXPECT_EQ(found->second, "40");
2560}
2561
2562TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
2563 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
2564 GetFirstVideoContent(&desc_)->description);
2565
2566 cricket::VideoCodecs codecs = vcd->codecs();
2567 codecs[0].params["x-google-min-bitrate"] = "10";
2568 vcd->set_codecs(codecs);
2569
2570 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2571 jdesc_.session_id(),
2572 jdesc_.session_version()));
2573 std::string message = webrtc::SdpSerialize(jdesc_);
2574 std::string sdp_with_fmtp = kSdpFullString;
2575 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
2576 "a=fmtp:120 x-google-min-bitrate=10\r\n",
2577 &sdp_with_fmtp);
2578 EXPECT_EQ(sdp_with_fmtp, message);
2579}
2580
2581TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) {
2582 JsepSessionDescription jdesc_with_icelite(kDummyString);
2583 std::string sdp_with_icelite = kSdpFullString;
2584 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
2585 cricket::SessionDescription* desc = jdesc_with_icelite.description();
2586 const cricket::TransportInfo* tinfo1 =
2587 desc->GetTransportInfoByName("audio_content_name");
2588 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
2589 const cricket::TransportInfo* tinfo2 =
2590 desc->GetTransportInfoByName("video_content_name");
2591 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
2592 InjectAfter(kSessionTime,
2593 "a=ice-lite\r\n",
2594 &sdp_with_icelite);
2595 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
2596 desc = jdesc_with_icelite.description();
2597 const cricket::TransportInfo* atinfo =
2598 desc->GetTransportInfoByName("audio_content_name");
2599 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
2600 const cricket::TransportInfo* vtinfo =
2601 desc->GetTransportInfoByName("video_content_name");
2602 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
2603}
2604
2605// Verifies that the candidates in the input SDP are parsed and serialized
2606// correctly in the output SDP.
2607TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
2608 std::string sdp_with_data = kSdpString;
2609 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
2610 JsepSessionDescription jdesc_output(kDummyString);
2611
2612 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2613 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
2614}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00002615
2616TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
2617 AddFingerprint();
2618 TransportInfo audio_transport_info =
2619 *(desc_.GetTransportInfoByName(kAudioContentName));
2620 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
2621 audio_transport_info.description.connection_role);
2622 audio_transport_info.description.connection_role =
2623 cricket::CONNECTIONROLE_ACTIVE;
2624
2625 TransportInfo video_transport_info =
2626 *(desc_.GetTransportInfoByName(kVideoContentName));
2627 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
2628 video_transport_info.description.connection_role);
2629 video_transport_info.description.connection_role =
2630 cricket::CONNECTIONROLE_ACTIVE;
2631
2632 desc_.RemoveTransportInfoByName(kAudioContentName);
2633 desc_.RemoveTransportInfoByName(kVideoContentName);
2634
2635 desc_.AddTransportInfo(audio_transport_info);
2636 desc_.AddTransportInfo(video_transport_info);
2637
2638 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2639 jdesc_.session_id(),
2640 jdesc_.session_version()));
2641 std::string message = webrtc::SdpSerialize(jdesc_);
2642 std::string sdp_with_dtlssetup = kSdpFullString;
2643
2644 // Fingerprint attribute is necessary to add DTLS setup attribute.
2645 InjectAfter(kAttributeIcePwdVoice,
2646 kFingerprint, &sdp_with_dtlssetup);
2647 InjectAfter(kAttributeIcePwdVideo,
2648 kFingerprint, &sdp_with_dtlssetup);
2649 // Now adding |setup| attribute.
2650 InjectAfter(kFingerprint,
2651 "a=setup:active\r\n", &sdp_with_dtlssetup);
2652 EXPECT_EQ(sdp_with_dtlssetup, message);
2653}
2654
2655TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
2656 JsepSessionDescription jdesc_with_dtlssetup(kDummyString);
2657 std::string sdp_with_dtlssetup = kSdpFullString;
2658 InjectAfter(kSessionTime,
2659 "a=setup:actpass\r\n",
2660 &sdp_with_dtlssetup);
2661 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
2662 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
2663 const cricket::TransportInfo* atinfo =
2664 desc->GetTransportInfoByName("audio_content_name");
2665 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
2666 atinfo->description.connection_role);
2667 const cricket::TransportInfo* vtinfo =
2668 desc->GetTransportInfoByName("video_content_name");
2669 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
2670 vtinfo->description.connection_role);
2671}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00002672
2673// Verifies that the order of the serialized m-lines follows the order of the
2674// ContentInfo in SessionDescription, and vise versa for deserialization.
2675TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
2676 JsepSessionDescription jdesc(kDummyString);
2677 const std::string media_content_sdps[3] = {
2678 kSdpAudioString,
2679 kSdpVideoString,
2680 kSdpSctpDataChannelString
2681 };
2682 const cricket::MediaType media_types[3] = {
2683 cricket::MEDIA_TYPE_AUDIO,
2684 cricket::MEDIA_TYPE_VIDEO,
2685 cricket::MEDIA_TYPE_DATA
2686 };
2687
2688 // Verifies all 6 permutations.
2689 for (size_t i = 0; i < 6; ++i) {
2690 size_t media_content_in_sdp[3];
2691 // The index of the first media content.
2692 media_content_in_sdp[0] = i / 2;
2693 // The index of the second media content.
2694 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
2695 // The index of the third media content.
2696 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
2697
2698 std::string sdp_string = kSdpSessionString;
2699 for (size_t i = 0; i < 3; ++i)
2700 sdp_string += media_content_sdps[media_content_in_sdp[i]];
2701
2702 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
2703 cricket::SessionDescription* desc = jdesc.description();
2704 EXPECT_EQ(3u, desc->contents().size());
2705
2706 for (size_t i = 0; i < 3; ++i) {
2707 const cricket::MediaContentDescription* mdesc =
2708 static_cast<const cricket::MediaContentDescription*>(
2709 desc->contents()[i].description);
2710 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
2711 }
2712
2713 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
2714 EXPECT_EQ(sdp_string, serialized_sdp);
2715 }
2716}