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