blob: 1bf3e681c372adead0b096ca74558343ca9e9a7e [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 * Copyright 2011 Google Inc.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004 *
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"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000034#include "talk/media/base/constants.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000035#include "webrtc/p2p/base/constants.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000036#include "talk/session/media/mediasession.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000037#include "webrtc/base/gunit.h"
38#include "webrtc/base/logging.h"
39#include "webrtc/base/messagedigest.h"
40#include "webrtc/base/scoped_ptr.h"
41#include "webrtc/base/sslfingerprint.h"
42#include "webrtc/base/stringencode.h"
43#include "webrtc/base/stringutils.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044
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;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058using cricket::NS_JINGLE_RTP;
59using cricket::RtpHeaderExtension;
60using cricket::RELAY_PORT_TYPE;
61using cricket::SessionDescription;
62using cricket::StreamParams;
63using cricket::STUN_PORT_TYPE;
64using cricket::TransportDescription;
65using cricket::TransportInfo;
66using cricket::VideoCodec;
67using cricket::VideoContentDescription;
68using webrtc::IceCandidateCollection;
69using webrtc::IceCandidateInterface;
70using webrtc::JsepIceCandidate;
71using webrtc::JsepSessionDescription;
72using webrtc::SdpParseError;
73using webrtc::SessionDescriptionInterface;
74
75typedef std::vector<AudioCodec> AudioCodecs;
76typedef std::vector<Candidate> Candidates;
77
Peter Boström0c4e06b2015-10-07 12:23:21 +020078static const uint32_t kDefaultSctpPort = 5000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020080static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
henrike@webrtc.org28e20752013-07-10 00:45:36 +000081static const char kCandidateUfragVoice[] = "ufrag_voice";
82static const char kCandidatePwdVoice[] = "pwd_voice";
deadbeef3f7219b2015-12-28 15:17:14 -080083static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
85static const char kCandidateUfragVideo[] = "ufrag_video";
86static const char kCandidatePwdVideo[] = "pwd_video";
87static const char kCandidateUfragData[] = "ufrag_data";
88static const char kCandidatePwdData[] = "pwd_data";
deadbeef3f7219b2015-12-28 15:17:14 -080089static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020091static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092static const char kCandidateFoundation1[] = "a0+B/1";
93static const char kCandidateFoundation2[] = "a0+B/2";
94static const char kCandidateFoundation3[] = "a0+B/3";
95static const char kCandidateFoundation4[] = "a0+B/4";
96static const char kAttributeCryptoVoice[] =
97 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
98 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
99 "dummy_session_params\r\n";
100static const char kAttributeCryptoVideo[] =
101 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
102 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
103static const char kFingerprint[] = "a=fingerprint:sha-1 "
104 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n";
105static const int kExtmapId = 1;
106static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
107static const char kExtmap[] =
108 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
109static const char kExtmapWithDirectionAndAttribute[] =
110 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
111
Peter Boström0c4e06b2015-10-07 12:23:21 +0200112static const uint8_t kIdentityDigest[] = {
113 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
114 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000115
lally@webrtc.org34807282015-02-24 20:19:39 +0000116static const char kDtlsSctp[] = "DTLS/SCTP";
117static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
118static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +0000119
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120struct CodecParams {
121 int max_ptime;
122 int ptime;
123 int min_ptime;
124 int sprop_stereo;
125 int stereo;
126 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000127 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000128};
129
130// Reference sdp string
131static const char kSdpFullString[] =
132 "v=0\r\n"
133 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
134 "s=-\r\n"
135 "t=0 0\r\n"
136 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
137 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
138 "c=IN IP4 74.125.127.126\r\n"
139 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
140 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
141 "generation 2\r\n"
142 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
143 "generation 2\r\n"
144 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
145 "generation 2\r\n"
146 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
147 "generation 2\r\n"
148 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
149 "raddr 192.168.1.5 rport 2346 "
150 "generation 2\r\n"
151 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
152 "raddr 192.168.1.5 rport 2348 "
153 "generation 2\r\n"
154 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
155 "a=mid:audio_content_name\r\n"
156 "a=sendrecv\r\n"
157 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800158 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000159 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
160 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
161 "dummy_session_params\r\n"
162 "a=rtpmap:111 opus/48000/2\r\n"
163 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000164 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000165 "a=ssrc:1 cname:stream_1_cname\r\n"
166 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
167 "a=ssrc:1 mslabel:local_stream_1\r\n"
168 "a=ssrc:1 label:audio_track_id_1\r\n"
169 "a=ssrc:4 cname:stream_2_cname\r\n"
170 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
171 "a=ssrc:4 mslabel:local_stream_2\r\n"
172 "a=ssrc:4 label:audio_track_id_2\r\n"
173 "m=video 3457 RTP/SAVPF 120\r\n"
174 "c=IN IP4 74.125.224.39\r\n"
175 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
176 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
177 "generation 2\r\n"
178 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
179 "generation 2\r\n"
180 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
181 "generation 2\r\n"
182 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
183 "generation 2\r\n"
184 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
185 "generation 2\r\n"
186 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
187 "generation 2\r\n"
188 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
189 "a=mid:video_content_name\r\n"
190 "a=sendrecv\r\n"
191 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
192 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
193 "a=rtpmap:120 VP8/90000\r\n"
194 "a=ssrc:2 cname:stream_1_cname\r\n"
195 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
196 "a=ssrc:2 mslabel:local_stream_1\r\n"
197 "a=ssrc:2 label:video_track_id_1\r\n"
198 "a=ssrc:3 cname:stream_1_cname\r\n"
199 "a=ssrc:3 msid:local_stream_1 video_track_id_2\r\n"
200 "a=ssrc:3 mslabel:local_stream_1\r\n"
201 "a=ssrc:3 label:video_track_id_2\r\n"
202 "a=ssrc-group:FEC 5 6\r\n"
203 "a=ssrc:5 cname:stream_2_cname\r\n"
204 "a=ssrc:5 msid:local_stream_2 video_track_id_3\r\n"
205 "a=ssrc:5 mslabel:local_stream_2\r\n"
206 "a=ssrc:5 label:video_track_id_3\r\n"
207 "a=ssrc:6 cname:stream_2_cname\r\n"
208 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
209 "a=ssrc:6 mslabel:local_stream_2\r\n"
210 "a=ssrc:6 label:video_track_id_3\r\n";
211
212// SDP reference string without the candidates.
213static const char kSdpString[] =
214 "v=0\r\n"
215 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
216 "s=-\r\n"
217 "t=0 0\r\n"
218 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000219 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000220 "c=IN IP4 0.0.0.0\r\n"
221 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000222 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
223 "a=mid:audio_content_name\r\n"
224 "a=sendrecv\r\n"
225 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800226 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000227 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
228 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
229 "dummy_session_params\r\n"
230 "a=rtpmap:111 opus/48000/2\r\n"
231 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000232 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000233 "a=ssrc:1 cname:stream_1_cname\r\n"
234 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
235 "a=ssrc:1 mslabel:local_stream_1\r\n"
236 "a=ssrc:1 label:audio_track_id_1\r\n"
237 "a=ssrc:4 cname:stream_2_cname\r\n"
238 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
239 "a=ssrc:4 mslabel:local_stream_2\r\n"
240 "a=ssrc:4 label:audio_track_id_2\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000241 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000242 "c=IN IP4 0.0.0.0\r\n"
243 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000244 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
245 "a=mid:video_content_name\r\n"
246 "a=sendrecv\r\n"
247 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
248 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
249 "a=rtpmap:120 VP8/90000\r\n"
250 "a=ssrc:2 cname:stream_1_cname\r\n"
251 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
252 "a=ssrc:2 mslabel:local_stream_1\r\n"
253 "a=ssrc:2 label:video_track_id_1\r\n"
254 "a=ssrc:3 cname:stream_1_cname\r\n"
255 "a=ssrc:3 msid:local_stream_1 video_track_id_2\r\n"
256 "a=ssrc:3 mslabel:local_stream_1\r\n"
257 "a=ssrc:3 label:video_track_id_2\r\n"
258 "a=ssrc-group:FEC 5 6\r\n"
259 "a=ssrc:5 cname:stream_2_cname\r\n"
260 "a=ssrc:5 msid:local_stream_2 video_track_id_3\r\n"
261 "a=ssrc:5 mslabel:local_stream_2\r\n"
262 "a=ssrc:5 label:video_track_id_3\r\n"
263 "a=ssrc:6 cname:stream_2_cname\r\n"
264 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
265 "a=ssrc:6 mslabel:local_stream_2\r\n"
266 "a=ssrc:6 label:video_track_id_3\r\n";
267
268static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000269 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000270 "c=IN IP4 0.0.0.0\r\n"
271 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000272 "a=ice-ufrag:ufrag_data\r\n"
273 "a=ice-pwd:pwd_data\r\n"
274 "a=mid:data_content_name\r\n"
275 "a=sendrecv\r\n"
276 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
277 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
278 "a=rtpmap:101 google-data/90000\r\n"
279 "a=ssrc:10 cname:data_channel_cname\r\n"
280 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
281 "a=ssrc:10 mslabel:data_channel\r\n"
282 "a=ssrc:10 label:data_channeld0\r\n";
283
284static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000285 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000286 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000287 "a=ice-ufrag:ufrag_data\r\n"
288 "a=ice-pwd:pwd_data\r\n"
289 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000290 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000291
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000292// draft-ietf-mmusic-sctp-sdp-12
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000293static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000294 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
295 "a=max-message-size=100000\r\n"
296 "a=sctp-port 5000\r\n"
297 "c=IN IP4 0.0.0.0\r\n"
298 "a=ice-ufrag:ufrag_data\r\n"
299 "a=ice-pwd:pwd_data\r\n"
300 "a=mid:data_content_name\r\n";
301
lally69f57602015-10-08 10:15:04 -0700302static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
303 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
304 "a=max-message-size=100000\r\n"
305 "a=sctp-port:5000\r\n"
306 "c=IN IP4 0.0.0.0\r\n"
307 "a=ice-ufrag:ufrag_data\r\n"
308 "a=ice-pwd:pwd_data\r\n"
309 "a=mid:data_content_name\r\n";
310
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311static const char kSdpSctpDataChannelWithCandidatesString[] =
312 "m=application 2345 DTLS/SCTP 5000\r\n"
313 "c=IN IP4 74.125.127.126\r\n"
314 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
315 "generation 2\r\n"
316 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
317 "generation 2\r\n"
318 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
319 "raddr 192.168.1.5 rport 2346 "
320 "generation 2\r\n"
321 "a=ice-ufrag:ufrag_data\r\n"
322 "a=ice-pwd:pwd_data\r\n"
323 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000324 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000325
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000326static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000327 "v=0\r\n"
328 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
329 "s=-\r\n"
330 "t=0 0\r\n"
331 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000332 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000333 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000334 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000335 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000336 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000337 "a=x-google-flag:conference\r\n";
338
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000339static const char kSdpSessionString[] =
340 "v=0\r\n"
341 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
342 "s=-\r\n"
343 "t=0 0\r\n"
344 "a=msid-semantic: WMS local_stream\r\n";
345
346static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000347 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000348 "c=IN IP4 0.0.0.0\r\n"
349 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000350 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
351 "a=mid:audio_content_name\r\n"
352 "a=sendrecv\r\n"
353 "a=rtpmap:111 opus/48000/2\r\n"
354 "a=ssrc:1 cname:stream_1_cname\r\n"
355 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
356 "a=ssrc:1 mslabel:local_stream\r\n"
357 "a=ssrc:1 label:audio_track_id_1\r\n";
358
359static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000360 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000361 "c=IN IP4 0.0.0.0\r\n"
362 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000363 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
364 "a=mid:video_content_name\r\n"
365 "a=sendrecv\r\n"
366 "a=rtpmap:120 VP8/90000\r\n"
367 "a=ssrc:2 cname:stream_1_cname\r\n"
368 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
369 "a=ssrc:2 mslabel:local_stream\r\n"
370 "a=ssrc:2 label:video_track_id_1\r\n";
371
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000372
373// One candidate reference string as per W3c spec.
374// candidate:<blah> not a=candidate:<blah>CRLF
375static const char kRawCandidate[] =
376 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
377// One candidate reference string.
378static const char kSdpOneCandidate[] =
379 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
380 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000381
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000382static const char kSdpTcpActiveCandidate[] =
383 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
384 "tcptype active generation 2";
385static const char kSdpTcpPassiveCandidate[] =
386 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
387 "tcptype passive generation 2";
388static const char kSdpTcpSOCandidate[] =
389 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
390 "tcptype so generation 2";
391static const char kSdpTcpInvalidCandidate[] =
392 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
393 "tcptype invalid generation 2";
394
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000395// One candidate reference string with IPV6 address.
396static const char kRawIPV6Candidate[] =
397 "candidate:a0+B/1 1 udp 2130706432 "
398 "abcd::abcd::abcd::abcd::abcd::abcd::abcd::abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000399
400// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800401static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000402 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800403 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000404
405// Session id and version
406static const char kSessionId[] = "18446744069414584320";
407static const char kSessionVersion[] = "18446462598732840960";
408
409// Ice options
410static const char kIceOption1[] = "iceoption1";
411static const char kIceOption2[] = "iceoption2";
412static const char kIceOption3[] = "iceoption3";
413
414// Content name
415static const char kAudioContentName[] = "audio_content_name";
416static const char kVideoContentName[] = "video_content_name";
417static const char kDataContentName[] = "data_content_name";
418
419// MediaStream 1
420static const char kStreamLabel1[] = "local_stream_1";
421static const char kStream1Cname[] = "stream_1_cname";
422static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200423static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000424static const char kVideoTrackId1[] = "video_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200425static const uint32_t kVideoTrack1Ssrc = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000426static const char kVideoTrackId2[] = "video_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200427static const uint32_t kVideoTrack2Ssrc = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000428
429// MediaStream 2
430static const char kStreamLabel2[] = "local_stream_2";
431static const char kStream2Cname[] = "stream_2_cname";
432static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200433static const uint32_t kAudioTrack2Ssrc = 4;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000434static const char kVideoTrackId3[] = "video_track_id_3";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200435static const uint32_t kVideoTrack3Ssrc = 5;
436static const uint32_t kVideoTrack4Ssrc = 6;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000437
438// DataChannel
439static const char kDataChannelLabel[] = "data_channel";
440static const char kDataChannelMsid[] = "data_channeld0";
441static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200442static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000443
444// Candidate
445static const char kDummyMid[] = "dummy_mid";
446static const int kDummyIndex = 123;
447
448// Misc
449static const char kDummyString[] = "dummy";
450
451// Helper functions
452
453static bool SdpDeserialize(const std::string& message,
454 JsepSessionDescription* jdesc) {
455 return webrtc::SdpDeserialize(message, jdesc, NULL);
456}
457
458static bool SdpDeserializeCandidate(const std::string& message,
459 JsepIceCandidate* candidate) {
460 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
461}
462
463// Add some extra |newlines| to the |message| after |line|.
464static void InjectAfter(const std::string& line,
465 const std::string& newlines,
466 std::string* message) {
467 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000468 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000469 tmp.c_str(), tmp.length(), message);
470}
471
472static void Replace(const std::string& line,
473 const std::string& newlines,
474 std::string* message) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000475 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000476 newlines.c_str(), newlines.length(), message);
477}
478
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000479// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
480// message.
481static void ExpectParseFailure(const std::string& bad_sdp,
482 const std::string& bad_part) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000483 JsepSessionDescription desc(kDummyString);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000484 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000485 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000486 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000487 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
488}
489
490// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
491static void ExpectParseFailure(const char* good_part, const char* bad_part) {
492 std::string bad_sdp = kSdpFullString;
493 Replace(good_part, bad_part, &bad_sdp);
494 ExpectParseFailure(bad_sdp, bad_part);
495}
496
497// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
498static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
499 const std::string& newlines,
500 const std::string& bad_part) {
501 std::string bad_sdp = kSdpFullString;
502 InjectAfter(injectpoint, newlines, &bad_sdp);
503 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000504}
505
506static void ReplaceDirection(cricket::MediaContentDirection direction,
507 std::string* message) {
508 std::string new_direction;
509 switch (direction) {
510 case cricket::MD_INACTIVE:
511 new_direction = "a=inactive";
512 break;
513 case cricket::MD_SENDONLY:
514 new_direction = "a=sendonly";
515 break;
516 case cricket::MD_RECVONLY:
517 new_direction = "a=recvonly";
518 break;
519 case cricket::MD_SENDRECV:
520 default:
521 new_direction = "a=sendrecv";
522 break;
523 }
524 Replace("a=sendrecv", new_direction, message);
525}
526
527static void ReplaceRejected(bool audio_rejected, bool video_rejected,
528 std::string* message) {
529 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800530 Replace("m=audio 9", "m=audio 0", message);
531 Replace(kAttributeIceUfragVoice, "", message);
532 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000533 }
534 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800535 Replace("m=video 9", "m=video 0", message);
536 Replace(kAttributeIceUfragVideo, "", message);
537 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000538 }
539}
540
541// WebRtcSdpTest
542
543class WebRtcSdpTest : public testing::Test {
544 public:
545 WebRtcSdpTest()
546 : jdesc_(kDummyString) {
547 // AudioContentDescription
548 audio_desc_ = CreateAudioContentDescription();
549 AudioCodec opus(111, "opus", 48000, 0, 2, 3);
550 audio_desc_->AddCodec(opus);
551 audio_desc_->AddCodec(AudioCodec(103, "ISAC", 16000, 32000, 1, 2));
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000552 audio_desc_->AddCodec(AudioCodec(104, "ISAC", 32000, 56000, 1, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000553 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
554
555 // VideoContentDescription
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000556 rtc::scoped_ptr<VideoContentDescription> video(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000557 new VideoContentDescription());
558 video_desc_ = video.get();
559 StreamParams video_stream1;
560 video_stream1.id = kVideoTrackId1;
561 video_stream1.cname = kStream1Cname;
562 video_stream1.sync_label = kStreamLabel1;
563 video_stream1.ssrcs.push_back(kVideoTrack1Ssrc);
564 video->AddStream(video_stream1);
565 StreamParams video_stream2;
566 video_stream2.id = kVideoTrackId2;
567 video_stream2.cname = kStream1Cname;
568 video_stream2.sync_label = kStreamLabel1;
569 video_stream2.ssrcs.push_back(kVideoTrack2Ssrc);
570 video->AddStream(video_stream2);
571 StreamParams video_stream3;
572 video_stream3.id = kVideoTrackId3;
573 video_stream3.cname = kStream2Cname;
574 video_stream3.sync_label = kStreamLabel2;
575 video_stream3.ssrcs.push_back(kVideoTrack3Ssrc);
576 video_stream3.ssrcs.push_back(kVideoTrack4Ssrc);
577 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream3.ssrcs);
578 video_stream3.ssrc_groups.push_back(ssrc_group);
579 video->AddStream(video_stream3);
580 video->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
581 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
582 video->set_protocol(cricket::kMediaProtocolSavpf);
583 video->AddCodec(VideoCodec(
584 120,
585 JsepSessionDescription::kDefaultVideoCodecName,
586 JsepSessionDescription::kMaxVideoCodecWidth,
587 JsepSessionDescription::kMaxVideoCodecHeight,
588 JsepSessionDescription::kDefaultVideoCodecFramerate,
589 JsepSessionDescription::kDefaultVideoCodecPreference));
590
591 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP,
592 video.release());
593
594 // TransportInfo
595 EXPECT_TRUE(desc_.AddTransportInfo(
596 TransportInfo(kAudioContentName,
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700597 TransportDescription(kCandidateUfragVoice,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000598 kCandidatePwdVoice))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000599 EXPECT_TRUE(desc_.AddTransportInfo(
600 TransportInfo(kVideoContentName,
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700601 TransportDescription(kCandidateUfragVideo,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000602 kCandidatePwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000603
604 // v4 host
605 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000606 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000607 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000608 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
609 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000610 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000611 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000612 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
613 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000614 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000615 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000616 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
617 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000618 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000619 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000620 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
621 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000622
623 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000624 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000625 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
626 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000627 cricket::LOCAL_PORT_TYPE,
628 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000629 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000630 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
631 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000632 cricket::LOCAL_PORT_TYPE,
633 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000634 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000635 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
636 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000637 cricket::LOCAL_PORT_TYPE,
638 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000639 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000640 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
641 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000642 cricket::LOCAL_PORT_TYPE,
643 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000644
645 // stun
646 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000647 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
648 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000649 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
650 address_stun, kCandidatePriority, "", "",
651 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000652 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000653 candidate9.set_related_address(rel_address_stun);
654
655 address_stun.SetPort(port_stun++);
656 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000657 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
658 address_stun, kCandidatePriority, "", "",
659 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000660 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000661 candidate10.set_related_address(rel_address_stun);
662
663 // relay
664 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000665 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000666 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
667 address_relay, kCandidatePriority, "", "",
668 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000669 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000670 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000671 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
672 address_relay, kCandidatePriority, "", "",
673 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000674 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000675
676 // voice
677 candidates_.push_back(candidate1);
678 candidates_.push_back(candidate2);
679 candidates_.push_back(candidate5);
680 candidates_.push_back(candidate6);
681 candidates_.push_back(candidate9);
682 candidates_.push_back(candidate10);
683
684 // video
685 candidates_.push_back(candidate3);
686 candidates_.push_back(candidate4);
687 candidates_.push_back(candidate7);
688 candidates_.push_back(candidate8);
689 candidates_.push_back(candidate11);
690 candidates_.push_back(candidate12);
691
692 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"),
693 0, candidate1));
694
695 // Set up JsepSessionDescription.
696 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
697 std::string mline_id;
698 int mline_index = 0;
699 for (size_t i = 0; i< candidates_.size(); ++i) {
700 // In this test, the audio m line index will be 0, and the video m line
701 // will be 1.
702 bool is_video = (i > 5);
703 mline_id = is_video ? "video_content_name" : "audio_content_name";
704 mline_index = is_video ? 1 : 0;
705 JsepIceCandidate jice(mline_id,
706 mline_index,
707 candidates_.at(i));
708 jdesc_.AddCandidate(&jice);
709 }
710 }
711
712 AudioContentDescription* CreateAudioContentDescription() {
713 AudioContentDescription* audio = new AudioContentDescription();
714 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -0800715 audio->set_rtcp_reduced_size(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000716 StreamParams audio_stream1;
717 audio_stream1.id = kAudioTrackId1;
718 audio_stream1.cname = kStream1Cname;
719 audio_stream1.sync_label = kStreamLabel1;
720 audio_stream1.ssrcs.push_back(kAudioTrack1Ssrc);
721 audio->AddStream(audio_stream1);
722 StreamParams audio_stream2;
723 audio_stream2.id = kAudioTrackId2;
724 audio_stream2.cname = kStream2Cname;
725 audio_stream2.sync_label = kStreamLabel2;
726 audio_stream2.ssrcs.push_back(kAudioTrack2Ssrc);
727 audio->AddStream(audio_stream2);
728 audio->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_32",
729 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
730 "dummy_session_params"));
731 audio->set_protocol(cricket::kMediaProtocolSavpf);
732 return audio;
733 }
734
735 template <class MCD>
736 void CompareMediaContentDescription(const MCD* cd1,
737 const MCD* cd2) {
738 // type
739 EXPECT_EQ(cd1->type(), cd1->type());
740
741 // content direction
742 EXPECT_EQ(cd1->direction(), cd2->direction());
743
744 // rtcp_mux
745 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
746
deadbeef13871492015-12-09 12:37:51 -0800747 // rtcp_reduced_size
748 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
749
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000750 // cryptos
751 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
752 if (cd1->cryptos().size() != cd2->cryptos().size()) {
753 ADD_FAILURE();
754 return;
755 }
756 for (size_t i = 0; i< cd1->cryptos().size(); ++i) {
757 const CryptoParams c1 = cd1->cryptos().at(i);
758 const CryptoParams c2 = cd2->cryptos().at(i);
759 EXPECT_TRUE(c1.Matches(c2));
760 EXPECT_EQ(c1.key_params, c2.key_params);
761 EXPECT_EQ(c1.session_params, c2.session_params);
762 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +0000763
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000764 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +0000765 // Use an equivalence class here, for old and new versions of the
766 // protocol description.
767 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:35 +0000768 || cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp
769 || cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
770 const bool cd2_is_also_dtls_sctp =
lally@webrtc.orgd7b61652015-02-24 20:18:55 +0000771 cd2->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:35 +0000772 || cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp
773 || cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
774 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +0000775 } else {
776 EXPECT_EQ(cd1->protocol(), cd2->protocol());
777 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000778
779 // codecs
780 EXPECT_EQ(cd1->codecs(), cd2->codecs());
781
782 // bandwidth
783 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
784
785 // streams
786 EXPECT_EQ(cd1->streams(), cd2->streams());
787
788 // extmap
789 ASSERT_EQ(cd1->rtp_header_extensions().size(),
790 cd2->rtp_header_extensions().size());
791 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) {
792 const RtpHeaderExtension ext1 = cd1->rtp_header_extensions().at(i);
793 const RtpHeaderExtension ext2 = cd2->rtp_header_extensions().at(i);
794 EXPECT_EQ(ext1.uri, ext2.uri);
795 EXPECT_EQ(ext1.id, ext2.id);
796 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000797 }
798
799
800 void CompareSessionDescription(const SessionDescription& desc1,
801 const SessionDescription& desc2) {
802 // Compare content descriptions.
803 if (desc1.contents().size() != desc2.contents().size()) {
804 ADD_FAILURE();
805 return;
806 }
807 for (size_t i = 0 ; i < desc1.contents().size(); ++i) {
808 const cricket::ContentInfo& c1 = desc1.contents().at(i);
809 const cricket::ContentInfo& c2 = desc2.contents().at(i);
810 // content name
811 EXPECT_EQ(c1.name, c2.name);
812 // content type
813 // Note, ASSERT will return from the function, but will not stop the test.
814 ASSERT_EQ(c1.type, c2.type);
815
816 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
817 if (IsAudioContent(&c1)) {
818 const AudioContentDescription* acd1 =
819 static_cast<const AudioContentDescription*>(c1.description);
820 const AudioContentDescription* acd2 =
821 static_cast<const AudioContentDescription*>(c2.description);
822 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
823 }
824
825 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
826 if (IsVideoContent(&c1)) {
827 const VideoContentDescription* vcd1 =
828 static_cast<const VideoContentDescription*>(c1.description);
829 const VideoContentDescription* vcd2 =
830 static_cast<const VideoContentDescription*>(c2.description);
831 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
832 }
833
834 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
835 if (IsDataContent(&c1)) {
836 const DataContentDescription* dcd1 =
837 static_cast<const DataContentDescription*>(c1.description);
838 const DataContentDescription* dcd2 =
839 static_cast<const DataContentDescription*>(c2.description);
840 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
841 }
842 }
843
844 // group
845 const cricket::ContentGroups groups1 = desc1.groups();
846 const cricket::ContentGroups groups2 = desc2.groups();
847 EXPECT_EQ(groups1.size(), groups1.size());
848 if (groups1.size() != groups2.size()) {
849 ADD_FAILURE();
850 return;
851 }
852 for (size_t i = 0; i < groups1.size(); ++i) {
853 const cricket::ContentGroup group1 = groups1.at(i);
854 const cricket::ContentGroup group2 = groups2.at(i);
855 EXPECT_EQ(group1.semantics(), group2.semantics());
856 const cricket::ContentNames names1 = group1.content_names();
857 const cricket::ContentNames names2 = group2.content_names();
858 EXPECT_EQ(names1.size(), names2.size());
859 if (names1.size() != names2.size()) {
860 ADD_FAILURE();
861 return;
862 }
863 cricket::ContentNames::const_iterator iter1 = names1.begin();
864 cricket::ContentNames::const_iterator iter2 = names2.begin();
865 while (iter1 != names1.end()) {
866 EXPECT_EQ(*iter1++, *iter2++);
867 }
868 }
869
870 // transport info
871 const cricket::TransportInfos transports1 = desc1.transport_infos();
872 const cricket::TransportInfos transports2 = desc2.transport_infos();
873 EXPECT_EQ(transports1.size(), transports2.size());
874 if (transports1.size() != transports2.size()) {
875 ADD_FAILURE();
876 return;
877 }
878 for (size_t i = 0; i < transports1.size(); ++i) {
879 const cricket::TransportInfo transport1 = transports1.at(i);
880 const cricket::TransportInfo transport2 = transports2.at(i);
881 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000882 EXPECT_EQ(transport1.description.ice_ufrag,
883 transport2.description.ice_ufrag);
884 EXPECT_EQ(transport1.description.ice_pwd,
885 transport2.description.ice_pwd);
886 if (transport1.description.identity_fingerprint) {
887 EXPECT_EQ(*transport1.description.identity_fingerprint,
888 *transport2.description.identity_fingerprint);
889 } else {
890 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
891 transport2.description.identity_fingerprint.get());
892 }
893 EXPECT_EQ(transport1.description.transport_options,
894 transport2.description.transport_options);
895 EXPECT_TRUE(CompareCandidates(transport1.description.candidates,
896 transport2.description.candidates));
897 }
deadbeefc80741f2015-10-22 13:14:45 -0700898
899 // global attributes
900 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000901 }
902
903 bool CompareCandidates(const Candidates& cs1, const Candidates& cs2) {
904 EXPECT_EQ(cs1.size(), cs2.size());
905 if (cs1.size() != cs2.size())
906 return false;
907 for (size_t i = 0; i< cs1.size(); ++i) {
908 const Candidate c1 = cs1.at(i);
909 const Candidate c2 = cs2.at(i);
910 EXPECT_TRUE(c1.IsEquivalent(c2));
911 }
912 return true;
913 }
914
915 bool CompareSessionDescription(
916 const JsepSessionDescription& desc1,
917 const JsepSessionDescription& desc2) {
918 EXPECT_EQ(desc1.session_id(), desc2.session_id());
919 EXPECT_EQ(desc1.session_version(), desc2.session_version());
920 CompareSessionDescription(*desc1.description(), *desc2.description());
921 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
922 return false;
923 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
924 const IceCandidateCollection* cc1 = desc1.candidates(i);
925 const IceCandidateCollection* cc2 = desc2.candidates(i);
926 if (cc1->count() != cc2->count())
927 return false;
928 for (size_t j = 0; j < cc1->count(); ++j) {
929 const IceCandidateInterface* c1 = cc1->at(j);
930 const IceCandidateInterface* c2 = cc2->at(j);
931 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
932 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
933 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
934 }
935 }
936 return true;
937 }
938
939 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
940 // them with invalid keywords so that the parser will just ignore them.
941 bool RemoveCandidateUfragPwd(std::string* sdp) {
942 const char ice_ufrag[] = "a=ice-ufrag";
943 const char ice_ufragx[] = "a=xice-ufrag";
944 const char ice_pwd[] = "a=ice-pwd";
945 const char ice_pwdx[] = "a=xice-pwd";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000946 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000947 ice_ufragx, strlen(ice_ufragx), sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000948 rtc::replace_substrs(ice_pwd, strlen(ice_pwd),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000949 ice_pwdx, strlen(ice_pwdx), sdp);
950 return true;
951 }
952
953 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
954 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, int mline_index,
955 const std::string& ufrag, const std::string& pwd) {
956 std::string content_name;
957 if (mline_index == 0) {
958 content_name = kAudioContentName;
959 } else if (mline_index == 1) {
960 content_name = kVideoContentName;
961 } else {
962 ASSERT(false);
963 }
964 TransportInfo transport_info(
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700965 content_name, TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000966 SessionDescription* desc =
967 const_cast<SessionDescription*>(jdesc->description());
968 desc->RemoveTransportInfoByName(content_name);
969 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
970 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
971 const IceCandidateCollection* cc = jdesc_.candidates(i);
972 for (size_t j = 0; j < cc->count(); ++j) {
973 if (cc->at(j)->sdp_mline_index() == mline_index) {
974 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(
975 ufrag);
976 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(
977 pwd);
978 }
979 }
980 }
981 return true;
982 }
983
984 void AddIceOptions(const std::string& content_name,
985 const std::vector<std::string>& transport_options) {
986 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
987 cricket::TransportInfo transport_info =
988 *(desc_.GetTransportInfoByName(content_name));
989 desc_.RemoveTransportInfoByName(content_name);
990 transport_info.description.transport_options = transport_options;
991 desc_.AddTransportInfo(transport_info);
992 }
993
deadbeef3f7219b2015-12-28 15:17:14 -0800994 void SetIceUfragPwd(const std::string& content_name,
995 const std::string& ice_ufrag,
996 const std::string& ice_pwd) {
997 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
998 cricket::TransportInfo transport_info =
999 *(desc_.GetTransportInfoByName(content_name));
1000 desc_.RemoveTransportInfoByName(content_name);
1001 transport_info.description.ice_ufrag = ice_ufrag;
1002 transport_info.description.ice_pwd = ice_pwd;
1003 desc_.AddTransportInfo(transport_info);
1004 }
1005
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001006 void AddFingerprint() {
1007 desc_.RemoveTransportInfoByName(kAudioContentName);
1008 desc_.RemoveTransportInfoByName(kVideoContentName);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001009 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001010 kIdentityDigest,
1011 sizeof(kIdentityDigest));
1012 EXPECT_TRUE(desc_.AddTransportInfo(
1013 TransportInfo(kAudioContentName,
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001014 TransportDescription(std::vector<std::string>(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001015 kCandidateUfragVoice,
1016 kCandidatePwdVoice,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001017 cricket::ICEMODE_FULL,
1018 cricket::CONNECTIONROLE_NONE,
1019 &fingerprint, Candidates()))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001020 EXPECT_TRUE(desc_.AddTransportInfo(
1021 TransportInfo(kVideoContentName,
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001022 TransportDescription(std::vector<std::string>(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001023 kCandidateUfragVideo,
1024 kCandidatePwdVideo,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001025 cricket::ICEMODE_FULL,
1026 cricket::CONNECTIONROLE_NONE,
1027 &fingerprint, Candidates()))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001028 }
1029
1030 void AddExtmap() {
1031 audio_desc_ = static_cast<AudioContentDescription*>(
1032 audio_desc_->Copy());
1033 video_desc_ = static_cast<VideoContentDescription*>(
1034 video_desc_->Copy());
1035 audio_desc_->AddRtpHeaderExtension(
1036 RtpHeaderExtension(kExtmapUri, kExtmapId));
1037 video_desc_->AddRtpHeaderExtension(
1038 RtpHeaderExtension(kExtmapUri, kExtmapId));
1039 desc_.RemoveContentByName(kAudioContentName);
1040 desc_.RemoveContentByName(kVideoContentName);
1041 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1042 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1043 }
1044
1045 void RemoveCryptos() {
1046 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1047 video_desc_->set_cryptos(std::vector<CryptoParams>());
1048 }
1049
1050 bool TestSerializeDirection(cricket::MediaContentDirection direction) {
1051 audio_desc_->set_direction(direction);
1052 video_desc_->set_direction(direction);
1053 std::string new_sdp = kSdpFullString;
1054 ReplaceDirection(direction, &new_sdp);
1055
1056 if (!jdesc_.Initialize(desc_.Copy(),
1057 jdesc_.session_id(),
1058 jdesc_.session_version())) {
1059 return false;
1060 }
1061 std::string message = webrtc::SdpSerialize(jdesc_);
1062 EXPECT_EQ(new_sdp, message);
1063 return true;
1064 }
1065
1066 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
1067 audio_desc_ = static_cast<AudioContentDescription*>(
1068 audio_desc_->Copy());
1069 video_desc_ = static_cast<VideoContentDescription*>(
1070 video_desc_->Copy());
1071 desc_.RemoveContentByName(kAudioContentName);
1072 desc_.RemoveContentByName(kVideoContentName);
1073 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1074 audio_desc_);
1075 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1076 video_desc_);
deadbeef3f7219b2015-12-28 15:17:14 -08001077 SetIceUfragPwd(kAudioContentName,
1078 audio_rejected ? "" : kCandidateUfragVoice,
1079 audio_rejected ? "" : kCandidatePwdVoice);
1080 SetIceUfragPwd(kVideoContentName,
1081 video_rejected ? "" : kCandidateUfragVideo,
1082 video_rejected ? "" : kCandidatePwdVideo);
1083
1084 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001085 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1086
deadbeef3f7219b2015-12-28 15:17:14 -08001087 JsepSessionDescription jdesc_no_candidates(kDummyString);
1088 if (!jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
1089 kSessionVersion)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001090 return false;
1091 }
deadbeef3f7219b2015-12-28 15:17:14 -08001092 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001093 EXPECT_EQ(new_sdp, message);
1094 return true;
1095 }
1096
1097 void AddSctpDataChannel() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001098 rtc::scoped_ptr<DataContentDescription> data(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001099 new DataContentDescription());
1100 data_desc_ = data.get();
1101 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
wu@webrtc.org78187522013-10-07 23:32:02 +00001102 DataCodec codec(cricket::kGoogleSctpDataCodecId,
1103 cricket::kGoogleSctpDataCodecName, 0);
1104 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1105 data_desc_->AddCodec(codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001106 desc_.AddContent(kDataContentName, NS_JINGLE_DRAFT_SCTP, data.release());
1107 EXPECT_TRUE(desc_.AddTransportInfo(
1108 TransportInfo(kDataContentName,
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001109 TransportDescription(kCandidateUfragData,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001110 kCandidatePwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001111 }
1112
1113 void AddRtpDataChannel() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001114 rtc::scoped_ptr<DataContentDescription> data(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001115 new DataContentDescription());
1116 data_desc_ = data.get();
1117
1118 data_desc_->AddCodec(DataCodec(101, "google-data", 1));
1119 StreamParams data_stream;
1120 data_stream.id = kDataChannelMsid;
1121 data_stream.cname = kDataChannelCname;
1122 data_stream.sync_label = kDataChannelLabel;
1123 data_stream.ssrcs.push_back(kDataChannelSsrc);
1124 data_desc_->AddStream(data_stream);
1125 data_desc_->AddCrypto(CryptoParams(
1126 1, "AES_CM_128_HMAC_SHA1_80",
1127 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
1128 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
1129 desc_.AddContent(kDataContentName, NS_JINGLE_RTP, data.release());
1130 EXPECT_TRUE(desc_.AddTransportInfo(
1131 TransportInfo(kDataContentName,
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001132 TransportDescription(kCandidateUfragData,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001133 kCandidatePwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001134 }
1135
1136 bool TestDeserializeDirection(cricket::MediaContentDirection direction) {
1137 std::string new_sdp = kSdpFullString;
1138 ReplaceDirection(direction, &new_sdp);
1139 JsepSessionDescription new_jdesc(kDummyString);
1140
1141 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1142
1143 audio_desc_->set_direction(direction);
1144 video_desc_->set_direction(direction);
1145 if (!jdesc_.Initialize(desc_.Copy(),
1146 jdesc_.session_id(),
1147 jdesc_.session_version())) {
1148 return false;
1149 }
1150 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1151 return true;
1152 }
1153
1154 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001155 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001156 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1157 JsepSessionDescription new_jdesc(JsepSessionDescription::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001158 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001159
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001160 audio_desc_ = static_cast<AudioContentDescription*>(
1161 audio_desc_->Copy());
1162 video_desc_ = static_cast<VideoContentDescription*>(
1163 video_desc_->Copy());
1164 desc_.RemoveContentByName(kAudioContentName);
1165 desc_.RemoveContentByName(kVideoContentName);
1166 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1167 audio_desc_);
1168 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1169 video_desc_);
deadbeef3f7219b2015-12-28 15:17:14 -08001170 SetIceUfragPwd(kAudioContentName,
1171 audio_rejected ? "" : kCandidateUfragVoice,
1172 audio_rejected ? "" : kCandidatePwdVoice);
1173 SetIceUfragPwd(kVideoContentName,
1174 video_rejected ? "" : kCandidateUfragVideo,
1175 video_rejected ? "" : kCandidatePwdVideo);
1176 JsepSessionDescription jdesc_no_candidates(kDummyString);
1177 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1178 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001179 return false;
1180 }
deadbeef3f7219b2015-12-28 15:17:14 -08001181 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001182 return true;
1183 }
1184
1185 void TestDeserializeExtmap(bool session_level, bool media_level) {
1186 AddExtmap();
1187 JsepSessionDescription new_jdesc("dummy");
1188 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1189 jdesc_.session_id(),
1190 jdesc_.session_version()));
1191 JsepSessionDescription jdesc_with_extmap("dummy");
1192 std::string sdp_with_extmap = kSdpString;
1193 if (session_level) {
1194 InjectAfter(kSessionTime, kExtmapWithDirectionAndAttribute,
1195 &sdp_with_extmap);
1196 }
1197 if (media_level) {
1198 InjectAfter(kAttributeIcePwdVoice, kExtmapWithDirectionAndAttribute,
1199 &sdp_with_extmap);
1200 InjectAfter(kAttributeIcePwdVideo, kExtmapWithDirectionAndAttribute,
1201 &sdp_with_extmap);
1202 }
1203 // The extmap can't be present at the same time in both session level and
1204 // media level.
1205 if (session_level && media_level) {
1206 SdpParseError error;
1207 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap,
1208 &jdesc_with_extmap, &error));
1209 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1210 } else {
1211 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1212 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1213 }
1214 }
1215
1216 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
1217 const std::string& name, int expected_value) {
1218 cricket::CodecParameterMap::const_iterator found = params.find(name);
1219 ASSERT_TRUE(found != params.end());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001220 EXPECT_EQ(found->second, rtc::ToString<int>(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001221 }
1222
1223 void TestDeserializeCodecParams(const CodecParams& params,
1224 JsepSessionDescription* jdesc_output) {
1225 std::string sdp =
1226 "v=0\r\n"
1227 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1228 "s=-\r\n"
1229 "t=0 0\r\n"
1230 // Include semantics for WebRTC Media Streams since it is supported by
1231 // this parser, and will be added to the SDP when serializing a session
1232 // description.
1233 "a=msid-semantic: WMS\r\n"
1234 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001235 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001236 // Pltype 111 listed before 103 and 104 in the map.
1237 "a=rtpmap:111 opus/48000/2\r\n"
1238 // Pltype 103 listed before 104.
1239 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001240 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001241 "a=fmtp:111 0-15,66,70\r\n"
1242 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001243 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001244 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001245 << "; sprop-stereo=" << params.sprop_stereo
1246 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001247 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001248 << "a=ptime:" << params.ptime << "\r\n"
1249 << "a=maxptime:" << params.max_ptime << "\r\n";
1250 sdp += os.str();
1251
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001252 os.clear();
1253 os.str("");
1254 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001255 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001256 << "a=rtpmap:99 VP8/90000\r\n"
1257 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001258 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001259 sdp += os.str();
1260
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001261 // Deserialize
1262 SdpParseError error;
1263 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1264
1265 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1266 ASSERT_TRUE(ac != NULL);
1267 const AudioContentDescription* acd =
1268 static_cast<const AudioContentDescription*>(ac->description);
1269 ASSERT_FALSE(acd->codecs().empty());
1270 cricket::AudioCodec opus = acd->codecs()[0];
1271 EXPECT_EQ("opus", opus.name);
1272 EXPECT_EQ(111, opus.id);
1273 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1274 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1275 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1276 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001277 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1278 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001279 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1280 cricket::AudioCodec codec = acd->codecs()[i];
1281 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1282 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
1283 if (codec.name == "ISAC") {
1284 if (codec.clockrate == 16000) {
1285 EXPECT_EQ(32000, codec.bitrate);
1286 } else {
1287 EXPECT_EQ(56000, codec.bitrate);
1288 }
1289 }
1290 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001291
1292 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1293 ASSERT_TRUE(vc != NULL);
1294 const VideoContentDescription* vcd =
1295 static_cast<const VideoContentDescription*>(vc->description);
1296 ASSERT_FALSE(vcd->codecs().empty());
1297 cricket::VideoCodec vp8 = vcd->codecs()[0];
1298 EXPECT_EQ("VP8", vp8.name);
1299 EXPECT_EQ(99, vp8.id);
1300 cricket::VideoCodec rtx = vcd->codecs()[1];
1301 EXPECT_EQ("RTX", rtx.name);
1302 EXPECT_EQ(95, rtx.id);
1303 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001304 }
1305
1306 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1307 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001308 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001309 "v=0\r\n"
1310 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1311 "s=-\r\n"
1312 "t=0 0\r\n"
1313 // Include semantics for WebRTC Media Streams since it is supported by
1314 // this parser, and will be added to the SDP when serializing a session
1315 // description.
1316 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001317 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001318 "a=rtpmap:111 opus/48000/2\r\n";
1319 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001320 "m=video 3457 RTP/SAVPF 101\r\n"
1321 "a=rtpmap:101 VP8/90000\r\n"
1322 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001323 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001324 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001325 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001326 os << sdp_session_and_audio;
1327 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
1328 os << sdp_video;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001329 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001330 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001331 // Deserialize
1332 SdpParseError error;
1333 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1334 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1335 ASSERT_TRUE(ac != NULL);
1336 const AudioContentDescription* acd =
1337 static_cast<const AudioContentDescription*>(ac->description);
1338 ASSERT_FALSE(acd->codecs().empty());
1339 cricket::AudioCodec opus = acd->codecs()[0];
1340 EXPECT_EQ(111, opus.id);
1341 EXPECT_TRUE(opus.HasFeedbackParam(
1342 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1343 cricket::kParamValueEmpty)));
1344
1345 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1346 ASSERT_TRUE(vc != NULL);
1347 const VideoContentDescription* vcd =
1348 static_cast<const VideoContentDescription*>(vc->description);
1349 ASSERT_FALSE(vcd->codecs().empty());
1350 cricket::VideoCodec vp8 = vcd->codecs()[0];
1351 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1352 vp8.name.c_str());
1353 EXPECT_EQ(101, vp8.id);
1354 EXPECT_TRUE(vp8.HasFeedbackParam(
1355 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1356 cricket::kParamValueEmpty)));
1357 EXPECT_TRUE(vp8.HasFeedbackParam(
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001358 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1359 cricket::kRtcpFbNackParamPli)));
1360 EXPECT_TRUE(vp8.HasFeedbackParam(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001361 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
1362 cricket::kParamValueEmpty)));
1363 EXPECT_TRUE(vp8.HasFeedbackParam(
1364 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
1365 cricket::kRtcpFbCcmParamFir)));
1366 }
1367
1368 // Two SDP messages can mean the same thing but be different strings, e.g.
1369 // some of the lines can be serialized in different order.
1370 // However, a deserialized description can be compared field by field and has
1371 // no order. If deserializer has already been tested, serializing then
1372 // deserializing and comparing JsepSessionDescription will test
1373 // the serializer sufficiently.
1374 void TestSerialize(const JsepSessionDescription& jdesc) {
1375 std::string message = webrtc::SdpSerialize(jdesc);
1376 JsepSessionDescription jdesc_output_des(kDummyString);
1377 SdpParseError error;
1378 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1379 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1380 }
1381
1382 protected:
1383 SessionDescription desc_;
1384 AudioContentDescription* audio_desc_;
1385 VideoContentDescription* video_desc_;
1386 DataContentDescription* data_desc_;
1387 Candidates candidates_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001388 rtc::scoped_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001389 JsepSessionDescription jdesc_;
1390};
1391
1392void TestMismatch(const std::string& string1, const std::string& string2) {
1393 int position = 0;
1394 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1395 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001396 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001397 break;
1398 }
1399 }
1400 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1401 << " character\n"
1402 << " 1: " << string1.substr(position, 20) << "\n"
1403 << " 2: " << string2.substr(position, 20) << "\n";
1404}
1405
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001406TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1407 // SessionDescription with desc and candidates.
1408 std::string message = webrtc::SdpSerialize(jdesc_);
1409 TestMismatch(std::string(kSdpFullString), message);
1410}
1411
1412TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
1413 JsepSessionDescription jdesc_empty(kDummyString);
1414 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
1415}
1416
guoweis@webrtc.org57ac2c82015-02-06 00:45:13 +00001417// This tests serialization of SDP with only IPv6 candidates and verifies that
1418// IPv6 is used as default address in c line according to preference.
1419TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIPv6Only) {
1420 // Only test 1 m line.
1421 desc_.RemoveContentByName("video_content_name");
1422 // Stun has a high preference than local host.
1423 cricket::Candidate candidate1(
1424 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1425 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1426 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1427 cricket::Candidate candidate2(
1428 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1429 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
1430 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1431 JsepSessionDescription jdesc(kDummyString);
1432 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1433
1434 // Only add the candidates to audio m line.
1435 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1436 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1437 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1438 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
1439 std::string message = webrtc::SdpSerialize(jdesc);
1440
1441 // Audio line should have a c line like this one.
1442 EXPECT_NE(message.find("c=IN IP6 ::1"), std::string::npos);
1443 // Shouldn't have a IP4 c line.
1444 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
1445}
1446
1447// This tests serialization of SDP with both IPv4 and IPv6 candidates and
1448// verifies that IPv4 is used as default address in c line even if the
1449// preference of IPv4 is lower.
1450TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothIPFamilies) {
1451 // Only test 1 m line.
1452 desc_.RemoveContentByName("video_content_name");
1453 cricket::Candidate candidate_v4(
1454 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1455 rtc::SocketAddress("192.168.1.5", 1234), kCandidatePriority, "", "",
1456 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1457 cricket::Candidate candidate_v6(
1458 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1459 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1460 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1461 JsepSessionDescription jdesc(kDummyString);
1462 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1463
1464 // Only add the candidates to audio m line.
1465 JsepIceCandidate jice_v4("audio_content_name", 0, candidate_v4);
1466 JsepIceCandidate jice_v6("audio_content_name", 0, candidate_v6);
1467 ASSERT_TRUE(jdesc.AddCandidate(&jice_v4));
1468 ASSERT_TRUE(jdesc.AddCandidate(&jice_v6));
1469 std::string message = webrtc::SdpSerialize(jdesc);
1470
1471 // Audio line should have a c line like this one.
1472 EXPECT_NE(message.find("c=IN IP4 192.168.1.5"), std::string::npos);
1473 // Shouldn't have a IP6 c line.
1474 EXPECT_EQ(message.find("c=IN IP6"), std::string::npos);
1475}
1476
1477// This tests serialization of SDP with both UDP and TCP candidates and
1478// verifies that UDP is used as default address in c line even if the
1479// preference of UDP is lower.
1480TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothProtocols) {
1481 // Only test 1 m line.
1482 desc_.RemoveContentByName("video_content_name");
1483 // Stun has a high preference than local host.
1484 cricket::Candidate candidate1(
1485 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1486 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1487 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1488 cricket::Candidate candidate2(
1489 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1490 rtc::SocketAddress("fe80::1234:5678:abcd:ef12", 1235), kCandidatePriority,
1491 "", "", cricket::LOCAL_PORT_TYPE, kCandidateGeneration,
1492 kCandidateFoundation1);
1493 JsepSessionDescription jdesc(kDummyString);
1494 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1495
1496 // Only add the candidates to audio m line.
1497 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1498 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1499 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1500 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
1501 std::string message = webrtc::SdpSerialize(jdesc);
1502
1503 // Audio line should have a c line like this one.
1504 EXPECT_NE(message.find("c=IN IP6 fe80::1234:5678:abcd:ef12"),
1505 std::string::npos);
1506 // Shouldn't have a IP4 c line.
1507 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
1508}
1509
1510// This tests serialization of SDP with only TCP candidates and verifies that
1511// null IPv4 is used as default address in c line.
1512TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithTCPOnly) {
1513 // Only test 1 m line.
1514 desc_.RemoveContentByName("video_content_name");
1515 // Stun has a high preference than local host.
1516 cricket::Candidate candidate1(
1517 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1518 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1519 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1520 cricket::Candidate candidate2(
1521 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1522 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
1523 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1524 JsepSessionDescription jdesc(kDummyString);
1525 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1526
1527 // Only add the candidates to audio m line.
1528 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1529 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1530 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1531 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
1532 std::string message = webrtc::SdpSerialize(jdesc);
1533
1534 // Audio line should have a c line like this one when no any default exists.
1535 EXPECT_NE(message.find("c=IN IP4 0.0.0.0"), std::string::npos);
1536}
1537
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001538// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1539// the case in a DTLS offer.
1540TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1541 AddFingerprint();
1542 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1543 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1544 kSessionId, kSessionVersion));
1545 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
1546
1547 std::string sdp_with_fingerprint = kSdpString;
1548 InjectAfter(kAttributeIcePwdVoice,
1549 kFingerprint, &sdp_with_fingerprint);
1550 InjectAfter(kAttributeIcePwdVideo,
1551 kFingerprint, &sdp_with_fingerprint);
1552
1553 EXPECT_EQ(sdp_with_fingerprint, message);
1554}
1555
1556// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1557// be the case in a DTLS answer.
1558TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1559 AddFingerprint();
1560 RemoveCryptos();
1561 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1562 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1563 kSessionId, kSessionVersion));
1564 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
1565
1566 std::string sdp_with_fingerprint = kSdpString;
1567 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1568 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
1569 InjectAfter(kAttributeIcePwdVoice,
1570 kFingerprint, &sdp_with_fingerprint);
1571 InjectAfter(kAttributeIcePwdVideo,
1572 kFingerprint, &sdp_with_fingerprint);
1573
1574 EXPECT_EQ(sdp_with_fingerprint, message);
1575}
1576
1577TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1578 // JsepSessionDescription with desc but without candidates.
1579 JsepSessionDescription jdesc_no_candidates(kDummyString);
deadbeef3f7219b2015-12-28 15:17:14 -08001580 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
1581 kSessionVersion));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001582 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
1583 EXPECT_EQ(std::string(kSdpString), message);
1584}
1585
1586TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1587 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1588 group.AddContentName(kAudioContentName);
1589 group.AddContentName(kVideoContentName);
1590 desc_.AddGroup(group);
1591 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1592 jdesc_.session_id(),
1593 jdesc_.session_version()));
1594 std::string message = webrtc::SdpSerialize(jdesc_);
1595 std::string sdp_with_bundle = kSdpFullString;
1596 InjectAfter(kSessionTime,
1597 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1598 &sdp_with_bundle);
1599 EXPECT_EQ(sdp_with_bundle, message);
1600}
1601
1602TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
1603 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1604 GetFirstVideoContent(&desc_)->description);
1605 vcd->set_bandwidth(100 * 1000);
1606 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1607 GetFirstAudioContent(&desc_)->description);
1608 acd->set_bandwidth(50 * 1000);
1609 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1610 jdesc_.session_id(),
1611 jdesc_.session_version()));
1612 std::string message = webrtc::SdpSerialize(jdesc_);
1613 std::string sdp_with_bandwidth = kSdpFullString;
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001614 InjectAfter("c=IN IP4 74.125.224.39\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001615 "b=AS:100\r\n",
1616 &sdp_with_bandwidth);
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001617 InjectAfter("c=IN IP4 74.125.127.126\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001618 "b=AS:50\r\n",
1619 &sdp_with_bandwidth);
1620 EXPECT_EQ(sdp_with_bandwidth, message);
1621}
1622
1623TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1624 std::vector<std::string> transport_options;
1625 transport_options.push_back(kIceOption1);
1626 transport_options.push_back(kIceOption3);
1627 AddIceOptions(kAudioContentName, transport_options);
1628 transport_options.clear();
1629 transport_options.push_back(kIceOption2);
1630 transport_options.push_back(kIceOption3);
1631 AddIceOptions(kVideoContentName, transport_options);
1632 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1633 jdesc_.session_id(),
1634 jdesc_.session_version()));
1635 std::string message = webrtc::SdpSerialize(jdesc_);
1636 std::string sdp_with_ice_options = kSdpFullString;
1637 InjectAfter(kAttributeIcePwdVoice,
1638 "a=ice-options:iceoption1 iceoption3\r\n",
1639 &sdp_with_ice_options);
1640 InjectAfter(kAttributeIcePwdVideo,
1641 "a=ice-options:iceoption2 iceoption3\r\n",
1642 &sdp_with_ice_options);
1643 EXPECT_EQ(sdp_with_ice_options, message);
1644}
1645
1646TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
1647 EXPECT_TRUE(TestSerializeDirection(cricket::MD_RECVONLY));
1648}
1649
1650TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
1651 EXPECT_TRUE(TestSerializeDirection(cricket::MD_SENDONLY));
1652}
1653
1654TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
1655 EXPECT_TRUE(TestSerializeDirection(cricket::MD_INACTIVE));
1656}
1657
1658TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
1659 EXPECT_TRUE(TestSerializeRejected(true, false));
1660}
1661
1662TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
1663 EXPECT_TRUE(TestSerializeRejected(false, true));
1664}
1665
1666TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
1667 EXPECT_TRUE(TestSerializeRejected(true, true));
1668}
1669
1670TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
1671 AddRtpDataChannel();
1672 JsepSessionDescription jsep_desc(kDummyString);
1673
1674 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1675 std::string message = webrtc::SdpSerialize(jsep_desc);
1676
1677 std::string expected_sdp = kSdpString;
1678 expected_sdp.append(kSdpRtpDataChannelString);
1679 EXPECT_EQ(expected_sdp, message);
1680}
1681
1682TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
1683 AddSctpDataChannel();
1684 JsepSessionDescription jsep_desc(kDummyString);
1685
1686 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1687 std::string message = webrtc::SdpSerialize(jsep_desc);
1688
1689 std::string expected_sdp = kSdpString;
1690 expected_sdp.append(kSdpSctpDataChannelString);
1691 EXPECT_EQ(message, expected_sdp);
1692}
1693
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001694TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
1695 AddSctpDataChannel();
1696 JsepSessionDescription jsep_desc(kDummyString);
1697
1698 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1699 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
1700 jsep_desc.description()->GetContentDescriptionByName(kDataContentName));
1701
1702 const int kNewPort = 1234;
1703 cricket::DataCodec codec(
1704 cricket::kGoogleSctpDataCodecId, cricket::kGoogleSctpDataCodecName, 0);
1705 codec.SetParam(cricket::kCodecParamPort, kNewPort);
1706 dcdesc->AddOrReplaceCodec(codec);
1707
1708 std::string message = webrtc::SdpSerialize(jsep_desc);
1709
1710 std::string expected_sdp = kSdpString;
1711 expected_sdp.append(kSdpSctpDataChannelString);
1712
1713 char default_portstr[16];
1714 char new_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001715 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001716 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001717 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
1718 rtc::replace_substrs(default_portstr, strlen(default_portstr),
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001719 new_portstr, strlen(new_portstr),
1720 &expected_sdp);
1721
1722 EXPECT_EQ(expected_sdp, message);
1723}
1724
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001725TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
1726 AddRtpDataChannel();
1727 data_desc_->set_bandwidth(100*1000);
1728 JsepSessionDescription jsep_desc(kDummyString);
1729
1730 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1731 std::string message = webrtc::SdpSerialize(jsep_desc);
1732
1733 std::string expected_sdp = kSdpString;
1734 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07001735 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00001736 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00001737 "b=AS:100\r\n",
1738 &expected_sdp);
1739 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001740}
1741
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001742TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
1743 AddExtmap();
1744 JsepSessionDescription desc_with_extmap("dummy");
1745 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(),
1746 kSessionId, kSessionVersion));
1747 std::string message = webrtc::SdpSerialize(desc_with_extmap);
1748
1749 std::string sdp_with_extmap = kSdpString;
1750 InjectAfter("a=mid:audio_content_name\r\n",
1751 kExtmap, &sdp_with_extmap);
1752 InjectAfter("a=mid:video_content_name\r\n",
1753 kExtmap, &sdp_with_extmap);
1754
1755 EXPECT_EQ(sdp_with_extmap, message);
1756}
1757
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001758TEST_F(WebRtcSdpTest, SerializeCandidates) {
1759 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00001760 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08001761
1762 Candidate candidate_with_ufrag(candidates_.front());
1763 candidate_with_ufrag.set_username("ABC");
1764 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
1765 candidate_with_ufrag));
1766 message = webrtc::SdpSerializeCandidate(*jcandidate_);
1767 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001768}
1769
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00001770// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
1771// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00001772TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001773 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001774 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
1775 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
1776 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00001777 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
1778 rtc::scoped_ptr<IceCandidateInterface> jcandidate(
1779 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
1780
1781 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
1782 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
1783}
1784
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001785TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
1786 JsepSessionDescription jdesc(kDummyString);
1787 // Deserialize
1788 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
1789 // Verify
1790 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1791}
1792
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001793TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
1794 JsepSessionDescription jdesc(kDummyString);
1795 const char kSdpWithoutMline[] =
1796 "v=0\r\n"
1797 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1798 "s=-\r\n"
1799 "t=0 0\r\n"
1800 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
1801 // Deserialize
1802 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
1803 EXPECT_EQ(0u, jdesc.description()->contents().size());
1804}
1805
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001806TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
1807 JsepSessionDescription jdesc(kDummyString);
1808 std::string sdp_without_carriage_return = kSdpFullString;
1809 Replace("\r\n", "\n", &sdp_without_carriage_return);
1810 // Deserialize
1811 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
1812 // Verify
1813 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1814}
1815
1816TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
1817 // SessionDescription with desc but without candidates.
1818 JsepSessionDescription jdesc_no_candidates(kDummyString);
1819 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
1820 kSessionId, kSessionVersion));
1821 JsepSessionDescription new_jdesc(kDummyString);
1822 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
1823 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
1824}
1825
1826TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
1827 static const char kSdpNoRtpmapString[] =
1828 "v=0\r\n"
1829 "o=- 11 22 IN IP4 127.0.0.1\r\n"
1830 "s=-\r\n"
1831 "t=0 0\r\n"
1832 "m=audio 49232 RTP/AVP 0 18 103\r\n"
1833 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001834 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001835 // The rtpmap line for static payload codec is optional.
1836 "a=rtpmap:18 G729/16000\r\n"
1837 "a=rtpmap:103 ISAC/16000\r\n";
1838
1839 JsepSessionDescription jdesc(kDummyString);
1840 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
1841 cricket::AudioContentDescription* audio =
1842 static_cast<AudioContentDescription*>(
1843 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
1844 AudioCodecs ref_codecs;
1845 // The codecs in the AudioContentDescription will be sorted by preference.
1846 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1, 3));
1847 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1, 2));
1848 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 32000, 1, 1));
1849 EXPECT_EQ(ref_codecs, audio->codecs());
1850}
1851
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001852TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
1853 static const char kSdpNoRtpmapString[] =
1854 "v=0\r\n"
1855 "o=- 11 22 IN IP4 127.0.0.1\r\n"
1856 "s=-\r\n"
1857 "t=0 0\r\n"
1858 "m=audio 49232 RTP/AVP 18 103\r\n"
1859 "a=fmtp:18 annexb=yes\r\n"
1860 "a=rtpmap:103 ISAC/16000\r\n";
1861
1862 JsepSessionDescription jdesc(kDummyString);
1863 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
1864 cricket::AudioContentDescription* audio =
1865 static_cast<AudioContentDescription*>(
1866 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
1867
1868 cricket::AudioCodec g729 = audio->codecs()[0];
1869 EXPECT_EQ("G729", g729.name);
1870 EXPECT_EQ(8000, g729.clockrate);
1871 EXPECT_EQ(18, g729.id);
1872 cricket::CodecParameterMap::iterator found =
1873 g729.params.find("annexb");
1874 ASSERT_TRUE(found != g729.params.end());
1875 EXPECT_EQ(found->second, "yes");
1876
1877 cricket::AudioCodec isac = audio->codecs()[1];
1878 EXPECT_EQ("ISAC", isac.name);
1879 EXPECT_EQ(103, isac.id);
1880 EXPECT_EQ(16000, isac.clockrate);
1881}
1882
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001883// Ensure that we can deserialize SDP with a=fingerprint properly.
1884TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
1885 // Add a DTLS a=fingerprint attribute to our session description.
1886 AddFingerprint();
1887 JsepSessionDescription new_jdesc(kDummyString);
1888 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1889 jdesc_.session_id(),
1890 jdesc_.session_version()));
1891
1892 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1893 std::string sdp_with_fingerprint = kSdpString;
1894 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1895 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
1896 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
1897 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
1898}
1899
1900TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
1901 JsepSessionDescription jdesc_with_bundle(kDummyString);
1902 std::string sdp_with_bundle = kSdpFullString;
1903 InjectAfter(kSessionTime,
1904 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1905 &sdp_with_bundle);
1906 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
1907 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1908 group.AddContentName(kAudioContentName);
1909 group.AddContentName(kVideoContentName);
1910 desc_.AddGroup(group);
1911 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1912 jdesc_.session_id(),
1913 jdesc_.session_version()));
1914 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
1915}
1916
1917TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
1918 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
1919 std::string sdp_with_bandwidth = kSdpFullString;
1920 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
1921 "b=AS:100\r\n",
1922 &sdp_with_bandwidth);
1923 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
1924 "b=AS:50\r\n",
1925 &sdp_with_bandwidth);
1926 EXPECT_TRUE(
1927 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
1928 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1929 GetFirstVideoContent(&desc_)->description);
1930 vcd->set_bandwidth(100 * 1000);
1931 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1932 GetFirstAudioContent(&desc_)->description);
1933 acd->set_bandwidth(50 * 1000);
1934 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1935 jdesc_.session_id(),
1936 jdesc_.session_version()));
1937 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
1938}
1939
1940TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
1941 JsepSessionDescription jdesc_with_ice_options(kDummyString);
1942 std::string sdp_with_ice_options = kSdpFullString;
1943 InjectAfter(kSessionTime,
1944 "a=ice-options:iceoption3\r\n",
1945 &sdp_with_ice_options);
1946 InjectAfter(kAttributeIcePwdVoice,
1947 "a=ice-options:iceoption1\r\n",
1948 &sdp_with_ice_options);
1949 InjectAfter(kAttributeIcePwdVideo,
1950 "a=ice-options:iceoption2\r\n",
1951 &sdp_with_ice_options);
1952 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
1953 std::vector<std::string> transport_options;
1954 transport_options.push_back(kIceOption3);
1955 transport_options.push_back(kIceOption1);
1956 AddIceOptions(kAudioContentName, transport_options);
1957 transport_options.clear();
1958 transport_options.push_back(kIceOption3);
1959 transport_options.push_back(kIceOption2);
1960 AddIceOptions(kVideoContentName, transport_options);
1961 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1962 jdesc_.session_id(),
1963 jdesc_.session_version()));
1964 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
1965}
1966
1967TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
1968 // Remove the original ice-ufrag and ice-pwd
1969 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyString);
1970 std::string sdp_with_ufrag_pwd = kSdpFullString;
1971 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
1972 // Add session level ufrag and pwd
1973 InjectAfter(kSessionTime,
1974 "a=ice-pwd:session+level+icepwd\r\n"
1975 "a=ice-ufrag:session+level+iceufrag\r\n",
1976 &sdp_with_ufrag_pwd);
1977 // Add media level ufrag and pwd for audio
1978 InjectAfter("a=mid:audio_content_name\r\n",
1979 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
1980 &sdp_with_ufrag_pwd);
1981 // Update the candidate ufrag and pwd to the expected ones.
1982 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0,
1983 "media+level+iceufrag", "media+level+icepwd"));
1984 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1,
1985 "session+level+iceufrag", "session+level+icepwd"));
1986 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
1987 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
1988}
1989
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001990TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
1991 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_RECVONLY));
1992}
1993
1994TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
1995 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_SENDONLY));
1996}
1997
1998TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
1999 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_INACTIVE));
2000}
2001
2002TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2003 EXPECT_TRUE(TestDeserializeRejected(true, false));
2004}
2005
2006TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2007 EXPECT_TRUE(TestDeserializeRejected(false, true));
2008}
2009
2010TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2011 EXPECT_TRUE(TestDeserializeRejected(true, true));
2012}
2013
2014// Tests that we can still handle the sdp uses mslabel and label instead of
2015// msid for backward compatibility.
2016TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07002017 jdesc_.description()->set_msid_supported(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002018 JsepSessionDescription jdesc(kDummyString);
2019 std::string sdp_without_msid = kSdpFullString;
2020 Replace("msid", "xmsid", &sdp_without_msid);
2021 // Deserialize
2022 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2023 // Verify
2024 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2025}
2026
2027TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2028 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2029
2030 std::string sdp = kSdpOneCandidate;
2031 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2032 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2033 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2034 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2035
2036 // Candidate line without generation extension.
2037 sdp = kSdpOneCandidate;
2038 Replace(" generation 2", "", &sdp);
2039 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2040 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2041 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2042 Candidate expected = jcandidate_->candidate();
2043 expected.set_generation(0);
2044 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2045
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002046 sdp = kSdpTcpActiveCandidate;
2047 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2048 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002049 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002050 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2051 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2052 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002053 rtc::scoped_ptr<IceCandidateInterface> jcandidate_template(
2054 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
2055 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(
2056 jcandidate_template->candidate()));
2057 sdp = kSdpTcpPassiveCandidate;
2058 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2059 sdp = kSdpTcpSOCandidate;
2060 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002061}
2062
2063// This test verifies the deserialization of candidate-attribute
2064// as per RFC 5245. Candiate-attribute will be of the format
2065// candidate:<blah>. This format will be used when candidates
2066// are trickled.
2067TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2068 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2069
2070 std::string candidate_attribute = kRawCandidate;
2071 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2072 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2073 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2074 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2075 EXPECT_EQ(2u, jcandidate.candidate().generation());
2076
2077 // Candidate line without generation extension.
2078 candidate_attribute = kRawCandidate;
2079 Replace(" generation 2", "", &candidate_attribute);
2080 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2081 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2082 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2083 Candidate expected = jcandidate_->candidate();
2084 expected.set_generation(0);
2085 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2086
2087 // Candidate line without candidate:
2088 candidate_attribute = kRawCandidate;
2089 Replace("candidate:", "", &candidate_attribute);
2090 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2091
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002092 // Candidate line with IPV6 address.
2093 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
2094}
2095
2096// This test verifies that the deserialization of an invalid candidate string
2097// fails.
2098TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
2099 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2100
2101 std::string candidate_attribute = kRawCandidate;
2102 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002103 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002104
2105 candidate_attribute = kSdpOneCandidate;
2106 candidate_attribute.replace(0, 1, "x");
2107 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2108
2109 candidate_attribute = kRawCandidate;
2110 candidate_attribute.append("\r\n");
2111 candidate_attribute.append(kRawCandidate);
2112 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2113
2114 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002115}
2116
2117TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2118 AddRtpDataChannel();
2119 JsepSessionDescription jdesc(kDummyString);
2120 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2121
2122 std::string sdp_with_data = kSdpString;
2123 sdp_with_data.append(kSdpRtpDataChannelString);
2124 JsepSessionDescription jdesc_output(kDummyString);
2125
2126 // Deserialize
2127 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2128 // Verify
2129 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2130}
2131
2132TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
2133 AddSctpDataChannel();
2134 JsepSessionDescription jdesc(kDummyString);
2135 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2136
2137 std::string sdp_with_data = kSdpString;
2138 sdp_with_data.append(kSdpSctpDataChannelString);
2139 JsepSessionDescription jdesc_output(kDummyString);
2140
lally@webrtc.org36300852015-02-24 20:19:35 +00002141 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2142 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2143 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2144
2145 // Verify with UDP/DTLS/SCTP.
2146 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2147 strlen(kDtlsSctp), kUdpDtlsSctp);
2148 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2149 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2150
2151 // Verify with TCP/DTLS/SCTP.
2152 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2153 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002154 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2155 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2156}
2157
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002158TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
2159 AddSctpDataChannel();
2160 JsepSessionDescription jdesc(kDummyString);
2161 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2162
2163 std::string sdp_with_data = kSdpString;
2164 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2165 JsepSessionDescription jdesc_output(kDummyString);
2166
lally@webrtc.org36300852015-02-24 20:19:35 +00002167 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002168 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2169 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002170
lally@webrtc.org36300852015-02-24 20:19:35 +00002171 // Verify with UDP/DTLS/SCTP.
2172 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2173 strlen(kDtlsSctp), kUdpDtlsSctp);
2174 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2175 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002176
lally@webrtc.org36300852015-02-24 20:19:35 +00002177 // Verify with TCP/DTLS/SCTP.
2178 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2179 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002180 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2181 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2182}
2183
lally69f57602015-10-08 10:15:04 -07002184TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
2185 AddSctpDataChannel();
2186 JsepSessionDescription jdesc(kDummyString);
2187 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2188
2189 std::string sdp_with_data = kSdpString;
2190 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
2191 JsepSessionDescription jdesc_output(kDummyString);
2192
2193 // Verify with DTLS/SCTP.
2194 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2195 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2196
2197 // Verify with UDP/DTLS/SCTP.
2198 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2199 strlen(kDtlsSctp), kUdpDtlsSctp);
2200 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2201 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2202
2203 // Verify with TCP/DTLS/SCTP.
2204 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2205 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
2206 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2207 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2208}
2209
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002210// Test to check the behaviour if sctp-port is specified
2211// on the m= line and in a=sctp-port.
2212TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
2213 AddSctpDataChannel();
2214 JsepSessionDescription jdesc(kDummyString);
2215 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2216
2217 std::string sdp_with_data = kSdpString;
2218 // Append m= attributes
2219 sdp_with_data.append(kSdpSctpDataChannelString);
2220 // Append a=sctp-port attribute
2221 sdp_with_data.append("a=sctp-port 5000\r\n");
2222 JsepSessionDescription jdesc_output(kDummyString);
2223
2224 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2225}
2226
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002227// For crbug/344475.
2228TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2229 std::string sdp_with_data = kSdpString;
2230 sdp_with_data.append(kSdpSctpDataChannelString);
2231 // Remove the "\n" at the end.
2232 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
2233 JsepSessionDescription jdesc_output(kDummyString);
2234
2235 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2236 // No crash is a pass.
2237}
2238
wu@webrtc.org78187522013-10-07 23:32:02 +00002239TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndNewPort) {
2240 AddSctpDataChannel();
Peter Boström0c4e06b2015-10-07 12:23:21 +02002241 const uint16_t kUnusualSctpPort = 9556;
wu@webrtc.org78187522013-10-07 23:32:02 +00002242 char default_portstr[16];
2243 char unusual_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002244 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
wu@webrtc.org78187522013-10-07 23:32:02 +00002245 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002246 rtc::sprintfn(unusual_portstr, sizeof(unusual_portstr), "%d",
wu@webrtc.org78187522013-10-07 23:32:02 +00002247 kUnusualSctpPort);
2248
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002249 // First setup the expected JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002250 JsepSessionDescription jdesc(kDummyString);
2251 // take our pre-built session description and change the SCTP port.
2252 cricket::SessionDescription* mutant = desc_.Copy();
2253 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
2254 mutant->GetContentDescriptionByName(kDataContentName));
2255 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002256 EXPECT_EQ(1U, codecs.size());
2257 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002258 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002259 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002260
2261 // note: mutant's owned by jdesc now.
2262 ASSERT_TRUE(jdesc.Initialize(mutant, kSessionId, kSessionVersion));
2263 mutant = NULL;
2264
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002265 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002266 std::string sdp_with_data = kSdpString;
2267 sdp_with_data.append(kSdpSctpDataChannelString);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002268 rtc::replace_substrs(default_portstr, strlen(default_portstr),
wu@webrtc.org78187522013-10-07 23:32:02 +00002269 unusual_portstr, strlen(unusual_portstr),
2270 &sdp_with_data);
2271 JsepSessionDescription jdesc_output(kDummyString);
2272
2273 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2274 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002275
2276 // We need to test the deserialized JsepSessionDescription from
2277 // kSdpSctpDataChannelStringWithSctpPort for
2278 // draft-ietf-mmusic-sctp-sdp-07
2279 // a=sctp-port
2280 sdp_with_data = kSdpString;
2281 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2282 rtc::replace_substrs(default_portstr, strlen(default_portstr),
2283 unusual_portstr, strlen(unusual_portstr),
2284 &sdp_with_data);
2285
2286 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2287 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002288}
2289
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002290TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002291 // We want to test that deserializing data content limits bandwidth
2292 // settings (it should never be greater than the default).
2293 // This should prevent someone from using unlimited data bandwidth through
2294 // JS and "breaking the Internet".
2295 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002296 std::string sdp_with_bandwidth = kSdpString;
2297 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
2298 InjectAfter("a=mid:data_content_name\r\n",
2299 "b=AS:100\r\n",
2300 &sdp_with_bandwidth);
2301 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2302
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002303 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2304}
2305
2306TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
2307 AddSctpDataChannel();
2308 JsepSessionDescription jdesc(kDummyString);
2309 DataContentDescription* dcd = static_cast<DataContentDescription*>(
2310 GetFirstDataContent(&desc_)->description);
2311 dcd->set_bandwidth(100 * 1000);
2312 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2313
2314 std::string sdp_with_bandwidth = kSdpString;
2315 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
2316 InjectAfter("a=mid:data_content_name\r\n",
2317 "b=AS:100\r\n",
2318 &sdp_with_bandwidth);
2319 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2320
2321 // SCTP has congestion control, so we shouldn't limit the bandwidth
2322 // as we do for RTP.
2323 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002324 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2325}
2326
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002327TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSessionLevelExtmap) {
2328 TestDeserializeExtmap(true, false);
2329}
2330
2331TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
2332 TestDeserializeExtmap(false, true);
2333}
2334
2335TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInvalidExtmap) {
2336 TestDeserializeExtmap(true, true);
2337}
2338
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002339TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
2340 JsepSessionDescription jdesc(kDummyString);
2341 std::string sdp = kSdpFullString;
2342 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2343 // Deserialize
2344 SdpParseError error;
2345 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
2346 const std::string lastline = "a=ssrc:6 label:video_track_id_3";
2347 EXPECT_EQ(lastline, error.line);
2348 EXPECT_EQ("Invalid SDP line.", error.description);
2349}
2350
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002351TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2352 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2353 std::string new_sdp = kSdpOneCandidate;
2354 Replace("udp", "unsupported_transport", &new_sdp);
2355 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2356 new_sdp = kSdpOneCandidate;
2357 Replace("udp", "uDP", &new_sdp);
2358 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2359 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2360 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2361 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2362}
2363
honghaiza54a0802015-12-16 18:37:23 -08002364TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002365 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08002366 EXPECT_TRUE(
2367 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002368 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2369 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2370 Candidate ref_candidate = jcandidate_->candidate();
2371 ref_candidate.set_username("user_rtp");
2372 ref_candidate.set_password("password_rtp");
2373 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2374}
2375
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002376TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
2377 JsepSessionDescription jdesc(kDummyString);
2378
2379 // Deserialize
2380 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2381
2382 // Verify
2383 cricket::AudioContentDescription* audio =
2384 static_cast<AudioContentDescription*>(
2385 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2386 EXPECT_TRUE(audio->conference_mode());
2387
2388 cricket::VideoContentDescription* video =
2389 static_cast<VideoContentDescription*>(
2390 jdesc.description()->GetContentDescriptionByName(cricket::CN_VIDEO));
2391 EXPECT_TRUE(video->conference_mode());
2392}
2393
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002394TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2395 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002396 const char kSdpEmptyType[] = " =candidate";
2397 const char kSdpEqualAsPlus[] = "a+candidate";
2398 const char kSdpSpaceAfterEqual[] = "a= candidate";
2399 const char kSdpUpperType[] = "A=candidate";
2400 const char kSdpEmptyLine[] = "";
2401 const char kSdpMissingValue[] = "a=";
2402
2403 const char kSdpBrokenFingerprint[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002404 "4AAD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002405 const char kSdpExtraField[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002406 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB XXX";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002407 const char kSdpMissingSpace[] = "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002408 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB";
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002409 // MD5 is not allowed in fingerprints.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002410 const char kSdpMd5[] = "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002411 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002412
2413 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002414 ExpectParseFailure("v=", kSdpDestroyer);
2415 ExpectParseFailure("o=", kSdpDestroyer);
2416 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002417 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002418 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002419
2420 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002421 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2422 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002423
2424 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002425 ExpectParseFailure("a=candidate", kSdpEmptyType);
2426 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2427 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
2428 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002429
2430 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2431 // because it's orthogonal to what we are replacing and hence
2432 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002433 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
2434 ExpectParseFailure("a=sendrecv", kSdpExtraField);
2435 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
2436 ExpectParseFailure("a=sendrecv", kSdpMd5);
2437
2438 // Empty Line
2439 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
2440 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002441}
2442
2443TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2444 // ssrc
2445 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
2446 ExpectParseFailure("a=ssrc-group:FEC 5 6", "a=ssrc-group:FEC badvalue 6");
2447 // crypto
2448 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
2449 // rtpmap
2450 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
2451 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
2452 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
2453 // candidate
2454 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
2455 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
2456 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
2457 ExpectParseFailure("rport 2346", "rport badvalue");
2458 ExpectParseFailure("rport 2346 generation 2",
2459 "rport 2346 generation badvalue");
2460 // m line
2461 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
2462 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
2463
2464 // bandwidth
2465 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2466 "b=AS:badvalue\r\n",
2467 "b=AS:badvalue");
2468 // rtcp-fb
2469 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2470 "a=rtcp-fb:badvalue nack\r\n",
2471 "a=rtcp-fb:badvalue nack");
2472 // extmap
2473 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2474 "a=extmap:badvalue http://example.com\r\n",
2475 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002476}
2477
2478TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
2479 JsepSessionDescription jdesc_output(kDummyString);
2480
2481 const char kSdpWithReorderedPlTypesString[] =
2482 "v=0\r\n"
2483 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2484 "s=-\r\n"
2485 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00002486 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002487 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
2488 // in the map.
2489 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002490 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002491
2492 // Deserialize
2493 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
2494
2495 const ContentInfo* ac = GetFirstAudioContent(jdesc_output.description());
2496 ASSERT_TRUE(ac != NULL);
2497 const AudioContentDescription* acd =
2498 static_cast<const AudioContentDescription*>(ac->description);
2499 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002500 EXPECT_EQ("ISAC", acd->codecs()[0].name);
2501 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002502 EXPECT_EQ(104, acd->codecs()[0].id);
2503}
2504
2505TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
2506 JsepSessionDescription jdesc_output(kDummyString);
2507 CodecParams params;
2508 params.max_ptime = 40;
2509 params.ptime = 30;
2510 params.min_ptime = 10;
2511 params.sprop_stereo = 1;
2512 params.stereo = 1;
2513 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002514 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002515 TestDeserializeCodecParams(params, &jdesc_output);
2516 TestSerialize(jdesc_output);
2517}
2518
2519TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
2520 const bool kUseWildcard = false;
2521 JsepSessionDescription jdesc_output(kDummyString);
2522 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
2523 TestSerialize(jdesc_output);
2524}
2525
2526TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
2527 const bool kUseWildcard = true;
2528 JsepSessionDescription jdesc_output(kDummyString);
2529 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
2530 TestSerialize(jdesc_output);
2531}
2532
2533TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
2534 JsepSessionDescription jdesc_output(kDummyString);
2535
2536 const char kSdpWithFmtpString[] =
2537 "v=0\r\n"
2538 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2539 "s=-\r\n"
2540 "t=0 0\r\n"
2541 "m=video 3457 RTP/SAVPF 120\r\n"
2542 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07002543 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
2544
2545 // Deserialize
2546 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07002547 EXPECT_TRUE(
2548 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07002549
2550 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2551 ASSERT_TRUE(vc != NULL);
2552 const VideoContentDescription* vcd =
2553 static_cast<const VideoContentDescription*>(vc->description);
2554 ASSERT_FALSE(vcd->codecs().empty());
2555 cricket::VideoCodec vp8 = vcd->codecs()[0];
2556 EXPECT_EQ("VP8", vp8.name);
2557 EXPECT_EQ(120, vp8.id);
2558 cricket::CodecParameterMap::iterator found =
2559 vp8.params.find("x-google-min-bitrate");
2560 ASSERT_TRUE(found != vp8.params.end());
2561 EXPECT_EQ(found->second, "10");
2562 found = vp8.params.find("x-google-max-quantization");
2563 ASSERT_TRUE(found != vp8.params.end());
2564 EXPECT_EQ(found->second, "40");
2565}
2566
2567TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
2568 JsepSessionDescription jdesc_output(kDummyString);
2569
2570 const char kSdpWithFmtpString[] =
2571 "v=0\r\n"
2572 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2573 "s=-\r\n"
2574 "t=0 0\r\n"
2575 "m=video 3457 RTP/SAVPF 120\r\n"
2576 "a=rtpmap:120 VP8/90000\r\n"
2577 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002578
2579 // Deserialize
2580 SdpParseError error;
2581 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output,
2582 &error));
2583
2584 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2585 ASSERT_TRUE(vc != NULL);
2586 const VideoContentDescription* vcd =
2587 static_cast<const VideoContentDescription*>(vc->description);
2588 ASSERT_FALSE(vcd->codecs().empty());
2589 cricket::VideoCodec vp8 = vcd->codecs()[0];
2590 EXPECT_EQ("VP8", vp8.name);
2591 EXPECT_EQ(120, vp8.id);
2592 cricket::CodecParameterMap::iterator found =
2593 vp8.params.find("x-google-min-bitrate");
2594 ASSERT_TRUE(found != vp8.params.end());
2595 EXPECT_EQ(found->second, "10");
2596 found = vp8.params.find("x-google-max-quantization");
2597 ASSERT_TRUE(found != vp8.params.end());
2598 EXPECT_EQ(found->second, "40");
2599}
2600
2601TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
2602 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
2603 GetFirstVideoContent(&desc_)->description);
2604
2605 cricket::VideoCodecs codecs = vcd->codecs();
2606 codecs[0].params["x-google-min-bitrate"] = "10";
2607 vcd->set_codecs(codecs);
2608
2609 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2610 jdesc_.session_id(),
2611 jdesc_.session_version()));
2612 std::string message = webrtc::SdpSerialize(jdesc_);
2613 std::string sdp_with_fmtp = kSdpFullString;
2614 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
2615 "a=fmtp:120 x-google-min-bitrate=10\r\n",
2616 &sdp_with_fmtp);
2617 EXPECT_EQ(sdp_with_fmtp, message);
2618}
2619
2620TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) {
2621 JsepSessionDescription jdesc_with_icelite(kDummyString);
2622 std::string sdp_with_icelite = kSdpFullString;
2623 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
2624 cricket::SessionDescription* desc = jdesc_with_icelite.description();
2625 const cricket::TransportInfo* tinfo1 =
2626 desc->GetTransportInfoByName("audio_content_name");
2627 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
2628 const cricket::TransportInfo* tinfo2 =
2629 desc->GetTransportInfoByName("video_content_name");
2630 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
2631 InjectAfter(kSessionTime,
2632 "a=ice-lite\r\n",
2633 &sdp_with_icelite);
2634 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
2635 desc = jdesc_with_icelite.description();
2636 const cricket::TransportInfo* atinfo =
2637 desc->GetTransportInfoByName("audio_content_name");
2638 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
2639 const cricket::TransportInfo* vtinfo =
2640 desc->GetTransportInfoByName("video_content_name");
2641 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
2642}
2643
2644// Verifies that the candidates in the input SDP are parsed and serialized
2645// correctly in the output SDP.
2646TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
2647 std::string sdp_with_data = kSdpString;
2648 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
2649 JsepSessionDescription jdesc_output(kDummyString);
2650
2651 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2652 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
2653}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00002654
2655TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
2656 AddFingerprint();
2657 TransportInfo audio_transport_info =
2658 *(desc_.GetTransportInfoByName(kAudioContentName));
2659 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
2660 audio_transport_info.description.connection_role);
2661 audio_transport_info.description.connection_role =
2662 cricket::CONNECTIONROLE_ACTIVE;
2663
2664 TransportInfo video_transport_info =
2665 *(desc_.GetTransportInfoByName(kVideoContentName));
2666 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
2667 video_transport_info.description.connection_role);
2668 video_transport_info.description.connection_role =
2669 cricket::CONNECTIONROLE_ACTIVE;
2670
2671 desc_.RemoveTransportInfoByName(kAudioContentName);
2672 desc_.RemoveTransportInfoByName(kVideoContentName);
2673
2674 desc_.AddTransportInfo(audio_transport_info);
2675 desc_.AddTransportInfo(video_transport_info);
2676
2677 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2678 jdesc_.session_id(),
2679 jdesc_.session_version()));
2680 std::string message = webrtc::SdpSerialize(jdesc_);
2681 std::string sdp_with_dtlssetup = kSdpFullString;
2682
2683 // Fingerprint attribute is necessary to add DTLS setup attribute.
2684 InjectAfter(kAttributeIcePwdVoice,
2685 kFingerprint, &sdp_with_dtlssetup);
2686 InjectAfter(kAttributeIcePwdVideo,
2687 kFingerprint, &sdp_with_dtlssetup);
2688 // Now adding |setup| attribute.
2689 InjectAfter(kFingerprint,
2690 "a=setup:active\r\n", &sdp_with_dtlssetup);
2691 EXPECT_EQ(sdp_with_dtlssetup, message);
2692}
2693
2694TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
2695 JsepSessionDescription jdesc_with_dtlssetup(kDummyString);
2696 std::string sdp_with_dtlssetup = kSdpFullString;
2697 InjectAfter(kSessionTime,
2698 "a=setup:actpass\r\n",
2699 &sdp_with_dtlssetup);
2700 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
2701 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
2702 const cricket::TransportInfo* atinfo =
2703 desc->GetTransportInfoByName("audio_content_name");
2704 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
2705 atinfo->description.connection_role);
2706 const cricket::TransportInfo* vtinfo =
2707 desc->GetTransportInfoByName("video_content_name");
2708 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
2709 vtinfo->description.connection_role);
2710}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00002711
2712// Verifies that the order of the serialized m-lines follows the order of the
2713// ContentInfo in SessionDescription, and vise versa for deserialization.
2714TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
2715 JsepSessionDescription jdesc(kDummyString);
2716 const std::string media_content_sdps[3] = {
2717 kSdpAudioString,
2718 kSdpVideoString,
2719 kSdpSctpDataChannelString
2720 };
2721 const cricket::MediaType media_types[3] = {
2722 cricket::MEDIA_TYPE_AUDIO,
2723 cricket::MEDIA_TYPE_VIDEO,
2724 cricket::MEDIA_TYPE_DATA
2725 };
2726
2727 // Verifies all 6 permutations.
2728 for (size_t i = 0; i < 6; ++i) {
2729 size_t media_content_in_sdp[3];
2730 // The index of the first media content.
2731 media_content_in_sdp[0] = i / 2;
2732 // The index of the second media content.
2733 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
2734 // The index of the third media content.
2735 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
2736
2737 std::string sdp_string = kSdpSessionString;
2738 for (size_t i = 0; i < 3; ++i)
2739 sdp_string += media_content_sdps[media_content_in_sdp[i]];
2740
2741 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
2742 cricket::SessionDescription* desc = jdesc.description();
2743 EXPECT_EQ(3u, desc->contents().size());
2744
2745 for (size_t i = 0; i < 3; ++i) {
2746 const cricket::MediaContentDescription* mdesc =
2747 static_cast<const cricket::MediaContentDescription*>(
2748 desc->contents()[i].description);
2749 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
2750 }
2751
2752 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
2753 EXPECT_EQ(sdp_string, serialized_sdp);
2754 }
2755}