blob: 6f2e3883571d34dac1d6724fc1546fdd5e6f3a41 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
3 * Copyright 2011, Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <set>
29#include <string>
30#include <vector>
31
32#include "talk/app/webrtc/jsepsessiondescription.h"
33#include "talk/app/webrtc/webrtcsdp.h"
34#include "talk/base/gunit.h"
35#include "talk/base/logging.h"
36#include "talk/base/messagedigest.h"
37#include "talk/base/scoped_ptr.h"
38#include "talk/base/sslfingerprint.h"
39#include "talk/base/stringencode.h"
40#include "talk/base/stringutils.h"
41#include "talk/media/base/constants.h"
42#include "talk/p2p/base/constants.h"
43#include "talk/session/media/mediasession.h"
44
45using cricket::AudioCodec;
46using cricket::AudioContentDescription;
47using cricket::Candidate;
48using cricket::ContentInfo;
49using cricket::CryptoParams;
50using cricket::ContentGroup;
51using cricket::DataCodec;
52using cricket::DataContentDescription;
53using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
54using cricket::ICE_CANDIDATE_COMPONENT_RTP;
55using cricket::kFecSsrcGroupSemantics;
56using cricket::LOCAL_PORT_TYPE;
57using cricket::NS_JINGLE_DRAFT_SCTP;
58using cricket::NS_JINGLE_ICE_UDP;
59using cricket::NS_JINGLE_RTP;
60using cricket::RtpHeaderExtension;
61using cricket::RELAY_PORT_TYPE;
62using cricket::SessionDescription;
63using cricket::StreamParams;
64using cricket::STUN_PORT_TYPE;
65using cricket::TransportDescription;
66using cricket::TransportInfo;
67using cricket::VideoCodec;
68using cricket::VideoContentDescription;
69using webrtc::IceCandidateCollection;
70using webrtc::IceCandidateInterface;
71using webrtc::JsepIceCandidate;
72using webrtc::JsepSessionDescription;
73using webrtc::SdpParseError;
74using webrtc::SessionDescriptionInterface;
75
76typedef std::vector<AudioCodec> AudioCodecs;
77typedef std::vector<Candidate> Candidates;
78
wu@webrtc.org78187522013-10-07 23:32:02 +000079static const uint32 kDefaultSctpPort = 5000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080static const char kSessionTime[] = "t=0 0\r\n";
81static const uint32 kCandidatePriority = 2130706432U; // pref = 1.0
82static const char kCandidateUfragVoice[] = "ufrag_voice";
83static const char kCandidatePwdVoice[] = "pwd_voice";
84static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
85static const char kCandidateUfragVideo[] = "ufrag_video";
86static const char kCandidatePwdVideo[] = "pwd_video";
87static const char kCandidateUfragData[] = "ufrag_data";
88static const char kCandidatePwdData[] = "pwd_data";
89static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
90static const uint32 kCandidateGeneration = 2;
91static const char kCandidateFoundation1[] = "a0+B/1";
92static const char kCandidateFoundation2[] = "a0+B/2";
93static const char kCandidateFoundation3[] = "a0+B/3";
94static const char kCandidateFoundation4[] = "a0+B/4";
95static const char kAttributeCryptoVoice[] =
96 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
97 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
98 "dummy_session_params\r\n";
99static const char kAttributeCryptoVideo[] =
100 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
101 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
102static const char kFingerprint[] = "a=fingerprint:sha-1 "
103 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n";
104static const int kExtmapId = 1;
105static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
106static const char kExtmap[] =
107 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
108static const char kExtmapWithDirectionAndAttribute[] =
109 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
110
111static const uint8 kIdentityDigest[] = {0x4A, 0xAD, 0xB9, 0xB1,
112 0x3F, 0x82, 0x18, 0x3B,
113 0x54, 0x02, 0x12, 0xDF,
114 0x3E, 0x5D, 0x49, 0x6B,
115 0x19, 0xE5, 0x7C, 0xAB};
116
117struct CodecParams {
118 int max_ptime;
119 int ptime;
120 int min_ptime;
121 int sprop_stereo;
122 int stereo;
123 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000124 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125};
126
127// Reference sdp string
128static const char kSdpFullString[] =
129 "v=0\r\n"
130 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
131 "s=-\r\n"
132 "t=0 0\r\n"
133 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
134 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
135 "c=IN IP4 74.125.127.126\r\n"
136 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
137 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
138 "generation 2\r\n"
139 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
140 "generation 2\r\n"
141 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
142 "generation 2\r\n"
143 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
144 "generation 2\r\n"
145 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
146 "raddr 192.168.1.5 rport 2346 "
147 "generation 2\r\n"
148 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
149 "raddr 192.168.1.5 rport 2348 "
150 "generation 2\r\n"
151 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
152 "a=mid:audio_content_name\r\n"
153 "a=sendrecv\r\n"
154 "a=rtcp-mux\r\n"
155 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
156 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
157 "dummy_session_params\r\n"
158 "a=rtpmap:111 opus/48000/2\r\n"
159 "a=rtpmap:103 ISAC/16000\r\n"
160 "a=rtpmap:104 CELT/32000/2\r\n"
161 "a=ssrc:1 cname:stream_1_cname\r\n"
162 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
163 "a=ssrc:1 mslabel:local_stream_1\r\n"
164 "a=ssrc:1 label:audio_track_id_1\r\n"
165 "a=ssrc:4 cname:stream_2_cname\r\n"
166 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
167 "a=ssrc:4 mslabel:local_stream_2\r\n"
168 "a=ssrc:4 label:audio_track_id_2\r\n"
169 "m=video 3457 RTP/SAVPF 120\r\n"
170 "c=IN IP4 74.125.224.39\r\n"
171 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
172 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
173 "generation 2\r\n"
174 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
175 "generation 2\r\n"
176 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
177 "generation 2\r\n"
178 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
179 "generation 2\r\n"
180 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
181 "generation 2\r\n"
182 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
183 "generation 2\r\n"
184 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
185 "a=mid:video_content_name\r\n"
186 "a=sendrecv\r\n"
187 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
188 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
189 "a=rtpmap:120 VP8/90000\r\n"
190 "a=ssrc:2 cname:stream_1_cname\r\n"
191 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
192 "a=ssrc:2 mslabel:local_stream_1\r\n"
193 "a=ssrc:2 label:video_track_id_1\r\n"
194 "a=ssrc:3 cname:stream_1_cname\r\n"
195 "a=ssrc:3 msid:local_stream_1 video_track_id_2\r\n"
196 "a=ssrc:3 mslabel:local_stream_1\r\n"
197 "a=ssrc:3 label:video_track_id_2\r\n"
198 "a=ssrc-group:FEC 5 6\r\n"
199 "a=ssrc:5 cname:stream_2_cname\r\n"
200 "a=ssrc:5 msid:local_stream_2 video_track_id_3\r\n"
201 "a=ssrc:5 mslabel:local_stream_2\r\n"
202 "a=ssrc:5 label:video_track_id_3\r\n"
203 "a=ssrc:6 cname:stream_2_cname\r\n"
204 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
205 "a=ssrc:6 mslabel:local_stream_2\r\n"
206 "a=ssrc:6 label:video_track_id_3\r\n";
207
208// SDP reference string without the candidates.
209static const char kSdpString[] =
210 "v=0\r\n"
211 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
212 "s=-\r\n"
213 "t=0 0\r\n"
214 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
215 "m=audio 1 RTP/SAVPF 111 103 104\r\n"
216 "c=IN IP4 0.0.0.0\r\n"
217 "a=rtcp:1 IN IP4 0.0.0.0\r\n"
218 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
219 "a=mid:audio_content_name\r\n"
220 "a=sendrecv\r\n"
221 "a=rtcp-mux\r\n"
222 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
223 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
224 "dummy_session_params\r\n"
225 "a=rtpmap:111 opus/48000/2\r\n"
226 "a=rtpmap:103 ISAC/16000\r\n"
227 "a=rtpmap:104 CELT/32000/2\r\n"
228 "a=ssrc:1 cname:stream_1_cname\r\n"
229 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
230 "a=ssrc:1 mslabel:local_stream_1\r\n"
231 "a=ssrc:1 label:audio_track_id_1\r\n"
232 "a=ssrc:4 cname:stream_2_cname\r\n"
233 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
234 "a=ssrc:4 mslabel:local_stream_2\r\n"
235 "a=ssrc:4 label:audio_track_id_2\r\n"
236 "m=video 1 RTP/SAVPF 120\r\n"
237 "c=IN IP4 0.0.0.0\r\n"
238 "a=rtcp:1 IN IP4 0.0.0.0\r\n"
239 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
240 "a=mid:video_content_name\r\n"
241 "a=sendrecv\r\n"
242 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
243 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
244 "a=rtpmap:120 VP8/90000\r\n"
245 "a=ssrc:2 cname:stream_1_cname\r\n"
246 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
247 "a=ssrc:2 mslabel:local_stream_1\r\n"
248 "a=ssrc:2 label:video_track_id_1\r\n"
249 "a=ssrc:3 cname:stream_1_cname\r\n"
250 "a=ssrc:3 msid:local_stream_1 video_track_id_2\r\n"
251 "a=ssrc:3 mslabel:local_stream_1\r\n"
252 "a=ssrc:3 label:video_track_id_2\r\n"
253 "a=ssrc-group:FEC 5 6\r\n"
254 "a=ssrc:5 cname:stream_2_cname\r\n"
255 "a=ssrc:5 msid:local_stream_2 video_track_id_3\r\n"
256 "a=ssrc:5 mslabel:local_stream_2\r\n"
257 "a=ssrc:5 label:video_track_id_3\r\n"
258 "a=ssrc:6 cname:stream_2_cname\r\n"
259 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
260 "a=ssrc:6 mslabel:local_stream_2\r\n"
261 "a=ssrc:6 label:video_track_id_3\r\n";
262
263static const char kSdpRtpDataChannelString[] =
264 "m=application 1 RTP/SAVPF 101\r\n"
265 "c=IN IP4 0.0.0.0\r\n"
266 "a=rtcp:1 IN IP4 0.0.0.0\r\n"
267 "a=ice-ufrag:ufrag_data\r\n"
268 "a=ice-pwd:pwd_data\r\n"
269 "a=mid:data_content_name\r\n"
270 "a=sendrecv\r\n"
271 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
272 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
273 "a=rtpmap:101 google-data/90000\r\n"
274 "a=ssrc:10 cname:data_channel_cname\r\n"
275 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
276 "a=ssrc:10 mslabel:data_channel\r\n"
277 "a=ssrc:10 label:data_channeld0\r\n";
278
279static const char kSdpSctpDataChannelString[] =
280 "m=application 1 DTLS/SCTP 5000\r\n"
281 "c=IN IP4 0.0.0.0\r\n"
282 "a=ice-ufrag:ufrag_data\r\n"
283 "a=ice-pwd:pwd_data\r\n"
284 "a=mid:data_content_name\r\n"
wu@webrtc.org78187522013-10-07 23:32:02 +0000285 "a=sctpmap:5000 webrtc-datachannel 65536\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000286
287static const char kSdpSctpDataChannelWithCandidatesString[] =
288 "m=application 2345 DTLS/SCTP 5000\r\n"
289 "c=IN IP4 74.125.127.126\r\n"
290 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
291 "generation 2\r\n"
292 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
293 "generation 2\r\n"
294 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
295 "raddr 192.168.1.5 rport 2346 "
296 "generation 2\r\n"
297 "a=ice-ufrag:ufrag_data\r\n"
298 "a=ice-pwd:pwd_data\r\n"
299 "a=mid:data_content_name\r\n"
wu@webrtc.org78187522013-10-07 23:32:02 +0000300 "a=sctpmap:5000 webrtc-datachannel 65536\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000301
302
303// One candidate reference string as per W3c spec.
304// candidate:<blah> not a=candidate:<blah>CRLF
305static const char kRawCandidate[] =
306 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
307// One candidate reference string.
308static const char kSdpOneCandidate[] =
309 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
310 "generation 2\r\n";
311
312// One candidate reference string.
313static const char kSdpOneCandidateOldFormat[] =
314 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
315 " eth0 username user_rtp password password_rtp generation 2\r\n";
316
317// Session id and version
318static const char kSessionId[] = "18446744069414584320";
319static const char kSessionVersion[] = "18446462598732840960";
320
321// Ice options
322static const char kIceOption1[] = "iceoption1";
323static const char kIceOption2[] = "iceoption2";
324static const char kIceOption3[] = "iceoption3";
325
326// Content name
327static const char kAudioContentName[] = "audio_content_name";
328static const char kVideoContentName[] = "video_content_name";
329static const char kDataContentName[] = "data_content_name";
330
331// MediaStream 1
332static const char kStreamLabel1[] = "local_stream_1";
333static const char kStream1Cname[] = "stream_1_cname";
334static const char kAudioTrackId1[] = "audio_track_id_1";
335static const uint32 kAudioTrack1Ssrc = 1;
336static const char kVideoTrackId1[] = "video_track_id_1";
337static const uint32 kVideoTrack1Ssrc = 2;
338static const char kVideoTrackId2[] = "video_track_id_2";
339static const uint32 kVideoTrack2Ssrc = 3;
340
341// MediaStream 2
342static const char kStreamLabel2[] = "local_stream_2";
343static const char kStream2Cname[] = "stream_2_cname";
344static const char kAudioTrackId2[] = "audio_track_id_2";
345static const uint32 kAudioTrack2Ssrc = 4;
346static const char kVideoTrackId3[] = "video_track_id_3";
347static const uint32 kVideoTrack3Ssrc = 5;
348static const uint32 kVideoTrack4Ssrc = 6;
349
350// DataChannel
351static const char kDataChannelLabel[] = "data_channel";
352static const char kDataChannelMsid[] = "data_channeld0";
353static const char kDataChannelCname[] = "data_channel_cname";
354static const uint32 kDataChannelSsrc = 10;
355
356// Candidate
357static const char kDummyMid[] = "dummy_mid";
358static const int kDummyIndex = 123;
359
360// Misc
361static const char kDummyString[] = "dummy";
362
363// Helper functions
364
365static bool SdpDeserialize(const std::string& message,
366 JsepSessionDescription* jdesc) {
367 return webrtc::SdpDeserialize(message, jdesc, NULL);
368}
369
370static bool SdpDeserializeCandidate(const std::string& message,
371 JsepIceCandidate* candidate) {
372 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
373}
374
375// Add some extra |newlines| to the |message| after |line|.
376static void InjectAfter(const std::string& line,
377 const std::string& newlines,
378 std::string* message) {
379 const std::string tmp = line + newlines;
380 talk_base::replace_substrs(line.c_str(), line.length(),
381 tmp.c_str(), tmp.length(), message);
382}
383
384static void Replace(const std::string& line,
385 const std::string& newlines,
386 std::string* message) {
387 talk_base::replace_substrs(line.c_str(), line.length(),
388 newlines.c_str(), newlines.length(), message);
389}
390
391static void ReplaceAndTryToParse(const char* search, const char* replace) {
392 JsepSessionDescription desc(kDummyString);
393 std::string sdp = kSdpFullString;
394 Replace(search, replace, &sdp);
395 SdpParseError error;
396 bool ret = webrtc::SdpDeserialize(sdp, &desc, &error);
397 EXPECT_FALSE(ret);
398 EXPECT_NE(std::string::npos, error.line.find(replace));
399}
400
401static void ReplaceDirection(cricket::MediaContentDirection direction,
402 std::string* message) {
403 std::string new_direction;
404 switch (direction) {
405 case cricket::MD_INACTIVE:
406 new_direction = "a=inactive";
407 break;
408 case cricket::MD_SENDONLY:
409 new_direction = "a=sendonly";
410 break;
411 case cricket::MD_RECVONLY:
412 new_direction = "a=recvonly";
413 break;
414 case cricket::MD_SENDRECV:
415 default:
416 new_direction = "a=sendrecv";
417 break;
418 }
419 Replace("a=sendrecv", new_direction, message);
420}
421
422static void ReplaceRejected(bool audio_rejected, bool video_rejected,
423 std::string* message) {
424 if (audio_rejected) {
425 Replace("m=audio 2345", "m=audio 0", message);
426 }
427 if (video_rejected) {
428 Replace("m=video 3457", "m=video 0", message);
429 }
430}
431
432// WebRtcSdpTest
433
434class WebRtcSdpTest : public testing::Test {
435 public:
436 WebRtcSdpTest()
437 : jdesc_(kDummyString) {
438 // AudioContentDescription
439 audio_desc_ = CreateAudioContentDescription();
440 AudioCodec opus(111, "opus", 48000, 0, 2, 3);
441 audio_desc_->AddCodec(opus);
442 audio_desc_->AddCodec(AudioCodec(103, "ISAC", 16000, 32000, 1, 2));
443 audio_desc_->AddCodec(AudioCodec(104, "CELT", 32000, 0, 2, 1));
444 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
445
446 // VideoContentDescription
447 talk_base::scoped_ptr<VideoContentDescription> video(
448 new VideoContentDescription());
449 video_desc_ = video.get();
450 StreamParams video_stream1;
451 video_stream1.id = kVideoTrackId1;
452 video_stream1.cname = kStream1Cname;
453 video_stream1.sync_label = kStreamLabel1;
454 video_stream1.ssrcs.push_back(kVideoTrack1Ssrc);
455 video->AddStream(video_stream1);
456 StreamParams video_stream2;
457 video_stream2.id = kVideoTrackId2;
458 video_stream2.cname = kStream1Cname;
459 video_stream2.sync_label = kStreamLabel1;
460 video_stream2.ssrcs.push_back(kVideoTrack2Ssrc);
461 video->AddStream(video_stream2);
462 StreamParams video_stream3;
463 video_stream3.id = kVideoTrackId3;
464 video_stream3.cname = kStream2Cname;
465 video_stream3.sync_label = kStreamLabel2;
466 video_stream3.ssrcs.push_back(kVideoTrack3Ssrc);
467 video_stream3.ssrcs.push_back(kVideoTrack4Ssrc);
468 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream3.ssrcs);
469 video_stream3.ssrc_groups.push_back(ssrc_group);
470 video->AddStream(video_stream3);
471 video->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
472 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
473 video->set_protocol(cricket::kMediaProtocolSavpf);
474 video->AddCodec(VideoCodec(
475 120,
476 JsepSessionDescription::kDefaultVideoCodecName,
477 JsepSessionDescription::kMaxVideoCodecWidth,
478 JsepSessionDescription::kMaxVideoCodecHeight,
479 JsepSessionDescription::kDefaultVideoCodecFramerate,
480 JsepSessionDescription::kDefaultVideoCodecPreference));
481
482 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP,
483 video.release());
484
485 // TransportInfo
486 EXPECT_TRUE(desc_.AddTransportInfo(
487 TransportInfo(kAudioContentName,
488 TransportDescription(NS_JINGLE_ICE_UDP,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000489 kCandidateUfragVoice,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000490 kCandidatePwdVoice))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000491 EXPECT_TRUE(desc_.AddTransportInfo(
492 TransportInfo(kVideoContentName,
493 TransportDescription(NS_JINGLE_ICE_UDP,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000494 kCandidateUfragVideo,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000495 kCandidatePwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000496
497 // v4 host
498 int port = 1234;
499 talk_base::SocketAddress address("192.168.1.5", port++);
500 Candidate candidate1(
501 "", ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
502 "", "", LOCAL_PORT_TYPE,
503 "", kCandidateGeneration, kCandidateFoundation1);
504 address.SetPort(port++);
505 Candidate candidate2(
506 "", ICE_CANDIDATE_COMPONENT_RTCP, "udp", address, kCandidatePriority,
507 "", "", LOCAL_PORT_TYPE,
508 "", kCandidateGeneration, kCandidateFoundation1);
509 address.SetPort(port++);
510 Candidate candidate3(
511 "", ICE_CANDIDATE_COMPONENT_RTCP, "udp", address, kCandidatePriority,
512 "", "", LOCAL_PORT_TYPE,
513 "", kCandidateGeneration, kCandidateFoundation1);
514 address.SetPort(port++);
515 Candidate candidate4(
516 "", ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
517 "", "", LOCAL_PORT_TYPE,
518 "", kCandidateGeneration, kCandidateFoundation1);
519
520 // v6 host
521 talk_base::SocketAddress v6_address("::1", port++);
522 cricket::Candidate candidate5(
523 "", cricket::ICE_CANDIDATE_COMPONENT_RTP,
524 "udp", v6_address, kCandidatePriority,
525 "", "", cricket::LOCAL_PORT_TYPE,
526 "", kCandidateGeneration, kCandidateFoundation2);
527 v6_address.SetPort(port++);
528 cricket::Candidate candidate6(
529 "", cricket::ICE_CANDIDATE_COMPONENT_RTCP,
530 "udp", v6_address, kCandidatePriority,
531 "", "", cricket::LOCAL_PORT_TYPE,
532 "", kCandidateGeneration, kCandidateFoundation2);
533 v6_address.SetPort(port++);
534 cricket::Candidate candidate7(
535 "", cricket::ICE_CANDIDATE_COMPONENT_RTCP,
536 "udp", v6_address, kCandidatePriority,
537 "", "", cricket::LOCAL_PORT_TYPE,
538 "", kCandidateGeneration, kCandidateFoundation2);
539 v6_address.SetPort(port++);
540 cricket::Candidate candidate8(
541 "", cricket::ICE_CANDIDATE_COMPONENT_RTP,
542 "udp", v6_address, kCandidatePriority,
543 "", "", cricket::LOCAL_PORT_TYPE,
544 "", kCandidateGeneration, kCandidateFoundation2);
545
546 // stun
547 int port_stun = 2345;
548 talk_base::SocketAddress address_stun("74.125.127.126", port_stun++);
549 talk_base::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
550 cricket::Candidate candidate9
551 ("", cricket::ICE_CANDIDATE_COMPONENT_RTP,
552 "udp", address_stun, kCandidatePriority,
553 "", "", STUN_PORT_TYPE,
554 "", kCandidateGeneration, kCandidateFoundation3);
555 candidate9.set_related_address(rel_address_stun);
556
557 address_stun.SetPort(port_stun++);
558 rel_address_stun.SetPort(port_stun++);
559 cricket::Candidate candidate10(
560 "", cricket::ICE_CANDIDATE_COMPONENT_RTCP,
561 "udp", address_stun, kCandidatePriority,
562 "", "", STUN_PORT_TYPE,
563 "", kCandidateGeneration, kCandidateFoundation3);
564 candidate10.set_related_address(rel_address_stun);
565
566 // relay
567 int port_relay = 3456;
568 talk_base::SocketAddress address_relay("74.125.224.39", port_relay++);
569 cricket::Candidate candidate11(
570 "", cricket::ICE_CANDIDATE_COMPONENT_RTCP,
571 "udp", address_relay, kCandidatePriority,
572 "", "",
573 cricket::RELAY_PORT_TYPE, "",
574 kCandidateGeneration, kCandidateFoundation4);
575 address_relay.SetPort(port_relay++);
576 cricket::Candidate candidate12(
577 "", cricket::ICE_CANDIDATE_COMPONENT_RTP,
578 "udp", address_relay, kCandidatePriority,
579 "", "",
580 RELAY_PORT_TYPE, "",
581 kCandidateGeneration, kCandidateFoundation4);
582
583 // voice
584 candidates_.push_back(candidate1);
585 candidates_.push_back(candidate2);
586 candidates_.push_back(candidate5);
587 candidates_.push_back(candidate6);
588 candidates_.push_back(candidate9);
589 candidates_.push_back(candidate10);
590
591 // video
592 candidates_.push_back(candidate3);
593 candidates_.push_back(candidate4);
594 candidates_.push_back(candidate7);
595 candidates_.push_back(candidate8);
596 candidates_.push_back(candidate11);
597 candidates_.push_back(candidate12);
598
599 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"),
600 0, candidate1));
601
602 // Set up JsepSessionDescription.
603 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
604 std::string mline_id;
605 int mline_index = 0;
606 for (size_t i = 0; i< candidates_.size(); ++i) {
607 // In this test, the audio m line index will be 0, and the video m line
608 // will be 1.
609 bool is_video = (i > 5);
610 mline_id = is_video ? "video_content_name" : "audio_content_name";
611 mline_index = is_video ? 1 : 0;
612 JsepIceCandidate jice(mline_id,
613 mline_index,
614 candidates_.at(i));
615 jdesc_.AddCandidate(&jice);
616 }
617 }
618
619 AudioContentDescription* CreateAudioContentDescription() {
620 AudioContentDescription* audio = new AudioContentDescription();
621 audio->set_rtcp_mux(true);
622 StreamParams audio_stream1;
623 audio_stream1.id = kAudioTrackId1;
624 audio_stream1.cname = kStream1Cname;
625 audio_stream1.sync_label = kStreamLabel1;
626 audio_stream1.ssrcs.push_back(kAudioTrack1Ssrc);
627 audio->AddStream(audio_stream1);
628 StreamParams audio_stream2;
629 audio_stream2.id = kAudioTrackId2;
630 audio_stream2.cname = kStream2Cname;
631 audio_stream2.sync_label = kStreamLabel2;
632 audio_stream2.ssrcs.push_back(kAudioTrack2Ssrc);
633 audio->AddStream(audio_stream2);
634 audio->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_32",
635 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
636 "dummy_session_params"));
637 audio->set_protocol(cricket::kMediaProtocolSavpf);
638 return audio;
639 }
640
641 template <class MCD>
642 void CompareMediaContentDescription(const MCD* cd1,
643 const MCD* cd2) {
644 // type
645 EXPECT_EQ(cd1->type(), cd1->type());
646
647 // content direction
648 EXPECT_EQ(cd1->direction(), cd2->direction());
649
650 // rtcp_mux
651 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
652
653 // cryptos
654 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
655 if (cd1->cryptos().size() != cd2->cryptos().size()) {
656 ADD_FAILURE();
657 return;
658 }
659 for (size_t i = 0; i< cd1->cryptos().size(); ++i) {
660 const CryptoParams c1 = cd1->cryptos().at(i);
661 const CryptoParams c2 = cd2->cryptos().at(i);
662 EXPECT_TRUE(c1.Matches(c2));
663 EXPECT_EQ(c1.key_params, c2.key_params);
664 EXPECT_EQ(c1.session_params, c2.session_params);
665 }
666 // protocol
667 EXPECT_EQ(cd1->protocol(), cd2->protocol());
668
669 // codecs
670 EXPECT_EQ(cd1->codecs(), cd2->codecs());
671
672 // bandwidth
673 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
674
675 // streams
676 EXPECT_EQ(cd1->streams(), cd2->streams());
677
678 // extmap
679 ASSERT_EQ(cd1->rtp_header_extensions().size(),
680 cd2->rtp_header_extensions().size());
681 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) {
682 const RtpHeaderExtension ext1 = cd1->rtp_header_extensions().at(i);
683 const RtpHeaderExtension ext2 = cd2->rtp_header_extensions().at(i);
684 EXPECT_EQ(ext1.uri, ext2.uri);
685 EXPECT_EQ(ext1.id, ext2.id);
686 }
687
688 // buffered mode latency
689 EXPECT_EQ(cd1->buffered_mode_latency(), cd2->buffered_mode_latency());
690 }
691
692
693 void CompareSessionDescription(const SessionDescription& desc1,
694 const SessionDescription& desc2) {
695 // Compare content descriptions.
696 if (desc1.contents().size() != desc2.contents().size()) {
697 ADD_FAILURE();
698 return;
699 }
700 for (size_t i = 0 ; i < desc1.contents().size(); ++i) {
701 const cricket::ContentInfo& c1 = desc1.contents().at(i);
702 const cricket::ContentInfo& c2 = desc2.contents().at(i);
703 // content name
704 EXPECT_EQ(c1.name, c2.name);
705 // content type
706 // Note, ASSERT will return from the function, but will not stop the test.
707 ASSERT_EQ(c1.type, c2.type);
708
709 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
710 if (IsAudioContent(&c1)) {
711 const AudioContentDescription* acd1 =
712 static_cast<const AudioContentDescription*>(c1.description);
713 const AudioContentDescription* acd2 =
714 static_cast<const AudioContentDescription*>(c2.description);
715 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
716 }
717
718 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
719 if (IsVideoContent(&c1)) {
720 const VideoContentDescription* vcd1 =
721 static_cast<const VideoContentDescription*>(c1.description);
722 const VideoContentDescription* vcd2 =
723 static_cast<const VideoContentDescription*>(c2.description);
724 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
725 }
726
727 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
728 if (IsDataContent(&c1)) {
729 const DataContentDescription* dcd1 =
730 static_cast<const DataContentDescription*>(c1.description);
731 const DataContentDescription* dcd2 =
732 static_cast<const DataContentDescription*>(c2.description);
733 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
734 }
735 }
736
737 // group
738 const cricket::ContentGroups groups1 = desc1.groups();
739 const cricket::ContentGroups groups2 = desc2.groups();
740 EXPECT_EQ(groups1.size(), groups1.size());
741 if (groups1.size() != groups2.size()) {
742 ADD_FAILURE();
743 return;
744 }
745 for (size_t i = 0; i < groups1.size(); ++i) {
746 const cricket::ContentGroup group1 = groups1.at(i);
747 const cricket::ContentGroup group2 = groups2.at(i);
748 EXPECT_EQ(group1.semantics(), group2.semantics());
749 const cricket::ContentNames names1 = group1.content_names();
750 const cricket::ContentNames names2 = group2.content_names();
751 EXPECT_EQ(names1.size(), names2.size());
752 if (names1.size() != names2.size()) {
753 ADD_FAILURE();
754 return;
755 }
756 cricket::ContentNames::const_iterator iter1 = names1.begin();
757 cricket::ContentNames::const_iterator iter2 = names2.begin();
758 while (iter1 != names1.end()) {
759 EXPECT_EQ(*iter1++, *iter2++);
760 }
761 }
762
763 // transport info
764 const cricket::TransportInfos transports1 = desc1.transport_infos();
765 const cricket::TransportInfos transports2 = desc2.transport_infos();
766 EXPECT_EQ(transports1.size(), transports2.size());
767 if (transports1.size() != transports2.size()) {
768 ADD_FAILURE();
769 return;
770 }
771 for (size_t i = 0; i < transports1.size(); ++i) {
772 const cricket::TransportInfo transport1 = transports1.at(i);
773 const cricket::TransportInfo transport2 = transports2.at(i);
774 EXPECT_EQ(transport1.content_name, transport2.content_name);
775 EXPECT_EQ(transport1.description.transport_type,
776 transport2.description.transport_type);
777 EXPECT_EQ(transport1.description.ice_ufrag,
778 transport2.description.ice_ufrag);
779 EXPECT_EQ(transport1.description.ice_pwd,
780 transport2.description.ice_pwd);
781 if (transport1.description.identity_fingerprint) {
782 EXPECT_EQ(*transport1.description.identity_fingerprint,
783 *transport2.description.identity_fingerprint);
784 } else {
785 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
786 transport2.description.identity_fingerprint.get());
787 }
788 EXPECT_EQ(transport1.description.transport_options,
789 transport2.description.transport_options);
790 EXPECT_TRUE(CompareCandidates(transport1.description.candidates,
791 transport2.description.candidates));
792 }
793 }
794
795 bool CompareCandidates(const Candidates& cs1, const Candidates& cs2) {
796 EXPECT_EQ(cs1.size(), cs2.size());
797 if (cs1.size() != cs2.size())
798 return false;
799 for (size_t i = 0; i< cs1.size(); ++i) {
800 const Candidate c1 = cs1.at(i);
801 const Candidate c2 = cs2.at(i);
802 EXPECT_TRUE(c1.IsEquivalent(c2));
803 }
804 return true;
805 }
806
807 bool CompareSessionDescription(
808 const JsepSessionDescription& desc1,
809 const JsepSessionDescription& desc2) {
810 EXPECT_EQ(desc1.session_id(), desc2.session_id());
811 EXPECT_EQ(desc1.session_version(), desc2.session_version());
812 CompareSessionDescription(*desc1.description(), *desc2.description());
813 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
814 return false;
815 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
816 const IceCandidateCollection* cc1 = desc1.candidates(i);
817 const IceCandidateCollection* cc2 = desc2.candidates(i);
818 if (cc1->count() != cc2->count())
819 return false;
820 for (size_t j = 0; j < cc1->count(); ++j) {
821 const IceCandidateInterface* c1 = cc1->at(j);
822 const IceCandidateInterface* c2 = cc2->at(j);
823 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
824 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
825 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
826 }
827 }
828 return true;
829 }
830
831 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
832 // them with invalid keywords so that the parser will just ignore them.
833 bool RemoveCandidateUfragPwd(std::string* sdp) {
834 const char ice_ufrag[] = "a=ice-ufrag";
835 const char ice_ufragx[] = "a=xice-ufrag";
836 const char ice_pwd[] = "a=ice-pwd";
837 const char ice_pwdx[] = "a=xice-pwd";
838 talk_base::replace_substrs(ice_ufrag, strlen(ice_ufrag),
839 ice_ufragx, strlen(ice_ufragx), sdp);
840 talk_base::replace_substrs(ice_pwd, strlen(ice_pwd),
841 ice_pwdx, strlen(ice_pwdx), sdp);
842 return true;
843 }
844
845 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
846 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, int mline_index,
847 const std::string& ufrag, const std::string& pwd) {
848 std::string content_name;
849 if (mline_index == 0) {
850 content_name = kAudioContentName;
851 } else if (mline_index == 1) {
852 content_name = kVideoContentName;
853 } else {
854 ASSERT(false);
855 }
856 TransportInfo transport_info(
857 content_name, TransportDescription(NS_JINGLE_ICE_UDP,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000858 ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000859 SessionDescription* desc =
860 const_cast<SessionDescription*>(jdesc->description());
861 desc->RemoveTransportInfoByName(content_name);
862 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
863 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
864 const IceCandidateCollection* cc = jdesc_.candidates(i);
865 for (size_t j = 0; j < cc->count(); ++j) {
866 if (cc->at(j)->sdp_mline_index() == mline_index) {
867 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(
868 ufrag);
869 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(
870 pwd);
871 }
872 }
873 }
874 return true;
875 }
876
877 void AddIceOptions(const std::string& content_name,
878 const std::vector<std::string>& transport_options) {
879 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
880 cricket::TransportInfo transport_info =
881 *(desc_.GetTransportInfoByName(content_name));
882 desc_.RemoveTransportInfoByName(content_name);
883 transport_info.description.transport_options = transport_options;
884 desc_.AddTransportInfo(transport_info);
885 }
886
887 void AddFingerprint() {
888 desc_.RemoveTransportInfoByName(kAudioContentName);
889 desc_.RemoveTransportInfoByName(kVideoContentName);
890 talk_base::SSLFingerprint fingerprint(talk_base::DIGEST_SHA_1,
891 kIdentityDigest,
892 sizeof(kIdentityDigest));
893 EXPECT_TRUE(desc_.AddTransportInfo(
894 TransportInfo(kAudioContentName,
895 TransportDescription(NS_JINGLE_ICE_UDP,
896 std::vector<std::string>(),
897 kCandidateUfragVoice,
898 kCandidatePwdVoice,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000899 cricket::ICEMODE_FULL,
900 cricket::CONNECTIONROLE_NONE,
901 &fingerprint, Candidates()))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902 EXPECT_TRUE(desc_.AddTransportInfo(
903 TransportInfo(kVideoContentName,
904 TransportDescription(NS_JINGLE_ICE_UDP,
905 std::vector<std::string>(),
906 kCandidateUfragVideo,
907 kCandidatePwdVideo,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000908 cricket::ICEMODE_FULL,
909 cricket::CONNECTIONROLE_NONE,
910 &fingerprint, Candidates()))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000911 }
912
913 void AddExtmap() {
914 audio_desc_ = static_cast<AudioContentDescription*>(
915 audio_desc_->Copy());
916 video_desc_ = static_cast<VideoContentDescription*>(
917 video_desc_->Copy());
918 audio_desc_->AddRtpHeaderExtension(
919 RtpHeaderExtension(kExtmapUri, kExtmapId));
920 video_desc_->AddRtpHeaderExtension(
921 RtpHeaderExtension(kExtmapUri, kExtmapId));
922 desc_.RemoveContentByName(kAudioContentName);
923 desc_.RemoveContentByName(kVideoContentName);
924 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
925 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
926 }
927
928 void RemoveCryptos() {
929 audio_desc_->set_cryptos(std::vector<CryptoParams>());
930 video_desc_->set_cryptos(std::vector<CryptoParams>());
931 }
932
933 bool TestSerializeDirection(cricket::MediaContentDirection direction) {
934 audio_desc_->set_direction(direction);
935 video_desc_->set_direction(direction);
936 std::string new_sdp = kSdpFullString;
937 ReplaceDirection(direction, &new_sdp);
938
939 if (!jdesc_.Initialize(desc_.Copy(),
940 jdesc_.session_id(),
941 jdesc_.session_version())) {
942 return false;
943 }
944 std::string message = webrtc::SdpSerialize(jdesc_);
945 EXPECT_EQ(new_sdp, message);
946 return true;
947 }
948
949 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
950 audio_desc_ = static_cast<AudioContentDescription*>(
951 audio_desc_->Copy());
952 video_desc_ = static_cast<VideoContentDescription*>(
953 video_desc_->Copy());
954 desc_.RemoveContentByName(kAudioContentName);
955 desc_.RemoveContentByName(kVideoContentName);
956 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
957 audio_desc_);
958 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
959 video_desc_);
960 std::string new_sdp = kSdpFullString;
961 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
962
963 if (!jdesc_.Initialize(desc_.Copy(),
964 jdesc_.session_id(),
965 jdesc_.session_version())) {
966 return false;
967 }
968 std::string message = webrtc::SdpSerialize(jdesc_);
969 EXPECT_EQ(new_sdp, message);
970 return true;
971 }
972
973 void AddSctpDataChannel() {
974 talk_base::scoped_ptr<DataContentDescription> data(
975 new DataContentDescription());
976 data_desc_ = data.get();
977 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
wu@webrtc.org78187522013-10-07 23:32:02 +0000978 DataCodec codec(cricket::kGoogleSctpDataCodecId,
979 cricket::kGoogleSctpDataCodecName, 0);
980 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
981 data_desc_->AddCodec(codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000982 desc_.AddContent(kDataContentName, NS_JINGLE_DRAFT_SCTP, data.release());
983 EXPECT_TRUE(desc_.AddTransportInfo(
984 TransportInfo(kDataContentName,
985 TransportDescription(NS_JINGLE_ICE_UDP,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000986 kCandidateUfragData,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000987 kCandidatePwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000988 }
989
990 void AddRtpDataChannel() {
991 talk_base::scoped_ptr<DataContentDescription> data(
992 new DataContentDescription());
993 data_desc_ = data.get();
994
995 data_desc_->AddCodec(DataCodec(101, "google-data", 1));
996 StreamParams data_stream;
997 data_stream.id = kDataChannelMsid;
998 data_stream.cname = kDataChannelCname;
999 data_stream.sync_label = kDataChannelLabel;
1000 data_stream.ssrcs.push_back(kDataChannelSsrc);
1001 data_desc_->AddStream(data_stream);
1002 data_desc_->AddCrypto(CryptoParams(
1003 1, "AES_CM_128_HMAC_SHA1_80",
1004 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
1005 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
1006 desc_.AddContent(kDataContentName, NS_JINGLE_RTP, data.release());
1007 EXPECT_TRUE(desc_.AddTransportInfo(
1008 TransportInfo(kDataContentName,
1009 TransportDescription(NS_JINGLE_ICE_UDP,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001010 kCandidateUfragData,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001011 kCandidatePwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001012 }
1013
1014 bool TestDeserializeDirection(cricket::MediaContentDirection direction) {
1015 std::string new_sdp = kSdpFullString;
1016 ReplaceDirection(direction, &new_sdp);
1017 JsepSessionDescription new_jdesc(kDummyString);
1018
1019 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1020
1021 audio_desc_->set_direction(direction);
1022 video_desc_->set_direction(direction);
1023 if (!jdesc_.Initialize(desc_.Copy(),
1024 jdesc_.session_id(),
1025 jdesc_.session_version())) {
1026 return false;
1027 }
1028 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1029 return true;
1030 }
1031
1032 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
1033 std::string new_sdp = kSdpFullString;
1034 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1035 JsepSessionDescription new_jdesc(JsepSessionDescription::kOffer);
1036
1037 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1038 audio_desc_ = static_cast<AudioContentDescription*>(
1039 audio_desc_->Copy());
1040 video_desc_ = static_cast<VideoContentDescription*>(
1041 video_desc_->Copy());
1042 desc_.RemoveContentByName(kAudioContentName);
1043 desc_.RemoveContentByName(kVideoContentName);
1044 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1045 audio_desc_);
1046 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1047 video_desc_);
1048 if (!jdesc_.Initialize(desc_.Copy(),
1049 jdesc_.session_id(),
1050 jdesc_.session_version())) {
1051 return false;
1052 }
1053 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1054 return true;
1055 }
1056
1057 void TestDeserializeExtmap(bool session_level, bool media_level) {
1058 AddExtmap();
1059 JsepSessionDescription new_jdesc("dummy");
1060 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1061 jdesc_.session_id(),
1062 jdesc_.session_version()));
1063 JsepSessionDescription jdesc_with_extmap("dummy");
1064 std::string sdp_with_extmap = kSdpString;
1065 if (session_level) {
1066 InjectAfter(kSessionTime, kExtmapWithDirectionAndAttribute,
1067 &sdp_with_extmap);
1068 }
1069 if (media_level) {
1070 InjectAfter(kAttributeIcePwdVoice, kExtmapWithDirectionAndAttribute,
1071 &sdp_with_extmap);
1072 InjectAfter(kAttributeIcePwdVideo, kExtmapWithDirectionAndAttribute,
1073 &sdp_with_extmap);
1074 }
1075 // The extmap can't be present at the same time in both session level and
1076 // media level.
1077 if (session_level && media_level) {
1078 SdpParseError error;
1079 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap,
1080 &jdesc_with_extmap, &error));
1081 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1082 } else {
1083 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1084 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1085 }
1086 }
1087
1088 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
1089 const std::string& name, int expected_value) {
1090 cricket::CodecParameterMap::const_iterator found = params.find(name);
1091 ASSERT_TRUE(found != params.end());
1092 EXPECT_EQ(found->second, talk_base::ToString<int>(expected_value));
1093 }
1094
1095 void TestDeserializeCodecParams(const CodecParams& params,
1096 JsepSessionDescription* jdesc_output) {
1097 std::string sdp =
1098 "v=0\r\n"
1099 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1100 "s=-\r\n"
1101 "t=0 0\r\n"
1102 // Include semantics for WebRTC Media Streams since it is supported by
1103 // this parser, and will be added to the SDP when serializing a session
1104 // description.
1105 "a=msid-semantic: WMS\r\n"
1106 // Pl type 111 preferred.
1107 "m=audio 1 RTP/SAVPF 111 104 103 102\r\n"
1108 // Pltype 111 listed before 103 and 104 in the map.
1109 "a=rtpmap:111 opus/48000/2\r\n"
1110 // Pltype 103 listed before 104.
1111 "a=rtpmap:103 ISAC/16000\r\n"
1112 "a=rtpmap:104 CELT/32000/2\r\n"
1113 "a=rtpmap:102 ISAC/32000/1\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001114 "a=fmtp:111 0-15,66,70\r\n"
1115 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001116 std::ostringstream os;
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001117 os << "minptime=" << params.min_ptime
1118 << "; stereo=" << params.stereo
1119 << "; sprop-stereo=" << params.sprop_stereo
1120 << "; useinbandfec=" << params.useinband
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001121 << " maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001122 << "a=ptime:" << params.ptime << "\r\n"
1123 << "a=maxptime:" << params.max_ptime << "\r\n";
1124 sdp += os.str();
1125
1126 // Deserialize
1127 SdpParseError error;
1128 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1129
1130 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1131 ASSERT_TRUE(ac != NULL);
1132 const AudioContentDescription* acd =
1133 static_cast<const AudioContentDescription*>(ac->description);
1134 ASSERT_FALSE(acd->codecs().empty());
1135 cricket::AudioCodec opus = acd->codecs()[0];
1136 EXPECT_EQ("opus", opus.name);
1137 EXPECT_EQ(111, opus.id);
1138 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1139 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1140 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1141 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001142 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1143 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001144 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1145 cricket::AudioCodec codec = acd->codecs()[i];
1146 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1147 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
1148 if (codec.name == "ISAC") {
1149 if (codec.clockrate == 16000) {
1150 EXPECT_EQ(32000, codec.bitrate);
1151 } else {
1152 EXPECT_EQ(56000, codec.bitrate);
1153 }
1154 }
1155 }
1156 }
1157
1158 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1159 bool use_wildcard) {
1160 std::string sdp =
1161 "v=0\r\n"
1162 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1163 "s=-\r\n"
1164 "t=0 0\r\n"
1165 // Include semantics for WebRTC Media Streams since it is supported by
1166 // this parser, and will be added to the SDP when serializing a session
1167 // description.
1168 "a=msid-semantic: WMS\r\n"
1169 "m=audio 1 RTP/SAVPF 111\r\n"
1170 "a=rtpmap:111 opus/48000/2\r\n"
1171 "a=rtcp-fb:111 nack\r\n"
1172 "m=video 3457 RTP/SAVPF 101\r\n"
1173 "a=rtpmap:101 VP8/90000\r\n"
1174 "a=rtcp-fb:101 nack\r\n"
1175 "a=rtcp-fb:101 goog-remb\r\n"
1176 "a=rtcp-fb:101 ccm fir\r\n";
1177 std::ostringstream os;
1178 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
1179 sdp += os.str();
1180 // Deserialize
1181 SdpParseError error;
1182 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1183 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1184 ASSERT_TRUE(ac != NULL);
1185 const AudioContentDescription* acd =
1186 static_cast<const AudioContentDescription*>(ac->description);
1187 ASSERT_FALSE(acd->codecs().empty());
1188 cricket::AudioCodec opus = acd->codecs()[0];
1189 EXPECT_EQ(111, opus.id);
1190 EXPECT_TRUE(opus.HasFeedbackParam(
1191 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1192 cricket::kParamValueEmpty)));
1193
1194 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1195 ASSERT_TRUE(vc != NULL);
1196 const VideoContentDescription* vcd =
1197 static_cast<const VideoContentDescription*>(vc->description);
1198 ASSERT_FALSE(vcd->codecs().empty());
1199 cricket::VideoCodec vp8 = vcd->codecs()[0];
1200 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1201 vp8.name.c_str());
1202 EXPECT_EQ(101, vp8.id);
1203 EXPECT_TRUE(vp8.HasFeedbackParam(
1204 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1205 cricket::kParamValueEmpty)));
1206 EXPECT_TRUE(vp8.HasFeedbackParam(
1207 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
1208 cricket::kParamValueEmpty)));
1209 EXPECT_TRUE(vp8.HasFeedbackParam(
1210 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
1211 cricket::kRtcpFbCcmParamFir)));
1212 }
1213
1214 // Two SDP messages can mean the same thing but be different strings, e.g.
1215 // some of the lines can be serialized in different order.
1216 // However, a deserialized description can be compared field by field and has
1217 // no order. If deserializer has already been tested, serializing then
1218 // deserializing and comparing JsepSessionDescription will test
1219 // the serializer sufficiently.
1220 void TestSerialize(const JsepSessionDescription& jdesc) {
1221 std::string message = webrtc::SdpSerialize(jdesc);
1222 JsepSessionDescription jdesc_output_des(kDummyString);
1223 SdpParseError error;
1224 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1225 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1226 }
1227
1228 protected:
1229 SessionDescription desc_;
1230 AudioContentDescription* audio_desc_;
1231 VideoContentDescription* video_desc_;
1232 DataContentDescription* data_desc_;
1233 Candidates candidates_;
1234 talk_base::scoped_ptr<IceCandidateInterface> jcandidate_;
1235 JsepSessionDescription jdesc_;
1236};
1237
1238void TestMismatch(const std::string& string1, const std::string& string2) {
1239 int position = 0;
1240 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1241 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001242 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001243 break;
1244 }
1245 }
1246 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1247 << " character\n"
1248 << " 1: " << string1.substr(position, 20) << "\n"
1249 << " 2: " << string2.substr(position, 20) << "\n";
1250}
1251
1252std::string GetLine(const std::string& message,
1253 const std::string& session_description_name) {
1254 size_t start = message.find(session_description_name);
1255 if (std::string::npos == start) {
1256 return "";
1257 }
1258 size_t stop = message.find("\r\n", start);
1259 if (std::string::npos == stop) {
1260 return "";
1261 }
1262 if (stop <= start) {
1263 return "";
1264 }
1265 return message.substr(start, stop - start);
1266}
1267
1268TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1269 // SessionDescription with desc and candidates.
1270 std::string message = webrtc::SdpSerialize(jdesc_);
1271 TestMismatch(std::string(kSdpFullString), message);
1272}
1273
1274TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
1275 JsepSessionDescription jdesc_empty(kDummyString);
1276 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
1277}
1278
1279// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1280// the case in a DTLS offer.
1281TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1282 AddFingerprint();
1283 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1284 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1285 kSessionId, kSessionVersion));
1286 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
1287
1288 std::string sdp_with_fingerprint = kSdpString;
1289 InjectAfter(kAttributeIcePwdVoice,
1290 kFingerprint, &sdp_with_fingerprint);
1291 InjectAfter(kAttributeIcePwdVideo,
1292 kFingerprint, &sdp_with_fingerprint);
1293
1294 EXPECT_EQ(sdp_with_fingerprint, message);
1295}
1296
1297// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1298// be the case in a DTLS answer.
1299TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1300 AddFingerprint();
1301 RemoveCryptos();
1302 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1303 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1304 kSessionId, kSessionVersion));
1305 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
1306
1307 std::string sdp_with_fingerprint = kSdpString;
1308 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1309 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
1310 InjectAfter(kAttributeIcePwdVoice,
1311 kFingerprint, &sdp_with_fingerprint);
1312 InjectAfter(kAttributeIcePwdVideo,
1313 kFingerprint, &sdp_with_fingerprint);
1314
1315 EXPECT_EQ(sdp_with_fingerprint, message);
1316}
1317
1318TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1319 // JsepSessionDescription with desc but without candidates.
1320 JsepSessionDescription jdesc_no_candidates(kDummyString);
1321 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
1322 kSessionId, kSessionVersion));
1323 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
1324 EXPECT_EQ(std::string(kSdpString), message);
1325}
1326
1327TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1328 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1329 group.AddContentName(kAudioContentName);
1330 group.AddContentName(kVideoContentName);
1331 desc_.AddGroup(group);
1332 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1333 jdesc_.session_id(),
1334 jdesc_.session_version()));
1335 std::string message = webrtc::SdpSerialize(jdesc_);
1336 std::string sdp_with_bundle = kSdpFullString;
1337 InjectAfter(kSessionTime,
1338 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1339 &sdp_with_bundle);
1340 EXPECT_EQ(sdp_with_bundle, message);
1341}
1342
1343TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
1344 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1345 GetFirstVideoContent(&desc_)->description);
1346 vcd->set_bandwidth(100 * 1000);
1347 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1348 GetFirstAudioContent(&desc_)->description);
1349 acd->set_bandwidth(50 * 1000);
1350 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1351 jdesc_.session_id(),
1352 jdesc_.session_version()));
1353 std::string message = webrtc::SdpSerialize(jdesc_);
1354 std::string sdp_with_bandwidth = kSdpFullString;
1355 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
1356 "b=AS:100\r\n",
1357 &sdp_with_bandwidth);
1358 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
1359 "b=AS:50\r\n",
1360 &sdp_with_bandwidth);
1361 EXPECT_EQ(sdp_with_bandwidth, message);
1362}
1363
1364TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1365 std::vector<std::string> transport_options;
1366 transport_options.push_back(kIceOption1);
1367 transport_options.push_back(kIceOption3);
1368 AddIceOptions(kAudioContentName, transport_options);
1369 transport_options.clear();
1370 transport_options.push_back(kIceOption2);
1371 transport_options.push_back(kIceOption3);
1372 AddIceOptions(kVideoContentName, transport_options);
1373 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1374 jdesc_.session_id(),
1375 jdesc_.session_version()));
1376 std::string message = webrtc::SdpSerialize(jdesc_);
1377 std::string sdp_with_ice_options = kSdpFullString;
1378 InjectAfter(kAttributeIcePwdVoice,
1379 "a=ice-options:iceoption1 iceoption3\r\n",
1380 &sdp_with_ice_options);
1381 InjectAfter(kAttributeIcePwdVideo,
1382 "a=ice-options:iceoption2 iceoption3\r\n",
1383 &sdp_with_ice_options);
1384 EXPECT_EQ(sdp_with_ice_options, message);
1385}
1386
1387TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
1388 EXPECT_TRUE(TestSerializeDirection(cricket::MD_RECVONLY));
1389}
1390
1391TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
1392 EXPECT_TRUE(TestSerializeDirection(cricket::MD_SENDONLY));
1393}
1394
1395TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
1396 EXPECT_TRUE(TestSerializeDirection(cricket::MD_INACTIVE));
1397}
1398
1399TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
1400 EXPECT_TRUE(TestSerializeRejected(true, false));
1401}
1402
1403TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
1404 EXPECT_TRUE(TestSerializeRejected(false, true));
1405}
1406
1407TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
1408 EXPECT_TRUE(TestSerializeRejected(true, true));
1409}
1410
1411TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
1412 AddRtpDataChannel();
1413 JsepSessionDescription jsep_desc(kDummyString);
1414
1415 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1416 std::string message = webrtc::SdpSerialize(jsep_desc);
1417
1418 std::string expected_sdp = kSdpString;
1419 expected_sdp.append(kSdpRtpDataChannelString);
1420 EXPECT_EQ(expected_sdp, message);
1421}
1422
1423TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
1424 AddSctpDataChannel();
1425 JsepSessionDescription jsep_desc(kDummyString);
1426
1427 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1428 std::string message = webrtc::SdpSerialize(jsep_desc);
1429
1430 std::string expected_sdp = kSdpString;
1431 expected_sdp.append(kSdpSctpDataChannelString);
1432 EXPECT_EQ(message, expected_sdp);
1433}
1434
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001435TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
1436 AddRtpDataChannel();
1437 data_desc_->set_bandwidth(100*1000);
1438 JsepSessionDescription jsep_desc(kDummyString);
1439
1440 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1441 std::string message = webrtc::SdpSerialize(jsep_desc);
1442
1443 std::string expected_sdp = kSdpString;
1444 expected_sdp.append(kSdpRtpDataChannelString);
1445 // We want to test that serializing data content ignores bandwidth
1446 // settings (it should always be the default). Thus, we don't do
1447 // the following:
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00001448 // TODO(pthatcher): We need to temporarily allow the SDP to control
1449 // this for backwards-compatibility. Once we don't need that any
1450 // more, remove this.
1451 InjectAfter("a=mid:data_content_name\r\na=sendrecv\r\n",
1452 "b=AS:100\r\n",
1453 &expected_sdp);
1454 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001455}
1456
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001457TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
1458 AddExtmap();
1459 JsepSessionDescription desc_with_extmap("dummy");
1460 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(),
1461 kSessionId, kSessionVersion));
1462 std::string message = webrtc::SdpSerialize(desc_with_extmap);
1463
1464 std::string sdp_with_extmap = kSdpString;
1465 InjectAfter("a=mid:audio_content_name\r\n",
1466 kExtmap, &sdp_with_extmap);
1467 InjectAfter("a=mid:video_content_name\r\n",
1468 kExtmap, &sdp_with_extmap);
1469
1470 EXPECT_EQ(sdp_with_extmap, message);
1471}
1472
1473
1474TEST_F(WebRtcSdpTest, SerializeCandidates) {
1475 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
1476 EXPECT_EQ(std::string(kSdpOneCandidate), message);
1477}
1478
1479TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
1480 JsepSessionDescription jdesc(kDummyString);
1481 // Deserialize
1482 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
1483 // Verify
1484 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1485}
1486
1487TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
1488 JsepSessionDescription jdesc(kDummyString);
1489 std::string sdp_without_carriage_return = kSdpFullString;
1490 Replace("\r\n", "\n", &sdp_without_carriage_return);
1491 // Deserialize
1492 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
1493 // Verify
1494 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1495}
1496
1497TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
1498 // SessionDescription with desc but without candidates.
1499 JsepSessionDescription jdesc_no_candidates(kDummyString);
1500 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
1501 kSessionId, kSessionVersion));
1502 JsepSessionDescription new_jdesc(kDummyString);
1503 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
1504 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
1505}
1506
1507TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
1508 static const char kSdpNoRtpmapString[] =
1509 "v=0\r\n"
1510 "o=- 11 22 IN IP4 127.0.0.1\r\n"
1511 "s=-\r\n"
1512 "t=0 0\r\n"
1513 "m=audio 49232 RTP/AVP 0 18 103\r\n"
1514 // Codec that doesn't appear in the m= line will be ignored.
1515 "a=rtpmap:104 CELT/32000/2\r\n"
1516 // The rtpmap line for static payload codec is optional.
1517 "a=rtpmap:18 G729/16000\r\n"
1518 "a=rtpmap:103 ISAC/16000\r\n";
1519
1520 JsepSessionDescription jdesc(kDummyString);
1521 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
1522 cricket::AudioContentDescription* audio =
1523 static_cast<AudioContentDescription*>(
1524 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
1525 AudioCodecs ref_codecs;
1526 // The codecs in the AudioContentDescription will be sorted by preference.
1527 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1, 3));
1528 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1, 2));
1529 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 32000, 1, 1));
1530 EXPECT_EQ(ref_codecs, audio->codecs());
1531}
1532
1533// Ensure that we can deserialize SDP with a=fingerprint properly.
1534TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
1535 // Add a DTLS a=fingerprint attribute to our session description.
1536 AddFingerprint();
1537 JsepSessionDescription new_jdesc(kDummyString);
1538 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1539 jdesc_.session_id(),
1540 jdesc_.session_version()));
1541
1542 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1543 std::string sdp_with_fingerprint = kSdpString;
1544 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1545 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
1546 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
1547 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
1548}
1549
1550TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
1551 JsepSessionDescription jdesc_with_bundle(kDummyString);
1552 std::string sdp_with_bundle = kSdpFullString;
1553 InjectAfter(kSessionTime,
1554 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1555 &sdp_with_bundle);
1556 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
1557 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1558 group.AddContentName(kAudioContentName);
1559 group.AddContentName(kVideoContentName);
1560 desc_.AddGroup(group);
1561 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1562 jdesc_.session_id(),
1563 jdesc_.session_version()));
1564 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
1565}
1566
1567TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
1568 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
1569 std::string sdp_with_bandwidth = kSdpFullString;
1570 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
1571 "b=AS:100\r\n",
1572 &sdp_with_bandwidth);
1573 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
1574 "b=AS:50\r\n",
1575 &sdp_with_bandwidth);
1576 EXPECT_TRUE(
1577 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
1578 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1579 GetFirstVideoContent(&desc_)->description);
1580 vcd->set_bandwidth(100 * 1000);
1581 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1582 GetFirstAudioContent(&desc_)->description);
1583 acd->set_bandwidth(50 * 1000);
1584 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1585 jdesc_.session_id(),
1586 jdesc_.session_version()));
1587 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
1588}
1589
1590TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
1591 JsepSessionDescription jdesc_with_ice_options(kDummyString);
1592 std::string sdp_with_ice_options = kSdpFullString;
1593 InjectAfter(kSessionTime,
1594 "a=ice-options:iceoption3\r\n",
1595 &sdp_with_ice_options);
1596 InjectAfter(kAttributeIcePwdVoice,
1597 "a=ice-options:iceoption1\r\n",
1598 &sdp_with_ice_options);
1599 InjectAfter(kAttributeIcePwdVideo,
1600 "a=ice-options:iceoption2\r\n",
1601 &sdp_with_ice_options);
1602 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
1603 std::vector<std::string> transport_options;
1604 transport_options.push_back(kIceOption3);
1605 transport_options.push_back(kIceOption1);
1606 AddIceOptions(kAudioContentName, transport_options);
1607 transport_options.clear();
1608 transport_options.push_back(kIceOption3);
1609 transport_options.push_back(kIceOption2);
1610 AddIceOptions(kVideoContentName, transport_options);
1611 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1612 jdesc_.session_id(),
1613 jdesc_.session_version()));
1614 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
1615}
1616
1617TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
1618 // Remove the original ice-ufrag and ice-pwd
1619 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyString);
1620 std::string sdp_with_ufrag_pwd = kSdpFullString;
1621 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
1622 // Add session level ufrag and pwd
1623 InjectAfter(kSessionTime,
1624 "a=ice-pwd:session+level+icepwd\r\n"
1625 "a=ice-ufrag:session+level+iceufrag\r\n",
1626 &sdp_with_ufrag_pwd);
1627 // Add media level ufrag and pwd for audio
1628 InjectAfter("a=mid:audio_content_name\r\n",
1629 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
1630 &sdp_with_ufrag_pwd);
1631 // Update the candidate ufrag and pwd to the expected ones.
1632 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0,
1633 "media+level+iceufrag", "media+level+icepwd"));
1634 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1,
1635 "session+level+iceufrag", "session+level+icepwd"));
1636 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
1637 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
1638}
1639
1640
1641TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
1642 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_RECVONLY));
1643}
1644
1645TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
1646 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_SENDONLY));
1647}
1648
1649TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
1650 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_INACTIVE));
1651}
1652
1653TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
1654 EXPECT_TRUE(TestDeserializeRejected(true, false));
1655}
1656
1657TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
1658 EXPECT_TRUE(TestDeserializeRejected(false, true));
1659}
1660
1661TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
1662 EXPECT_TRUE(TestDeserializeRejected(true, true));
1663}
1664
1665// Tests that we can still handle the sdp uses mslabel and label instead of
1666// msid for backward compatibility.
1667TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
1668 JsepSessionDescription jdesc(kDummyString);
1669 std::string sdp_without_msid = kSdpFullString;
1670 Replace("msid", "xmsid", &sdp_without_msid);
1671 // Deserialize
1672 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
1673 // Verify
1674 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1675}
1676
1677TEST_F(WebRtcSdpTest, DeserializeCandidate) {
1678 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
1679
1680 std::string sdp = kSdpOneCandidate;
1681 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
1682 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
1683 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
1684 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
1685
1686 // Candidate line without generation extension.
1687 sdp = kSdpOneCandidate;
1688 Replace(" generation 2", "", &sdp);
1689 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
1690 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
1691 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
1692 Candidate expected = jcandidate_->candidate();
1693 expected.set_generation(0);
1694 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
1695
1696 // Multiple candidate lines.
1697 // Only the first line will be deserialized. The rest will be ignored.
1698 sdp = kSdpOneCandidate;
1699 sdp.append("a=candidate:1 2 tcp 1234 192.168.1.100 5678 typ host\r\n");
1700 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
1701 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
1702 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
1703 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
1704}
1705
1706// This test verifies the deserialization of candidate-attribute
1707// as per RFC 5245. Candiate-attribute will be of the format
1708// candidate:<blah>. This format will be used when candidates
1709// are trickled.
1710TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
1711 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
1712
1713 std::string candidate_attribute = kRawCandidate;
1714 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
1715 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
1716 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
1717 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
1718 EXPECT_EQ(2u, jcandidate.candidate().generation());
1719
1720 // Candidate line without generation extension.
1721 candidate_attribute = kRawCandidate;
1722 Replace(" generation 2", "", &candidate_attribute);
1723 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
1724 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
1725 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
1726 Candidate expected = jcandidate_->candidate();
1727 expected.set_generation(0);
1728 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
1729
1730 // Candidate line without candidate:
1731 candidate_attribute = kRawCandidate;
1732 Replace("candidate:", "", &candidate_attribute);
1733 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
1734
1735 // Concatenating additional candidate. Expecting deserialization to fail.
1736 candidate_attribute = kRawCandidate;
1737 candidate_attribute.append("candidate:1 2 udp 1234 192.168.1.1 typ host");
1738 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
1739}
1740
1741TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
1742 AddRtpDataChannel();
1743 JsepSessionDescription jdesc(kDummyString);
1744 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1745
1746 std::string sdp_with_data = kSdpString;
1747 sdp_with_data.append(kSdpRtpDataChannelString);
1748 JsepSessionDescription jdesc_output(kDummyString);
1749
1750 // Deserialize
1751 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
1752 // Verify
1753 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
1754}
1755
1756TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
1757 AddSctpDataChannel();
1758 JsepSessionDescription jdesc(kDummyString);
1759 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1760
1761 std::string sdp_with_data = kSdpString;
1762 sdp_with_data.append(kSdpSctpDataChannelString);
1763 JsepSessionDescription jdesc_output(kDummyString);
1764
1765 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
1766 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
1767}
1768
wu@webrtc.org78187522013-10-07 23:32:02 +00001769TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndNewPort) {
1770 AddSctpDataChannel();
1771 const uint16 kUnusualSctpPort = 9556;
1772 char default_portstr[16];
1773 char unusual_portstr[16];
1774 talk_base::sprintfn(default_portstr, sizeof(default_portstr), "%d",
1775 kDefaultSctpPort);
1776 talk_base::sprintfn(unusual_portstr, sizeof(unusual_portstr), "%d",
1777 kUnusualSctpPort);
1778
1779 JsepSessionDescription jdesc(kDummyString);
1780 // take our pre-built session description and change the SCTP port.
1781 cricket::SessionDescription* mutant = desc_.Copy();
1782 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
1783 mutant->GetContentDescriptionByName(kDataContentName));
1784 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
1785 EXPECT_EQ(codecs.size(), 1UL);
1786 EXPECT_EQ(codecs[0].id, cricket::kGoogleSctpDataCodecId);
1787 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
1788
1789 // note: mutant's owned by jdesc now.
1790 ASSERT_TRUE(jdesc.Initialize(mutant, kSessionId, kSessionVersion));
1791 mutant = NULL;
1792
1793 std::string sdp_with_data = kSdpString;
1794 sdp_with_data.append(kSdpSctpDataChannelString);
1795 talk_base::replace_substrs(default_portstr, strlen(default_portstr),
1796 unusual_portstr, strlen(unusual_portstr),
1797 &sdp_with_data);
1798 JsepSessionDescription jdesc_output(kDummyString);
1799
1800 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
1801 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
1802}
1803
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001804TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
1805 AddRtpDataChannel();
1806 JsepSessionDescription jdesc(kDummyString);
1807 // We want to test that deserializing data content ignores bandwidth
1808 // settings (it should always be the default). Thus, we don't do
1809 // the following:
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00001810 // TODO(pthatcher): We need to temporarily allow the SDP to control
1811 // this for backwards-compatibility. Once we don't need that any
1812 // more, remove this.
1813 DataContentDescription* dcd = static_cast<DataContentDescription*>(
1814 GetFirstDataContent(&desc_)->description);
1815 dcd->set_bandwidth(100 * 1000);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001816 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1817
1818 std::string sdp_with_bandwidth = kSdpString;
1819 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
1820 InjectAfter("a=mid:data_content_name\r\n",
1821 "b=AS:100\r\n",
1822 &sdp_with_bandwidth);
1823 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
1824
1825 EXPECT_TRUE(
1826 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
1827 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
1828}
1829
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001830TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSessionLevelExtmap) {
1831 TestDeserializeExtmap(true, false);
1832}
1833
1834TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
1835 TestDeserializeExtmap(false, true);
1836}
1837
1838TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInvalidExtmap) {
1839 TestDeserializeExtmap(true, true);
1840}
1841
1842TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
1843 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
1844 std::string new_sdp = kSdpOneCandidate;
1845 Replace("udp", "unsupported_transport", &new_sdp);
1846 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
1847 new_sdp = kSdpOneCandidate;
1848 Replace("udp", "uDP", &new_sdp);
1849 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
1850 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
1851 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
1852 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
1853}
1854
1855TEST_F(WebRtcSdpTest, DeserializeCandidateOldFormat) {
1856 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
1857 EXPECT_TRUE(SdpDeserializeCandidate(kSdpOneCandidateOldFormat,&jcandidate));
1858 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
1859 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
1860 Candidate ref_candidate = jcandidate_->candidate();
1861 ref_candidate.set_username("user_rtp");
1862 ref_candidate.set_password("password_rtp");
1863 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
1864}
1865
1866TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
1867 const char kSdpDestroyer[] = "!@#$%^&";
1868 const char kSdpInvalidLine1[] = " =candidate";
1869 const char kSdpInvalidLine2[] = "a+candidate";
1870 const char kSdpInvalidLine3[] = "a= candidate";
1871 // Broken fingerprint.
1872 const char kSdpInvalidLine4[] = "a=fingerprint:sha-1 "
1873 "4AAD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB";
1874 // Extra field.
1875 const char kSdpInvalidLine5[] = "a=fingerprint:sha-1 "
1876 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB XXX";
1877 // Missing space.
1878 const char kSdpInvalidLine6[] = "a=fingerprint:sha-1"
1879 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB";
1880
1881 // Broken session description
1882 ReplaceAndTryToParse("v=", kSdpDestroyer);
1883 ReplaceAndTryToParse("o=", kSdpDestroyer);
1884 ReplaceAndTryToParse("s=-", kSdpDestroyer);
1885 // Broken time description
1886 ReplaceAndTryToParse("t=", kSdpDestroyer);
1887
1888 // Broken media description
1889 ReplaceAndTryToParse("m=video", kSdpDestroyer);
1890
1891 // Invalid lines
1892 ReplaceAndTryToParse("a=candidate", kSdpInvalidLine1);
1893 ReplaceAndTryToParse("a=candidate", kSdpInvalidLine2);
1894 ReplaceAndTryToParse("a=candidate", kSdpInvalidLine3);
1895
1896 // Bogus fingerprint replacing a=sendrev. We selected this attribute
1897 // because it's orthogonal to what we are replacing and hence
1898 // safe.
1899 ReplaceAndTryToParse("a=sendrecv", kSdpInvalidLine4);
1900 ReplaceAndTryToParse("a=sendrecv", kSdpInvalidLine5);
1901 ReplaceAndTryToParse("a=sendrecv", kSdpInvalidLine6);
1902}
1903
1904TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
1905 JsepSessionDescription jdesc_output(kDummyString);
1906
1907 const char kSdpWithReorderedPlTypesString[] =
1908 "v=0\r\n"
1909 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1910 "s=-\r\n"
1911 "t=0 0\r\n"
1912 "m=audio 1 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
1913 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
1914 // in the map.
1915 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
1916 "a=rtpmap:104 CELT/32000/2\r\n";
1917
1918 // Deserialize
1919 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
1920
1921 const ContentInfo* ac = GetFirstAudioContent(jdesc_output.description());
1922 ASSERT_TRUE(ac != NULL);
1923 const AudioContentDescription* acd =
1924 static_cast<const AudioContentDescription*>(ac->description);
1925 ASSERT_FALSE(acd->codecs().empty());
1926 EXPECT_EQ("CELT", acd->codecs()[0].name);
1927 EXPECT_EQ(104, acd->codecs()[0].id);
1928}
1929
1930TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
1931 JsepSessionDescription jdesc_output(kDummyString);
1932 CodecParams params;
1933 params.max_ptime = 40;
1934 params.ptime = 30;
1935 params.min_ptime = 10;
1936 params.sprop_stereo = 1;
1937 params.stereo = 1;
1938 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001939 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001940 TestDeserializeCodecParams(params, &jdesc_output);
1941 TestSerialize(jdesc_output);
1942}
1943
1944TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
1945 const bool kUseWildcard = false;
1946 JsepSessionDescription jdesc_output(kDummyString);
1947 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
1948 TestSerialize(jdesc_output);
1949}
1950
1951TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
1952 const bool kUseWildcard = true;
1953 JsepSessionDescription jdesc_output(kDummyString);
1954 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
1955 TestSerialize(jdesc_output);
1956}
1957
1958TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
1959 JsepSessionDescription jdesc_output(kDummyString);
1960
1961 const char kSdpWithFmtpString[] =
1962 "v=0\r\n"
1963 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1964 "s=-\r\n"
1965 "t=0 0\r\n"
1966 "m=video 3457 RTP/SAVPF 120\r\n"
1967 "a=rtpmap:120 VP8/90000\r\n"
1968 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
1969
1970 // Deserialize
1971 SdpParseError error;
1972 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output,
1973 &error));
1974
1975 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
1976 ASSERT_TRUE(vc != NULL);
1977 const VideoContentDescription* vcd =
1978 static_cast<const VideoContentDescription*>(vc->description);
1979 ASSERT_FALSE(vcd->codecs().empty());
1980 cricket::VideoCodec vp8 = vcd->codecs()[0];
1981 EXPECT_EQ("VP8", vp8.name);
1982 EXPECT_EQ(120, vp8.id);
1983 cricket::CodecParameterMap::iterator found =
1984 vp8.params.find("x-google-min-bitrate");
1985 ASSERT_TRUE(found != vp8.params.end());
1986 EXPECT_EQ(found->second, "10");
1987 found = vp8.params.find("x-google-max-quantization");
1988 ASSERT_TRUE(found != vp8.params.end());
1989 EXPECT_EQ(found->second, "40");
1990}
1991
1992TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
1993 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1994 GetFirstVideoContent(&desc_)->description);
1995
1996 cricket::VideoCodecs codecs = vcd->codecs();
1997 codecs[0].params["x-google-min-bitrate"] = "10";
1998 vcd->set_codecs(codecs);
1999
2000 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2001 jdesc_.session_id(),
2002 jdesc_.session_version()));
2003 std::string message = webrtc::SdpSerialize(jdesc_);
2004 std::string sdp_with_fmtp = kSdpFullString;
2005 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
2006 "a=fmtp:120 x-google-min-bitrate=10\r\n",
2007 &sdp_with_fmtp);
2008 EXPECT_EQ(sdp_with_fmtp, message);
2009}
2010
2011TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) {
2012 JsepSessionDescription jdesc_with_icelite(kDummyString);
2013 std::string sdp_with_icelite = kSdpFullString;
2014 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
2015 cricket::SessionDescription* desc = jdesc_with_icelite.description();
2016 const cricket::TransportInfo* tinfo1 =
2017 desc->GetTransportInfoByName("audio_content_name");
2018 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
2019 const cricket::TransportInfo* tinfo2 =
2020 desc->GetTransportInfoByName("video_content_name");
2021 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
2022 InjectAfter(kSessionTime,
2023 "a=ice-lite\r\n",
2024 &sdp_with_icelite);
2025 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
2026 desc = jdesc_with_icelite.description();
2027 const cricket::TransportInfo* atinfo =
2028 desc->GetTransportInfoByName("audio_content_name");
2029 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
2030 const cricket::TransportInfo* vtinfo =
2031 desc->GetTransportInfoByName("video_content_name");
2032 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
2033}
2034
2035// Verifies that the candidates in the input SDP are parsed and serialized
2036// correctly in the output SDP.
2037TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
2038 std::string sdp_with_data = kSdpString;
2039 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
2040 JsepSessionDescription jdesc_output(kDummyString);
2041
2042 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2043 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
2044}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00002045
2046TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
2047 AddFingerprint();
2048 TransportInfo audio_transport_info =
2049 *(desc_.GetTransportInfoByName(kAudioContentName));
2050 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
2051 audio_transport_info.description.connection_role);
2052 audio_transport_info.description.connection_role =
2053 cricket::CONNECTIONROLE_ACTIVE;
2054
2055 TransportInfo video_transport_info =
2056 *(desc_.GetTransportInfoByName(kVideoContentName));
2057 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
2058 video_transport_info.description.connection_role);
2059 video_transport_info.description.connection_role =
2060 cricket::CONNECTIONROLE_ACTIVE;
2061
2062 desc_.RemoveTransportInfoByName(kAudioContentName);
2063 desc_.RemoveTransportInfoByName(kVideoContentName);
2064
2065 desc_.AddTransportInfo(audio_transport_info);
2066 desc_.AddTransportInfo(video_transport_info);
2067
2068 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2069 jdesc_.session_id(),
2070 jdesc_.session_version()));
2071 std::string message = webrtc::SdpSerialize(jdesc_);
2072 std::string sdp_with_dtlssetup = kSdpFullString;
2073
2074 // Fingerprint attribute is necessary to add DTLS setup attribute.
2075 InjectAfter(kAttributeIcePwdVoice,
2076 kFingerprint, &sdp_with_dtlssetup);
2077 InjectAfter(kAttributeIcePwdVideo,
2078 kFingerprint, &sdp_with_dtlssetup);
2079 // Now adding |setup| attribute.
2080 InjectAfter(kFingerprint,
2081 "a=setup:active\r\n", &sdp_with_dtlssetup);
2082 EXPECT_EQ(sdp_with_dtlssetup, message);
2083}
2084
2085TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
2086 JsepSessionDescription jdesc_with_dtlssetup(kDummyString);
2087 std::string sdp_with_dtlssetup = kSdpFullString;
2088 InjectAfter(kSessionTime,
2089 "a=setup:actpass\r\n",
2090 &sdp_with_dtlssetup);
2091 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
2092 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
2093 const cricket::TransportInfo* atinfo =
2094 desc->GetTransportInfoByName("audio_content_name");
2095 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
2096 atinfo->description.connection_role);
2097 const cricket::TransportInfo* vtinfo =
2098 desc->GetTransportInfoByName("video_content_name");
2099 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
2100 vtinfo->description.connection_role);
2101}