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