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