Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(319)

Side by Side Diff: webrtc/api/webrtcsdp_unittest.cc

Issue 2514883002: Create //webrtc/api:libjingle_peerconnection_api + refactorings. (Closed)
Patch Set: Rebase Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/api/webrtcsdp.cc ('k') | webrtc/api/webrtcsession.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2011 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include <memory>
12 #include <set>
13 #include <string>
14 #include <vector>
15
16 #include "webrtc/api/jsepsessiondescription.h"
17 #ifdef WEBRTC_ANDROID
18 #include "webrtc/api/test/androidtestinitializer.h"
19 #endif
20 #include "webrtc/api/webrtcsdp.h"
21 #include "webrtc/base/checks.h"
22 #include "webrtc/base/gunit.h"
23 #include "webrtc/base/logging.h"
24 #include "webrtc/base/messagedigest.h"
25 #include "webrtc/base/sslfingerprint.h"
26 #include "webrtc/base/stringencode.h"
27 #include "webrtc/base/stringutils.h"
28 #include "webrtc/media/base/mediaconstants.h"
29 #include "webrtc/media/engine/webrtcvideoengine2.h"
30 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h"
31 #include "webrtc/p2p/base/p2pconstants.h"
32 #include "webrtc/pc/mediasession.h"
33
34 using cricket::AudioCodec;
35 using cricket::AudioContentDescription;
36 using cricket::Candidate;
37 using cricket::ContentInfo;
38 using cricket::CryptoParams;
39 using cricket::ContentGroup;
40 using cricket::DataCodec;
41 using cricket::DataContentDescription;
42 using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
43 using cricket::ICE_CANDIDATE_COMPONENT_RTP;
44 using cricket::kFecSsrcGroupSemantics;
45 using cricket::LOCAL_PORT_TYPE;
46 using cricket::NS_JINGLE_DRAFT_SCTP;
47 using cricket::NS_JINGLE_RTP;
48 using cricket::RELAY_PORT_TYPE;
49 using cricket::SessionDescription;
50 using cricket::StreamParams;
51 using cricket::STUN_PORT_TYPE;
52 using cricket::TransportDescription;
53 using cricket::TransportInfo;
54 using cricket::VideoCodec;
55 using cricket::VideoContentDescription;
56 using webrtc::IceCandidateCollection;
57 using webrtc::IceCandidateInterface;
58 using webrtc::JsepIceCandidate;
59 using webrtc::JsepSessionDescription;
60 using webrtc::RtpExtension;
61 using webrtc::SdpParseError;
62 using webrtc::SessionDescriptionInterface;
63
64 typedef std::vector<AudioCodec> AudioCodecs;
65 typedef std::vector<Candidate> Candidates;
66
67 static const uint32_t kDefaultSctpPort = 5000;
68 static const char kSessionTime[] = "t=0 0\r\n";
69 static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
70 static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
71 static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
72 static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
73 static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
74 static const uint32_t kCandidateGeneration = 2;
75 static const char kCandidateFoundation1[] = "a0+B/1";
76 static const char kCandidateFoundation2[] = "a0+B/2";
77 static const char kCandidateFoundation3[] = "a0+B/3";
78 static const char kCandidateFoundation4[] = "a0+B/4";
79 static const char kAttributeCryptoVoice[] =
80 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
81 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
82 "dummy_session_params\r\n";
83 static const char kAttributeCryptoVideo[] =
84 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
85 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
86 static const char kFingerprint[] = "a=fingerprint:sha-1 "
87 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n";
88 static const int kExtmapId = 1;
89 static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
90 static const char kExtmap[] =
91 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
92 static const char kExtmapWithDirectionAndAttribute[] =
93 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
94
95 static const uint8_t kIdentityDigest[] = {
96 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
97 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
98
99 static const char kDtlsSctp[] = "DTLS/SCTP";
100 static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
101 static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
102
103 struct CodecParams {
104 int max_ptime;
105 int ptime;
106 int min_ptime;
107 int sprop_stereo;
108 int stereo;
109 int useinband;
110 int maxaveragebitrate;
111 };
112
113 // TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
114 // instead of "a=crypto", and have an explicit test for adding "a=crypto".
115 // Currently it's the other way around.
116
117 // Reference sdp string
118 static const char kSdpFullString[] =
119 "v=0\r\n"
120 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
121 "s=-\r\n"
122 "t=0 0\r\n"
123 "a=msid-semantic: WMS local_stream_1\r\n"
124 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
125 "c=IN IP4 74.125.127.126\r\n"
126 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
127 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
128 "generation 2\r\n"
129 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
130 "generation 2\r\n"
131 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
132 "generation 2\r\n"
133 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
134 "generation 2\r\n"
135 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
136 "raddr 192.168.1.5 rport 2346 "
137 "generation 2\r\n"
138 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
139 "raddr 192.168.1.5 rport 2348 "
140 "generation 2\r\n"
141 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
142 "a=mid:audio_content_name\r\n"
143 "a=sendrecv\r\n"
144 "a=rtcp-mux\r\n"
145 "a=rtcp-rsize\r\n"
146 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
147 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
148 "dummy_session_params\r\n"
149 "a=rtpmap:111 opus/48000/2\r\n"
150 "a=rtpmap:103 ISAC/16000\r\n"
151 "a=rtpmap:104 ISAC/32000\r\n"
152 "a=ssrc:1 cname:stream_1_cname\r\n"
153 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
154 "a=ssrc:1 mslabel:local_stream_1\r\n"
155 "a=ssrc:1 label:audio_track_id_1\r\n"
156 "m=video 3457 RTP/SAVPF 120\r\n"
157 "c=IN IP4 74.125.224.39\r\n"
158 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
159 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
160 "generation 2\r\n"
161 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
162 "generation 2\r\n"
163 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
164 "generation 2\r\n"
165 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
166 "generation 2\r\n"
167 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
168 "generation 2\r\n"
169 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
170 "generation 2\r\n"
171 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
172 "a=mid:video_content_name\r\n"
173 "a=sendrecv\r\n"
174 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
175 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
176 "a=rtpmap:120 VP8/90000\r\n"
177 "a=ssrc-group:FEC 2 3\r\n"
178 "a=ssrc:2 cname:stream_1_cname\r\n"
179 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
180 "a=ssrc:2 mslabel:local_stream_1\r\n"
181 "a=ssrc:2 label:video_track_id_1\r\n"
182 "a=ssrc:3 cname:stream_1_cname\r\n"
183 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
184 "a=ssrc:3 mslabel:local_stream_1\r\n"
185 "a=ssrc:3 label:video_track_id_1\r\n";
186
187 // SDP reference string without the candidates.
188 static const char kSdpString[] =
189 "v=0\r\n"
190 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
191 "s=-\r\n"
192 "t=0 0\r\n"
193 "a=msid-semantic: WMS local_stream_1\r\n"
194 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
195 "c=IN IP4 0.0.0.0\r\n"
196 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
197 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
198 "a=mid:audio_content_name\r\n"
199 "a=sendrecv\r\n"
200 "a=rtcp-mux\r\n"
201 "a=rtcp-rsize\r\n"
202 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
203 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
204 "dummy_session_params\r\n"
205 "a=rtpmap:111 opus/48000/2\r\n"
206 "a=rtpmap:103 ISAC/16000\r\n"
207 "a=rtpmap:104 ISAC/32000\r\n"
208 "a=ssrc:1 cname:stream_1_cname\r\n"
209 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
210 "a=ssrc:1 mslabel:local_stream_1\r\n"
211 "a=ssrc:1 label:audio_track_id_1\r\n"
212 "m=video 9 RTP/SAVPF 120\r\n"
213 "c=IN IP4 0.0.0.0\r\n"
214 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
215 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
216 "a=mid:video_content_name\r\n"
217 "a=sendrecv\r\n"
218 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
219 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
220 "a=rtpmap:120 VP8/90000\r\n"
221 "a=ssrc-group:FEC 2 3\r\n"
222 "a=ssrc:2 cname:stream_1_cname\r\n"
223 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
224 "a=ssrc:2 mslabel:local_stream_1\r\n"
225 "a=ssrc:2 label:video_track_id_1\r\n"
226 "a=ssrc:3 cname:stream_1_cname\r\n"
227 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
228 "a=ssrc:3 mslabel:local_stream_1\r\n"
229 "a=ssrc:3 label:video_track_id_1\r\n";
230
231 static const char kSdpRtpDataChannelString[] =
232 "m=application 9 RTP/SAVPF 101\r\n"
233 "c=IN IP4 0.0.0.0\r\n"
234 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
235 "a=ice-ufrag:ufrag_data\r\n"
236 "a=ice-pwd:pwd_data\r\n"
237 "a=mid:data_content_name\r\n"
238 "a=sendrecv\r\n"
239 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
240 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
241 "a=rtpmap:101 google-data/90000\r\n"
242 "a=ssrc:10 cname:data_channel_cname\r\n"
243 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
244 "a=ssrc:10 mslabel:data_channel\r\n"
245 "a=ssrc:10 label:data_channeld0\r\n";
246
247 static const char kSdpSctpDataChannelString[] =
248 "m=application 9 DTLS/SCTP 5000\r\n"
249 "c=IN IP4 0.0.0.0\r\n"
250 "a=ice-ufrag:ufrag_data\r\n"
251 "a=ice-pwd:pwd_data\r\n"
252 "a=mid:data_content_name\r\n"
253 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
254
255 // draft-ietf-mmusic-sctp-sdp-12
256 static const char kSdpSctpDataChannelStringWithSctpPort[] =
257 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
258 "a=max-message-size=100000\r\n"
259 "a=sctp-port 5000\r\n"
260 "c=IN IP4 0.0.0.0\r\n"
261 "a=ice-ufrag:ufrag_data\r\n"
262 "a=ice-pwd:pwd_data\r\n"
263 "a=mid:data_content_name\r\n";
264
265 static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
266 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
267 "a=max-message-size=100000\r\n"
268 "a=sctp-port:5000\r\n"
269 "c=IN IP4 0.0.0.0\r\n"
270 "a=ice-ufrag:ufrag_data\r\n"
271 "a=ice-pwd:pwd_data\r\n"
272 "a=mid:data_content_name\r\n";
273
274 static const char kSdpSctpDataChannelWithCandidatesString[] =
275 "m=application 2345 DTLS/SCTP 5000\r\n"
276 "c=IN IP4 74.125.127.126\r\n"
277 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
278 "generation 2\r\n"
279 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
280 "generation 2\r\n"
281 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
282 "raddr 192.168.1.5 rport 2346 "
283 "generation 2\r\n"
284 "a=ice-ufrag:ufrag_data\r\n"
285 "a=ice-pwd:pwd_data\r\n"
286 "a=mid:data_content_name\r\n"
287 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
288
289 static const char kSdpConferenceString[] =
290 "v=0\r\n"
291 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
292 "s=-\r\n"
293 "t=0 0\r\n"
294 "a=msid-semantic: WMS\r\n"
295 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
296 "c=IN IP4 0.0.0.0\r\n"
297 "a=x-google-flag:conference\r\n"
298 "m=video 9 RTP/SAVPF 120\r\n"
299 "c=IN IP4 0.0.0.0\r\n"
300 "a=x-google-flag:conference\r\n";
301
302 static const char kSdpSessionString[] =
303 "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 local_stream\r\n";
308
309 static const char kSdpAudioString[] =
310 "m=audio 9 RTP/SAVPF 111\r\n"
311 "c=IN IP4 0.0.0.0\r\n"
312 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
313 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
314 "a=mid:audio_content_name\r\n"
315 "a=sendrecv\r\n"
316 "a=rtpmap:111 opus/48000/2\r\n"
317 "a=ssrc:1 cname:stream_1_cname\r\n"
318 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
319 "a=ssrc:1 mslabel:local_stream\r\n"
320 "a=ssrc:1 label:audio_track_id_1\r\n";
321
322 static const char kSdpVideoString[] =
323 "m=video 9 RTP/SAVPF 120\r\n"
324 "c=IN IP4 0.0.0.0\r\n"
325 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
326 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
327 "a=mid:video_content_name\r\n"
328 "a=sendrecv\r\n"
329 "a=rtpmap:120 VP8/90000\r\n"
330 "a=ssrc:2 cname:stream_1_cname\r\n"
331 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
332 "a=ssrc:2 mslabel:local_stream\r\n"
333 "a=ssrc:2 label:video_track_id_1\r\n";
334
335 // Reference sdp string using bundle-only.
336 static const char kBundleOnlySdpFullString[] =
337 "v=0\r\n"
338 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
339 "s=-\r\n"
340 "t=0 0\r\n"
341 "a=group:BUNDLE audio_content_name video_content_name\r\n"
342 "a=msid-semantic: WMS local_stream_1\r\n"
343 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
344 "c=IN IP4 74.125.127.126\r\n"
345 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
346 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
347 "generation 2\r\n"
348 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
349 "generation 2\r\n"
350 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
351 "generation 2\r\n"
352 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
353 "generation 2\r\n"
354 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
355 "raddr 192.168.1.5 rport 2346 "
356 "generation 2\r\n"
357 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
358 "raddr 192.168.1.5 rport 2348 "
359 "generation 2\r\n"
360 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
361 "a=mid:audio_content_name\r\n"
362 "a=sendrecv\r\n"
363 "a=rtcp-mux\r\n"
364 "a=rtcp-rsize\r\n"
365 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
366 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
367 "dummy_session_params\r\n"
368 "a=rtpmap:111 opus/48000/2\r\n"
369 "a=rtpmap:103 ISAC/16000\r\n"
370 "a=rtpmap:104 ISAC/32000\r\n"
371 "a=ssrc:1 cname:stream_1_cname\r\n"
372 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
373 "a=ssrc:1 mslabel:local_stream_1\r\n"
374 "a=ssrc:1 label:audio_track_id_1\r\n"
375 "m=video 0 RTP/SAVPF 120\r\n"
376 "c=IN IP4 0.0.0.0\r\n"
377 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
378 "a=bundle-only\r\n"
379 "a=mid:video_content_name\r\n"
380 "a=sendrecv\r\n"
381 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
382 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
383 "a=rtpmap:120 VP8/90000\r\n"
384 "a=ssrc-group:FEC 2 3\r\n"
385 "a=ssrc:2 cname:stream_1_cname\r\n"
386 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
387 "a=ssrc:2 mslabel:local_stream_1\r\n"
388 "a=ssrc:2 label:video_track_id_1\r\n"
389 "a=ssrc:3 cname:stream_1_cname\r\n"
390 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
391 "a=ssrc:3 mslabel:local_stream_1\r\n"
392 "a=ssrc:3 label:video_track_id_1\r\n";
393
394 // Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
395 // tracks.
396 static const char kPlanBSdpFullString[] =
397 "v=0\r\n"
398 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
399 "s=-\r\n"
400 "t=0 0\r\n"
401 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
402 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
403 "c=IN IP4 74.125.127.126\r\n"
404 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
405 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
406 "generation 2\r\n"
407 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
408 "generation 2\r\n"
409 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
410 "generation 2\r\n"
411 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
412 "generation 2\r\n"
413 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
414 "raddr 192.168.1.5 rport 2346 "
415 "generation 2\r\n"
416 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
417 "raddr 192.168.1.5 rport 2348 "
418 "generation 2\r\n"
419 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
420 "a=mid:audio_content_name\r\n"
421 "a=sendrecv\r\n"
422 "a=rtcp-mux\r\n"
423 "a=rtcp-rsize\r\n"
424 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
425 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
426 "dummy_session_params\r\n"
427 "a=rtpmap:111 opus/48000/2\r\n"
428 "a=rtpmap:103 ISAC/16000\r\n"
429 "a=rtpmap:104 ISAC/32000\r\n"
430 "a=ssrc:1 cname:stream_1_cname\r\n"
431 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
432 "a=ssrc:1 mslabel:local_stream_1\r\n"
433 "a=ssrc:1 label:audio_track_id_1\r\n"
434 "a=ssrc:4 cname:stream_2_cname\r\n"
435 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
436 "a=ssrc:4 mslabel:local_stream_2\r\n"
437 "a=ssrc:4 label:audio_track_id_2\r\n"
438 "m=video 3457 RTP/SAVPF 120\r\n"
439 "c=IN IP4 74.125.224.39\r\n"
440 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
441 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
442 "generation 2\r\n"
443 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
444 "generation 2\r\n"
445 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
446 "generation 2\r\n"
447 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
448 "generation 2\r\n"
449 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
450 "generation 2\r\n"
451 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
452 "generation 2\r\n"
453 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
454 "a=mid:video_content_name\r\n"
455 "a=sendrecv\r\n"
456 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
457 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
458 "a=rtpmap:120 VP8/90000\r\n"
459 "a=ssrc-group:FEC 2 3\r\n"
460 "a=ssrc:2 cname:stream_1_cname\r\n"
461 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
462 "a=ssrc:2 mslabel:local_stream_1\r\n"
463 "a=ssrc:2 label:video_track_id_1\r\n"
464 "a=ssrc:3 cname:stream_1_cname\r\n"
465 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
466 "a=ssrc:3 mslabel:local_stream_1\r\n"
467 "a=ssrc:3 label:video_track_id_1\r\n"
468 "a=ssrc:5 cname:stream_2_cname\r\n"
469 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
470 "a=ssrc:5 mslabel:local_stream_2\r\n"
471 "a=ssrc:5 label:video_track_id_2\r\n"
472 "a=ssrc:6 cname:stream_2_cname\r\n"
473 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
474 "a=ssrc:6 mslabel:local_stream_2\r\n"
475 "a=ssrc:6 label:video_track_id_3\r\n";
476
477 // Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
478 // tracks, but with the unified plan "a=msid" attribute.
479 static const char kPlanBSdpFullStringWithMsid[] =
480 "v=0\r\n"
481 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
482 "s=-\r\n"
483 "t=0 0\r\n"
484 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
485 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
486 "c=IN IP4 74.125.127.126\r\n"
487 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
488 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
489 "generation 2\r\n"
490 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
491 "generation 2\r\n"
492 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
493 "generation 2\r\n"
494 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
495 "generation 2\r\n"
496 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
497 "raddr 192.168.1.5 rport 2346 "
498 "generation 2\r\n"
499 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
500 "raddr 192.168.1.5 rport 2348 "
501 "generation 2\r\n"
502 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
503 "a=mid:audio_content_name\r\n"
504 "a=msid:local_stream_1 audio_track_id_1\r\n"
505 "a=sendrecv\r\n"
506 "a=rtcp-mux\r\n"
507 "a=rtcp-rsize\r\n"
508 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
509 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
510 "dummy_session_params\r\n"
511 "a=rtpmap:111 opus/48000/2\r\n"
512 "a=rtpmap:103 ISAC/16000\r\n"
513 "a=rtpmap:104 ISAC/32000\r\n"
514 "a=ssrc:1 cname:stream_1_cname\r\n"
515 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
516 "a=ssrc:1 mslabel:local_stream_1\r\n"
517 "a=ssrc:1 label:audio_track_id_1\r\n"
518 "a=ssrc:4 cname:stream_2_cname\r\n"
519 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
520 "a=ssrc:4 mslabel:local_stream_2\r\n"
521 "a=ssrc:4 label:audio_track_id_2\r\n"
522 "m=video 3457 RTP/SAVPF 120\r\n"
523 "c=IN IP4 74.125.224.39\r\n"
524 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
525 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
526 "generation 2\r\n"
527 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
528 "generation 2\r\n"
529 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
530 "generation 2\r\n"
531 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
532 "generation 2\r\n"
533 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
534 "generation 2\r\n"
535 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
536 "generation 2\r\n"
537 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
538 "a=mid:video_content_name\r\n"
539 "a=msid:local_stream_1 video_track_id_1\r\n"
540 "a=sendrecv\r\n"
541 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
542 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
543 "a=rtpmap:120 VP8/90000\r\n"
544 "a=ssrc-group:FEC 2 3\r\n"
545 "a=ssrc:2 cname:stream_1_cname\r\n"
546 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
547 "a=ssrc:2 mslabel:local_stream_1\r\n"
548 "a=ssrc:2 label:video_track_id_1\r\n"
549 "a=ssrc:3 cname:stream_1_cname\r\n"
550 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
551 "a=ssrc:3 mslabel:local_stream_1\r\n"
552 "a=ssrc:3 label:video_track_id_1\r\n"
553 "a=ssrc:5 cname:stream_2_cname\r\n"
554 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
555 "a=ssrc:5 mslabel:local_stream_2\r\n"
556 "a=ssrc:5 label:video_track_id_2\r\n"
557 "a=ssrc:6 cname:stream_2_cname\r\n"
558 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
559 "a=ssrc:6 mslabel:local_stream_2\r\n"
560 "a=ssrc:6 label:video_track_id_3\r\n";
561
562 // Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
563 // tracks.
564 static const char kUnifiedPlanSdpFullString[] =
565 "v=0\r\n"
566 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
567 "s=-\r\n"
568 "t=0 0\r\n"
569 "a=msid-semantic: WMS local_stream_1\r\n"
570 // Audio track 1, stream 1 (with candidates).
571 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
572 "c=IN IP4 74.125.127.126\r\n"
573 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
574 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
575 "generation 2\r\n"
576 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
577 "generation 2\r\n"
578 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
579 "generation 2\r\n"
580 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
581 "generation 2\r\n"
582 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
583 "raddr 192.168.1.5 rport 2346 "
584 "generation 2\r\n"
585 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
586 "raddr 192.168.1.5 rport 2348 "
587 "generation 2\r\n"
588 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
589 "a=mid:audio_content_name\r\n"
590 "a=msid:local_stream_1 audio_track_id_1\r\n"
591 "a=sendrecv\r\n"
592 "a=rtcp-mux\r\n"
593 "a=rtcp-rsize\r\n"
594 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
595 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
596 "dummy_session_params\r\n"
597 "a=rtpmap:111 opus/48000/2\r\n"
598 "a=rtpmap:103 ISAC/16000\r\n"
599 "a=rtpmap:104 ISAC/32000\r\n"
600 "a=ssrc:1 cname:stream_1_cname\r\n"
601 // Video track 1, stream 1 (with candidates).
602 "m=video 3457 RTP/SAVPF 120\r\n"
603 "c=IN IP4 74.125.224.39\r\n"
604 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
605 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
606 "generation 2\r\n"
607 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
608 "generation 2\r\n"
609 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
610 "generation 2\r\n"
611 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
612 "generation 2\r\n"
613 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
614 "generation 2\r\n"
615 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
616 "generation 2\r\n"
617 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
618 "a=mid:video_content_name\r\n"
619 "a=msid:local_stream_1 video_track_id_1\r\n"
620 "a=sendrecv\r\n"
621 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
622 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
623 "a=rtpmap:120 VP8/90000\r\n"
624 "a=ssrc-group:FEC 2 3\r\n"
625 "a=ssrc:2 cname:stream_1_cname\r\n"
626 "a=ssrc:3 cname:stream_1_cname\r\n"
627 // Audio track 2, stream 2.
628 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
629 "c=IN IP4 0.0.0.0\r\n"
630 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
631 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
632 "a=mid:audio_content_name_2\r\n"
633 "a=msid:local_stream_2 audio_track_id_2\r\n"
634 "a=sendrecv\r\n"
635 "a=rtcp-mux\r\n"
636 "a=rtcp-rsize\r\n"
637 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
638 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
639 "dummy_session_params\r\n"
640 "a=rtpmap:111 opus/48000/2\r\n"
641 "a=rtpmap:103 ISAC/16000\r\n"
642 "a=rtpmap:104 ISAC/32000\r\n"
643 "a=ssrc:4 cname:stream_2_cname\r\n"
644 // Video track 2, stream 2.
645 "m=video 9 RTP/SAVPF 120\r\n"
646 "c=IN IP4 0.0.0.0\r\n"
647 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
648 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
649 "a=mid:video_content_name_2\r\n"
650 "a=msid:local_stream_2 video_track_id_2\r\n"
651 "a=sendrecv\r\n"
652 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
653 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
654 "a=rtpmap:120 VP8/90000\r\n"
655 "a=ssrc:5 cname:stream_2_cname\r\n"
656 // Video track 3, stream 2.
657 "m=video 9 RTP/SAVPF 120\r\n"
658 "c=IN IP4 0.0.0.0\r\n"
659 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
660 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
661 "a=mid:video_content_name_3\r\n"
662 "a=msid:local_stream_2 video_track_id_3\r\n"
663 "a=sendrecv\r\n"
664 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
665 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
666 "a=rtpmap:120 VP8/90000\r\n"
667 "a=ssrc:6 cname:stream_2_cname\r\n";
668
669 // One candidate reference string as per W3c spec.
670 // candidate:<blah> not a=candidate:<blah>CRLF
671 static const char kRawCandidate[] =
672 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
673 // One candidate reference string.
674 static const char kSdpOneCandidate[] =
675 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
676 "generation 2\r\n";
677
678 static const char kSdpTcpActiveCandidate[] =
679 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
680 "tcptype active generation 2";
681 static const char kSdpTcpPassiveCandidate[] =
682 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
683 "tcptype passive generation 2";
684 static const char kSdpTcpSOCandidate[] =
685 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
686 "tcptype so generation 2";
687 static const char kSdpTcpInvalidCandidate[] =
688 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
689 "tcptype invalid generation 2";
690
691 // One candidate reference string with IPV6 address.
692 static const char kRawIPV6Candidate[] =
693 "candidate:a0+B/1 1 udp 2130706432 "
694 "abcd::abcd::abcd::abcd::abcd::abcd::abcd::abcd 1234 typ host generation 2";
695
696 // One candidate reference string.
697 static const char kSdpOneCandidateWithUfragPwd[] =
698 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
699 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
700
701 // Session id and version
702 static const char kSessionId[] = "18446744069414584320";
703 static const char kSessionVersion[] = "18446462598732840960";
704
705 // ICE options.
706 static const char kIceOption1[] = "iceoption1";
707 static const char kIceOption2[] = "iceoption2";
708 static const char kIceOption3[] = "iceoption3";
709
710 // ICE ufrags/passwords.
711 static const char kUfragVoice[] = "ufrag_voice";
712 static const char kPwdVoice[] = "pwd_voice";
713 static const char kUfragVideo[] = "ufrag_video";
714 static const char kPwdVideo[] = "pwd_video";
715 static const char kUfragData[] = "ufrag_data";
716 static const char kPwdData[] = "pwd_data";
717
718 // Extra ufrags/passwords for extra unified plan m= sections.
719 static const char kUfragVoice2[] = "ufrag_voice_2";
720 static const char kPwdVoice2[] = "pwd_voice_2";
721 static const char kUfragVideo2[] = "ufrag_video_2";
722 static const char kPwdVideo2[] = "pwd_video_2";
723 static const char kUfragVideo3[] = "ufrag_video_3";
724 static const char kPwdVideo3[] = "pwd_video_3";
725
726 // Content name
727 static const char kAudioContentName[] = "audio_content_name";
728 static const char kVideoContentName[] = "video_content_name";
729 static const char kDataContentName[] = "data_content_name";
730
731 // Extra content names for extra unified plan m= sections.
732 static const char kAudioContentName2[] = "audio_content_name_2";
733 static const char kVideoContentName2[] = "video_content_name_2";
734 static const char kVideoContentName3[] = "video_content_name_3";
735
736 // MediaStream 1
737 static const char kStreamLabel1[] = "local_stream_1";
738 static const char kStream1Cname[] = "stream_1_cname";
739 static const char kAudioTrackId1[] = "audio_track_id_1";
740 static const uint32_t kAudioTrack1Ssrc = 1;
741 static const char kVideoTrackId1[] = "video_track_id_1";
742 static const uint32_t kVideoTrack1Ssrc1 = 2;
743 static const uint32_t kVideoTrack1Ssrc2 = 3;
744
745 // MediaStream 2
746 static const char kStreamLabel2[] = "local_stream_2";
747 static const char kStream2Cname[] = "stream_2_cname";
748 static const char kAudioTrackId2[] = "audio_track_id_2";
749 static const uint32_t kAudioTrack2Ssrc = 4;
750 static const char kVideoTrackId2[] = "video_track_id_2";
751 static const uint32_t kVideoTrack2Ssrc = 5;
752 static const char kVideoTrackId3[] = "video_track_id_3";
753 static const uint32_t kVideoTrack3Ssrc = 6;
754
755 // DataChannel
756 static const char kDataChannelLabel[] = "data_channel";
757 static const char kDataChannelMsid[] = "data_channeld0";
758 static const char kDataChannelCname[] = "data_channel_cname";
759 static const uint32_t kDataChannelSsrc = 10;
760
761 // Candidate
762 static const char kDummyMid[] = "dummy_mid";
763 static const int kDummyIndex = 123;
764
765 // Misc
766 static const char kDummyString[] = "dummy";
767
768 // Helper functions
769
770 static bool SdpDeserialize(const std::string& message,
771 JsepSessionDescription* jdesc) {
772 return webrtc::SdpDeserialize(message, jdesc, NULL);
773 }
774
775 static bool SdpDeserializeCandidate(const std::string& message,
776 JsepIceCandidate* candidate) {
777 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
778 }
779
780 // Add some extra |newlines| to the |message| after |line|.
781 static void InjectAfter(const std::string& line,
782 const std::string& newlines,
783 std::string* message) {
784 const std::string tmp = line + newlines;
785 rtc::replace_substrs(line.c_str(), line.length(),
786 tmp.c_str(), tmp.length(), message);
787 }
788
789 static void Replace(const std::string& line,
790 const std::string& newlines,
791 std::string* message) {
792 rtc::replace_substrs(line.c_str(), line.length(),
793 newlines.c_str(), newlines.length(), message);
794 }
795
796 // Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
797 // message.
798 static void ExpectParseFailure(const std::string& bad_sdp,
799 const std::string& bad_part) {
800 JsepSessionDescription desc(kDummyString);
801 SdpParseError error;
802 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
803 EXPECT_FALSE(ret);
804 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
805 }
806
807 // Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
808 static void ExpectParseFailure(const char* good_part, const char* bad_part) {
809 std::string bad_sdp = kSdpFullString;
810 Replace(good_part, bad_part, &bad_sdp);
811 ExpectParseFailure(bad_sdp, bad_part);
812 }
813
814 // Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
815 static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
816 const std::string& newlines,
817 const std::string& bad_part) {
818 std::string bad_sdp = kSdpFullString;
819 InjectAfter(injectpoint, newlines, &bad_sdp);
820 ExpectParseFailure(bad_sdp, bad_part);
821 }
822
823 static void ReplaceDirection(cricket::MediaContentDirection direction,
824 std::string* message) {
825 std::string new_direction;
826 switch (direction) {
827 case cricket::MD_INACTIVE:
828 new_direction = "a=inactive";
829 break;
830 case cricket::MD_SENDONLY:
831 new_direction = "a=sendonly";
832 break;
833 case cricket::MD_RECVONLY:
834 new_direction = "a=recvonly";
835 break;
836 case cricket::MD_SENDRECV:
837 default:
838 new_direction = "a=sendrecv";
839 break;
840 }
841 Replace("a=sendrecv", new_direction, message);
842 }
843
844 static void ReplaceRejected(bool audio_rejected, bool video_rejected,
845 std::string* message) {
846 if (audio_rejected) {
847 Replace("m=audio 9", "m=audio 0", message);
848 Replace(kAttributeIceUfragVoice, "", message);
849 Replace(kAttributeIcePwdVoice, "", message);
850 }
851 if (video_rejected) {
852 Replace("m=video 9", "m=video 0", message);
853 Replace(kAttributeIceUfragVideo, "", message);
854 Replace(kAttributeIcePwdVideo, "", message);
855 }
856 }
857
858 // WebRtcSdpTest
859
860 class WebRtcSdpTest : public testing::Test {
861 public:
862 WebRtcSdpTest()
863 : jdesc_(kDummyString) {
864 #ifdef WEBRTC_ANDROID
865 webrtc::InitializeAndroidObjects();
866 #endif
867 // AudioContentDescription
868 audio_desc_ = CreateAudioContentDescription();
869 StreamParams audio_stream;
870 audio_stream.id = kAudioTrackId1;
871 audio_stream.cname = kStream1Cname;
872 audio_stream.sync_label = kStreamLabel1;
873 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
874 audio_desc_->AddStream(audio_stream);
875 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
876
877 // VideoContentDescription
878 video_desc_ = CreateVideoContentDescription();
879 StreamParams video_stream;
880 video_stream.id = kVideoTrackId1;
881 video_stream.cname = kStream1Cname;
882 video_stream.sync_label = kStreamLabel1;
883 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
884 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
885 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
886 video_stream.ssrc_groups.push_back(ssrc_group);
887 video_desc_->AddStream(video_stream);
888 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
889
890 // TransportInfo
891 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
892 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice))));
893 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
894 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo))));
895
896 // v4 host
897 int port = 1234;
898 rtc::SocketAddress address("192.168.1.5", port++);
899 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
900 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
901 kCandidateGeneration, kCandidateFoundation1);
902 address.SetPort(port++);
903 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
904 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
905 kCandidateGeneration, kCandidateFoundation1);
906 address.SetPort(port++);
907 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
908 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
909 kCandidateGeneration, kCandidateFoundation1);
910 address.SetPort(port++);
911 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
912 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
913 kCandidateGeneration, kCandidateFoundation1);
914
915 // v6 host
916 rtc::SocketAddress v6_address("::1", port++);
917 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
918 v6_address, kCandidatePriority, "", "",
919 cricket::LOCAL_PORT_TYPE,
920 kCandidateGeneration, kCandidateFoundation2);
921 v6_address.SetPort(port++);
922 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
923 v6_address, kCandidatePriority, "", "",
924 cricket::LOCAL_PORT_TYPE,
925 kCandidateGeneration, kCandidateFoundation2);
926 v6_address.SetPort(port++);
927 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
928 v6_address, kCandidatePriority, "", "",
929 cricket::LOCAL_PORT_TYPE,
930 kCandidateGeneration, kCandidateFoundation2);
931 v6_address.SetPort(port++);
932 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
933 v6_address, kCandidatePriority, "", "",
934 cricket::LOCAL_PORT_TYPE,
935 kCandidateGeneration, kCandidateFoundation2);
936
937 // stun
938 int port_stun = 2345;
939 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
940 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
941 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
942 address_stun, kCandidatePriority, "", "",
943 STUN_PORT_TYPE, kCandidateGeneration,
944 kCandidateFoundation3);
945 candidate9.set_related_address(rel_address_stun);
946
947 address_stun.SetPort(port_stun++);
948 rel_address_stun.SetPort(port_stun++);
949 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
950 address_stun, kCandidatePriority, "", "",
951 STUN_PORT_TYPE, kCandidateGeneration,
952 kCandidateFoundation3);
953 candidate10.set_related_address(rel_address_stun);
954
955 // relay
956 int port_relay = 3456;
957 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
958 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
959 address_relay, kCandidatePriority, "", "",
960 cricket::RELAY_PORT_TYPE,
961 kCandidateGeneration, kCandidateFoundation4);
962 address_relay.SetPort(port_relay++);
963 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
964 address_relay, kCandidatePriority, "", "",
965 RELAY_PORT_TYPE, kCandidateGeneration,
966 kCandidateFoundation4);
967
968 // voice
969 candidates_.push_back(candidate1);
970 candidates_.push_back(candidate2);
971 candidates_.push_back(candidate5);
972 candidates_.push_back(candidate6);
973 candidates_.push_back(candidate9);
974 candidates_.push_back(candidate10);
975
976 // video
977 candidates_.push_back(candidate3);
978 candidates_.push_back(candidate4);
979 candidates_.push_back(candidate7);
980 candidates_.push_back(candidate8);
981 candidates_.push_back(candidate11);
982 candidates_.push_back(candidate12);
983
984 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"),
985 0, candidate1));
986
987 // Set up JsepSessionDescription.
988 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
989 std::string mline_id;
990 int mline_index = 0;
991 for (size_t i = 0; i< candidates_.size(); ++i) {
992 // In this test, the audio m line index will be 0, and the video m line
993 // will be 1.
994 bool is_video = (i > 5);
995 mline_id = is_video ? "video_content_name" : "audio_content_name";
996 mline_index = is_video ? 1 : 0;
997 JsepIceCandidate jice(mline_id,
998 mline_index,
999 candidates_.at(i));
1000 jdesc_.AddCandidate(&jice);
1001 }
1002 }
1003
1004 // Turns the existing reference description into a description using
1005 // a=bundle-only. This means no transport attributes and a 0 port value on
1006 // the m= sections not associated with the BUNDLE-tag.
1007 void MakeBundleOnlyDescription() {
1008 // Remove video candidates. JsepSessionDescription doesn't make it
1009 // simple.
1010 const IceCandidateCollection* video_candidates_collection =
1011 jdesc_.candidates(1);
1012 ASSERT_NE(nullptr, video_candidates_collection);
1013 std::vector<cricket::Candidate> video_candidates;
1014 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1015 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1016 c.set_transport_name("video_content_name");
1017 video_candidates.push_back(c);
1018 }
1019 jdesc_.RemoveCandidates(video_candidates);
1020
1021 // And the rest of the transport attributes.
1022 desc_.transport_infos()[1].description.ice_ufrag.clear();
1023 desc_.transport_infos()[1].description.ice_pwd.clear();
1024 desc_.transport_infos()[1].description.connection_role =
1025 cricket::CONNECTIONROLE_NONE;
1026
1027 // Set bundle-only flag.
1028 desc_.contents()[1].bundle_only = true;
1029
1030 // Add BUNDLE group.
1031 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1032 group.AddContentName(kAudioContentName);
1033 group.AddContentName(kVideoContentName);
1034 desc_.AddGroup(group);
1035
1036 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1037 jdesc_.session_version()));
1038 }
1039
1040 // Turns the existing reference description into a plan B description,
1041 // with 2 audio tracks and 3 video tracks.
1042 void MakePlanBDescription() {
1043 audio_desc_ = static_cast<AudioContentDescription*>(audio_desc_->Copy());
1044 video_desc_ = static_cast<VideoContentDescription*>(video_desc_->Copy());
1045
1046 StreamParams audio_track_2;
1047 audio_track_2.id = kAudioTrackId2;
1048 audio_track_2.cname = kStream2Cname;
1049 audio_track_2.sync_label = kStreamLabel2;
1050 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1051 audio_desc_->AddStream(audio_track_2);
1052
1053 StreamParams video_track_2;
1054 video_track_2.id = kVideoTrackId2;
1055 video_track_2.cname = kStream2Cname;
1056 video_track_2.sync_label = kStreamLabel2;
1057 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1058 video_desc_->AddStream(video_track_2);
1059
1060 StreamParams video_track_3;
1061 video_track_3.id = kVideoTrackId3;
1062 video_track_3.cname = kStream2Cname;
1063 video_track_3.sync_label = kStreamLabel2;
1064 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1065 video_desc_->AddStream(video_track_3);
1066
1067 desc_.RemoveContentByName(kAudioContentName);
1068 desc_.RemoveContentByName(kVideoContentName);
1069 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1070 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1071
1072 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1073 jdesc_.session_version()));
1074 }
1075
1076 // Turns the existing reference description into a unified plan description,
1077 // with 2 audio tracks and 3 video tracks.
1078 void MakeUnifiedPlanDescription() {
1079 // Audio track 2.
1080 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1081 StreamParams audio_track_2;
1082 audio_track_2.id = kAudioTrackId2;
1083 audio_track_2.cname = kStream2Cname;
1084 audio_track_2.sync_label = kStreamLabel2;
1085 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1086 audio_desc_2->AddStream(audio_track_2);
1087 desc_.AddContent(kAudioContentName2, NS_JINGLE_RTP, audio_desc_2);
1088 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1089 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
1090
1091 // Video track 2, in stream 2.
1092 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1093 StreamParams video_track_2;
1094 video_track_2.id = kVideoTrackId2;
1095 video_track_2.cname = kStream2Cname;
1096 video_track_2.sync_label = kStreamLabel2;
1097 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1098 video_desc_2->AddStream(video_track_2);
1099 desc_.AddContent(kVideoContentName2, NS_JINGLE_RTP, video_desc_2);
1100 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1101 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2))));
1102
1103 // Video track 3, in stream 2.
1104 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1105 StreamParams video_track_3;
1106 video_track_3.id = kVideoTrackId3;
1107 video_track_3.cname = kStream2Cname;
1108 video_track_3.sync_label = kStreamLabel2;
1109 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1110 video_desc_3->AddStream(video_track_3);
1111 desc_.AddContent(kVideoContentName3, NS_JINGLE_RTP, video_desc_3);
1112 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1113 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3))));
1114
1115 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1116 jdesc_.session_version()));
1117 }
1118
1119 // Creates an audio content description with no streams, and some default
1120 // configuration.
1121 AudioContentDescription* CreateAudioContentDescription() {
1122 AudioContentDescription* audio = new AudioContentDescription();
1123 audio->set_rtcp_mux(true);
1124 audio->set_rtcp_reduced_size(true);
1125 audio->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_32",
1126 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1127 "dummy_session_params"));
1128 audio->set_protocol(cricket::kMediaProtocolSavpf);
1129 AudioCodec opus(111, "opus", 48000, 0, 2);
1130 audio->AddCodec(opus);
1131 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 32000, 1));
1132 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 56000, 1));
1133 return audio;
1134 }
1135
1136 // Creates a video content description with no streams, and some default
1137 // configuration.
1138 VideoContentDescription* CreateVideoContentDescription() {
1139 VideoContentDescription* video = new VideoContentDescription();
1140 video->AddCrypto(CryptoParams(
1141 1, "AES_CM_128_HMAC_SHA1_80",
1142 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1143 video->set_protocol(cricket::kMediaProtocolSavpf);
1144 video->AddCodec(
1145 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
1146 return video;
1147 }
1148
1149 template <class MCD>
1150 void CompareMediaContentDescription(const MCD* cd1,
1151 const MCD* cd2) {
1152 // type
1153 EXPECT_EQ(cd1->type(), cd1->type());
1154
1155 // content direction
1156 EXPECT_EQ(cd1->direction(), cd2->direction());
1157
1158 // rtcp_mux
1159 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1160
1161 // rtcp_reduced_size
1162 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1163
1164 // cryptos
1165 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1166 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1167 ADD_FAILURE();
1168 return;
1169 }
1170 for (size_t i = 0; i< cd1->cryptos().size(); ++i) {
1171 const CryptoParams c1 = cd1->cryptos().at(i);
1172 const CryptoParams c2 = cd2->cryptos().at(i);
1173 EXPECT_TRUE(c1.Matches(c2));
1174 EXPECT_EQ(c1.key_params, c2.key_params);
1175 EXPECT_EQ(c1.session_params, c2.session_params);
1176 }
1177
1178 // protocol
1179 // Use an equivalence class here, for old and new versions of the
1180 // protocol description.
1181 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp
1182 || cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp
1183 || cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
1184 const bool cd2_is_also_dtls_sctp =
1185 cd2->protocol() == cricket::kMediaProtocolDtlsSctp
1186 || cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp
1187 || cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
1188 EXPECT_TRUE(cd2_is_also_dtls_sctp);
1189 } else {
1190 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1191 }
1192
1193 // codecs
1194 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1195
1196 // bandwidth
1197 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1198
1199 // streams
1200 EXPECT_EQ(cd1->streams(), cd2->streams());
1201
1202 // extmap
1203 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1204 cd2->rtp_header_extensions().size());
1205 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) {
1206 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1207 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
1208 EXPECT_EQ(ext1.uri, ext2.uri);
1209 EXPECT_EQ(ext1.id, ext2.id);
1210 }
1211 }
1212
1213
1214 void CompareSessionDescription(const SessionDescription& desc1,
1215 const SessionDescription& desc2) {
1216 // Compare content descriptions.
1217 if (desc1.contents().size() != desc2.contents().size()) {
1218 ADD_FAILURE();
1219 return;
1220 }
1221 for (size_t i = 0 ; i < desc1.contents().size(); ++i) {
1222 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1223 const cricket::ContentInfo& c2 = desc2.contents().at(i);
1224 // ContentInfo properties.
1225 EXPECT_EQ(c1.name, c2.name);
1226 EXPECT_EQ(c1.type, c2.type);
1227 EXPECT_EQ(c1.rejected, c2.rejected);
1228 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
1229
1230 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1231 if (IsAudioContent(&c1)) {
1232 const AudioContentDescription* acd1 =
1233 static_cast<const AudioContentDescription*>(c1.description);
1234 const AudioContentDescription* acd2 =
1235 static_cast<const AudioContentDescription*>(c2.description);
1236 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1237 }
1238
1239 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1240 if (IsVideoContent(&c1)) {
1241 const VideoContentDescription* vcd1 =
1242 static_cast<const VideoContentDescription*>(c1.description);
1243 const VideoContentDescription* vcd2 =
1244 static_cast<const VideoContentDescription*>(c2.description);
1245 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1246 }
1247
1248 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
1249 if (IsDataContent(&c1)) {
1250 const DataContentDescription* dcd1 =
1251 static_cast<const DataContentDescription*>(c1.description);
1252 const DataContentDescription* dcd2 =
1253 static_cast<const DataContentDescription*>(c2.description);
1254 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
1255 }
1256 }
1257
1258 // group
1259 const cricket::ContentGroups groups1 = desc1.groups();
1260 const cricket::ContentGroups groups2 = desc2.groups();
1261 EXPECT_EQ(groups1.size(), groups1.size());
1262 if (groups1.size() != groups2.size()) {
1263 ADD_FAILURE();
1264 return;
1265 }
1266 for (size_t i = 0; i < groups1.size(); ++i) {
1267 const cricket::ContentGroup group1 = groups1.at(i);
1268 const cricket::ContentGroup group2 = groups2.at(i);
1269 EXPECT_EQ(group1.semantics(), group2.semantics());
1270 const cricket::ContentNames names1 = group1.content_names();
1271 const cricket::ContentNames names2 = group2.content_names();
1272 EXPECT_EQ(names1.size(), names2.size());
1273 if (names1.size() != names2.size()) {
1274 ADD_FAILURE();
1275 return;
1276 }
1277 cricket::ContentNames::const_iterator iter1 = names1.begin();
1278 cricket::ContentNames::const_iterator iter2 = names2.begin();
1279 while (iter1 != names1.end()) {
1280 EXPECT_EQ(*iter1++, *iter2++);
1281 }
1282 }
1283
1284 // transport info
1285 const cricket::TransportInfos transports1 = desc1.transport_infos();
1286 const cricket::TransportInfos transports2 = desc2.transport_infos();
1287 EXPECT_EQ(transports1.size(), transports2.size());
1288 if (transports1.size() != transports2.size()) {
1289 ADD_FAILURE();
1290 return;
1291 }
1292 for (size_t i = 0; i < transports1.size(); ++i) {
1293 const cricket::TransportInfo transport1 = transports1.at(i);
1294 const cricket::TransportInfo transport2 = transports2.at(i);
1295 EXPECT_EQ(transport1.content_name, transport2.content_name);
1296 EXPECT_EQ(transport1.description.ice_ufrag,
1297 transport2.description.ice_ufrag);
1298 EXPECT_EQ(transport1.description.ice_pwd,
1299 transport2.description.ice_pwd);
1300 if (transport1.description.identity_fingerprint) {
1301 EXPECT_EQ(*transport1.description.identity_fingerprint,
1302 *transport2.description.identity_fingerprint);
1303 } else {
1304 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1305 transport2.description.identity_fingerprint.get());
1306 }
1307 EXPECT_EQ(transport1.description.transport_options,
1308 transport2.description.transport_options);
1309 }
1310
1311 // global attributes
1312 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
1313 }
1314
1315 bool CompareSessionDescription(
1316 const JsepSessionDescription& desc1,
1317 const JsepSessionDescription& desc2) {
1318 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1319 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1320 CompareSessionDescription(*desc1.description(), *desc2.description());
1321 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1322 return false;
1323 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1324 const IceCandidateCollection* cc1 = desc1.candidates(i);
1325 const IceCandidateCollection* cc2 = desc2.candidates(i);
1326 if (cc1->count() != cc2->count()) {
1327 ADD_FAILURE();
1328 return false;
1329 }
1330 for (size_t j = 0; j < cc1->count(); ++j) {
1331 const IceCandidateInterface* c1 = cc1->at(j);
1332 const IceCandidateInterface* c2 = cc2->at(j);
1333 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1334 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1335 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1336 }
1337 }
1338 return true;
1339 }
1340
1341 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1342 // them with invalid keywords so that the parser will just ignore them.
1343 bool RemoveCandidateUfragPwd(std::string* sdp) {
1344 const char ice_ufrag[] = "a=ice-ufrag";
1345 const char ice_ufragx[] = "a=xice-ufrag";
1346 const char ice_pwd[] = "a=ice-pwd";
1347 const char ice_pwdx[] = "a=xice-pwd";
1348 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag),
1349 ice_ufragx, strlen(ice_ufragx), sdp);
1350 rtc::replace_substrs(ice_pwd, strlen(ice_pwd),
1351 ice_pwdx, strlen(ice_pwdx), sdp);
1352 return true;
1353 }
1354
1355 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
1356 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, int mline_index,
1357 const std::string& ufrag, const std::string& pwd) {
1358 std::string content_name;
1359 if (mline_index == 0) {
1360 content_name = kAudioContentName;
1361 } else if (mline_index == 1) {
1362 content_name = kVideoContentName;
1363 } else {
1364 RTC_NOTREACHED();
1365 }
1366 TransportInfo transport_info(
1367 content_name, TransportDescription(ufrag, pwd));
1368 SessionDescription* desc =
1369 const_cast<SessionDescription*>(jdesc->description());
1370 desc->RemoveTransportInfoByName(content_name);
1371 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
1372 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1373 const IceCandidateCollection* cc = jdesc_.candidates(i);
1374 for (size_t j = 0; j < cc->count(); ++j) {
1375 if (cc->at(j)->sdp_mline_index() == mline_index) {
1376 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(
1377 ufrag);
1378 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(
1379 pwd);
1380 }
1381 }
1382 }
1383 return true;
1384 }
1385
1386 void AddIceOptions(const std::string& content_name,
1387 const std::vector<std::string>& transport_options) {
1388 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1389 cricket::TransportInfo transport_info =
1390 *(desc_.GetTransportInfoByName(content_name));
1391 desc_.RemoveTransportInfoByName(content_name);
1392 transport_info.description.transport_options = transport_options;
1393 desc_.AddTransportInfo(transport_info);
1394 }
1395
1396 void SetIceUfragPwd(const std::string& content_name,
1397 const std::string& ice_ufrag,
1398 const std::string& ice_pwd) {
1399 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1400 cricket::TransportInfo transport_info =
1401 *(desc_.GetTransportInfoByName(content_name));
1402 desc_.RemoveTransportInfoByName(content_name);
1403 transport_info.description.ice_ufrag = ice_ufrag;
1404 transport_info.description.ice_pwd = ice_pwd;
1405 desc_.AddTransportInfo(transport_info);
1406 }
1407
1408 void AddFingerprint() {
1409 desc_.RemoveTransportInfoByName(kAudioContentName);
1410 desc_.RemoveTransportInfoByName(kVideoContentName);
1411 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1,
1412 kIdentityDigest,
1413 sizeof(kIdentityDigest));
1414 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1415 kAudioContentName,
1416 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1417 cricket::ICEMODE_FULL,
1418 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1419 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1420 kVideoContentName,
1421 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1422 cricket::ICEMODE_FULL,
1423 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1424 }
1425
1426 void AddExtmap() {
1427 audio_desc_ = static_cast<AudioContentDescription*>(
1428 audio_desc_->Copy());
1429 video_desc_ = static_cast<VideoContentDescription*>(
1430 video_desc_->Copy());
1431 audio_desc_->AddRtpHeaderExtension(RtpExtension(kExtmapUri, kExtmapId));
1432 video_desc_->AddRtpHeaderExtension(RtpExtension(kExtmapUri, kExtmapId));
1433 desc_.RemoveContentByName(kAudioContentName);
1434 desc_.RemoveContentByName(kVideoContentName);
1435 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1436 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1437 }
1438
1439 void RemoveCryptos() {
1440 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1441 video_desc_->set_cryptos(std::vector<CryptoParams>());
1442 }
1443
1444 bool TestSerializeDirection(cricket::MediaContentDirection direction) {
1445 audio_desc_->set_direction(direction);
1446 video_desc_->set_direction(direction);
1447 std::string new_sdp = kSdpFullString;
1448 ReplaceDirection(direction, &new_sdp);
1449
1450 if (!jdesc_.Initialize(desc_.Copy(),
1451 jdesc_.session_id(),
1452 jdesc_.session_version())) {
1453 return false;
1454 }
1455 std::string message = webrtc::SdpSerialize(jdesc_, false);
1456 EXPECT_EQ(new_sdp, message);
1457 return true;
1458 }
1459
1460 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
1461 audio_desc_ = static_cast<AudioContentDescription*>(
1462 audio_desc_->Copy());
1463 video_desc_ = static_cast<VideoContentDescription*>(
1464 video_desc_->Copy());
1465 desc_.RemoveContentByName(kAudioContentName);
1466 desc_.RemoveContentByName(kVideoContentName);
1467 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1468 audio_desc_);
1469 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1470 video_desc_);
1471 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1472 audio_rejected ? "" : kPwdVoice);
1473 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1474 video_rejected ? "" : kPwdVideo);
1475
1476 std::string new_sdp = kSdpString;
1477 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1478
1479 JsepSessionDescription jdesc_no_candidates(kDummyString);
1480 if (!jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
1481 kSessionVersion)) {
1482 return false;
1483 }
1484 std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false);
1485 EXPECT_EQ(new_sdp, message);
1486 return true;
1487 }
1488
1489 void AddSctpDataChannel() {
1490 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
1491 data_desc_ = data.get();
1492 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
1493 DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
1494 cricket::kGoogleSctpDataCodecName);
1495 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1496 data_desc_->AddCodec(codec);
1497 desc_.AddContent(kDataContentName, NS_JINGLE_DRAFT_SCTP, data.release());
1498 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1499 kDataContentName, TransportDescription(kUfragData, kPwdData))));
1500 }
1501
1502 void AddRtpDataChannel() {
1503 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
1504 data_desc_ = data.get();
1505
1506 data_desc_->AddCodec(DataCodec(101, "google-data"));
1507 StreamParams data_stream;
1508 data_stream.id = kDataChannelMsid;
1509 data_stream.cname = kDataChannelCname;
1510 data_stream.sync_label = kDataChannelLabel;
1511 data_stream.ssrcs.push_back(kDataChannelSsrc);
1512 data_desc_->AddStream(data_stream);
1513 data_desc_->AddCrypto(CryptoParams(
1514 1, "AES_CM_128_HMAC_SHA1_80",
1515 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
1516 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
1517 desc_.AddContent(kDataContentName, NS_JINGLE_RTP, data.release());
1518 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1519 kDataContentName, TransportDescription(kUfragData, kPwdData))));
1520 }
1521
1522 bool TestDeserializeDirection(cricket::MediaContentDirection direction) {
1523 std::string new_sdp = kSdpFullString;
1524 ReplaceDirection(direction, &new_sdp);
1525 JsepSessionDescription new_jdesc(kDummyString);
1526
1527 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1528
1529 audio_desc_->set_direction(direction);
1530 video_desc_->set_direction(direction);
1531 if (!jdesc_.Initialize(desc_.Copy(),
1532 jdesc_.session_id(),
1533 jdesc_.session_version())) {
1534 return false;
1535 }
1536 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1537 return true;
1538 }
1539
1540 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
1541 std::string new_sdp = kSdpString;
1542 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1543 JsepSessionDescription new_jdesc(JsepSessionDescription::kOffer);
1544 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1545
1546 audio_desc_ = static_cast<AudioContentDescription*>(
1547 audio_desc_->Copy());
1548 video_desc_ = static_cast<VideoContentDescription*>(
1549 video_desc_->Copy());
1550 desc_.RemoveContentByName(kAudioContentName);
1551 desc_.RemoveContentByName(kVideoContentName);
1552 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1553 audio_desc_);
1554 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1555 video_desc_);
1556 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1557 audio_rejected ? "" : kPwdVoice);
1558 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1559 video_rejected ? "" : kPwdVideo);
1560 JsepSessionDescription jdesc_no_candidates(kDummyString);
1561 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1562 jdesc_.session_version())) {
1563 return false;
1564 }
1565 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
1566 return true;
1567 }
1568
1569 void TestDeserializeExtmap(bool session_level, bool media_level) {
1570 AddExtmap();
1571 JsepSessionDescription new_jdesc("dummy");
1572 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1573 jdesc_.session_id(),
1574 jdesc_.session_version()));
1575 JsepSessionDescription jdesc_with_extmap("dummy");
1576 std::string sdp_with_extmap = kSdpString;
1577 if (session_level) {
1578 InjectAfter(kSessionTime, kExtmapWithDirectionAndAttribute,
1579 &sdp_with_extmap);
1580 }
1581 if (media_level) {
1582 InjectAfter(kAttributeIcePwdVoice, kExtmapWithDirectionAndAttribute,
1583 &sdp_with_extmap);
1584 InjectAfter(kAttributeIcePwdVideo, kExtmapWithDirectionAndAttribute,
1585 &sdp_with_extmap);
1586 }
1587 // The extmap can't be present at the same time in both session level and
1588 // media level.
1589 if (session_level && media_level) {
1590 SdpParseError error;
1591 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap,
1592 &jdesc_with_extmap, &error));
1593 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1594 } else {
1595 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1596 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1597 }
1598 }
1599
1600 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
1601 const std::string& name, int expected_value) {
1602 cricket::CodecParameterMap::const_iterator found = params.find(name);
1603 ASSERT_TRUE(found != params.end());
1604 EXPECT_EQ(found->second, rtc::ToString<int>(expected_value));
1605 }
1606
1607 void TestDeserializeCodecParams(const CodecParams& params,
1608 JsepSessionDescription* jdesc_output) {
1609 std::string sdp =
1610 "v=0\r\n"
1611 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1612 "s=-\r\n"
1613 "t=0 0\r\n"
1614 // Include semantics for WebRTC Media Streams since it is supported by
1615 // this parser, and will be added to the SDP when serializing a session
1616 // description.
1617 "a=msid-semantic: WMS\r\n"
1618 // Pl type 111 preferred.
1619 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
1620 // Pltype 111 listed before 103 and 104 in the map.
1621 "a=rtpmap:111 opus/48000/2\r\n"
1622 // Pltype 103 listed before 104.
1623 "a=rtpmap:103 ISAC/16000\r\n"
1624 "a=rtpmap:104 ISAC/32000\r\n"
1625 "a=fmtp:111 0-15,66,70\r\n"
1626 "a=fmtp:111 ";
1627 std::ostringstream os;
1628 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
1629 << "; sprop-stereo=" << params.sprop_stereo
1630 << "; useinbandfec=" << params.useinband
1631 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
1632 << "a=ptime:" << params.ptime << "\r\n"
1633 << "a=maxptime:" << params.max_ptime << "\r\n";
1634 sdp += os.str();
1635
1636 os.clear();
1637 os.str("");
1638 // Pl type 100 preferred.
1639 os << "m=video 9 RTP/SAVPF 99 95\r\n"
1640 << "a=rtpmap:99 VP8/90000\r\n"
1641 << "a=rtpmap:95 RTX/90000\r\n"
1642 << "a=fmtp:95 apt=99;\r\n";
1643 sdp += os.str();
1644
1645 // Deserialize
1646 SdpParseError error;
1647 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1648
1649 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1650 ASSERT_TRUE(ac != NULL);
1651 const AudioContentDescription* acd =
1652 static_cast<const AudioContentDescription*>(ac->description);
1653 ASSERT_FALSE(acd->codecs().empty());
1654 cricket::AudioCodec opus = acd->codecs()[0];
1655 EXPECT_EQ("opus", opus.name);
1656 EXPECT_EQ(111, opus.id);
1657 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1658 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1659 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1660 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
1661 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1662 params.maxaveragebitrate);
1663 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1664 cricket::AudioCodec codec = acd->codecs()[i];
1665 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1666 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
1667 if (codec.name == "ISAC") {
1668 if (codec.clockrate == 16000) {
1669 EXPECT_EQ(32000, codec.bitrate);
1670 } else {
1671 EXPECT_EQ(56000, codec.bitrate);
1672 }
1673 }
1674 }
1675
1676 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1677 ASSERT_TRUE(vc != NULL);
1678 const VideoContentDescription* vcd =
1679 static_cast<const VideoContentDescription*>(vc->description);
1680 ASSERT_FALSE(vcd->codecs().empty());
1681 cricket::VideoCodec vp8 = vcd->codecs()[0];
1682 EXPECT_EQ("VP8", vp8.name);
1683 EXPECT_EQ(99, vp8.id);
1684 cricket::VideoCodec rtx = vcd->codecs()[1];
1685 EXPECT_EQ("RTX", rtx.name);
1686 EXPECT_EQ(95, rtx.id);
1687 VerifyCodecParameter(rtx.params, "apt", vp8.id);
1688 }
1689
1690 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1691 bool use_wildcard) {
1692 std::string sdp_session_and_audio =
1693 "v=0\r\n"
1694 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1695 "s=-\r\n"
1696 "t=0 0\r\n"
1697 // Include semantics for WebRTC Media Streams since it is supported by
1698 // this parser, and will be added to the SDP when serializing a session
1699 // description.
1700 "a=msid-semantic: WMS\r\n"
1701 "m=audio 9 RTP/SAVPF 111\r\n"
1702 "a=rtpmap:111 opus/48000/2\r\n";
1703 std::string sdp_video =
1704 "m=video 3457 RTP/SAVPF 101\r\n"
1705 "a=rtpmap:101 VP8/90000\r\n"
1706 "a=rtcp-fb:101 nack\r\n"
1707 "a=rtcp-fb:101 nack pli\r\n"
1708 "a=rtcp-fb:101 goog-remb\r\n";
1709 std::ostringstream os;
1710 os << sdp_session_and_audio;
1711 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
1712 os << sdp_video;
1713 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
1714 std::string sdp = os.str();
1715 // Deserialize
1716 SdpParseError error;
1717 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1718 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1719 ASSERT_TRUE(ac != NULL);
1720 const AudioContentDescription* acd =
1721 static_cast<const AudioContentDescription*>(ac->description);
1722 ASSERT_FALSE(acd->codecs().empty());
1723 cricket::AudioCodec opus = acd->codecs()[0];
1724 EXPECT_EQ(111, opus.id);
1725 EXPECT_TRUE(opus.HasFeedbackParam(
1726 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1727 cricket::kParamValueEmpty)));
1728
1729 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1730 ASSERT_TRUE(vc != NULL);
1731 const VideoContentDescription* vcd =
1732 static_cast<const VideoContentDescription*>(vc->description);
1733 ASSERT_FALSE(vcd->codecs().empty());
1734 cricket::VideoCodec vp8 = vcd->codecs()[0];
1735 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1736 vp8.name.c_str());
1737 EXPECT_EQ(101, vp8.id);
1738 EXPECT_TRUE(vp8.HasFeedbackParam(
1739 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1740 cricket::kParamValueEmpty)));
1741 EXPECT_TRUE(vp8.HasFeedbackParam(
1742 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1743 cricket::kRtcpFbNackParamPli)));
1744 EXPECT_TRUE(vp8.HasFeedbackParam(
1745 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
1746 cricket::kParamValueEmpty)));
1747 EXPECT_TRUE(vp8.HasFeedbackParam(
1748 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
1749 cricket::kRtcpFbCcmParamFir)));
1750 }
1751
1752 // Two SDP messages can mean the same thing but be different strings, e.g.
1753 // some of the lines can be serialized in different order.
1754 // However, a deserialized description can be compared field by field and has
1755 // no order. If deserializer has already been tested, serializing then
1756 // deserializing and comparing JsepSessionDescription will test
1757 // the serializer sufficiently.
1758 void TestSerialize(const JsepSessionDescription& jdesc,
1759 bool unified_plan_sdp) {
1760 std::string message = webrtc::SdpSerialize(jdesc, unified_plan_sdp);
1761 JsepSessionDescription jdesc_output_des(kDummyString);
1762 SdpParseError error;
1763 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1764 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1765 }
1766
1767 protected:
1768 SessionDescription desc_;
1769 AudioContentDescription* audio_desc_;
1770 VideoContentDescription* video_desc_;
1771 DataContentDescription* data_desc_;
1772 Candidates candidates_;
1773 std::unique_ptr<IceCandidateInterface> jcandidate_;
1774 JsepSessionDescription jdesc_;
1775 };
1776
1777 void TestMismatch(const std::string& string1, const std::string& string2) {
1778 int position = 0;
1779 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1780 if (string1.c_str()[i] != string2.c_str()[i]) {
1781 position = static_cast<int>(i);
1782 break;
1783 }
1784 }
1785 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1786 << " character\n"
1787 << " 1: " << string1.substr(position, 20) << "\n"
1788 << " 2: " << string2.substr(position, 20) << "\n";
1789 }
1790
1791 TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1792 // SessionDescription with desc and candidates.
1793 std::string message = webrtc::SdpSerialize(jdesc_, false);
1794 TestMismatch(std::string(kSdpFullString), message);
1795 }
1796
1797 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
1798 JsepSessionDescription jdesc_empty(kDummyString);
1799 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty, false));
1800 }
1801
1802 // This tests serialization of SDP with only IPv6 candidates and verifies that
1803 // IPv6 is used as default address in c line according to preference.
1804 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIPv6Only) {
1805 // Only test 1 m line.
1806 desc_.RemoveContentByName("video_content_name");
1807 // Stun has a high preference than local host.
1808 cricket::Candidate candidate1(
1809 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1810 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1811 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1812 cricket::Candidate candidate2(
1813 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1814 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
1815 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1816 JsepSessionDescription jdesc(kDummyString);
1817 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1818
1819 // Only add the candidates to audio m line.
1820 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1821 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1822 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1823 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
1824 std::string message = webrtc::SdpSerialize(jdesc, false);
1825
1826 // Audio line should have a c line like this one.
1827 EXPECT_NE(message.find("c=IN IP6 ::1"), std::string::npos);
1828 // Shouldn't have a IP4 c line.
1829 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
1830 }
1831
1832 // This tests serialization of SDP with both IPv4 and IPv6 candidates and
1833 // verifies that IPv4 is used as default address in c line even if the
1834 // preference of IPv4 is lower.
1835 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothIPFamilies) {
1836 // Only test 1 m line.
1837 desc_.RemoveContentByName("video_content_name");
1838 cricket::Candidate candidate_v4(
1839 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1840 rtc::SocketAddress("192.168.1.5", 1234), kCandidatePriority, "", "",
1841 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1842 cricket::Candidate candidate_v6(
1843 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1844 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1845 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1846 JsepSessionDescription jdesc(kDummyString);
1847 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1848
1849 // Only add the candidates to audio m line.
1850 JsepIceCandidate jice_v4("audio_content_name", 0, candidate_v4);
1851 JsepIceCandidate jice_v6("audio_content_name", 0, candidate_v6);
1852 ASSERT_TRUE(jdesc.AddCandidate(&jice_v4));
1853 ASSERT_TRUE(jdesc.AddCandidate(&jice_v6));
1854 std::string message = webrtc::SdpSerialize(jdesc, false);
1855
1856 // Audio line should have a c line like this one.
1857 EXPECT_NE(message.find("c=IN IP4 192.168.1.5"), std::string::npos);
1858 // Shouldn't have a IP6 c line.
1859 EXPECT_EQ(message.find("c=IN IP6"), std::string::npos);
1860 }
1861
1862 // This tests serialization of SDP with both UDP and TCP candidates and
1863 // verifies that UDP is used as default address in c line even if the
1864 // preference of UDP is lower.
1865 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothProtocols) {
1866 // Only test 1 m line.
1867 desc_.RemoveContentByName("video_content_name");
1868 // Stun has a high preference than local host.
1869 cricket::Candidate candidate1(
1870 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1871 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1872 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1873 cricket::Candidate candidate2(
1874 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1875 rtc::SocketAddress("fe80::1234:5678:abcd:ef12", 1235), kCandidatePriority,
1876 "", "", cricket::LOCAL_PORT_TYPE, kCandidateGeneration,
1877 kCandidateFoundation1);
1878 JsepSessionDescription jdesc(kDummyString);
1879 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1880
1881 // Only add the candidates to audio m line.
1882 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1883 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1884 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1885 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
1886 std::string message = webrtc::SdpSerialize(jdesc, false);
1887
1888 // Audio line should have a c line like this one.
1889 EXPECT_NE(message.find("c=IN IP6 fe80::1234:5678:abcd:ef12"),
1890 std::string::npos);
1891 // Shouldn't have a IP4 c line.
1892 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
1893 }
1894
1895 // This tests serialization of SDP with only TCP candidates and verifies that
1896 // null IPv4 is used as default address in c line.
1897 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithTCPOnly) {
1898 // Only test 1 m line.
1899 desc_.RemoveContentByName("video_content_name");
1900 // Stun has a high preference than local host.
1901 cricket::Candidate candidate1(
1902 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1903 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1904 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1905 cricket::Candidate candidate2(
1906 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1907 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
1908 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1909 JsepSessionDescription jdesc(kDummyString);
1910 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1911
1912 // Only add the candidates to audio m line.
1913 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1914 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1915 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1916 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
1917 std::string message = webrtc::SdpSerialize(jdesc, false);
1918
1919 // Audio line should have a c line like this one when no any default exists.
1920 EXPECT_NE(message.find("c=IN IP4 0.0.0.0"), std::string::npos);
1921 }
1922
1923 // This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1924 // the case in a DTLS offer.
1925 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1926 AddFingerprint();
1927 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1928 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1929 kSessionId, kSessionVersion));
1930 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint, false);
1931
1932 std::string sdp_with_fingerprint = kSdpString;
1933 InjectAfter(kAttributeIcePwdVoice,
1934 kFingerprint, &sdp_with_fingerprint);
1935 InjectAfter(kAttributeIcePwdVideo,
1936 kFingerprint, &sdp_with_fingerprint);
1937
1938 EXPECT_EQ(sdp_with_fingerprint, message);
1939 }
1940
1941 // This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1942 // be the case in a DTLS answer.
1943 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1944 AddFingerprint();
1945 RemoveCryptos();
1946 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1947 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1948 kSessionId, kSessionVersion));
1949 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint, false);
1950
1951 std::string sdp_with_fingerprint = kSdpString;
1952 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1953 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
1954 InjectAfter(kAttributeIcePwdVoice,
1955 kFingerprint, &sdp_with_fingerprint);
1956 InjectAfter(kAttributeIcePwdVideo,
1957 kFingerprint, &sdp_with_fingerprint);
1958
1959 EXPECT_EQ(sdp_with_fingerprint, message);
1960 }
1961
1962 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1963 // JsepSessionDescription with desc but without candidates.
1964 JsepSessionDescription jdesc_no_candidates(kDummyString);
1965 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
1966 kSessionVersion));
1967 std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false);
1968 EXPECT_EQ(std::string(kSdpString), message);
1969 }
1970
1971 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1972 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1973 group.AddContentName(kAudioContentName);
1974 group.AddContentName(kVideoContentName);
1975 desc_.AddGroup(group);
1976 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1977 jdesc_.session_id(),
1978 jdesc_.session_version()));
1979 std::string message = webrtc::SdpSerialize(jdesc_, false);
1980 std::string sdp_with_bundle = kSdpFullString;
1981 InjectAfter(kSessionTime,
1982 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1983 &sdp_with_bundle);
1984 EXPECT_EQ(sdp_with_bundle, message);
1985 }
1986
1987 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
1988 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1989 GetFirstVideoContent(&desc_)->description);
1990 vcd->set_bandwidth(100 * 1000);
1991 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1992 GetFirstAudioContent(&desc_)->description);
1993 acd->set_bandwidth(50 * 1000);
1994 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1995 jdesc_.session_id(),
1996 jdesc_.session_version()));
1997 std::string message = webrtc::SdpSerialize(jdesc_, false);
1998 std::string sdp_with_bandwidth = kSdpFullString;
1999 InjectAfter("c=IN IP4 74.125.224.39\r\n",
2000 "b=AS:100\r\n",
2001 &sdp_with_bandwidth);
2002 InjectAfter("c=IN IP4 74.125.127.126\r\n",
2003 "b=AS:50\r\n",
2004 &sdp_with_bandwidth);
2005 EXPECT_EQ(sdp_with_bandwidth, message);
2006 }
2007
2008 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
2009 std::vector<std::string> transport_options;
2010 transport_options.push_back(kIceOption1);
2011 transport_options.push_back(kIceOption3);
2012 AddIceOptions(kAudioContentName, transport_options);
2013 transport_options.clear();
2014 transport_options.push_back(kIceOption2);
2015 transport_options.push_back(kIceOption3);
2016 AddIceOptions(kVideoContentName, transport_options);
2017 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2018 jdesc_.session_id(),
2019 jdesc_.session_version()));
2020 std::string message = webrtc::SdpSerialize(jdesc_, false);
2021 std::string sdp_with_ice_options = kSdpFullString;
2022 InjectAfter(kAttributeIcePwdVoice,
2023 "a=ice-options:iceoption1 iceoption3\r\n",
2024 &sdp_with_ice_options);
2025 InjectAfter(kAttributeIcePwdVideo,
2026 "a=ice-options:iceoption2 iceoption3\r\n",
2027 &sdp_with_ice_options);
2028 EXPECT_EQ(sdp_with_ice_options, message);
2029 }
2030
2031 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
2032 EXPECT_TRUE(TestSerializeDirection(cricket::MD_RECVONLY));
2033 }
2034
2035 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
2036 EXPECT_TRUE(TestSerializeDirection(cricket::MD_SENDONLY));
2037 }
2038
2039 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
2040 EXPECT_TRUE(TestSerializeDirection(cricket::MD_INACTIVE));
2041 }
2042
2043 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2044 EXPECT_TRUE(TestSerializeRejected(true, false));
2045 }
2046
2047 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2048 EXPECT_TRUE(TestSerializeRejected(false, true));
2049 }
2050
2051 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2052 EXPECT_TRUE(TestSerializeRejected(true, true));
2053 }
2054
2055 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
2056 AddRtpDataChannel();
2057 JsepSessionDescription jsep_desc(kDummyString);
2058
2059 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2060 std::string message = webrtc::SdpSerialize(jsep_desc, false);
2061
2062 std::string expected_sdp = kSdpString;
2063 expected_sdp.append(kSdpRtpDataChannelString);
2064 EXPECT_EQ(expected_sdp, message);
2065 }
2066
2067 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
2068 AddSctpDataChannel();
2069 JsepSessionDescription jsep_desc(kDummyString);
2070
2071 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2072 std::string message = webrtc::SdpSerialize(jsep_desc, false);
2073
2074 std::string expected_sdp = kSdpString;
2075 expected_sdp.append(kSdpSctpDataChannelString);
2076 EXPECT_EQ(message, expected_sdp);
2077 }
2078
2079 TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
2080 AddSctpDataChannel();
2081 JsepSessionDescription jsep_desc(kDummyString);
2082
2083 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2084 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
2085 jsep_desc.description()->GetContentDescriptionByName(kDataContentName));
2086
2087 const int kNewPort = 1234;
2088 cricket::DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
2089 cricket::kGoogleSctpDataCodecName);
2090 codec.SetParam(cricket::kCodecParamPort, kNewPort);
2091 dcdesc->AddOrReplaceCodec(codec);
2092
2093 std::string message = webrtc::SdpSerialize(jsep_desc, false);
2094
2095 std::string expected_sdp = kSdpString;
2096 expected_sdp.append(kSdpSctpDataChannelString);
2097
2098 char default_portstr[16];
2099 char new_portstr[16];
2100 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
2101 kDefaultSctpPort);
2102 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
2103 rtc::replace_substrs(default_portstr, strlen(default_portstr),
2104 new_portstr, strlen(new_portstr),
2105 &expected_sdp);
2106
2107 EXPECT_EQ(expected_sdp, message);
2108 }
2109
2110 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
2111 AddRtpDataChannel();
2112 data_desc_->set_bandwidth(100*1000);
2113 JsepSessionDescription jsep_desc(kDummyString);
2114
2115 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2116 std::string message = webrtc::SdpSerialize(jsep_desc, false);
2117
2118 std::string expected_sdp = kSdpString;
2119 expected_sdp.append(kSdpRtpDataChannelString);
2120 // Serializing data content shouldn't ignore bandwidth settings.
2121 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
2122 "b=AS:100\r\n",
2123 &expected_sdp);
2124 EXPECT_EQ(expected_sdp, message);
2125 }
2126
2127 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
2128 AddExtmap();
2129 JsepSessionDescription desc_with_extmap("dummy");
2130 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(),
2131 kSessionId, kSessionVersion));
2132 std::string message = webrtc::SdpSerialize(desc_with_extmap, false);
2133
2134 std::string sdp_with_extmap = kSdpString;
2135 InjectAfter("a=mid:audio_content_name\r\n",
2136 kExtmap, &sdp_with_extmap);
2137 InjectAfter("a=mid:video_content_name\r\n",
2138 kExtmap, &sdp_with_extmap);
2139
2140 EXPECT_EQ(sdp_with_extmap, message);
2141 }
2142
2143 TEST_F(WebRtcSdpTest, SerializeCandidates) {
2144 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
2145 EXPECT_EQ(std::string(kRawCandidate), message);
2146
2147 Candidate candidate_with_ufrag(candidates_.front());
2148 candidate_with_ufrag.set_username("ABC");
2149 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2150 candidate_with_ufrag));
2151 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2152 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
2153
2154 Candidate candidate_with_network_info(candidates_.front());
2155 candidate_with_network_info.set_network_id(1);
2156 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2157 candidate_with_network_info));
2158 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2159 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2160 candidate_with_network_info.set_network_cost(999);
2161 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2162 candidate_with_network_info));
2163 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2164 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2165 message);
2166 }
2167
2168 // TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2169 // RFC 6544.
2170 TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
2171 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
2172 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2173 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2174 kCandidateFoundation1);
2175 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
2176 std::unique_ptr<IceCandidateInterface> jcandidate(
2177 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
2178
2179 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2180 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2181 }
2182
2183 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
2184 cricket::VideoCodec h264_codec("H264");
2185 h264_codec.SetParam("profile-level-id", "42e01f");
2186 h264_codec.SetParam("level-asymmetry-allowed", "1");
2187 h264_codec.SetParam("packetization-mode", "1");
2188 video_desc_->AddCodec(h264_codec);
2189
2190 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
2191
2192 std::string message = webrtc::SdpSerialize(jdesc_, false);
2193 size_t after_pt = message.find(" H264/90000");
2194 ASSERT_NE(after_pt, std::string::npos);
2195 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2196 ASSERT_NE(before_pt, std::string::npos);
2197 before_pt += strlen("a=rtpmap:");
2198 std::string pt = message.substr(before_pt, after_pt - before_pt);
2199 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2200 std::string to_find = "a=fmtp:" + pt + " ";
2201 size_t fmtp_pos = message.find(to_find);
2202 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
2203 size_t fmtp_endpos = message.find("\n", fmtp_pos);
2204 ASSERT_NE(std::string::npos, fmtp_endpos);
2205 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2206 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2207 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2208 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
2209 // Check that there are no spaces after semicolons.
2210 // https://bugs.webrtc.org/5793
2211 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
2212 }
2213
2214 TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
2215 JsepSessionDescription jdesc(kDummyString);
2216 // Deserialize
2217 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2218 // Verify
2219 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2220 }
2221
2222 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
2223 JsepSessionDescription jdesc(kDummyString);
2224 const char kSdpWithoutMline[] =
2225 "v=0\r\n"
2226 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2227 "s=-\r\n"
2228 "t=0 0\r\n"
2229 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
2230 // Deserialize
2231 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2232 EXPECT_EQ(0u, jdesc.description()->contents().size());
2233 }
2234
2235 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
2236 JsepSessionDescription jdesc(kDummyString);
2237 std::string sdp_without_carriage_return = kSdpFullString;
2238 Replace("\r\n", "\n", &sdp_without_carriage_return);
2239 // Deserialize
2240 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2241 // Verify
2242 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2243 }
2244
2245 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2246 // SessionDescription with desc but without candidates.
2247 JsepSessionDescription jdesc_no_candidates(kDummyString);
2248 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
2249 kSessionId, kSessionVersion));
2250 JsepSessionDescription new_jdesc(kDummyString);
2251 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2252 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2253 }
2254
2255 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2256 static const char kSdpNoRtpmapString[] =
2257 "v=0\r\n"
2258 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2259 "s=-\r\n"
2260 "t=0 0\r\n"
2261 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2262 // Codec that doesn't appear in the m= line will be ignored.
2263 "a=rtpmap:104 ISAC/32000\r\n"
2264 // The rtpmap line for static payload codec is optional.
2265 "a=rtpmap:18 G729/16000\r\n"
2266 "a=rtpmap:103 ISAC/16000\r\n";
2267
2268 JsepSessionDescription jdesc(kDummyString);
2269 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2270 cricket::AudioContentDescription* audio =
2271 static_cast<AudioContentDescription*>(
2272 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2273 AudioCodecs ref_codecs;
2274 // The codecs in the AudioContentDescription should be in the same order as
2275 // the payload types (<fmt>s) on the m= line.
2276 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2277 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
2278 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 32000, 1));
2279 EXPECT_EQ(ref_codecs, audio->codecs());
2280 }
2281
2282 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2283 static const char kSdpNoRtpmapString[] =
2284 "v=0\r\n"
2285 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2286 "s=-\r\n"
2287 "t=0 0\r\n"
2288 "m=audio 49232 RTP/AVP 18 103\r\n"
2289 "a=fmtp:18 annexb=yes\r\n"
2290 "a=rtpmap:103 ISAC/16000\r\n";
2291
2292 JsepSessionDescription jdesc(kDummyString);
2293 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2294 cricket::AudioContentDescription* audio =
2295 static_cast<AudioContentDescription*>(
2296 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2297
2298 cricket::AudioCodec g729 = audio->codecs()[0];
2299 EXPECT_EQ("G729", g729.name);
2300 EXPECT_EQ(8000, g729.clockrate);
2301 EXPECT_EQ(18, g729.id);
2302 cricket::CodecParameterMap::iterator found =
2303 g729.params.find("annexb");
2304 ASSERT_TRUE(found != g729.params.end());
2305 EXPECT_EQ(found->second, "yes");
2306
2307 cricket::AudioCodec isac = audio->codecs()[1];
2308 EXPECT_EQ("ISAC", isac.name);
2309 EXPECT_EQ(103, isac.id);
2310 EXPECT_EQ(16000, isac.clockrate);
2311 }
2312
2313 // Ensure that we can deserialize SDP with a=fingerprint properly.
2314 TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2315 // Add a DTLS a=fingerprint attribute to our session description.
2316 AddFingerprint();
2317 JsepSessionDescription new_jdesc(kDummyString);
2318 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
2319 jdesc_.session_id(),
2320 jdesc_.session_version()));
2321
2322 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
2323 std::string sdp_with_fingerprint = kSdpString;
2324 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2325 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2326 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2327 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2328 }
2329
2330 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
2331 JsepSessionDescription jdesc_with_bundle(kDummyString);
2332 std::string sdp_with_bundle = kSdpFullString;
2333 InjectAfter(kSessionTime,
2334 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2335 &sdp_with_bundle);
2336 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2337 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2338 group.AddContentName(kAudioContentName);
2339 group.AddContentName(kVideoContentName);
2340 desc_.AddGroup(group);
2341 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2342 jdesc_.session_id(),
2343 jdesc_.session_version()));
2344 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2345 }
2346
2347 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
2348 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2349 std::string sdp_with_bandwidth = kSdpFullString;
2350 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
2351 "b=AS:100\r\n",
2352 &sdp_with_bandwidth);
2353 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
2354 "b=AS:50\r\n",
2355 &sdp_with_bandwidth);
2356 EXPECT_TRUE(
2357 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2358 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
2359 GetFirstVideoContent(&desc_)->description);
2360 vcd->set_bandwidth(100 * 1000);
2361 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
2362 GetFirstAudioContent(&desc_)->description);
2363 acd->set_bandwidth(50 * 1000);
2364 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2365 jdesc_.session_id(),
2366 jdesc_.session_version()));
2367 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2368 }
2369
2370 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
2371 JsepSessionDescription jdesc_with_ice_options(kDummyString);
2372 std::string sdp_with_ice_options = kSdpFullString;
2373 InjectAfter(kSessionTime,
2374 "a=ice-options:iceoption3\r\n",
2375 &sdp_with_ice_options);
2376 InjectAfter(kAttributeIcePwdVoice,
2377 "a=ice-options:iceoption1\r\n",
2378 &sdp_with_ice_options);
2379 InjectAfter(kAttributeIcePwdVideo,
2380 "a=ice-options:iceoption2\r\n",
2381 &sdp_with_ice_options);
2382 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2383 std::vector<std::string> transport_options;
2384 transport_options.push_back(kIceOption3);
2385 transport_options.push_back(kIceOption1);
2386 AddIceOptions(kAudioContentName, transport_options);
2387 transport_options.clear();
2388 transport_options.push_back(kIceOption3);
2389 transport_options.push_back(kIceOption2);
2390 AddIceOptions(kVideoContentName, transport_options);
2391 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2392 jdesc_.session_id(),
2393 jdesc_.session_version()));
2394 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2395 }
2396
2397 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2398 // Remove the original ice-ufrag and ice-pwd
2399 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyString);
2400 std::string sdp_with_ufrag_pwd = kSdpFullString;
2401 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2402 // Add session level ufrag and pwd
2403 InjectAfter(kSessionTime,
2404 "a=ice-pwd:session+level+icepwd\r\n"
2405 "a=ice-ufrag:session+level+iceufrag\r\n",
2406 &sdp_with_ufrag_pwd);
2407 // Add media level ufrag and pwd for audio
2408 InjectAfter("a=mid:audio_content_name\r\n",
2409 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2410 &sdp_with_ufrag_pwd);
2411 // Update the candidate ufrag and pwd to the expected ones.
2412 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0,
2413 "media+level+iceufrag", "media+level+icepwd"));
2414 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1,
2415 "session+level+iceufrag", "session+level+icepwd"));
2416 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2417 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2418 }
2419
2420 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
2421 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_RECVONLY));
2422 }
2423
2424 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
2425 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_SENDONLY));
2426 }
2427
2428 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
2429 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_INACTIVE));
2430 }
2431
2432 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2433 EXPECT_TRUE(TestDeserializeRejected(true, false));
2434 }
2435
2436 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2437 EXPECT_TRUE(TestDeserializeRejected(false, true));
2438 }
2439
2440 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2441 EXPECT_TRUE(TestDeserializeRejected(true, true));
2442 }
2443
2444 // Tests that we can still handle the sdp uses mslabel and label instead of
2445 // msid for backward compatibility.
2446 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
2447 jdesc_.description()->set_msid_supported(false);
2448 JsepSessionDescription jdesc(kDummyString);
2449 std::string sdp_without_msid = kSdpFullString;
2450 Replace("msid", "xmsid", &sdp_without_msid);
2451 // Deserialize
2452 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2453 // Verify
2454 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2455 }
2456
2457 TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2458 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2459
2460 std::string sdp = kSdpOneCandidate;
2461 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2462 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2463 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2464 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2465 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2466
2467 // Candidate line without generation extension.
2468 sdp = kSdpOneCandidate;
2469 Replace(" generation 2", "", &sdp);
2470 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2471 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2472 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2473 Candidate expected = jcandidate_->candidate();
2474 expected.set_generation(0);
2475 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2476
2477 // Candidate with network id and/or cost.
2478 sdp = kSdpOneCandidate;
2479 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2480 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2481 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2482 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2483 expected = jcandidate_->candidate();
2484 expected.set_network_id(2);
2485 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2486 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2487 // Add network cost
2488 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2489 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2490 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2491 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2492
2493 sdp = kSdpTcpActiveCandidate;
2494 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2495 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
2496 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
2497 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2498 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2499 kCandidateFoundation1);
2500 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2501 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
2502 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(
2503 jcandidate_template->candidate()));
2504 sdp = kSdpTcpPassiveCandidate;
2505 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2506 sdp = kSdpTcpSOCandidate;
2507 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2508 }
2509
2510 // This test verifies the deserialization of candidate-attribute
2511 // as per RFC 5245. Candiate-attribute will be of the format
2512 // candidate:<blah>. This format will be used when candidates
2513 // are trickled.
2514 TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2515 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2516
2517 std::string candidate_attribute = kRawCandidate;
2518 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2519 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2520 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2521 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2522 EXPECT_EQ(2u, jcandidate.candidate().generation());
2523
2524 // Candidate line without generation extension.
2525 candidate_attribute = kRawCandidate;
2526 Replace(" generation 2", "", &candidate_attribute);
2527 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2528 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2529 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2530 Candidate expected = jcandidate_->candidate();
2531 expected.set_generation(0);
2532 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2533
2534 // Candidate line without candidate:
2535 candidate_attribute = kRawCandidate;
2536 Replace("candidate:", "", &candidate_attribute);
2537 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2538
2539 // Candidate line with IPV6 address.
2540 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
2541 }
2542
2543 // This test verifies that the deserialization of an invalid candidate string
2544 // fails.
2545 TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
2546 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2547
2548 std::string candidate_attribute = kRawCandidate;
2549 candidate_attribute.replace(0, 1, "x");
2550 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2551
2552 candidate_attribute = kSdpOneCandidate;
2553 candidate_attribute.replace(0, 1, "x");
2554 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2555
2556 candidate_attribute = kRawCandidate;
2557 candidate_attribute.append("\r\n");
2558 candidate_attribute.append(kRawCandidate);
2559 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2560
2561 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
2562 }
2563
2564 TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2565 AddRtpDataChannel();
2566 JsepSessionDescription jdesc(kDummyString);
2567 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2568
2569 std::string sdp_with_data = kSdpString;
2570 sdp_with_data.append(kSdpRtpDataChannelString);
2571 JsepSessionDescription jdesc_output(kDummyString);
2572
2573 // Deserialize
2574 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2575 // Verify
2576 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2577 }
2578
2579 TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
2580 AddSctpDataChannel();
2581 JsepSessionDescription jdesc(kDummyString);
2582 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2583
2584 std::string sdp_with_data = kSdpString;
2585 sdp_with_data.append(kSdpSctpDataChannelString);
2586 JsepSessionDescription jdesc_output(kDummyString);
2587
2588 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2589 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2590 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2591
2592 // Verify with UDP/DTLS/SCTP.
2593 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2594 strlen(kDtlsSctp), kUdpDtlsSctp);
2595 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2596 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2597
2598 // Verify with TCP/DTLS/SCTP.
2599 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2600 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
2601 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2602 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2603 }
2604
2605 TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
2606 AddSctpDataChannel();
2607 JsepSessionDescription jdesc(kDummyString);
2608 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2609
2610 std::string sdp_with_data = kSdpString;
2611 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2612 JsepSessionDescription jdesc_output(kDummyString);
2613
2614 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
2615 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2616 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2617
2618 // Verify with UDP/DTLS/SCTP.
2619 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2620 strlen(kDtlsSctp), kUdpDtlsSctp);
2621 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2622 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2623
2624 // Verify with TCP/DTLS/SCTP.
2625 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2626 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
2627 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2628 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2629 }
2630
2631 TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
2632 AddSctpDataChannel();
2633 JsepSessionDescription jdesc(kDummyString);
2634 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2635
2636 std::string sdp_with_data = kSdpString;
2637 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
2638 JsepSessionDescription jdesc_output(kDummyString);
2639
2640 // Verify with DTLS/SCTP.
2641 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2642 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2643
2644 // Verify with UDP/DTLS/SCTP.
2645 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2646 strlen(kDtlsSctp), kUdpDtlsSctp);
2647 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2648 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2649
2650 // Verify with TCP/DTLS/SCTP.
2651 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2652 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
2653 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2654 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2655 }
2656
2657 // Test to check the behaviour if sctp-port is specified
2658 // on the m= line and in a=sctp-port.
2659 TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
2660 AddSctpDataChannel();
2661 JsepSessionDescription jdesc(kDummyString);
2662 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2663
2664 std::string sdp_with_data = kSdpString;
2665 // Append m= attributes
2666 sdp_with_data.append(kSdpSctpDataChannelString);
2667 // Append a=sctp-port attribute
2668 sdp_with_data.append("a=sctp-port 5000\r\n");
2669 JsepSessionDescription jdesc_output(kDummyString);
2670
2671 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2672 }
2673
2674 // For crbug/344475.
2675 TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2676 std::string sdp_with_data = kSdpString;
2677 sdp_with_data.append(kSdpSctpDataChannelString);
2678 // Remove the "\n" at the end.
2679 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
2680 JsepSessionDescription jdesc_output(kDummyString);
2681
2682 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2683 // No crash is a pass.
2684 }
2685
2686 TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndNewPort) {
2687 AddSctpDataChannel();
2688 const uint16_t kUnusualSctpPort = 9556;
2689 char default_portstr[16];
2690 char unusual_portstr[16];
2691 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
2692 kDefaultSctpPort);
2693 rtc::sprintfn(unusual_portstr, sizeof(unusual_portstr), "%d",
2694 kUnusualSctpPort);
2695
2696 // First setup the expected JsepSessionDescription.
2697 JsepSessionDescription jdesc(kDummyString);
2698 // take our pre-built session description and change the SCTP port.
2699 cricket::SessionDescription* mutant = desc_.Copy();
2700 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
2701 mutant->GetContentDescriptionByName(kDataContentName));
2702 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
2703 EXPECT_EQ(1U, codecs.size());
2704 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, codecs[0].id);
2705 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
2706 dcdesc->set_codecs(codecs);
2707
2708 // note: mutant's owned by jdesc now.
2709 ASSERT_TRUE(jdesc.Initialize(mutant, kSessionId, kSessionVersion));
2710 mutant = NULL;
2711
2712 // Then get the deserialized JsepSessionDescription.
2713 std::string sdp_with_data = kSdpString;
2714 sdp_with_data.append(kSdpSctpDataChannelString);
2715 rtc::replace_substrs(default_portstr, strlen(default_portstr),
2716 unusual_portstr, strlen(unusual_portstr),
2717 &sdp_with_data);
2718 JsepSessionDescription jdesc_output(kDummyString);
2719
2720 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2721 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2722
2723 // We need to test the deserialized JsepSessionDescription from
2724 // kSdpSctpDataChannelStringWithSctpPort for
2725 // draft-ietf-mmusic-sctp-sdp-07
2726 // a=sctp-port
2727 sdp_with_data = kSdpString;
2728 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2729 rtc::replace_substrs(default_portstr, strlen(default_portstr),
2730 unusual_portstr, strlen(unusual_portstr),
2731 &sdp_with_data);
2732
2733 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2734 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2735 }
2736
2737 TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
2738 // We want to test that deserializing data content limits bandwidth
2739 // settings (it should never be greater than the default).
2740 // This should prevent someone from using unlimited data bandwidth through
2741 // JS and "breaking the Internet".
2742 // See: https://code.google.com/p/chromium/issues/detail?id=280726
2743 std::string sdp_with_bandwidth = kSdpString;
2744 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
2745 InjectAfter("a=mid:data_content_name\r\n",
2746 "b=AS:100\r\n",
2747 &sdp_with_bandwidth);
2748 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2749
2750 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2751 }
2752
2753 TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
2754 AddSctpDataChannel();
2755 JsepSessionDescription jdesc(kDummyString);
2756 DataContentDescription* dcd = static_cast<DataContentDescription*>(
2757 GetFirstDataContent(&desc_)->description);
2758 dcd->set_bandwidth(100 * 1000);
2759 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2760
2761 std::string sdp_with_bandwidth = kSdpString;
2762 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
2763 InjectAfter("a=mid:data_content_name\r\n",
2764 "b=AS:100\r\n",
2765 &sdp_with_bandwidth);
2766 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2767
2768 // SCTP has congestion control, so we shouldn't limit the bandwidth
2769 // as we do for RTP.
2770 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2771 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2772 }
2773
2774 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSessionLevelExtmap) {
2775 TestDeserializeExtmap(true, false);
2776 }
2777
2778 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
2779 TestDeserializeExtmap(false, true);
2780 }
2781
2782 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInvalidExtmap) {
2783 TestDeserializeExtmap(true, true);
2784 }
2785
2786 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
2787 JsepSessionDescription jdesc(kDummyString);
2788 std::string sdp = kSdpFullString;
2789 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2790 // Deserialize
2791 SdpParseError error;
2792 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
2793 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
2794 EXPECT_EQ(lastline, error.line);
2795 EXPECT_EQ("Invalid SDP line.", error.description);
2796 }
2797
2798 TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2799 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2800 std::string new_sdp = kSdpOneCandidate;
2801 Replace("udp", "unsupported_transport", &new_sdp);
2802 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2803 new_sdp = kSdpOneCandidate;
2804 Replace("udp", "uDP", &new_sdp);
2805 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2806 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2807 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2808 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2809 }
2810
2811 TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
2812 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2813 EXPECT_TRUE(
2814 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
2815 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2816 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2817 Candidate ref_candidate = jcandidate_->candidate();
2818 ref_candidate.set_username("user_rtp");
2819 ref_candidate.set_password("password_rtp");
2820 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2821 }
2822
2823 TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
2824 JsepSessionDescription jdesc(kDummyString);
2825
2826 // Deserialize
2827 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2828
2829 // Verify
2830 cricket::AudioContentDescription* audio =
2831 static_cast<AudioContentDescription*>(
2832 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2833 EXPECT_TRUE(audio->conference_mode());
2834
2835 cricket::VideoContentDescription* video =
2836 static_cast<VideoContentDescription*>(
2837 jdesc.description()->GetContentDescriptionByName(cricket::CN_VIDEO));
2838 EXPECT_TRUE(video->conference_mode());
2839 }
2840
2841 TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2842 const char kSdpDestroyer[] = "!@#$%^&";
2843 const char kSdpEmptyType[] = " =candidate";
2844 const char kSdpEqualAsPlus[] = "a+candidate";
2845 const char kSdpSpaceAfterEqual[] = "a= candidate";
2846 const char kSdpUpperType[] = "A=candidate";
2847 const char kSdpEmptyLine[] = "";
2848 const char kSdpMissingValue[] = "a=";
2849
2850 const char kSdpBrokenFingerprint[] = "a=fingerprint:sha-1 "
2851 "4AAD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB";
2852 const char kSdpExtraField[] = "a=fingerprint:sha-1 "
2853 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB XXX";
2854 const char kSdpMissingSpace[] = "a=fingerprint:sha-1"
2855 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB";
2856 // MD5 is not allowed in fingerprints.
2857 const char kSdpMd5[] = "a=fingerprint:md5 "
2858 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
2859
2860 // Broken session description
2861 ExpectParseFailure("v=", kSdpDestroyer);
2862 ExpectParseFailure("o=", kSdpDestroyer);
2863 ExpectParseFailure("s=-", kSdpDestroyer);
2864 // Broken time description
2865 ExpectParseFailure("t=", kSdpDestroyer);
2866
2867 // Broken media description
2868 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2869 ExpectParseFailure("m=video", kSdpDestroyer);
2870
2871 // Invalid lines
2872 ExpectParseFailure("a=candidate", kSdpEmptyType);
2873 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2874 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
2875 ExpectParseFailure("a=candidate", kSdpUpperType);
2876
2877 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2878 // because it's orthogonal to what we are replacing and hence
2879 // safe.
2880 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
2881 ExpectParseFailure("a=sendrecv", kSdpExtraField);
2882 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
2883 ExpectParseFailure("a=sendrecv", kSdpMd5);
2884
2885 // Empty Line
2886 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
2887 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
2888 }
2889
2890 TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2891 // ssrc
2892 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
2893 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
2894 // crypto
2895 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
2896 // rtpmap
2897 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
2898 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
2899 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
2900 // candidate
2901 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
2902 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
2903 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
2904 ExpectParseFailure("rport 2346", "rport badvalue");
2905 ExpectParseFailure("rport 2346 generation 2",
2906 "rport 2346 generation badvalue");
2907 // m line
2908 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
2909 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
2910
2911 // bandwidth
2912 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2913 "b=AS:badvalue\r\n",
2914 "b=AS:badvalue");
2915 // rtcp-fb
2916 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2917 "a=rtcp-fb:badvalue nack\r\n",
2918 "a=rtcp-fb:badvalue nack");
2919 // extmap
2920 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2921 "a=extmap:badvalue http://example.com\r\n",
2922 "a=extmap:badvalue http://example.com");
2923 }
2924
2925 TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
2926 JsepSessionDescription jdesc_output(kDummyString);
2927
2928 const char kSdpWithReorderedPlTypesString[] =
2929 "v=0\r\n"
2930 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2931 "s=-\r\n"
2932 "t=0 0\r\n"
2933 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
2934 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
2935 // in the map.
2936 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
2937 "a=rtpmap:104 ISAC/32000\r\n";
2938
2939 // Deserialize
2940 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
2941
2942 const ContentInfo* ac = GetFirstAudioContent(jdesc_output.description());
2943 ASSERT_TRUE(ac != NULL);
2944 const AudioContentDescription* acd =
2945 static_cast<const AudioContentDescription*>(ac->description);
2946 ASSERT_FALSE(acd->codecs().empty());
2947 EXPECT_EQ("ISAC", acd->codecs()[0].name);
2948 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
2949 EXPECT_EQ(104, acd->codecs()[0].id);
2950 }
2951
2952 TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
2953 JsepSessionDescription jdesc_output(kDummyString);
2954 CodecParams params;
2955 params.max_ptime = 40;
2956 params.ptime = 30;
2957 params.min_ptime = 10;
2958 params.sprop_stereo = 1;
2959 params.stereo = 1;
2960 params.useinband = 1;
2961 params.maxaveragebitrate = 128000;
2962 TestDeserializeCodecParams(params, &jdesc_output);
2963 TestSerialize(jdesc_output, false);
2964 }
2965
2966 TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
2967 const bool kUseWildcard = false;
2968 JsepSessionDescription jdesc_output(kDummyString);
2969 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
2970 TestSerialize(jdesc_output, false);
2971 }
2972
2973 TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
2974 const bool kUseWildcard = true;
2975 JsepSessionDescription jdesc_output(kDummyString);
2976 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
2977 TestSerialize(jdesc_output, false);
2978 }
2979
2980 TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
2981 JsepSessionDescription jdesc_output(kDummyString);
2982
2983 const char kSdpWithFmtpString[] =
2984 "v=0\r\n"
2985 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2986 "s=-\r\n"
2987 "t=0 0\r\n"
2988 "m=video 3457 RTP/SAVPF 120\r\n"
2989 "a=rtpmap:120 VP8/90000\r\n"
2990 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
2991
2992 // Deserialize
2993 SdpParseError error;
2994 EXPECT_TRUE(
2995 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
2996
2997 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2998 ASSERT_TRUE(vc != NULL);
2999 const VideoContentDescription* vcd =
3000 static_cast<const VideoContentDescription*>(vc->description);
3001 ASSERT_FALSE(vcd->codecs().empty());
3002 cricket::VideoCodec vp8 = vcd->codecs()[0];
3003 EXPECT_EQ("VP8", vp8.name);
3004 EXPECT_EQ(120, vp8.id);
3005 cricket::CodecParameterMap::iterator found =
3006 vp8.params.find("x-google-min-bitrate");
3007 ASSERT_TRUE(found != vp8.params.end());
3008 EXPECT_EQ(found->second, "10");
3009 found = vp8.params.find("x-google-max-quantization");
3010 ASSERT_TRUE(found != vp8.params.end());
3011 EXPECT_EQ(found->second, "40");
3012 }
3013
3014 TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
3015 JsepSessionDescription jdesc_output(kDummyString);
3016
3017 const char kSdpWithFmtpString[] =
3018 "v=0\r\n"
3019 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3020 "s=-\r\n"
3021 "t=0 0\r\n"
3022 "m=video 49170 RTP/AVP 98\r\n"
3023 "a=rtpmap:98 H264/90000\r\n"
3024 "a=fmtp:98 profile-level-id=42A01E; "
3025 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3026
3027 // Deserialize.
3028 SdpParseError error;
3029 EXPECT_TRUE(
3030 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3031
3032 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
3033 ASSERT_TRUE(vc != NULL);
3034 const VideoContentDescription* vcd =
3035 static_cast<const VideoContentDescription*>(vc->description);
3036 ASSERT_TRUE(vcd != NULL);
3037 ASSERT_FALSE(vcd->codecs().empty());
3038 cricket::VideoCodec h264 = vcd->codecs()[0];
3039 EXPECT_EQ("H264", h264.name);
3040 EXPECT_EQ(98, h264.id);
3041 cricket::CodecParameterMap::const_iterator found =
3042 h264.params.find("profile-level-id");
3043 ASSERT_TRUE(found != h264.params.end());
3044 EXPECT_EQ(found->second, "42A01E");
3045 found = h264.params.find("sprop-parameter-sets");
3046 ASSERT_TRUE(found != h264.params.end());
3047 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3048 }
3049
3050 TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
3051 JsepSessionDescription jdesc_output(kDummyString);
3052
3053 const char kSdpWithFmtpString[] =
3054 "v=0\r\n"
3055 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3056 "s=-\r\n"
3057 "t=0 0\r\n"
3058 "m=video 3457 RTP/SAVPF 120\r\n"
3059 "a=rtpmap:120 VP8/90000\r\n"
3060 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
3061
3062 // Deserialize
3063 SdpParseError error;
3064 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output,
3065 &error));
3066
3067 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
3068 ASSERT_TRUE(vc != NULL);
3069 const VideoContentDescription* vcd =
3070 static_cast<const VideoContentDescription*>(vc->description);
3071 ASSERT_FALSE(vcd->codecs().empty());
3072 cricket::VideoCodec vp8 = vcd->codecs()[0];
3073 EXPECT_EQ("VP8", vp8.name);
3074 EXPECT_EQ(120, vp8.id);
3075 cricket::CodecParameterMap::iterator found =
3076 vp8.params.find("x-google-min-bitrate");
3077 ASSERT_TRUE(found != vp8.params.end());
3078 EXPECT_EQ(found->second, "10");
3079 found = vp8.params.find("x-google-max-quantization");
3080 ASSERT_TRUE(found != vp8.params.end());
3081 EXPECT_EQ(found->second, "40");
3082 }
3083
3084 TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
3085 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
3086 GetFirstVideoContent(&desc_)->description);
3087
3088 cricket::VideoCodecs codecs = vcd->codecs();
3089 codecs[0].params["x-google-min-bitrate"] = "10";
3090 vcd->set_codecs(codecs);
3091
3092 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3093 jdesc_.session_id(),
3094 jdesc_.session_version()));
3095 std::string message = webrtc::SdpSerialize(jdesc_, false);
3096 std::string sdp_with_fmtp = kSdpFullString;
3097 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
3098 "a=fmtp:120 x-google-min-bitrate=10\r\n",
3099 &sdp_with_fmtp);
3100 EXPECT_EQ(sdp_with_fmtp, message);
3101 }
3102
3103 TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) {
3104 JsepSessionDescription jdesc_with_icelite(kDummyString);
3105 std::string sdp_with_icelite = kSdpFullString;
3106 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3107 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3108 const cricket::TransportInfo* tinfo1 =
3109 desc->GetTransportInfoByName("audio_content_name");
3110 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3111 const cricket::TransportInfo* tinfo2 =
3112 desc->GetTransportInfoByName("video_content_name");
3113 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
3114 InjectAfter(kSessionTime,
3115 "a=ice-lite\r\n",
3116 &sdp_with_icelite);
3117 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3118 desc = jdesc_with_icelite.description();
3119 const cricket::TransportInfo* atinfo =
3120 desc->GetTransportInfoByName("audio_content_name");
3121 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3122 const cricket::TransportInfo* vtinfo =
3123 desc->GetTransportInfoByName("video_content_name");
3124 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
3125 }
3126
3127 // Verifies that the candidates in the input SDP are parsed and serialized
3128 // correctly in the output SDP.
3129 TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3130 std::string sdp_with_data = kSdpString;
3131 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
3132 JsepSessionDescription jdesc_output(kDummyString);
3133
3134 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3135 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output, false));
3136 }
3137
3138 TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3139 AddFingerprint();
3140 TransportInfo audio_transport_info =
3141 *(desc_.GetTransportInfoByName(kAudioContentName));
3142 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3143 audio_transport_info.description.connection_role);
3144 audio_transport_info.description.connection_role =
3145 cricket::CONNECTIONROLE_ACTIVE;
3146
3147 TransportInfo video_transport_info =
3148 *(desc_.GetTransportInfoByName(kVideoContentName));
3149 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3150 video_transport_info.description.connection_role);
3151 video_transport_info.description.connection_role =
3152 cricket::CONNECTIONROLE_ACTIVE;
3153
3154 desc_.RemoveTransportInfoByName(kAudioContentName);
3155 desc_.RemoveTransportInfoByName(kVideoContentName);
3156
3157 desc_.AddTransportInfo(audio_transport_info);
3158 desc_.AddTransportInfo(video_transport_info);
3159
3160 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3161 jdesc_.session_id(),
3162 jdesc_.session_version()));
3163 std::string message = webrtc::SdpSerialize(jdesc_, false);
3164 std::string sdp_with_dtlssetup = kSdpFullString;
3165
3166 // Fingerprint attribute is necessary to add DTLS setup attribute.
3167 InjectAfter(kAttributeIcePwdVoice,
3168 kFingerprint, &sdp_with_dtlssetup);
3169 InjectAfter(kAttributeIcePwdVideo,
3170 kFingerprint, &sdp_with_dtlssetup);
3171 // Now adding |setup| attribute.
3172 InjectAfter(kFingerprint,
3173 "a=setup:active\r\n", &sdp_with_dtlssetup);
3174 EXPECT_EQ(sdp_with_dtlssetup, message);
3175 }
3176
3177 TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
3178 JsepSessionDescription jdesc_with_dtlssetup(kDummyString);
3179 std::string sdp_with_dtlssetup = kSdpFullString;
3180 InjectAfter(kSessionTime,
3181 "a=setup:actpass\r\n",
3182 &sdp_with_dtlssetup);
3183 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3184 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3185 const cricket::TransportInfo* atinfo =
3186 desc->GetTransportInfoByName("audio_content_name");
3187 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3188 atinfo->description.connection_role);
3189 const cricket::TransportInfo* vtinfo =
3190 desc->GetTransportInfoByName("video_content_name");
3191 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3192 vtinfo->description.connection_role);
3193 }
3194
3195 // Verifies that the order of the serialized m-lines follows the order of the
3196 // ContentInfo in SessionDescription, and vise versa for deserialization.
3197 TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
3198 JsepSessionDescription jdesc(kDummyString);
3199 const std::string media_content_sdps[3] = {
3200 kSdpAudioString,
3201 kSdpVideoString,
3202 kSdpSctpDataChannelString
3203 };
3204 const cricket::MediaType media_types[3] = {
3205 cricket::MEDIA_TYPE_AUDIO,
3206 cricket::MEDIA_TYPE_VIDEO,
3207 cricket::MEDIA_TYPE_DATA
3208 };
3209
3210 // Verifies all 6 permutations.
3211 for (size_t i = 0; i < 6; ++i) {
3212 size_t media_content_in_sdp[3];
3213 // The index of the first media content.
3214 media_content_in_sdp[0] = i / 2;
3215 // The index of the second media content.
3216 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3217 // The index of the third media content.
3218 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3219
3220 std::string sdp_string = kSdpSessionString;
3221 for (size_t i = 0; i < 3; ++i)
3222 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3223
3224 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3225 cricket::SessionDescription* desc = jdesc.description();
3226 EXPECT_EQ(3u, desc->contents().size());
3227
3228 for (size_t i = 0; i < 3; ++i) {
3229 const cricket::MediaContentDescription* mdesc =
3230 static_cast<const cricket::MediaContentDescription*>(
3231 desc->contents()[i].description);
3232 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3233 }
3234
3235 std::string serialized_sdp = webrtc::SdpSerialize(jdesc, false);
3236 EXPECT_EQ(sdp_string, serialized_sdp);
3237 }
3238 }
3239
3240 TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3241 MakeBundleOnlyDescription();
3242 JsepSessionDescription deserialized_description(kDummyString);
3243 ASSERT_TRUE(
3244 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3245 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3246 }
3247
3248 // The semantics of "a=bundle-only" are only defined when it's used in
3249 // combination with a 0 port on the m= line. We should ignore it if used with a
3250 // nonzero port.
3251 TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3252 // Make the base bundle-only description but unset the bundle-only flag.
3253 MakeBundleOnlyDescription();
3254 jdesc_.description()->contents()[1].bundle_only = false;
3255
3256 std::string modified_sdp = kBundleOnlySdpFullString;
3257 Replace("m=video 0", "m=video 9", &modified_sdp);
3258 JsepSessionDescription deserialized_description(kDummyString);
3259 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3260 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3261 }
3262
3263 TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3264 MakeBundleOnlyDescription();
3265 TestSerialize(jdesc_, false);
3266 }
3267
3268 TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3269 MakePlanBDescription();
3270
3271 JsepSessionDescription deserialized_description(kDummyString);
3272 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3273
3274 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3275 }
3276
3277 TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3278 MakePlanBDescription();
3279 TestSerialize(jdesc_, false);
3280 }
3281
3282 // Some WebRTC endpoints include the msid in both the Plan B and Unified Plan
3283 // ways, to make SDP that's compatible with both Plan B and Unified Plan (to
3284 // some extent). If we parse this, the Plan B msid attribute (which is more
3285 // specific, since it's at the SSRC level) should take priority.
3286 TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescriptionWithMsid) {
3287 MakePlanBDescription();
3288
3289 JsepSessionDescription deserialized_description(kDummyString);
3290 EXPECT_TRUE(
3291 SdpDeserialize(kPlanBSdpFullStringWithMsid, &deserialized_description));
3292
3293 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3294 }
3295
3296 TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3297 MakeUnifiedPlanDescription();
3298
3299 JsepSessionDescription deserialized_description(kDummyString);
3300 EXPECT_TRUE(
3301 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3302
3303 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3304 }
3305
3306 TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3307 MakeUnifiedPlanDescription();
3308 TestSerialize(jdesc_, true);
3309 }
3310
3311 // Regression test for heap overflow bug:
3312 // https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3313 TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
3314 // The issue occurs when the sctp-port attribute is found in a video
3315 // description. The actual heap overflow occurs when parsing the fmtp line.
3316 static const char kSdpWithSctpPortInVideoDescription[] =
3317 "v=0\r\n"
3318 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3319 "s=-\r\n"
3320 "t=0 0\r\n"
3321 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3322 "a=sctp-port 5000\r\n"
3323 "a=fmtp:108 foo=10\r\n";
3324
3325 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3326 "sctp-port");
3327 }
3328
3329 // Regression test for integer overflow bug:
3330 // https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3331 TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
3332 // Bandwidth attribute is the max signed 32-bit int, which will get
3333 // multiplied by 1000 and cause int overflow if not careful.
3334 static const char kSdpWithLargeBandwidth[] =
3335 "v=0\r\n"
3336 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3337 "s=-\r\n"
3338 "t=0 0\r\n"
3339 "m=video 3457 RTP/SAVPF 120\r\n"
3340 "b=AS:2147483647\r\n"
3341 "foo=fail\r\n";
3342
3343 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3344 }
3345
3346 // Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3347 // the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3348 // Regression test for:
3349 // https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3350 TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3351 // Important piece is "ufrag foo pwd bar".
3352 static const char kSdpWithIceCredentialsInCandidateString[] =
3353 "v=0\r\n"
3354 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3355 "s=-\r\n"
3356 "t=0 0\r\n"
3357 "m=audio 9 RTP/SAVPF 111\r\n"
3358 "c=IN IP4 0.0.0.0\r\n"
3359 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3360 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3361 "a=rtpmap:111 opus/48000/2\r\n"
3362 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3363 "generation 2 ufrag foo pwd bar\r\n";
3364
3365 JsepSessionDescription jdesc_output(kDummyString);
3366 EXPECT_TRUE(
3367 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
3368 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3369 ASSERT_NE(nullptr, candidates);
3370 ASSERT_EQ(1, candidates->count());
3371 cricket::Candidate c = candidates->at(0)->candidate();
3372 EXPECT_EQ("ufrag_voice", c.username());
3373 EXPECT_EQ("pwd_voice", c.password());
3374 }
OLDNEW
« no previous file with comments | « webrtc/api/webrtcsdp.cc ('k') | webrtc/api/webrtcsession.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698