blob: 9f5e1eba6e428ba811fd8f6d50b43405a6b4beda [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
3 * Copyright 2011, Google Inc.
4 *
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.orgd4e598d2014-07-29 17:36:52 +000034#include "webrtc/base/gunit.h"
35#include "webrtc/base/logging.h"
36#include "webrtc/base/messagedigest.h"
37#include "webrtc/base/scoped_ptr.h"
38#include "webrtc/base/sslfingerprint.h"
39#include "webrtc/base/stringencode.h"
40#include "webrtc/base/stringutils.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000041#include "talk/media/base/constants.h"
42#include "talk/p2p/base/constants.h"
43#include "talk/session/media/mediasession.h"
44
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;
58using cricket::NS_JINGLE_ICE_UDP;
59using cricket::NS_JINGLE_RTP;
60using cricket::RtpHeaderExtension;
61using cricket::RELAY_PORT_TYPE;
62using cricket::SessionDescription;
63using cricket::StreamParams;
64using cricket::STUN_PORT_TYPE;
65using cricket::TransportDescription;
66using cricket::TransportInfo;
67using cricket::VideoCodec;
68using cricket::VideoContentDescription;
69using webrtc::IceCandidateCollection;
70using webrtc::IceCandidateInterface;
71using webrtc::JsepIceCandidate;
72using webrtc::JsepSessionDescription;
73using webrtc::SdpParseError;
74using webrtc::SessionDescriptionInterface;
75
76typedef std::vector<AudioCodec> AudioCodecs;
77typedef std::vector<Candidate> Candidates;
78
wu@webrtc.org78187522013-10-07 23:32:02 +000079static const uint32 kDefaultSctpPort = 5000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080static const char kSessionTime[] = "t=0 0\r\n";
81static const uint32 kCandidatePriority = 2130706432U; // pref = 1.0
82static const char kCandidateUfragVoice[] = "ufrag_voice";
83static const char kCandidatePwdVoice[] = "pwd_voice";
84static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
85static const char kCandidateUfragVideo[] = "ufrag_video";
86static const char kCandidatePwdVideo[] = "pwd_video";
87static const char kCandidateUfragData[] = "ufrag_data";
88static const char kCandidatePwdData[] = "pwd_data";
89static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
90static const uint32 kCandidateGeneration = 2;
91static const char kCandidateFoundation1[] = "a0+B/1";
92static const char kCandidateFoundation2[] = "a0+B/2";
93static const char kCandidateFoundation3[] = "a0+B/3";
94static const char kCandidateFoundation4[] = "a0+B/4";
95static const char kAttributeCryptoVoice[] =
96 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
97 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
98 "dummy_session_params\r\n";
99static const char kAttributeCryptoVideo[] =
100 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
101 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
102static const char kFingerprint[] = "a=fingerprint:sha-1 "
103 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n";
104static const int kExtmapId = 1;
105static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
106static const char kExtmap[] =
107 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
108static const char kExtmapWithDirectionAndAttribute[] =
109 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
110
111static const uint8 kIdentityDigest[] = {0x4A, 0xAD, 0xB9, 0xB1,
112 0x3F, 0x82, 0x18, 0x3B,
113 0x54, 0x02, 0x12, 0xDF,
114 0x3E, 0x5D, 0x49, 0x6B,
115 0x19, 0xE5, 0x7C, 0xAB};
116
117struct CodecParams {
118 int max_ptime;
119 int ptime;
120 int min_ptime;
121 int sprop_stereo;
122 int stereo;
123 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000124 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125};
126
127// Reference sdp string
128static const char kSdpFullString[] =
129 "v=0\r\n"
130 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
131 "s=-\r\n"
132 "t=0 0\r\n"
133 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
134 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
135 "c=IN IP4 74.125.127.126\r\n"
136 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
137 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
138 "generation 2\r\n"
139 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
140 "generation 2\r\n"
141 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
142 "generation 2\r\n"
143 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
144 "generation 2\r\n"
145 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
146 "raddr 192.168.1.5 rport 2346 "
147 "generation 2\r\n"
148 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
149 "raddr 192.168.1.5 rport 2348 "
150 "generation 2\r\n"
151 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
152 "a=mid:audio_content_name\r\n"
153 "a=sendrecv\r\n"
154 "a=rtcp-mux\r\n"
155 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
156 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
157 "dummy_session_params\r\n"
158 "a=rtpmap:111 opus/48000/2\r\n"
159 "a=rtpmap:103 ISAC/16000\r\n"
160 "a=rtpmap:104 CELT/32000/2\r\n"
161 "a=ssrc:1 cname:stream_1_cname\r\n"
162 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
163 "a=ssrc:1 mslabel:local_stream_1\r\n"
164 "a=ssrc:1 label:audio_track_id_1\r\n"
165 "a=ssrc:4 cname:stream_2_cname\r\n"
166 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
167 "a=ssrc:4 mslabel:local_stream_2\r\n"
168 "a=ssrc:4 label:audio_track_id_2\r\n"
169 "m=video 3457 RTP/SAVPF 120\r\n"
170 "c=IN IP4 74.125.224.39\r\n"
171 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
172 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
173 "generation 2\r\n"
174 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
175 "generation 2\r\n"
176 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
177 "generation 2\r\n"
178 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
179 "generation 2\r\n"
180 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
181 "generation 2\r\n"
182 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
183 "generation 2\r\n"
184 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
185 "a=mid:video_content_name\r\n"
186 "a=sendrecv\r\n"
187 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
188 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
189 "a=rtpmap:120 VP8/90000\r\n"
190 "a=ssrc:2 cname:stream_1_cname\r\n"
191 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
192 "a=ssrc:2 mslabel:local_stream_1\r\n"
193 "a=ssrc:2 label:video_track_id_1\r\n"
194 "a=ssrc:3 cname:stream_1_cname\r\n"
195 "a=ssrc:3 msid:local_stream_1 video_track_id_2\r\n"
196 "a=ssrc:3 mslabel:local_stream_1\r\n"
197 "a=ssrc:3 label:video_track_id_2\r\n"
198 "a=ssrc-group:FEC 5 6\r\n"
199 "a=ssrc:5 cname:stream_2_cname\r\n"
200 "a=ssrc:5 msid:local_stream_2 video_track_id_3\r\n"
201 "a=ssrc:5 mslabel:local_stream_2\r\n"
202 "a=ssrc:5 label:video_track_id_3\r\n"
203 "a=ssrc:6 cname:stream_2_cname\r\n"
204 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
205 "a=ssrc:6 mslabel:local_stream_2\r\n"
206 "a=ssrc:6 label:video_track_id_3\r\n";
207
208// SDP reference string without the candidates.
209static const char kSdpString[] =
210 "v=0\r\n"
211 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
212 "s=-\r\n"
213 "t=0 0\r\n"
214 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
215 "m=audio 1 RTP/SAVPF 111 103 104\r\n"
216 "c=IN IP4 0.0.0.0\r\n"
217 "a=rtcp:1 IN IP4 0.0.0.0\r\n"
218 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
219 "a=mid:audio_content_name\r\n"
220 "a=sendrecv\r\n"
221 "a=rtcp-mux\r\n"
222 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
223 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
224 "dummy_session_params\r\n"
225 "a=rtpmap:111 opus/48000/2\r\n"
226 "a=rtpmap:103 ISAC/16000\r\n"
227 "a=rtpmap:104 CELT/32000/2\r\n"
228 "a=ssrc:1 cname:stream_1_cname\r\n"
229 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
230 "a=ssrc:1 mslabel:local_stream_1\r\n"
231 "a=ssrc:1 label:audio_track_id_1\r\n"
232 "a=ssrc:4 cname:stream_2_cname\r\n"
233 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
234 "a=ssrc:4 mslabel:local_stream_2\r\n"
235 "a=ssrc:4 label:audio_track_id_2\r\n"
236 "m=video 1 RTP/SAVPF 120\r\n"
237 "c=IN IP4 0.0.0.0\r\n"
238 "a=rtcp:1 IN IP4 0.0.0.0\r\n"
239 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
240 "a=mid:video_content_name\r\n"
241 "a=sendrecv\r\n"
242 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
243 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
244 "a=rtpmap:120 VP8/90000\r\n"
245 "a=ssrc:2 cname:stream_1_cname\r\n"
246 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
247 "a=ssrc:2 mslabel:local_stream_1\r\n"
248 "a=ssrc:2 label:video_track_id_1\r\n"
249 "a=ssrc:3 cname:stream_1_cname\r\n"
250 "a=ssrc:3 msid:local_stream_1 video_track_id_2\r\n"
251 "a=ssrc:3 mslabel:local_stream_1\r\n"
252 "a=ssrc:3 label:video_track_id_2\r\n"
253 "a=ssrc-group:FEC 5 6\r\n"
254 "a=ssrc:5 cname:stream_2_cname\r\n"
255 "a=ssrc:5 msid:local_stream_2 video_track_id_3\r\n"
256 "a=ssrc:5 mslabel:local_stream_2\r\n"
257 "a=ssrc:5 label:video_track_id_3\r\n"
258 "a=ssrc:6 cname:stream_2_cname\r\n"
259 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
260 "a=ssrc:6 mslabel:local_stream_2\r\n"
261 "a=ssrc:6 label:video_track_id_3\r\n";
262
263static const char kSdpRtpDataChannelString[] =
264 "m=application 1 RTP/SAVPF 101\r\n"
265 "c=IN IP4 0.0.0.0\r\n"
266 "a=rtcp:1 IN IP4 0.0.0.0\r\n"
267 "a=ice-ufrag:ufrag_data\r\n"
268 "a=ice-pwd:pwd_data\r\n"
269 "a=mid:data_content_name\r\n"
270 "a=sendrecv\r\n"
271 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
272 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
273 "a=rtpmap:101 google-data/90000\r\n"
274 "a=ssrc:10 cname:data_channel_cname\r\n"
275 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
276 "a=ssrc:10 mslabel:data_channel\r\n"
277 "a=ssrc:10 label:data_channeld0\r\n";
278
279static const char kSdpSctpDataChannelString[] =
280 "m=application 1 DTLS/SCTP 5000\r\n"
281 "c=IN IP4 0.0.0.0\r\n"
282 "a=ice-ufrag:ufrag_data\r\n"
283 "a=ice-pwd:pwd_data\r\n"
284 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000285 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000286
287static const char kSdpSctpDataChannelWithCandidatesString[] =
288 "m=application 2345 DTLS/SCTP 5000\r\n"
289 "c=IN IP4 74.125.127.126\r\n"
290 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
291 "generation 2\r\n"
292 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
293 "generation 2\r\n"
294 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
295 "raddr 192.168.1.5 rport 2346 "
296 "generation 2\r\n"
297 "a=ice-ufrag:ufrag_data\r\n"
298 "a=ice-pwd:pwd_data\r\n"
299 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000300 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000301
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000302static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000303 "v=0\r\n"
304 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
305 "s=-\r\n"
306 "t=0 0\r\n"
307 "a=msid-semantic: WMS\r\n"
308 "m=audio 1 RTP/SAVPF 111 103 104\r\n"
309 "c=IN IP4 0.0.0.0\r\n"
310 "a=x-google-flag:conference\r\n"
311 "m=video 1 RTP/SAVPF 120\r\n"
312 "c=IN IP4 0.0.0.0\r\n"
313 "a=x-google-flag:conference\r\n";
314
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000315static const char kSdpSessionString[] =
316 "v=0\r\n"
317 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
318 "s=-\r\n"
319 "t=0 0\r\n"
320 "a=msid-semantic: WMS local_stream\r\n";
321
322static const char kSdpAudioString[] =
323 "m=audio 1 RTP/SAVPF 111\r\n"
324 "c=IN IP4 0.0.0.0\r\n"
325 "a=rtcp:1 IN IP4 0.0.0.0\r\n"
326 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
327 "a=mid:audio_content_name\r\n"
328 "a=sendrecv\r\n"
329 "a=rtpmap:111 opus/48000/2\r\n"
330 "a=ssrc:1 cname:stream_1_cname\r\n"
331 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
332 "a=ssrc:1 mslabel:local_stream\r\n"
333 "a=ssrc:1 label:audio_track_id_1\r\n";
334
335static const char kSdpVideoString[] =
336 "m=video 1 RTP/SAVPF 120\r\n"
337 "c=IN IP4 0.0.0.0\r\n"
338 "a=rtcp:1 IN IP4 0.0.0.0\r\n"
339 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
340 "a=mid:video_content_name\r\n"
341 "a=sendrecv\r\n"
342 "a=rtpmap:120 VP8/90000\r\n"
343 "a=ssrc:2 cname:stream_1_cname\r\n"
344 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
345 "a=ssrc:2 mslabel:local_stream\r\n"
346 "a=ssrc:2 label:video_track_id_1\r\n";
347
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000348
349// One candidate reference string as per W3c spec.
350// candidate:<blah> not a=candidate:<blah>CRLF
351static const char kRawCandidate[] =
352 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
353// One candidate reference string.
354static const char kSdpOneCandidate[] =
355 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
356 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000357
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000358static const char kSdpTcpActiveCandidate[] =
359 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
360 "tcptype active generation 2";
361static const char kSdpTcpPassiveCandidate[] =
362 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
363 "tcptype passive generation 2";
364static const char kSdpTcpSOCandidate[] =
365 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
366 "tcptype so generation 2";
367static const char kSdpTcpInvalidCandidate[] =
368 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
369 "tcptype invalid generation 2";
370
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000371// One candidate reference string with IPV6 address.
372static const char kRawIPV6Candidate[] =
373 "candidate:a0+B/1 1 udp 2130706432 "
374 "abcd::abcd::abcd::abcd::abcd::abcd::abcd::abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000375
376// One candidate reference string.
377static const char kSdpOneCandidateOldFormat[] =
378 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
379 " eth0 username user_rtp password password_rtp generation 2\r\n";
380
381// Session id and version
382static const char kSessionId[] = "18446744069414584320";
383static const char kSessionVersion[] = "18446462598732840960";
384
385// Ice options
386static const char kIceOption1[] = "iceoption1";
387static const char kIceOption2[] = "iceoption2";
388static const char kIceOption3[] = "iceoption3";
389
390// Content name
391static const char kAudioContentName[] = "audio_content_name";
392static const char kVideoContentName[] = "video_content_name";
393static const char kDataContentName[] = "data_content_name";
394
395// MediaStream 1
396static const char kStreamLabel1[] = "local_stream_1";
397static const char kStream1Cname[] = "stream_1_cname";
398static const char kAudioTrackId1[] = "audio_track_id_1";
399static const uint32 kAudioTrack1Ssrc = 1;
400static const char kVideoTrackId1[] = "video_track_id_1";
401static const uint32 kVideoTrack1Ssrc = 2;
402static const char kVideoTrackId2[] = "video_track_id_2";
403static const uint32 kVideoTrack2Ssrc = 3;
404
405// MediaStream 2
406static const char kStreamLabel2[] = "local_stream_2";
407static const char kStream2Cname[] = "stream_2_cname";
408static const char kAudioTrackId2[] = "audio_track_id_2";
409static const uint32 kAudioTrack2Ssrc = 4;
410static const char kVideoTrackId3[] = "video_track_id_3";
411static const uint32 kVideoTrack3Ssrc = 5;
412static const uint32 kVideoTrack4Ssrc = 6;
413
414// DataChannel
415static const char kDataChannelLabel[] = "data_channel";
416static const char kDataChannelMsid[] = "data_channeld0";
417static const char kDataChannelCname[] = "data_channel_cname";
418static const uint32 kDataChannelSsrc = 10;
419
420// Candidate
421static const char kDummyMid[] = "dummy_mid";
422static const int kDummyIndex = 123;
423
424// Misc
425static const char kDummyString[] = "dummy";
426
427// Helper functions
428
429static bool SdpDeserialize(const std::string& message,
430 JsepSessionDescription* jdesc) {
431 return webrtc::SdpDeserialize(message, jdesc, NULL);
432}
433
434static bool SdpDeserializeCandidate(const std::string& message,
435 JsepIceCandidate* candidate) {
436 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
437}
438
439// Add some extra |newlines| to the |message| after |line|.
440static void InjectAfter(const std::string& line,
441 const std::string& newlines,
442 std::string* message) {
443 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000444 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000445 tmp.c_str(), tmp.length(), message);
446}
447
448static void Replace(const std::string& line,
449 const std::string& newlines,
450 std::string* message) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000451 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000452 newlines.c_str(), newlines.length(), message);
453}
454
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000455// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
456// message.
457static void ExpectParseFailure(const std::string& bad_sdp,
458 const std::string& bad_part) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000459 JsepSessionDescription desc(kDummyString);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000460 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000461 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000462 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000463 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
464}
465
466// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
467static void ExpectParseFailure(const char* good_part, const char* bad_part) {
468 std::string bad_sdp = kSdpFullString;
469 Replace(good_part, bad_part, &bad_sdp);
470 ExpectParseFailure(bad_sdp, bad_part);
471}
472
473// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
474static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
475 const std::string& newlines,
476 const std::string& bad_part) {
477 std::string bad_sdp = kSdpFullString;
478 InjectAfter(injectpoint, newlines, &bad_sdp);
479 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000480}
481
482static void ReplaceDirection(cricket::MediaContentDirection direction,
483 std::string* message) {
484 std::string new_direction;
485 switch (direction) {
486 case cricket::MD_INACTIVE:
487 new_direction = "a=inactive";
488 break;
489 case cricket::MD_SENDONLY:
490 new_direction = "a=sendonly";
491 break;
492 case cricket::MD_RECVONLY:
493 new_direction = "a=recvonly";
494 break;
495 case cricket::MD_SENDRECV:
496 default:
497 new_direction = "a=sendrecv";
498 break;
499 }
500 Replace("a=sendrecv", new_direction, message);
501}
502
503static void ReplaceRejected(bool audio_rejected, bool video_rejected,
504 std::string* message) {
505 if (audio_rejected) {
506 Replace("m=audio 2345", "m=audio 0", message);
507 }
508 if (video_rejected) {
509 Replace("m=video 3457", "m=video 0", message);
510 }
511}
512
513// WebRtcSdpTest
514
515class WebRtcSdpTest : public testing::Test {
516 public:
517 WebRtcSdpTest()
518 : jdesc_(kDummyString) {
519 // AudioContentDescription
520 audio_desc_ = CreateAudioContentDescription();
521 AudioCodec opus(111, "opus", 48000, 0, 2, 3);
522 audio_desc_->AddCodec(opus);
523 audio_desc_->AddCodec(AudioCodec(103, "ISAC", 16000, 32000, 1, 2));
524 audio_desc_->AddCodec(AudioCodec(104, "CELT", 32000, 0, 2, 1));
525 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
526
527 // VideoContentDescription
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000528 rtc::scoped_ptr<VideoContentDescription> video(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000529 new VideoContentDescription());
530 video_desc_ = video.get();
531 StreamParams video_stream1;
532 video_stream1.id = kVideoTrackId1;
533 video_stream1.cname = kStream1Cname;
534 video_stream1.sync_label = kStreamLabel1;
535 video_stream1.ssrcs.push_back(kVideoTrack1Ssrc);
536 video->AddStream(video_stream1);
537 StreamParams video_stream2;
538 video_stream2.id = kVideoTrackId2;
539 video_stream2.cname = kStream1Cname;
540 video_stream2.sync_label = kStreamLabel1;
541 video_stream2.ssrcs.push_back(kVideoTrack2Ssrc);
542 video->AddStream(video_stream2);
543 StreamParams video_stream3;
544 video_stream3.id = kVideoTrackId3;
545 video_stream3.cname = kStream2Cname;
546 video_stream3.sync_label = kStreamLabel2;
547 video_stream3.ssrcs.push_back(kVideoTrack3Ssrc);
548 video_stream3.ssrcs.push_back(kVideoTrack4Ssrc);
549 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream3.ssrcs);
550 video_stream3.ssrc_groups.push_back(ssrc_group);
551 video->AddStream(video_stream3);
552 video->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
553 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
554 video->set_protocol(cricket::kMediaProtocolSavpf);
555 video->AddCodec(VideoCodec(
556 120,
557 JsepSessionDescription::kDefaultVideoCodecName,
558 JsepSessionDescription::kMaxVideoCodecWidth,
559 JsepSessionDescription::kMaxVideoCodecHeight,
560 JsepSessionDescription::kDefaultVideoCodecFramerate,
561 JsepSessionDescription::kDefaultVideoCodecPreference));
562
563 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP,
564 video.release());
565
566 // TransportInfo
567 EXPECT_TRUE(desc_.AddTransportInfo(
568 TransportInfo(kAudioContentName,
569 TransportDescription(NS_JINGLE_ICE_UDP,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000570 kCandidateUfragVoice,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000571 kCandidatePwdVoice))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000572 EXPECT_TRUE(desc_.AddTransportInfo(
573 TransportInfo(kVideoContentName,
574 TransportDescription(NS_JINGLE_ICE_UDP,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000575 kCandidateUfragVideo,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000576 kCandidatePwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000577
578 // v4 host
579 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000580 rtc::SocketAddress address("192.168.1.5", port++);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000581 Candidate candidate1(
582 "", ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
583 "", "", LOCAL_PORT_TYPE,
584 "", kCandidateGeneration, kCandidateFoundation1);
585 address.SetPort(port++);
586 Candidate candidate2(
587 "", ICE_CANDIDATE_COMPONENT_RTCP, "udp", address, kCandidatePriority,
588 "", "", LOCAL_PORT_TYPE,
589 "", kCandidateGeneration, kCandidateFoundation1);
590 address.SetPort(port++);
591 Candidate candidate3(
592 "", ICE_CANDIDATE_COMPONENT_RTCP, "udp", address, kCandidatePriority,
593 "", "", LOCAL_PORT_TYPE,
594 "", kCandidateGeneration, kCandidateFoundation1);
595 address.SetPort(port++);
596 Candidate candidate4(
597 "", ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
598 "", "", LOCAL_PORT_TYPE,
599 "", kCandidateGeneration, kCandidateFoundation1);
600
601 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000602 rtc::SocketAddress v6_address("::1", port++);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000603 cricket::Candidate candidate5(
604 "", cricket::ICE_CANDIDATE_COMPONENT_RTP,
605 "udp", v6_address, kCandidatePriority,
606 "", "", cricket::LOCAL_PORT_TYPE,
607 "", kCandidateGeneration, kCandidateFoundation2);
608 v6_address.SetPort(port++);
609 cricket::Candidate candidate6(
610 "", cricket::ICE_CANDIDATE_COMPONENT_RTCP,
611 "udp", v6_address, kCandidatePriority,
612 "", "", cricket::LOCAL_PORT_TYPE,
613 "", kCandidateGeneration, kCandidateFoundation2);
614 v6_address.SetPort(port++);
615 cricket::Candidate candidate7(
616 "", cricket::ICE_CANDIDATE_COMPONENT_RTCP,
617 "udp", v6_address, kCandidatePriority,
618 "", "", cricket::LOCAL_PORT_TYPE,
619 "", kCandidateGeneration, kCandidateFoundation2);
620 v6_address.SetPort(port++);
621 cricket::Candidate candidate8(
622 "", cricket::ICE_CANDIDATE_COMPONENT_RTP,
623 "udp", v6_address, kCandidatePriority,
624 "", "", cricket::LOCAL_PORT_TYPE,
625 "", kCandidateGeneration, kCandidateFoundation2);
626
627 // stun
628 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000629 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
630 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000631 cricket::Candidate candidate9
632 ("", cricket::ICE_CANDIDATE_COMPONENT_RTP,
633 "udp", address_stun, kCandidatePriority,
634 "", "", STUN_PORT_TYPE,
635 "", kCandidateGeneration, kCandidateFoundation3);
636 candidate9.set_related_address(rel_address_stun);
637
638 address_stun.SetPort(port_stun++);
639 rel_address_stun.SetPort(port_stun++);
640 cricket::Candidate candidate10(
641 "", cricket::ICE_CANDIDATE_COMPONENT_RTCP,
642 "udp", address_stun, kCandidatePriority,
643 "", "", STUN_PORT_TYPE,
644 "", kCandidateGeneration, kCandidateFoundation3);
645 candidate10.set_related_address(rel_address_stun);
646
647 // relay
648 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000649 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000650 cricket::Candidate candidate11(
651 "", cricket::ICE_CANDIDATE_COMPONENT_RTCP,
652 "udp", address_relay, kCandidatePriority,
653 "", "",
654 cricket::RELAY_PORT_TYPE, "",
655 kCandidateGeneration, kCandidateFoundation4);
656 address_relay.SetPort(port_relay++);
657 cricket::Candidate candidate12(
658 "", cricket::ICE_CANDIDATE_COMPONENT_RTP,
659 "udp", address_relay, kCandidatePriority,
660 "", "",
661 RELAY_PORT_TYPE, "",
662 kCandidateGeneration, kCandidateFoundation4);
663
664 // voice
665 candidates_.push_back(candidate1);
666 candidates_.push_back(candidate2);
667 candidates_.push_back(candidate5);
668 candidates_.push_back(candidate6);
669 candidates_.push_back(candidate9);
670 candidates_.push_back(candidate10);
671
672 // video
673 candidates_.push_back(candidate3);
674 candidates_.push_back(candidate4);
675 candidates_.push_back(candidate7);
676 candidates_.push_back(candidate8);
677 candidates_.push_back(candidate11);
678 candidates_.push_back(candidate12);
679
680 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"),
681 0, candidate1));
682
683 // Set up JsepSessionDescription.
684 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
685 std::string mline_id;
686 int mline_index = 0;
687 for (size_t i = 0; i< candidates_.size(); ++i) {
688 // In this test, the audio m line index will be 0, and the video m line
689 // will be 1.
690 bool is_video = (i > 5);
691 mline_id = is_video ? "video_content_name" : "audio_content_name";
692 mline_index = is_video ? 1 : 0;
693 JsepIceCandidate jice(mline_id,
694 mline_index,
695 candidates_.at(i));
696 jdesc_.AddCandidate(&jice);
697 }
698 }
699
700 AudioContentDescription* CreateAudioContentDescription() {
701 AudioContentDescription* audio = new AudioContentDescription();
702 audio->set_rtcp_mux(true);
703 StreamParams audio_stream1;
704 audio_stream1.id = kAudioTrackId1;
705 audio_stream1.cname = kStream1Cname;
706 audio_stream1.sync_label = kStreamLabel1;
707 audio_stream1.ssrcs.push_back(kAudioTrack1Ssrc);
708 audio->AddStream(audio_stream1);
709 StreamParams audio_stream2;
710 audio_stream2.id = kAudioTrackId2;
711 audio_stream2.cname = kStream2Cname;
712 audio_stream2.sync_label = kStreamLabel2;
713 audio_stream2.ssrcs.push_back(kAudioTrack2Ssrc);
714 audio->AddStream(audio_stream2);
715 audio->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_32",
716 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
717 "dummy_session_params"));
718 audio->set_protocol(cricket::kMediaProtocolSavpf);
719 return audio;
720 }
721
722 template <class MCD>
723 void CompareMediaContentDescription(const MCD* cd1,
724 const MCD* cd2) {
725 // type
726 EXPECT_EQ(cd1->type(), cd1->type());
727
728 // content direction
729 EXPECT_EQ(cd1->direction(), cd2->direction());
730
731 // rtcp_mux
732 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
733
734 // cryptos
735 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
736 if (cd1->cryptos().size() != cd2->cryptos().size()) {
737 ADD_FAILURE();
738 return;
739 }
740 for (size_t i = 0; i< cd1->cryptos().size(); ++i) {
741 const CryptoParams c1 = cd1->cryptos().at(i);
742 const CryptoParams c2 = cd2->cryptos().at(i);
743 EXPECT_TRUE(c1.Matches(c2));
744 EXPECT_EQ(c1.key_params, c2.key_params);
745 EXPECT_EQ(c1.session_params, c2.session_params);
746 }
747 // protocol
748 EXPECT_EQ(cd1->protocol(), cd2->protocol());
749
750 // codecs
751 EXPECT_EQ(cd1->codecs(), cd2->codecs());
752
753 // bandwidth
754 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
755
756 // streams
757 EXPECT_EQ(cd1->streams(), cd2->streams());
758
759 // extmap
760 ASSERT_EQ(cd1->rtp_header_extensions().size(),
761 cd2->rtp_header_extensions().size());
762 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) {
763 const RtpHeaderExtension ext1 = cd1->rtp_header_extensions().at(i);
764 const RtpHeaderExtension ext2 = cd2->rtp_header_extensions().at(i);
765 EXPECT_EQ(ext1.uri, ext2.uri);
766 EXPECT_EQ(ext1.id, ext2.id);
767 }
768
769 // buffered mode latency
770 EXPECT_EQ(cd1->buffered_mode_latency(), cd2->buffered_mode_latency());
771 }
772
773
774 void CompareSessionDescription(const SessionDescription& desc1,
775 const SessionDescription& desc2) {
776 // Compare content descriptions.
777 if (desc1.contents().size() != desc2.contents().size()) {
778 ADD_FAILURE();
779 return;
780 }
781 for (size_t i = 0 ; i < desc1.contents().size(); ++i) {
782 const cricket::ContentInfo& c1 = desc1.contents().at(i);
783 const cricket::ContentInfo& c2 = desc2.contents().at(i);
784 // content name
785 EXPECT_EQ(c1.name, c2.name);
786 // content type
787 // Note, ASSERT will return from the function, but will not stop the test.
788 ASSERT_EQ(c1.type, c2.type);
789
790 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
791 if (IsAudioContent(&c1)) {
792 const AudioContentDescription* acd1 =
793 static_cast<const AudioContentDescription*>(c1.description);
794 const AudioContentDescription* acd2 =
795 static_cast<const AudioContentDescription*>(c2.description);
796 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
797 }
798
799 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
800 if (IsVideoContent(&c1)) {
801 const VideoContentDescription* vcd1 =
802 static_cast<const VideoContentDescription*>(c1.description);
803 const VideoContentDescription* vcd2 =
804 static_cast<const VideoContentDescription*>(c2.description);
805 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
806 }
807
808 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
809 if (IsDataContent(&c1)) {
810 const DataContentDescription* dcd1 =
811 static_cast<const DataContentDescription*>(c1.description);
812 const DataContentDescription* dcd2 =
813 static_cast<const DataContentDescription*>(c2.description);
814 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
815 }
816 }
817
818 // group
819 const cricket::ContentGroups groups1 = desc1.groups();
820 const cricket::ContentGroups groups2 = desc2.groups();
821 EXPECT_EQ(groups1.size(), groups1.size());
822 if (groups1.size() != groups2.size()) {
823 ADD_FAILURE();
824 return;
825 }
826 for (size_t i = 0; i < groups1.size(); ++i) {
827 const cricket::ContentGroup group1 = groups1.at(i);
828 const cricket::ContentGroup group2 = groups2.at(i);
829 EXPECT_EQ(group1.semantics(), group2.semantics());
830 const cricket::ContentNames names1 = group1.content_names();
831 const cricket::ContentNames names2 = group2.content_names();
832 EXPECT_EQ(names1.size(), names2.size());
833 if (names1.size() != names2.size()) {
834 ADD_FAILURE();
835 return;
836 }
837 cricket::ContentNames::const_iterator iter1 = names1.begin();
838 cricket::ContentNames::const_iterator iter2 = names2.begin();
839 while (iter1 != names1.end()) {
840 EXPECT_EQ(*iter1++, *iter2++);
841 }
842 }
843
844 // transport info
845 const cricket::TransportInfos transports1 = desc1.transport_infos();
846 const cricket::TransportInfos transports2 = desc2.transport_infos();
847 EXPECT_EQ(transports1.size(), transports2.size());
848 if (transports1.size() != transports2.size()) {
849 ADD_FAILURE();
850 return;
851 }
852 for (size_t i = 0; i < transports1.size(); ++i) {
853 const cricket::TransportInfo transport1 = transports1.at(i);
854 const cricket::TransportInfo transport2 = transports2.at(i);
855 EXPECT_EQ(transport1.content_name, transport2.content_name);
856 EXPECT_EQ(transport1.description.transport_type,
857 transport2.description.transport_type);
858 EXPECT_EQ(transport1.description.ice_ufrag,
859 transport2.description.ice_ufrag);
860 EXPECT_EQ(transport1.description.ice_pwd,
861 transport2.description.ice_pwd);
862 if (transport1.description.identity_fingerprint) {
863 EXPECT_EQ(*transport1.description.identity_fingerprint,
864 *transport2.description.identity_fingerprint);
865 } else {
866 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
867 transport2.description.identity_fingerprint.get());
868 }
869 EXPECT_EQ(transport1.description.transport_options,
870 transport2.description.transport_options);
871 EXPECT_TRUE(CompareCandidates(transport1.description.candidates,
872 transport2.description.candidates));
873 }
874 }
875
876 bool CompareCandidates(const Candidates& cs1, const Candidates& cs2) {
877 EXPECT_EQ(cs1.size(), cs2.size());
878 if (cs1.size() != cs2.size())
879 return false;
880 for (size_t i = 0; i< cs1.size(); ++i) {
881 const Candidate c1 = cs1.at(i);
882 const Candidate c2 = cs2.at(i);
883 EXPECT_TRUE(c1.IsEquivalent(c2));
884 }
885 return true;
886 }
887
888 bool CompareSessionDescription(
889 const JsepSessionDescription& desc1,
890 const JsepSessionDescription& desc2) {
891 EXPECT_EQ(desc1.session_id(), desc2.session_id());
892 EXPECT_EQ(desc1.session_version(), desc2.session_version());
893 CompareSessionDescription(*desc1.description(), *desc2.description());
894 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
895 return false;
896 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
897 const IceCandidateCollection* cc1 = desc1.candidates(i);
898 const IceCandidateCollection* cc2 = desc2.candidates(i);
899 if (cc1->count() != cc2->count())
900 return false;
901 for (size_t j = 0; j < cc1->count(); ++j) {
902 const IceCandidateInterface* c1 = cc1->at(j);
903 const IceCandidateInterface* c2 = cc2->at(j);
904 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
905 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
906 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
907 }
908 }
909 return true;
910 }
911
912 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
913 // them with invalid keywords so that the parser will just ignore them.
914 bool RemoveCandidateUfragPwd(std::string* sdp) {
915 const char ice_ufrag[] = "a=ice-ufrag";
916 const char ice_ufragx[] = "a=xice-ufrag";
917 const char ice_pwd[] = "a=ice-pwd";
918 const char ice_pwdx[] = "a=xice-pwd";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000919 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000920 ice_ufragx, strlen(ice_ufragx), sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000921 rtc::replace_substrs(ice_pwd, strlen(ice_pwd),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000922 ice_pwdx, strlen(ice_pwdx), sdp);
923 return true;
924 }
925
926 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
927 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, int mline_index,
928 const std::string& ufrag, const std::string& pwd) {
929 std::string content_name;
930 if (mline_index == 0) {
931 content_name = kAudioContentName;
932 } else if (mline_index == 1) {
933 content_name = kVideoContentName;
934 } else {
935 ASSERT(false);
936 }
937 TransportInfo transport_info(
938 content_name, TransportDescription(NS_JINGLE_ICE_UDP,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000939 ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000940 SessionDescription* desc =
941 const_cast<SessionDescription*>(jdesc->description());
942 desc->RemoveTransportInfoByName(content_name);
943 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
944 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
945 const IceCandidateCollection* cc = jdesc_.candidates(i);
946 for (size_t j = 0; j < cc->count(); ++j) {
947 if (cc->at(j)->sdp_mline_index() == mline_index) {
948 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(
949 ufrag);
950 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(
951 pwd);
952 }
953 }
954 }
955 return true;
956 }
957
958 void AddIceOptions(const std::string& content_name,
959 const std::vector<std::string>& transport_options) {
960 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
961 cricket::TransportInfo transport_info =
962 *(desc_.GetTransportInfoByName(content_name));
963 desc_.RemoveTransportInfoByName(content_name);
964 transport_info.description.transport_options = transport_options;
965 desc_.AddTransportInfo(transport_info);
966 }
967
968 void AddFingerprint() {
969 desc_.RemoveTransportInfoByName(kAudioContentName);
970 desc_.RemoveTransportInfoByName(kVideoContentName);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000971 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000972 kIdentityDigest,
973 sizeof(kIdentityDigest));
974 EXPECT_TRUE(desc_.AddTransportInfo(
975 TransportInfo(kAudioContentName,
976 TransportDescription(NS_JINGLE_ICE_UDP,
977 std::vector<std::string>(),
978 kCandidateUfragVoice,
979 kCandidatePwdVoice,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000980 cricket::ICEMODE_FULL,
981 cricket::CONNECTIONROLE_NONE,
982 &fingerprint, Candidates()))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000983 EXPECT_TRUE(desc_.AddTransportInfo(
984 TransportInfo(kVideoContentName,
985 TransportDescription(NS_JINGLE_ICE_UDP,
986 std::vector<std::string>(),
987 kCandidateUfragVideo,
988 kCandidatePwdVideo,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000989 cricket::ICEMODE_FULL,
990 cricket::CONNECTIONROLE_NONE,
991 &fingerprint, Candidates()))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000992 }
993
994 void AddExtmap() {
995 audio_desc_ = static_cast<AudioContentDescription*>(
996 audio_desc_->Copy());
997 video_desc_ = static_cast<VideoContentDescription*>(
998 video_desc_->Copy());
999 audio_desc_->AddRtpHeaderExtension(
1000 RtpHeaderExtension(kExtmapUri, kExtmapId));
1001 video_desc_->AddRtpHeaderExtension(
1002 RtpHeaderExtension(kExtmapUri, kExtmapId));
1003 desc_.RemoveContentByName(kAudioContentName);
1004 desc_.RemoveContentByName(kVideoContentName);
1005 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1006 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1007 }
1008
1009 void RemoveCryptos() {
1010 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1011 video_desc_->set_cryptos(std::vector<CryptoParams>());
1012 }
1013
1014 bool TestSerializeDirection(cricket::MediaContentDirection direction) {
1015 audio_desc_->set_direction(direction);
1016 video_desc_->set_direction(direction);
1017 std::string new_sdp = kSdpFullString;
1018 ReplaceDirection(direction, &new_sdp);
1019
1020 if (!jdesc_.Initialize(desc_.Copy(),
1021 jdesc_.session_id(),
1022 jdesc_.session_version())) {
1023 return false;
1024 }
1025 std::string message = webrtc::SdpSerialize(jdesc_);
1026 EXPECT_EQ(new_sdp, message);
1027 return true;
1028 }
1029
1030 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
1031 audio_desc_ = static_cast<AudioContentDescription*>(
1032 audio_desc_->Copy());
1033 video_desc_ = static_cast<VideoContentDescription*>(
1034 video_desc_->Copy());
1035 desc_.RemoveContentByName(kAudioContentName);
1036 desc_.RemoveContentByName(kVideoContentName);
1037 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1038 audio_desc_);
1039 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1040 video_desc_);
1041 std::string new_sdp = kSdpFullString;
1042 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1043
1044 if (!jdesc_.Initialize(desc_.Copy(),
1045 jdesc_.session_id(),
1046 jdesc_.session_version())) {
1047 return false;
1048 }
1049 std::string message = webrtc::SdpSerialize(jdesc_);
1050 EXPECT_EQ(new_sdp, message);
1051 return true;
1052 }
1053
1054 void AddSctpDataChannel() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001055 rtc::scoped_ptr<DataContentDescription> data(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001056 new DataContentDescription());
1057 data_desc_ = data.get();
1058 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
wu@webrtc.org78187522013-10-07 23:32:02 +00001059 DataCodec codec(cricket::kGoogleSctpDataCodecId,
1060 cricket::kGoogleSctpDataCodecName, 0);
1061 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1062 data_desc_->AddCodec(codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001063 desc_.AddContent(kDataContentName, NS_JINGLE_DRAFT_SCTP, data.release());
1064 EXPECT_TRUE(desc_.AddTransportInfo(
1065 TransportInfo(kDataContentName,
1066 TransportDescription(NS_JINGLE_ICE_UDP,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001067 kCandidateUfragData,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001068 kCandidatePwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001069 }
1070
1071 void AddRtpDataChannel() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001072 rtc::scoped_ptr<DataContentDescription> data(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001073 new DataContentDescription());
1074 data_desc_ = data.get();
1075
1076 data_desc_->AddCodec(DataCodec(101, "google-data", 1));
1077 StreamParams data_stream;
1078 data_stream.id = kDataChannelMsid;
1079 data_stream.cname = kDataChannelCname;
1080 data_stream.sync_label = kDataChannelLabel;
1081 data_stream.ssrcs.push_back(kDataChannelSsrc);
1082 data_desc_->AddStream(data_stream);
1083 data_desc_->AddCrypto(CryptoParams(
1084 1, "AES_CM_128_HMAC_SHA1_80",
1085 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
1086 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
1087 desc_.AddContent(kDataContentName, NS_JINGLE_RTP, data.release());
1088 EXPECT_TRUE(desc_.AddTransportInfo(
1089 TransportInfo(kDataContentName,
1090 TransportDescription(NS_JINGLE_ICE_UDP,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001091 kCandidateUfragData,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001092 kCandidatePwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001093 }
1094
1095 bool TestDeserializeDirection(cricket::MediaContentDirection direction) {
1096 std::string new_sdp = kSdpFullString;
1097 ReplaceDirection(direction, &new_sdp);
1098 JsepSessionDescription new_jdesc(kDummyString);
1099
1100 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1101
1102 audio_desc_->set_direction(direction);
1103 video_desc_->set_direction(direction);
1104 if (!jdesc_.Initialize(desc_.Copy(),
1105 jdesc_.session_id(),
1106 jdesc_.session_version())) {
1107 return false;
1108 }
1109 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1110 return true;
1111 }
1112
1113 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
1114 std::string new_sdp = kSdpFullString;
1115 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1116 JsepSessionDescription new_jdesc(JsepSessionDescription::kOffer);
1117
1118 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1119 audio_desc_ = static_cast<AudioContentDescription*>(
1120 audio_desc_->Copy());
1121 video_desc_ = static_cast<VideoContentDescription*>(
1122 video_desc_->Copy());
1123 desc_.RemoveContentByName(kAudioContentName);
1124 desc_.RemoveContentByName(kVideoContentName);
1125 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1126 audio_desc_);
1127 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1128 video_desc_);
1129 if (!jdesc_.Initialize(desc_.Copy(),
1130 jdesc_.session_id(),
1131 jdesc_.session_version())) {
1132 return false;
1133 }
1134 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1135 return true;
1136 }
1137
1138 void TestDeserializeExtmap(bool session_level, bool media_level) {
1139 AddExtmap();
1140 JsepSessionDescription new_jdesc("dummy");
1141 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1142 jdesc_.session_id(),
1143 jdesc_.session_version()));
1144 JsepSessionDescription jdesc_with_extmap("dummy");
1145 std::string sdp_with_extmap = kSdpString;
1146 if (session_level) {
1147 InjectAfter(kSessionTime, kExtmapWithDirectionAndAttribute,
1148 &sdp_with_extmap);
1149 }
1150 if (media_level) {
1151 InjectAfter(kAttributeIcePwdVoice, kExtmapWithDirectionAndAttribute,
1152 &sdp_with_extmap);
1153 InjectAfter(kAttributeIcePwdVideo, kExtmapWithDirectionAndAttribute,
1154 &sdp_with_extmap);
1155 }
1156 // The extmap can't be present at the same time in both session level and
1157 // media level.
1158 if (session_level && media_level) {
1159 SdpParseError error;
1160 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap,
1161 &jdesc_with_extmap, &error));
1162 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1163 } else {
1164 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1165 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1166 }
1167 }
1168
1169 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
1170 const std::string& name, int expected_value) {
1171 cricket::CodecParameterMap::const_iterator found = params.find(name);
1172 ASSERT_TRUE(found != params.end());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001173 EXPECT_EQ(found->second, rtc::ToString<int>(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001174 }
1175
1176 void TestDeserializeCodecParams(const CodecParams& params,
1177 JsepSessionDescription* jdesc_output) {
1178 std::string sdp =
1179 "v=0\r\n"
1180 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1181 "s=-\r\n"
1182 "t=0 0\r\n"
1183 // Include semantics for WebRTC Media Streams since it is supported by
1184 // this parser, and will be added to the SDP when serializing a session
1185 // description.
1186 "a=msid-semantic: WMS\r\n"
1187 // Pl type 111 preferred.
1188 "m=audio 1 RTP/SAVPF 111 104 103 102\r\n"
1189 // Pltype 111 listed before 103 and 104 in the map.
1190 "a=rtpmap:111 opus/48000/2\r\n"
1191 // Pltype 103 listed before 104.
1192 "a=rtpmap:103 ISAC/16000\r\n"
1193 "a=rtpmap:104 CELT/32000/2\r\n"
1194 "a=rtpmap:102 ISAC/32000/1\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001195 "a=fmtp:111 0-15,66,70\r\n"
1196 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001197 std::ostringstream os;
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001198 os << "minptime=" << params.min_ptime
1199 << "; stereo=" << params.stereo
1200 << "; sprop-stereo=" << params.sprop_stereo
1201 << "; useinbandfec=" << params.useinband
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001202 << " maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001203 << "a=ptime:" << params.ptime << "\r\n"
1204 << "a=maxptime:" << params.max_ptime << "\r\n";
1205 sdp += os.str();
1206
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001207 os.clear();
1208 os.str("");
1209 // Pl type 100 preferred.
1210 os << "m=video 1 RTP/SAVPF 99 95\r\n"
1211 << "a=rtpmap:99 VP8/90000\r\n"
1212 << "a=rtpmap:95 RTX/90000\r\n"
1213 << "a=fmtp:95 apt=99;rtx-time=1000\r\n";
1214 sdp += os.str();
1215
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001216 // Deserialize
1217 SdpParseError error;
1218 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1219
1220 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1221 ASSERT_TRUE(ac != NULL);
1222 const AudioContentDescription* acd =
1223 static_cast<const AudioContentDescription*>(ac->description);
1224 ASSERT_FALSE(acd->codecs().empty());
1225 cricket::AudioCodec opus = acd->codecs()[0];
1226 EXPECT_EQ("opus", opus.name);
1227 EXPECT_EQ(111, opus.id);
1228 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1229 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1230 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1231 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001232 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1233 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001234 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1235 cricket::AudioCodec codec = acd->codecs()[i];
1236 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1237 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
1238 if (codec.name == "ISAC") {
1239 if (codec.clockrate == 16000) {
1240 EXPECT_EQ(32000, codec.bitrate);
1241 } else {
1242 EXPECT_EQ(56000, codec.bitrate);
1243 }
1244 }
1245 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001246
1247 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1248 ASSERT_TRUE(vc != NULL);
1249 const VideoContentDescription* vcd =
1250 static_cast<const VideoContentDescription*>(vc->description);
1251 ASSERT_FALSE(vcd->codecs().empty());
1252 cricket::VideoCodec vp8 = vcd->codecs()[0];
1253 EXPECT_EQ("VP8", vp8.name);
1254 EXPECT_EQ(99, vp8.id);
1255 cricket::VideoCodec rtx = vcd->codecs()[1];
1256 EXPECT_EQ("RTX", rtx.name);
1257 EXPECT_EQ(95, rtx.id);
1258 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001259 }
1260
1261 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1262 bool use_wildcard) {
1263 std::string sdp =
1264 "v=0\r\n"
1265 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1266 "s=-\r\n"
1267 "t=0 0\r\n"
1268 // Include semantics for WebRTC Media Streams since it is supported by
1269 // this parser, and will be added to the SDP when serializing a session
1270 // description.
1271 "a=msid-semantic: WMS\r\n"
1272 "m=audio 1 RTP/SAVPF 111\r\n"
1273 "a=rtpmap:111 opus/48000/2\r\n"
1274 "a=rtcp-fb:111 nack\r\n"
1275 "m=video 3457 RTP/SAVPF 101\r\n"
1276 "a=rtpmap:101 VP8/90000\r\n"
1277 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001278 "a=rtcp-fb:101 nack pli\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001279 "a=rtcp-fb:101 goog-remb\r\n"
1280 "a=rtcp-fb:101 ccm fir\r\n";
1281 std::ostringstream os;
1282 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
1283 sdp += os.str();
1284 // Deserialize
1285 SdpParseError error;
1286 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1287 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1288 ASSERT_TRUE(ac != NULL);
1289 const AudioContentDescription* acd =
1290 static_cast<const AudioContentDescription*>(ac->description);
1291 ASSERT_FALSE(acd->codecs().empty());
1292 cricket::AudioCodec opus = acd->codecs()[0];
1293 EXPECT_EQ(111, opus.id);
1294 EXPECT_TRUE(opus.HasFeedbackParam(
1295 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1296 cricket::kParamValueEmpty)));
1297
1298 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1299 ASSERT_TRUE(vc != NULL);
1300 const VideoContentDescription* vcd =
1301 static_cast<const VideoContentDescription*>(vc->description);
1302 ASSERT_FALSE(vcd->codecs().empty());
1303 cricket::VideoCodec vp8 = vcd->codecs()[0];
1304 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1305 vp8.name.c_str());
1306 EXPECT_EQ(101, vp8.id);
1307 EXPECT_TRUE(vp8.HasFeedbackParam(
1308 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1309 cricket::kParamValueEmpty)));
1310 EXPECT_TRUE(vp8.HasFeedbackParam(
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001311 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1312 cricket::kRtcpFbNackParamPli)));
1313 EXPECT_TRUE(vp8.HasFeedbackParam(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001314 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
1315 cricket::kParamValueEmpty)));
1316 EXPECT_TRUE(vp8.HasFeedbackParam(
1317 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
1318 cricket::kRtcpFbCcmParamFir)));
1319 }
1320
1321 // Two SDP messages can mean the same thing but be different strings, e.g.
1322 // some of the lines can be serialized in different order.
1323 // However, a deserialized description can be compared field by field and has
1324 // no order. If deserializer has already been tested, serializing then
1325 // deserializing and comparing JsepSessionDescription will test
1326 // the serializer sufficiently.
1327 void TestSerialize(const JsepSessionDescription& jdesc) {
1328 std::string message = webrtc::SdpSerialize(jdesc);
1329 JsepSessionDescription jdesc_output_des(kDummyString);
1330 SdpParseError error;
1331 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1332 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1333 }
1334
1335 protected:
1336 SessionDescription desc_;
1337 AudioContentDescription* audio_desc_;
1338 VideoContentDescription* video_desc_;
1339 DataContentDescription* data_desc_;
1340 Candidates candidates_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001341 rtc::scoped_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001342 JsepSessionDescription jdesc_;
1343};
1344
1345void TestMismatch(const std::string& string1, const std::string& string2) {
1346 int position = 0;
1347 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1348 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001349 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001350 break;
1351 }
1352 }
1353 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1354 << " character\n"
1355 << " 1: " << string1.substr(position, 20) << "\n"
1356 << " 2: " << string2.substr(position, 20) << "\n";
1357}
1358
1359std::string GetLine(const std::string& message,
1360 const std::string& session_description_name) {
1361 size_t start = message.find(session_description_name);
1362 if (std::string::npos == start) {
1363 return "";
1364 }
1365 size_t stop = message.find("\r\n", start);
1366 if (std::string::npos == stop) {
1367 return "";
1368 }
1369 if (stop <= start) {
1370 return "";
1371 }
1372 return message.substr(start, stop - start);
1373}
1374
1375TEST_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
1386// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1387// the case in a DTLS offer.
1388TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1389 AddFingerprint();
1390 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1391 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1392 kSessionId, kSessionVersion));
1393 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
1394
1395 std::string sdp_with_fingerprint = kSdpString;
1396 InjectAfter(kAttributeIcePwdVoice,
1397 kFingerprint, &sdp_with_fingerprint);
1398 InjectAfter(kAttributeIcePwdVideo,
1399 kFingerprint, &sdp_with_fingerprint);
1400
1401 EXPECT_EQ(sdp_with_fingerprint, message);
1402}
1403
1404// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1405// be the case in a DTLS answer.
1406TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1407 AddFingerprint();
1408 RemoveCryptos();
1409 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1410 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1411 kSessionId, kSessionVersion));
1412 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
1413
1414 std::string sdp_with_fingerprint = kSdpString;
1415 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1416 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
1417 InjectAfter(kAttributeIcePwdVoice,
1418 kFingerprint, &sdp_with_fingerprint);
1419 InjectAfter(kAttributeIcePwdVideo,
1420 kFingerprint, &sdp_with_fingerprint);
1421
1422 EXPECT_EQ(sdp_with_fingerprint, message);
1423}
1424
1425TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1426 // JsepSessionDescription with desc but without candidates.
1427 JsepSessionDescription jdesc_no_candidates(kDummyString);
1428 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
1429 kSessionId, kSessionVersion));
1430 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
1431 EXPECT_EQ(std::string(kSdpString), message);
1432}
1433
1434TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1435 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1436 group.AddContentName(kAudioContentName);
1437 group.AddContentName(kVideoContentName);
1438 desc_.AddGroup(group);
1439 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1440 jdesc_.session_id(),
1441 jdesc_.session_version()));
1442 std::string message = webrtc::SdpSerialize(jdesc_);
1443 std::string sdp_with_bundle = kSdpFullString;
1444 InjectAfter(kSessionTime,
1445 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1446 &sdp_with_bundle);
1447 EXPECT_EQ(sdp_with_bundle, message);
1448}
1449
1450TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
1451 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1452 GetFirstVideoContent(&desc_)->description);
1453 vcd->set_bandwidth(100 * 1000);
1454 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1455 GetFirstAudioContent(&desc_)->description);
1456 acd->set_bandwidth(50 * 1000);
1457 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1458 jdesc_.session_id(),
1459 jdesc_.session_version()));
1460 std::string message = webrtc::SdpSerialize(jdesc_);
1461 std::string sdp_with_bandwidth = kSdpFullString;
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001462 InjectAfter("c=IN IP4 74.125.224.39\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001463 "b=AS:100\r\n",
1464 &sdp_with_bandwidth);
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001465 InjectAfter("c=IN IP4 74.125.127.126\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001466 "b=AS:50\r\n",
1467 &sdp_with_bandwidth);
1468 EXPECT_EQ(sdp_with_bandwidth, message);
1469}
1470
1471TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1472 std::vector<std::string> transport_options;
1473 transport_options.push_back(kIceOption1);
1474 transport_options.push_back(kIceOption3);
1475 AddIceOptions(kAudioContentName, transport_options);
1476 transport_options.clear();
1477 transport_options.push_back(kIceOption2);
1478 transport_options.push_back(kIceOption3);
1479 AddIceOptions(kVideoContentName, transport_options);
1480 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1481 jdesc_.session_id(),
1482 jdesc_.session_version()));
1483 std::string message = webrtc::SdpSerialize(jdesc_);
1484 std::string sdp_with_ice_options = kSdpFullString;
1485 InjectAfter(kAttributeIcePwdVoice,
1486 "a=ice-options:iceoption1 iceoption3\r\n",
1487 &sdp_with_ice_options);
1488 InjectAfter(kAttributeIcePwdVideo,
1489 "a=ice-options:iceoption2 iceoption3\r\n",
1490 &sdp_with_ice_options);
1491 EXPECT_EQ(sdp_with_ice_options, message);
1492}
1493
1494TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
1495 EXPECT_TRUE(TestSerializeDirection(cricket::MD_RECVONLY));
1496}
1497
1498TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
1499 EXPECT_TRUE(TestSerializeDirection(cricket::MD_SENDONLY));
1500}
1501
1502TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
1503 EXPECT_TRUE(TestSerializeDirection(cricket::MD_INACTIVE));
1504}
1505
1506TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
1507 EXPECT_TRUE(TestSerializeRejected(true, false));
1508}
1509
1510TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
1511 EXPECT_TRUE(TestSerializeRejected(false, true));
1512}
1513
1514TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
1515 EXPECT_TRUE(TestSerializeRejected(true, true));
1516}
1517
1518TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
1519 AddRtpDataChannel();
1520 JsepSessionDescription jsep_desc(kDummyString);
1521
1522 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1523 std::string message = webrtc::SdpSerialize(jsep_desc);
1524
1525 std::string expected_sdp = kSdpString;
1526 expected_sdp.append(kSdpRtpDataChannelString);
1527 EXPECT_EQ(expected_sdp, message);
1528}
1529
1530TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
1531 AddSctpDataChannel();
1532 JsepSessionDescription jsep_desc(kDummyString);
1533
1534 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1535 std::string message = webrtc::SdpSerialize(jsep_desc);
1536
1537 std::string expected_sdp = kSdpString;
1538 expected_sdp.append(kSdpSctpDataChannelString);
1539 EXPECT_EQ(message, expected_sdp);
1540}
1541
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001542TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
1543 AddSctpDataChannel();
1544 JsepSessionDescription jsep_desc(kDummyString);
1545
1546 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1547 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
1548 jsep_desc.description()->GetContentDescriptionByName(kDataContentName));
1549
1550 const int kNewPort = 1234;
1551 cricket::DataCodec codec(
1552 cricket::kGoogleSctpDataCodecId, cricket::kGoogleSctpDataCodecName, 0);
1553 codec.SetParam(cricket::kCodecParamPort, kNewPort);
1554 dcdesc->AddOrReplaceCodec(codec);
1555
1556 std::string message = webrtc::SdpSerialize(jsep_desc);
1557
1558 std::string expected_sdp = kSdpString;
1559 expected_sdp.append(kSdpSctpDataChannelString);
1560
1561 char default_portstr[16];
1562 char new_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001563 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001564 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001565 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
1566 rtc::replace_substrs(default_portstr, strlen(default_portstr),
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001567 new_portstr, strlen(new_portstr),
1568 &expected_sdp);
1569
1570 EXPECT_EQ(expected_sdp, message);
1571}
1572
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001573TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
1574 AddRtpDataChannel();
1575 data_desc_->set_bandwidth(100*1000);
1576 JsepSessionDescription jsep_desc(kDummyString);
1577
1578 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1579 std::string message = webrtc::SdpSerialize(jsep_desc);
1580
1581 std::string expected_sdp = kSdpString;
1582 expected_sdp.append(kSdpRtpDataChannelString);
1583 // We want to test that serializing data content ignores bandwidth
1584 // settings (it should always be the default). Thus, we don't do
1585 // the following:
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00001586 // TODO(pthatcher): We need to temporarily allow the SDP to control
1587 // this for backwards-compatibility. Once we don't need that any
1588 // more, remove this.
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001589 InjectAfter("m=application 1 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00001590 "b=AS:100\r\n",
1591 &expected_sdp);
1592 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001593}
1594
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001595TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
1596 AddExtmap();
1597 JsepSessionDescription desc_with_extmap("dummy");
1598 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(),
1599 kSessionId, kSessionVersion));
1600 std::string message = webrtc::SdpSerialize(desc_with_extmap);
1601
1602 std::string sdp_with_extmap = kSdpString;
1603 InjectAfter("a=mid:audio_content_name\r\n",
1604 kExtmap, &sdp_with_extmap);
1605 InjectAfter("a=mid:video_content_name\r\n",
1606 kExtmap, &sdp_with_extmap);
1607
1608 EXPECT_EQ(sdp_with_extmap, message);
1609}
1610
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001611TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBufferLatency) {
1612 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1613 GetFirstVideoContent(&desc_)->description);
1614 vcd->set_buffered_mode_latency(128);
1615
1616 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1617 jdesc_.session_id(),
1618 jdesc_.session_version()));
1619 std::string message = webrtc::SdpSerialize(jdesc_);
1620 std::string sdp_with_buffer_latency = kSdpFullString;
1621 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
1622 "a=x-google-buffer-latency:128\r\n",
1623 &sdp_with_buffer_latency);
1624 EXPECT_EQ(sdp_with_buffer_latency, message);
1625}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001626
1627TEST_F(WebRtcSdpTest, SerializeCandidates) {
1628 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00001629 EXPECT_EQ(std::string(kRawCandidate), message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001630}
1631
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00001632// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
1633// RFC 6544.
1634TEST_F(WebRtcSdpTest, DISABLED_SerializeTcpCandidates) {
1635 Candidate candidate(
1636 "", ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1637 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
1638 "", "", LOCAL_PORT_TYPE,
1639 "", kCandidateGeneration, kCandidateFoundation1);
1640 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
1641 rtc::scoped_ptr<IceCandidateInterface> jcandidate(
1642 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
1643
1644 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
1645 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
1646}
1647
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001648TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
1649 JsepSessionDescription jdesc(kDummyString);
1650 // Deserialize
1651 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
1652 // Verify
1653 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1654}
1655
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001656TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
1657 JsepSessionDescription jdesc(kDummyString);
1658 const char kSdpWithoutMline[] =
1659 "v=0\r\n"
1660 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1661 "s=-\r\n"
1662 "t=0 0\r\n"
1663 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
1664 // Deserialize
1665 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
1666 EXPECT_EQ(0u, jdesc.description()->contents().size());
1667}
1668
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001669TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
1670 JsepSessionDescription jdesc(kDummyString);
1671 std::string sdp_without_carriage_return = kSdpFullString;
1672 Replace("\r\n", "\n", &sdp_without_carriage_return);
1673 // Deserialize
1674 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
1675 // Verify
1676 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1677}
1678
1679TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
1680 // SessionDescription with desc but without candidates.
1681 JsepSessionDescription jdesc_no_candidates(kDummyString);
1682 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
1683 kSessionId, kSessionVersion));
1684 JsepSessionDescription new_jdesc(kDummyString);
1685 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
1686 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
1687}
1688
1689TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
1690 static const char kSdpNoRtpmapString[] =
1691 "v=0\r\n"
1692 "o=- 11 22 IN IP4 127.0.0.1\r\n"
1693 "s=-\r\n"
1694 "t=0 0\r\n"
1695 "m=audio 49232 RTP/AVP 0 18 103\r\n"
1696 // Codec that doesn't appear in the m= line will be ignored.
1697 "a=rtpmap:104 CELT/32000/2\r\n"
1698 // The rtpmap line for static payload codec is optional.
1699 "a=rtpmap:18 G729/16000\r\n"
1700 "a=rtpmap:103 ISAC/16000\r\n";
1701
1702 JsepSessionDescription jdesc(kDummyString);
1703 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
1704 cricket::AudioContentDescription* audio =
1705 static_cast<AudioContentDescription*>(
1706 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
1707 AudioCodecs ref_codecs;
1708 // The codecs in the AudioContentDescription will be sorted by preference.
1709 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1, 3));
1710 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1, 2));
1711 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 32000, 1, 1));
1712 EXPECT_EQ(ref_codecs, audio->codecs());
1713}
1714
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001715TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
1716 static const char kSdpNoRtpmapString[] =
1717 "v=0\r\n"
1718 "o=- 11 22 IN IP4 127.0.0.1\r\n"
1719 "s=-\r\n"
1720 "t=0 0\r\n"
1721 "m=audio 49232 RTP/AVP 18 103\r\n"
1722 "a=fmtp:18 annexb=yes\r\n"
1723 "a=rtpmap:103 ISAC/16000\r\n";
1724
1725 JsepSessionDescription jdesc(kDummyString);
1726 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
1727 cricket::AudioContentDescription* audio =
1728 static_cast<AudioContentDescription*>(
1729 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
1730
1731 cricket::AudioCodec g729 = audio->codecs()[0];
1732 EXPECT_EQ("G729", g729.name);
1733 EXPECT_EQ(8000, g729.clockrate);
1734 EXPECT_EQ(18, g729.id);
1735 cricket::CodecParameterMap::iterator found =
1736 g729.params.find("annexb");
1737 ASSERT_TRUE(found != g729.params.end());
1738 EXPECT_EQ(found->second, "yes");
1739
1740 cricket::AudioCodec isac = audio->codecs()[1];
1741 EXPECT_EQ("ISAC", isac.name);
1742 EXPECT_EQ(103, isac.id);
1743 EXPECT_EQ(16000, isac.clockrate);
1744}
1745
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001746// Ensure that we can deserialize SDP with a=fingerprint properly.
1747TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
1748 // Add a DTLS a=fingerprint attribute to our session description.
1749 AddFingerprint();
1750 JsepSessionDescription new_jdesc(kDummyString);
1751 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1752 jdesc_.session_id(),
1753 jdesc_.session_version()));
1754
1755 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1756 std::string sdp_with_fingerprint = kSdpString;
1757 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1758 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
1759 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
1760 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
1761}
1762
1763TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
1764 JsepSessionDescription jdesc_with_bundle(kDummyString);
1765 std::string sdp_with_bundle = kSdpFullString;
1766 InjectAfter(kSessionTime,
1767 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1768 &sdp_with_bundle);
1769 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
1770 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1771 group.AddContentName(kAudioContentName);
1772 group.AddContentName(kVideoContentName);
1773 desc_.AddGroup(group);
1774 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1775 jdesc_.session_id(),
1776 jdesc_.session_version()));
1777 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
1778}
1779
1780TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
1781 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
1782 std::string sdp_with_bandwidth = kSdpFullString;
1783 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
1784 "b=AS:100\r\n",
1785 &sdp_with_bandwidth);
1786 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
1787 "b=AS:50\r\n",
1788 &sdp_with_bandwidth);
1789 EXPECT_TRUE(
1790 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
1791 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1792 GetFirstVideoContent(&desc_)->description);
1793 vcd->set_bandwidth(100 * 1000);
1794 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1795 GetFirstAudioContent(&desc_)->description);
1796 acd->set_bandwidth(50 * 1000);
1797 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1798 jdesc_.session_id(),
1799 jdesc_.session_version()));
1800 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
1801}
1802
1803TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
1804 JsepSessionDescription jdesc_with_ice_options(kDummyString);
1805 std::string sdp_with_ice_options = kSdpFullString;
1806 InjectAfter(kSessionTime,
1807 "a=ice-options:iceoption3\r\n",
1808 &sdp_with_ice_options);
1809 InjectAfter(kAttributeIcePwdVoice,
1810 "a=ice-options:iceoption1\r\n",
1811 &sdp_with_ice_options);
1812 InjectAfter(kAttributeIcePwdVideo,
1813 "a=ice-options:iceoption2\r\n",
1814 &sdp_with_ice_options);
1815 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
1816 std::vector<std::string> transport_options;
1817 transport_options.push_back(kIceOption3);
1818 transport_options.push_back(kIceOption1);
1819 AddIceOptions(kAudioContentName, transport_options);
1820 transport_options.clear();
1821 transport_options.push_back(kIceOption3);
1822 transport_options.push_back(kIceOption2);
1823 AddIceOptions(kVideoContentName, transport_options);
1824 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1825 jdesc_.session_id(),
1826 jdesc_.session_version()));
1827 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
1828}
1829
1830TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
1831 // Remove the original ice-ufrag and ice-pwd
1832 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyString);
1833 std::string sdp_with_ufrag_pwd = kSdpFullString;
1834 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
1835 // Add session level ufrag and pwd
1836 InjectAfter(kSessionTime,
1837 "a=ice-pwd:session+level+icepwd\r\n"
1838 "a=ice-ufrag:session+level+iceufrag\r\n",
1839 &sdp_with_ufrag_pwd);
1840 // Add media level ufrag and pwd for audio
1841 InjectAfter("a=mid:audio_content_name\r\n",
1842 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
1843 &sdp_with_ufrag_pwd);
1844 // Update the candidate ufrag and pwd to the expected ones.
1845 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0,
1846 "media+level+iceufrag", "media+level+icepwd"));
1847 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1,
1848 "session+level+iceufrag", "session+level+icepwd"));
1849 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
1850 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
1851}
1852
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001853TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBufferLatency) {
1854 JsepSessionDescription jdesc_with_buffer_latency(kDummyString);
1855 std::string sdp_with_buffer_latency = kSdpFullString;
1856 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
1857 "a=x-google-buffer-latency:128\r\n",
1858 &sdp_with_buffer_latency);
1859
1860 EXPECT_TRUE(
1861 SdpDeserialize(sdp_with_buffer_latency, &jdesc_with_buffer_latency));
1862 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1863 GetFirstVideoContent(&desc_)->description);
1864 vcd->set_buffered_mode_latency(128);
1865 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1866 jdesc_.session_id(),
1867 jdesc_.session_version()));
1868 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_buffer_latency));
1869}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001870
1871TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
1872 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_RECVONLY));
1873}
1874
1875TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
1876 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_SENDONLY));
1877}
1878
1879TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
1880 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_INACTIVE));
1881}
1882
1883TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
1884 EXPECT_TRUE(TestDeserializeRejected(true, false));
1885}
1886
1887TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
1888 EXPECT_TRUE(TestDeserializeRejected(false, true));
1889}
1890
1891TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
1892 EXPECT_TRUE(TestDeserializeRejected(true, true));
1893}
1894
1895// Tests that we can still handle the sdp uses mslabel and label instead of
1896// msid for backward compatibility.
1897TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
1898 JsepSessionDescription jdesc(kDummyString);
1899 std::string sdp_without_msid = kSdpFullString;
1900 Replace("msid", "xmsid", &sdp_without_msid);
1901 // Deserialize
1902 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
1903 // Verify
1904 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1905}
1906
1907TEST_F(WebRtcSdpTest, DeserializeCandidate) {
1908 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
1909
1910 std::string sdp = kSdpOneCandidate;
1911 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
1912 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
1913 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
1914 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
1915
1916 // Candidate line without generation extension.
1917 sdp = kSdpOneCandidate;
1918 Replace(" generation 2", "", &sdp);
1919 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
1920 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
1921 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
1922 Candidate expected = jcandidate_->candidate();
1923 expected.set_generation(0);
1924 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
1925
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00001926 sdp = kSdpTcpActiveCandidate;
1927 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
1928 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
1929 Candidate candidate(
1930 "", ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1931 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
1932 "", "", LOCAL_PORT_TYPE,
1933 "", kCandidateGeneration, kCandidateFoundation1);
1934 rtc::scoped_ptr<IceCandidateInterface> jcandidate_template(
1935 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
1936 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(
1937 jcandidate_template->candidate()));
1938 sdp = kSdpTcpPassiveCandidate;
1939 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
1940 sdp = kSdpTcpSOCandidate;
1941 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001942}
1943
1944// This test verifies the deserialization of candidate-attribute
1945// as per RFC 5245. Candiate-attribute will be of the format
1946// candidate:<blah>. This format will be used when candidates
1947// are trickled.
1948TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
1949 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
1950
1951 std::string candidate_attribute = kRawCandidate;
1952 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
1953 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
1954 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
1955 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
1956 EXPECT_EQ(2u, jcandidate.candidate().generation());
1957
1958 // Candidate line without generation extension.
1959 candidate_attribute = kRawCandidate;
1960 Replace(" generation 2", "", &candidate_attribute);
1961 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
1962 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
1963 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
1964 Candidate expected = jcandidate_->candidate();
1965 expected.set_generation(0);
1966 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
1967
1968 // Candidate line without candidate:
1969 candidate_attribute = kRawCandidate;
1970 Replace("candidate:", "", &candidate_attribute);
1971 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
1972
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00001973 // Candidate line with IPV6 address.
1974 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
1975}
1976
1977// This test verifies that the deserialization of an invalid candidate string
1978// fails.
1979TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
1980 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
1981
1982 std::string candidate_attribute = kRawCandidate;
1983 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001984 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00001985
1986 candidate_attribute = kSdpOneCandidate;
1987 candidate_attribute.replace(0, 1, "x");
1988 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
1989
1990 candidate_attribute = kRawCandidate;
1991 candidate_attribute.append("\r\n");
1992 candidate_attribute.append(kRawCandidate);
1993 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
1994
1995 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001996}
1997
1998TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
1999 AddRtpDataChannel();
2000 JsepSessionDescription jdesc(kDummyString);
2001 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2002
2003 std::string sdp_with_data = kSdpString;
2004 sdp_with_data.append(kSdpRtpDataChannelString);
2005 JsepSessionDescription jdesc_output(kDummyString);
2006
2007 // Deserialize
2008 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2009 // Verify
2010 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2011}
2012
2013TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
2014 AddSctpDataChannel();
2015 JsepSessionDescription jdesc(kDummyString);
2016 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2017
2018 std::string sdp_with_data = kSdpString;
2019 sdp_with_data.append(kSdpSctpDataChannelString);
2020 JsepSessionDescription jdesc_output(kDummyString);
2021
2022 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2023 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2024}
2025
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002026// For crbug/344475.
2027TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2028 std::string sdp_with_data = kSdpString;
2029 sdp_with_data.append(kSdpSctpDataChannelString);
2030 // Remove the "\n" at the end.
2031 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
2032 JsepSessionDescription jdesc_output(kDummyString);
2033
2034 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2035 // No crash is a pass.
2036}
2037
wu@webrtc.org78187522013-10-07 23:32:02 +00002038TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndNewPort) {
2039 AddSctpDataChannel();
2040 const uint16 kUnusualSctpPort = 9556;
2041 char default_portstr[16];
2042 char unusual_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002043 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
wu@webrtc.org78187522013-10-07 23:32:02 +00002044 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002045 rtc::sprintfn(unusual_portstr, sizeof(unusual_portstr), "%d",
wu@webrtc.org78187522013-10-07 23:32:02 +00002046 kUnusualSctpPort);
2047
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002048 // First setup the expected JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002049 JsepSessionDescription jdesc(kDummyString);
2050 // take our pre-built session description and change the SCTP port.
2051 cricket::SessionDescription* mutant = desc_.Copy();
2052 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
2053 mutant->GetContentDescriptionByName(kDataContentName));
2054 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
2055 EXPECT_EQ(codecs.size(), 1UL);
2056 EXPECT_EQ(codecs[0].id, cricket::kGoogleSctpDataCodecId);
2057 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002058 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002059
2060 // note: mutant's owned by jdesc now.
2061 ASSERT_TRUE(jdesc.Initialize(mutant, kSessionId, kSessionVersion));
2062 mutant = NULL;
2063
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002064 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002065 std::string sdp_with_data = kSdpString;
2066 sdp_with_data.append(kSdpSctpDataChannelString);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002067 rtc::replace_substrs(default_portstr, strlen(default_portstr),
wu@webrtc.org78187522013-10-07 23:32:02 +00002068 unusual_portstr, strlen(unusual_portstr),
2069 &sdp_with_data);
2070 JsepSessionDescription jdesc_output(kDummyString);
2071
2072 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2073 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2074}
2075
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002076TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
2077 AddRtpDataChannel();
2078 JsepSessionDescription jdesc(kDummyString);
2079 // We want to test that deserializing data content ignores bandwidth
2080 // settings (it should always be the default). Thus, we don't do
2081 // the following:
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002082 // TODO(pthatcher): We need to temporarily allow the SDP to control
2083 // this for backwards-compatibility. Once we don't need that any
2084 // more, remove this.
2085 DataContentDescription* dcd = static_cast<DataContentDescription*>(
2086 GetFirstDataContent(&desc_)->description);
2087 dcd->set_bandwidth(100 * 1000);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002088 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2089
2090 std::string sdp_with_bandwidth = kSdpString;
2091 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
2092 InjectAfter("a=mid:data_content_name\r\n",
2093 "b=AS:100\r\n",
2094 &sdp_with_bandwidth);
2095 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2096
2097 EXPECT_TRUE(
2098 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2099 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2100}
2101
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002102TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSessionLevelExtmap) {
2103 TestDeserializeExtmap(true, false);
2104}
2105
2106TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
2107 TestDeserializeExtmap(false, true);
2108}
2109
2110TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInvalidExtmap) {
2111 TestDeserializeExtmap(true, true);
2112}
2113
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002114TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
2115 JsepSessionDescription jdesc(kDummyString);
2116 std::string sdp = kSdpFullString;
2117 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2118 // Deserialize
2119 SdpParseError error;
2120 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
2121 const std::string lastline = "a=ssrc:6 label:video_track_id_3";
2122 EXPECT_EQ(lastline, error.line);
2123 EXPECT_EQ("Invalid SDP line.", error.description);
2124}
2125
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002126TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2127 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2128 std::string new_sdp = kSdpOneCandidate;
2129 Replace("udp", "unsupported_transport", &new_sdp);
2130 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2131 new_sdp = kSdpOneCandidate;
2132 Replace("udp", "uDP", &new_sdp);
2133 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2134 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2135 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2136 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2137}
2138
2139TEST_F(WebRtcSdpTest, DeserializeCandidateOldFormat) {
2140 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2141 EXPECT_TRUE(SdpDeserializeCandidate(kSdpOneCandidateOldFormat,&jcandidate));
2142 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2143 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2144 Candidate ref_candidate = jcandidate_->candidate();
2145 ref_candidate.set_username("user_rtp");
2146 ref_candidate.set_password("password_rtp");
2147 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2148}
2149
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002150TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
2151 JsepSessionDescription jdesc(kDummyString);
2152
2153 // Deserialize
2154 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2155
2156 // Verify
2157 cricket::AudioContentDescription* audio =
2158 static_cast<AudioContentDescription*>(
2159 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2160 EXPECT_TRUE(audio->conference_mode());
2161
2162 cricket::VideoContentDescription* video =
2163 static_cast<VideoContentDescription*>(
2164 jdesc.description()->GetContentDescriptionByName(cricket::CN_VIDEO));
2165 EXPECT_TRUE(video->conference_mode());
2166}
2167
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002168TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2169 const char kSdpDestroyer[] = "!@#$%^&";
2170 const char kSdpInvalidLine1[] = " =candidate";
2171 const char kSdpInvalidLine2[] = "a+candidate";
2172 const char kSdpInvalidLine3[] = "a= candidate";
2173 // Broken fingerprint.
2174 const char kSdpInvalidLine4[] = "a=fingerprint:sha-1 "
2175 "4AAD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB";
2176 // Extra field.
2177 const char kSdpInvalidLine5[] = "a=fingerprint:sha-1 "
2178 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB XXX";
2179 // Missing space.
2180 const char kSdpInvalidLine6[] = "a=fingerprint:sha-1"
2181 "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 +00002182 // MD5 is not allowed in fingerprints.
2183 const char kSdpInvalidLine7[] = "a=fingerprint:md5 "
2184 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002185
2186 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002187 ExpectParseFailure("v=", kSdpDestroyer);
2188 ExpectParseFailure("o=", kSdpDestroyer);
2189 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002190 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002191 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002192
2193 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002194 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2195 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002196
2197 // Invalid lines
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002198 ExpectParseFailure("a=candidate", kSdpInvalidLine1);
2199 ExpectParseFailure("a=candidate", kSdpInvalidLine2);
2200 ExpectParseFailure("a=candidate", kSdpInvalidLine3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002201
2202 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2203 // because it's orthogonal to what we are replacing and hence
2204 // safe.
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002205 ExpectParseFailure("a=sendrecv", kSdpInvalidLine4);
2206 ExpectParseFailure("a=sendrecv", kSdpInvalidLine5);
2207 ExpectParseFailure("a=sendrecv", kSdpInvalidLine6);
2208 ExpectParseFailure("a=sendrecv", kSdpInvalidLine7);
2209}
2210
2211TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2212 // ssrc
2213 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
2214 ExpectParseFailure("a=ssrc-group:FEC 5 6", "a=ssrc-group:FEC badvalue 6");
2215 // crypto
2216 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
2217 // rtpmap
2218 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
2219 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
2220 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
2221 // candidate
2222 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
2223 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
2224 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
2225 ExpectParseFailure("rport 2346", "rport badvalue");
2226 ExpectParseFailure("rport 2346 generation 2",
2227 "rport 2346 generation badvalue");
2228 // m line
2229 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
2230 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
2231
2232 // bandwidth
2233 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2234 "b=AS:badvalue\r\n",
2235 "b=AS:badvalue");
2236 // rtcp-fb
2237 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2238 "a=rtcp-fb:badvalue nack\r\n",
2239 "a=rtcp-fb:badvalue nack");
2240 // extmap
2241 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2242 "a=extmap:badvalue http://example.com\r\n",
2243 "a=extmap:badvalue http://example.com");
2244 // x-google-buffer-latency
2245 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2246 "a=x-google-buffer-latency:badvalue\r\n",
2247 "a=x-google-buffer-latency:badvalue");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002248}
2249
2250TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
2251 JsepSessionDescription jdesc_output(kDummyString);
2252
2253 const char kSdpWithReorderedPlTypesString[] =
2254 "v=0\r\n"
2255 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2256 "s=-\r\n"
2257 "t=0 0\r\n"
2258 "m=audio 1 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
2259 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
2260 // in the map.
2261 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
2262 "a=rtpmap:104 CELT/32000/2\r\n";
2263
2264 // Deserialize
2265 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
2266
2267 const ContentInfo* ac = GetFirstAudioContent(jdesc_output.description());
2268 ASSERT_TRUE(ac != NULL);
2269 const AudioContentDescription* acd =
2270 static_cast<const AudioContentDescription*>(ac->description);
2271 ASSERT_FALSE(acd->codecs().empty());
2272 EXPECT_EQ("CELT", acd->codecs()[0].name);
2273 EXPECT_EQ(104, acd->codecs()[0].id);
2274}
2275
2276TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
2277 JsepSessionDescription jdesc_output(kDummyString);
2278 CodecParams params;
2279 params.max_ptime = 40;
2280 params.ptime = 30;
2281 params.min_ptime = 10;
2282 params.sprop_stereo = 1;
2283 params.stereo = 1;
2284 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002285 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002286 TestDeserializeCodecParams(params, &jdesc_output);
2287 TestSerialize(jdesc_output);
2288}
2289
2290TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
2291 const bool kUseWildcard = false;
2292 JsepSessionDescription jdesc_output(kDummyString);
2293 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
2294 TestSerialize(jdesc_output);
2295}
2296
2297TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
2298 const bool kUseWildcard = true;
2299 JsepSessionDescription jdesc_output(kDummyString);
2300 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
2301 TestSerialize(jdesc_output);
2302}
2303
2304TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
2305 JsepSessionDescription jdesc_output(kDummyString);
2306
2307 const char kSdpWithFmtpString[] =
2308 "v=0\r\n"
2309 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2310 "s=-\r\n"
2311 "t=0 0\r\n"
2312 "m=video 3457 RTP/SAVPF 120\r\n"
2313 "a=rtpmap:120 VP8/90000\r\n"
2314 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
2315
2316 // Deserialize
2317 SdpParseError error;
2318 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output,
2319 &error));
2320
2321 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2322 ASSERT_TRUE(vc != NULL);
2323 const VideoContentDescription* vcd =
2324 static_cast<const VideoContentDescription*>(vc->description);
2325 ASSERT_FALSE(vcd->codecs().empty());
2326 cricket::VideoCodec vp8 = vcd->codecs()[0];
2327 EXPECT_EQ("VP8", vp8.name);
2328 EXPECT_EQ(120, vp8.id);
2329 cricket::CodecParameterMap::iterator found =
2330 vp8.params.find("x-google-min-bitrate");
2331 ASSERT_TRUE(found != vp8.params.end());
2332 EXPECT_EQ(found->second, "10");
2333 found = vp8.params.find("x-google-max-quantization");
2334 ASSERT_TRUE(found != vp8.params.end());
2335 EXPECT_EQ(found->second, "40");
2336}
2337
2338TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
2339 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
2340 GetFirstVideoContent(&desc_)->description);
2341
2342 cricket::VideoCodecs codecs = vcd->codecs();
2343 codecs[0].params["x-google-min-bitrate"] = "10";
2344 vcd->set_codecs(codecs);
2345
2346 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2347 jdesc_.session_id(),
2348 jdesc_.session_version()));
2349 std::string message = webrtc::SdpSerialize(jdesc_);
2350 std::string sdp_with_fmtp = kSdpFullString;
2351 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
2352 "a=fmtp:120 x-google-min-bitrate=10\r\n",
2353 &sdp_with_fmtp);
2354 EXPECT_EQ(sdp_with_fmtp, message);
2355}
2356
2357TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) {
2358 JsepSessionDescription jdesc_with_icelite(kDummyString);
2359 std::string sdp_with_icelite = kSdpFullString;
2360 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
2361 cricket::SessionDescription* desc = jdesc_with_icelite.description();
2362 const cricket::TransportInfo* tinfo1 =
2363 desc->GetTransportInfoByName("audio_content_name");
2364 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
2365 const cricket::TransportInfo* tinfo2 =
2366 desc->GetTransportInfoByName("video_content_name");
2367 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
2368 InjectAfter(kSessionTime,
2369 "a=ice-lite\r\n",
2370 &sdp_with_icelite);
2371 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
2372 desc = jdesc_with_icelite.description();
2373 const cricket::TransportInfo* atinfo =
2374 desc->GetTransportInfoByName("audio_content_name");
2375 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
2376 const cricket::TransportInfo* vtinfo =
2377 desc->GetTransportInfoByName("video_content_name");
2378 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
2379}
2380
2381// Verifies that the candidates in the input SDP are parsed and serialized
2382// correctly in the output SDP.
2383TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
2384 std::string sdp_with_data = kSdpString;
2385 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
2386 JsepSessionDescription jdesc_output(kDummyString);
2387
2388 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2389 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
2390}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00002391
2392TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
2393 AddFingerprint();
2394 TransportInfo audio_transport_info =
2395 *(desc_.GetTransportInfoByName(kAudioContentName));
2396 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
2397 audio_transport_info.description.connection_role);
2398 audio_transport_info.description.connection_role =
2399 cricket::CONNECTIONROLE_ACTIVE;
2400
2401 TransportInfo video_transport_info =
2402 *(desc_.GetTransportInfoByName(kVideoContentName));
2403 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
2404 video_transport_info.description.connection_role);
2405 video_transport_info.description.connection_role =
2406 cricket::CONNECTIONROLE_ACTIVE;
2407
2408 desc_.RemoveTransportInfoByName(kAudioContentName);
2409 desc_.RemoveTransportInfoByName(kVideoContentName);
2410
2411 desc_.AddTransportInfo(audio_transport_info);
2412 desc_.AddTransportInfo(video_transport_info);
2413
2414 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2415 jdesc_.session_id(),
2416 jdesc_.session_version()));
2417 std::string message = webrtc::SdpSerialize(jdesc_);
2418 std::string sdp_with_dtlssetup = kSdpFullString;
2419
2420 // Fingerprint attribute is necessary to add DTLS setup attribute.
2421 InjectAfter(kAttributeIcePwdVoice,
2422 kFingerprint, &sdp_with_dtlssetup);
2423 InjectAfter(kAttributeIcePwdVideo,
2424 kFingerprint, &sdp_with_dtlssetup);
2425 // Now adding |setup| attribute.
2426 InjectAfter(kFingerprint,
2427 "a=setup:active\r\n", &sdp_with_dtlssetup);
2428 EXPECT_EQ(sdp_with_dtlssetup, message);
2429}
2430
2431TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
2432 JsepSessionDescription jdesc_with_dtlssetup(kDummyString);
2433 std::string sdp_with_dtlssetup = kSdpFullString;
2434 InjectAfter(kSessionTime,
2435 "a=setup:actpass\r\n",
2436 &sdp_with_dtlssetup);
2437 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
2438 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
2439 const cricket::TransportInfo* atinfo =
2440 desc->GetTransportInfoByName("audio_content_name");
2441 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
2442 atinfo->description.connection_role);
2443 const cricket::TransportInfo* vtinfo =
2444 desc->GetTransportInfoByName("video_content_name");
2445 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
2446 vtinfo->description.connection_role);
2447}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00002448
2449// Verifies that the order of the serialized m-lines follows the order of the
2450// ContentInfo in SessionDescription, and vise versa for deserialization.
2451TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
2452 JsepSessionDescription jdesc(kDummyString);
2453 const std::string media_content_sdps[3] = {
2454 kSdpAudioString,
2455 kSdpVideoString,
2456 kSdpSctpDataChannelString
2457 };
2458 const cricket::MediaType media_types[3] = {
2459 cricket::MEDIA_TYPE_AUDIO,
2460 cricket::MEDIA_TYPE_VIDEO,
2461 cricket::MEDIA_TYPE_DATA
2462 };
2463
2464 // Verifies all 6 permutations.
2465 for (size_t i = 0; i < 6; ++i) {
2466 size_t media_content_in_sdp[3];
2467 // The index of the first media content.
2468 media_content_in_sdp[0] = i / 2;
2469 // The index of the second media content.
2470 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
2471 // The index of the third media content.
2472 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
2473
2474 std::string sdp_string = kSdpSessionString;
2475 for (size_t i = 0; i < 3; ++i)
2476 sdp_string += media_content_sdps[media_content_in_sdp[i]];
2477
2478 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
2479 cricket::SessionDescription* desc = jdesc.description();
2480 EXPECT_EQ(3u, desc->contents().size());
2481
2482 for (size_t i = 0; i < 3; ++i) {
2483 const cricket::MediaContentDescription* mdesc =
2484 static_cast<const cricket::MediaContentDescription*>(
2485 desc->contents()[i].description);
2486 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
2487 }
2488
2489 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
2490 EXPECT_EQ(sdp_string, serialized_sdp);
2491 }
2492}