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