blob: cb6a392ab40bb3a99f46b4c3e52974e1452b2aa9 [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";
83static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
84static const char kCandidateUfragVideo[] = "ufrag_video";
85static const char kCandidatePwdVideo[] = "pwd_video";
86static const char kCandidateUfragData[] = "ufrag_data";
87static const char kCandidatePwdData[] = "pwd_data";
88static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020089static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090static const char kCandidateFoundation1[] = "a0+B/1";
91static const char kCandidateFoundation2[] = "a0+B/2";
92static const char kCandidateFoundation3[] = "a0+B/3";
93static const char kCandidateFoundation4[] = "a0+B/4";
94static const char kAttributeCryptoVoice[] =
95 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
96 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
97 "dummy_session_params\r\n";
98static const char kAttributeCryptoVideo[] =
99 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
100 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
101static const char kFingerprint[] = "a=fingerprint:sha-1 "
102 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n";
103static const int kExtmapId = 1;
104static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
105static const char kExtmap[] =
106 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
107static const char kExtmapWithDirectionAndAttribute[] =
108 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
109
Peter Boström0c4e06b2015-10-07 12:23:21 +0200110static const uint8_t kIdentityDigest[] = {
111 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
112 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000113
lally@webrtc.org34807282015-02-24 20:19:39 +0000114static const char kDtlsSctp[] = "DTLS/SCTP";
115static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
116static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +0000117
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000118struct CodecParams {
119 int max_ptime;
120 int ptime;
121 int min_ptime;
122 int sprop_stereo;
123 int stereo;
124 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000125 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000126};
127
128// Reference sdp string
129static const char kSdpFullString[] =
130 "v=0\r\n"
131 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
132 "s=-\r\n"
133 "t=0 0\r\n"
134 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
135 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
136 "c=IN IP4 74.125.127.126\r\n"
137 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
138 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
139 "generation 2\r\n"
140 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
141 "generation 2\r\n"
142 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
143 "generation 2\r\n"
144 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
145 "generation 2\r\n"
146 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
147 "raddr 192.168.1.5 rport 2346 "
148 "generation 2\r\n"
149 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
150 "raddr 192.168.1.5 rport 2348 "
151 "generation 2\r\n"
152 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
153 "a=mid:audio_content_name\r\n"
154 "a=sendrecv\r\n"
155 "a=rtcp-mux\r\n"
156 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
157 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
158 "dummy_session_params\r\n"
159 "a=rtpmap:111 opus/48000/2\r\n"
160 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000161 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000162 "a=ssrc:1 cname:stream_1_cname\r\n"
163 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
164 "a=ssrc:1 mslabel:local_stream_1\r\n"
165 "a=ssrc:1 label:audio_track_id_1\r\n"
166 "a=ssrc:4 cname:stream_2_cname\r\n"
167 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
168 "a=ssrc:4 mslabel:local_stream_2\r\n"
169 "a=ssrc:4 label:audio_track_id_2\r\n"
170 "m=video 3457 RTP/SAVPF 120\r\n"
171 "c=IN IP4 74.125.224.39\r\n"
172 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
173 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
174 "generation 2\r\n"
175 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
176 "generation 2\r\n"
177 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
178 "generation 2\r\n"
179 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
180 "generation 2\r\n"
181 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
182 "generation 2\r\n"
183 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
184 "generation 2\r\n"
185 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
186 "a=mid:video_content_name\r\n"
187 "a=sendrecv\r\n"
188 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
189 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
190 "a=rtpmap:120 VP8/90000\r\n"
191 "a=ssrc:2 cname:stream_1_cname\r\n"
192 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
193 "a=ssrc:2 mslabel:local_stream_1\r\n"
194 "a=ssrc:2 label:video_track_id_1\r\n"
195 "a=ssrc:3 cname:stream_1_cname\r\n"
196 "a=ssrc:3 msid:local_stream_1 video_track_id_2\r\n"
197 "a=ssrc:3 mslabel:local_stream_1\r\n"
198 "a=ssrc:3 label:video_track_id_2\r\n"
199 "a=ssrc-group:FEC 5 6\r\n"
200 "a=ssrc:5 cname:stream_2_cname\r\n"
201 "a=ssrc:5 msid:local_stream_2 video_track_id_3\r\n"
202 "a=ssrc:5 mslabel:local_stream_2\r\n"
203 "a=ssrc:5 label:video_track_id_3\r\n"
204 "a=ssrc:6 cname:stream_2_cname\r\n"
205 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
206 "a=ssrc:6 mslabel:local_stream_2\r\n"
207 "a=ssrc:6 label:video_track_id_3\r\n";
208
209// SDP reference string without the candidates.
210static const char kSdpString[] =
211 "v=0\r\n"
212 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
213 "s=-\r\n"
214 "t=0 0\r\n"
215 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000216 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000217 "c=IN IP4 0.0.0.0\r\n"
218 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000219 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
220 "a=mid:audio_content_name\r\n"
221 "a=sendrecv\r\n"
222 "a=rtcp-mux\r\n"
223 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
224 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
225 "dummy_session_params\r\n"
226 "a=rtpmap:111 opus/48000/2\r\n"
227 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000228 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000229 "a=ssrc:1 cname:stream_1_cname\r\n"
230 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
231 "a=ssrc:1 mslabel:local_stream_1\r\n"
232 "a=ssrc:1 label:audio_track_id_1\r\n"
233 "a=ssrc:4 cname:stream_2_cname\r\n"
234 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
235 "a=ssrc:4 mslabel:local_stream_2\r\n"
236 "a=ssrc:4 label:audio_track_id_2\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000237 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000238 "c=IN IP4 0.0.0.0\r\n"
239 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000240 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
241 "a=mid:video_content_name\r\n"
242 "a=sendrecv\r\n"
243 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
244 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
245 "a=rtpmap:120 VP8/90000\r\n"
246 "a=ssrc:2 cname:stream_1_cname\r\n"
247 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
248 "a=ssrc:2 mslabel:local_stream_1\r\n"
249 "a=ssrc:2 label:video_track_id_1\r\n"
250 "a=ssrc:3 cname:stream_1_cname\r\n"
251 "a=ssrc:3 msid:local_stream_1 video_track_id_2\r\n"
252 "a=ssrc:3 mslabel:local_stream_1\r\n"
253 "a=ssrc:3 label:video_track_id_2\r\n"
254 "a=ssrc-group:FEC 5 6\r\n"
255 "a=ssrc:5 cname:stream_2_cname\r\n"
256 "a=ssrc:5 msid:local_stream_2 video_track_id_3\r\n"
257 "a=ssrc:5 mslabel:local_stream_2\r\n"
258 "a=ssrc:5 label:video_track_id_3\r\n"
259 "a=ssrc:6 cname:stream_2_cname\r\n"
260 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
261 "a=ssrc:6 mslabel:local_stream_2\r\n"
262 "a=ssrc:6 label:video_track_id_3\r\n";
263
264static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000265 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000266 "c=IN IP4 0.0.0.0\r\n"
267 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000268 "a=ice-ufrag:ufrag_data\r\n"
269 "a=ice-pwd:pwd_data\r\n"
270 "a=mid:data_content_name\r\n"
271 "a=sendrecv\r\n"
272 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
273 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
274 "a=rtpmap:101 google-data/90000\r\n"
275 "a=ssrc:10 cname:data_channel_cname\r\n"
276 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
277 "a=ssrc:10 mslabel:data_channel\r\n"
278 "a=ssrc:10 label:data_channeld0\r\n";
279
280static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000281 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000282 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000283 "a=ice-ufrag:ufrag_data\r\n"
284 "a=ice-pwd:pwd_data\r\n"
285 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000286 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000287
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000288// draft-ietf-mmusic-sctp-sdp-12
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000289static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000290 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
291 "a=max-message-size=100000\r\n"
292 "a=sctp-port 5000\r\n"
293 "c=IN IP4 0.0.0.0\r\n"
294 "a=ice-ufrag:ufrag_data\r\n"
295 "a=ice-pwd:pwd_data\r\n"
296 "a=mid:data_content_name\r\n";
297
lally69f57602015-10-08 10:15:04 -0700298static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
299 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
300 "a=max-message-size=100000\r\n"
301 "a=sctp-port:5000\r\n"
302 "c=IN IP4 0.0.0.0\r\n"
303 "a=ice-ufrag:ufrag_data\r\n"
304 "a=ice-pwd:pwd_data\r\n"
305 "a=mid:data_content_name\r\n";
306
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000307static const char kSdpSctpDataChannelWithCandidatesString[] =
308 "m=application 2345 DTLS/SCTP 5000\r\n"
309 "c=IN IP4 74.125.127.126\r\n"
310 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
311 "generation 2\r\n"
312 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
313 "generation 2\r\n"
314 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
315 "raddr 192.168.1.5 rport 2346 "
316 "generation 2\r\n"
317 "a=ice-ufrag:ufrag_data\r\n"
318 "a=ice-pwd:pwd_data\r\n"
319 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000320 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000321
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000322static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000323 "v=0\r\n"
324 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
325 "s=-\r\n"
326 "t=0 0\r\n"
327 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000328 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000329 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000330 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000331 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000332 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000333 "a=x-google-flag:conference\r\n";
334
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000335static const char kSdpSessionString[] =
336 "v=0\r\n"
337 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
338 "s=-\r\n"
339 "t=0 0\r\n"
340 "a=msid-semantic: WMS local_stream\r\n";
341
342static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000343 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000344 "c=IN IP4 0.0.0.0\r\n"
345 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000346 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
347 "a=mid:audio_content_name\r\n"
348 "a=sendrecv\r\n"
349 "a=rtpmap:111 opus/48000/2\r\n"
350 "a=ssrc:1 cname:stream_1_cname\r\n"
351 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
352 "a=ssrc:1 mslabel:local_stream\r\n"
353 "a=ssrc:1 label:audio_track_id_1\r\n";
354
355static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000356 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000357 "c=IN IP4 0.0.0.0\r\n"
358 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000359 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
360 "a=mid:video_content_name\r\n"
361 "a=sendrecv\r\n"
362 "a=rtpmap:120 VP8/90000\r\n"
363 "a=ssrc:2 cname:stream_1_cname\r\n"
364 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
365 "a=ssrc:2 mslabel:local_stream\r\n"
366 "a=ssrc:2 label:video_track_id_1\r\n";
367
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000368
369// One candidate reference string as per W3c spec.
370// candidate:<blah> not a=candidate:<blah>CRLF
371static const char kRawCandidate[] =
372 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
373// One candidate reference string.
374static const char kSdpOneCandidate[] =
375 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
376 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000377
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000378static const char kSdpTcpActiveCandidate[] =
379 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
380 "tcptype active generation 2";
381static const char kSdpTcpPassiveCandidate[] =
382 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
383 "tcptype passive generation 2";
384static const char kSdpTcpSOCandidate[] =
385 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
386 "tcptype so generation 2";
387static const char kSdpTcpInvalidCandidate[] =
388 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
389 "tcptype invalid generation 2";
390
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000391// One candidate reference string with IPV6 address.
392static const char kRawIPV6Candidate[] =
393 "candidate:a0+B/1 1 udp 2130706432 "
394 "abcd::abcd::abcd::abcd::abcd::abcd::abcd::abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000395
396// One candidate reference string.
397static const char kSdpOneCandidateOldFormat[] =
398 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
399 " eth0 username user_rtp password password_rtp generation 2\r\n";
400
401// Session id and version
402static const char kSessionId[] = "18446744069414584320";
403static const char kSessionVersion[] = "18446462598732840960";
404
405// Ice options
406static const char kIceOption1[] = "iceoption1";
407static const char kIceOption2[] = "iceoption2";
408static const char kIceOption3[] = "iceoption3";
409
410// Content name
411static const char kAudioContentName[] = "audio_content_name";
412static const char kVideoContentName[] = "video_content_name";
413static const char kDataContentName[] = "data_content_name";
414
415// MediaStream 1
416static const char kStreamLabel1[] = "local_stream_1";
417static const char kStream1Cname[] = "stream_1_cname";
418static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200419static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000420static const char kVideoTrackId1[] = "video_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200421static const uint32_t kVideoTrack1Ssrc = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000422static const char kVideoTrackId2[] = "video_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200423static const uint32_t kVideoTrack2Ssrc = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000424
425// MediaStream 2
426static const char kStreamLabel2[] = "local_stream_2";
427static const char kStream2Cname[] = "stream_2_cname";
428static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200429static const uint32_t kAudioTrack2Ssrc = 4;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000430static const char kVideoTrackId3[] = "video_track_id_3";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200431static const uint32_t kVideoTrack3Ssrc = 5;
432static const uint32_t kVideoTrack4Ssrc = 6;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000433
434// DataChannel
435static const char kDataChannelLabel[] = "data_channel";
436static const char kDataChannelMsid[] = "data_channeld0";
437static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200438static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000439
440// Candidate
441static const char kDummyMid[] = "dummy_mid";
442static const int kDummyIndex = 123;
443
444// Misc
445static const char kDummyString[] = "dummy";
446
447// Helper functions
448
449static bool SdpDeserialize(const std::string& message,
450 JsepSessionDescription* jdesc) {
451 return webrtc::SdpDeserialize(message, jdesc, NULL);
452}
453
454static bool SdpDeserializeCandidate(const std::string& message,
455 JsepIceCandidate* candidate) {
456 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
457}
458
459// Add some extra |newlines| to the |message| after |line|.
460static void InjectAfter(const std::string& line,
461 const std::string& newlines,
462 std::string* message) {
463 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000464 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000465 tmp.c_str(), tmp.length(), message);
466}
467
468static void Replace(const std::string& line,
469 const std::string& newlines,
470 std::string* message) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000471 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000472 newlines.c_str(), newlines.length(), message);
473}
474
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000475// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
476// message.
477static void ExpectParseFailure(const std::string& bad_sdp,
478 const std::string& bad_part) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000479 JsepSessionDescription desc(kDummyString);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000480 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000481 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000482 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000483 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
484}
485
486// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
487static void ExpectParseFailure(const char* good_part, const char* bad_part) {
488 std::string bad_sdp = kSdpFullString;
489 Replace(good_part, bad_part, &bad_sdp);
490 ExpectParseFailure(bad_sdp, bad_part);
491}
492
493// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
494static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
495 const std::string& newlines,
496 const std::string& bad_part) {
497 std::string bad_sdp = kSdpFullString;
498 InjectAfter(injectpoint, newlines, &bad_sdp);
499 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000500}
501
502static void ReplaceDirection(cricket::MediaContentDirection direction,
503 std::string* message) {
504 std::string new_direction;
505 switch (direction) {
506 case cricket::MD_INACTIVE:
507 new_direction = "a=inactive";
508 break;
509 case cricket::MD_SENDONLY:
510 new_direction = "a=sendonly";
511 break;
512 case cricket::MD_RECVONLY:
513 new_direction = "a=recvonly";
514 break;
515 case cricket::MD_SENDRECV:
516 default:
517 new_direction = "a=sendrecv";
518 break;
519 }
520 Replace("a=sendrecv", new_direction, message);
521}
522
523static void ReplaceRejected(bool audio_rejected, bool video_rejected,
524 std::string* message) {
525 if (audio_rejected) {
526 Replace("m=audio 2345", "m=audio 0", message);
527 }
528 if (video_rejected) {
529 Replace("m=video 3457", "m=video 0", message);
530 }
531}
532
533// WebRtcSdpTest
534
535class WebRtcSdpTest : public testing::Test {
536 public:
537 WebRtcSdpTest()
538 : jdesc_(kDummyString) {
539 // AudioContentDescription
540 audio_desc_ = CreateAudioContentDescription();
541 AudioCodec opus(111, "opus", 48000, 0, 2, 3);
542 audio_desc_->AddCodec(opus);
543 audio_desc_->AddCodec(AudioCodec(103, "ISAC", 16000, 32000, 1, 2));
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000544 audio_desc_->AddCodec(AudioCodec(104, "ISAC", 32000, 56000, 1, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000545 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
546
547 // VideoContentDescription
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000548 rtc::scoped_ptr<VideoContentDescription> video(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000549 new VideoContentDescription());
550 video_desc_ = video.get();
551 StreamParams video_stream1;
552 video_stream1.id = kVideoTrackId1;
553 video_stream1.cname = kStream1Cname;
554 video_stream1.sync_label = kStreamLabel1;
555 video_stream1.ssrcs.push_back(kVideoTrack1Ssrc);
556 video->AddStream(video_stream1);
557 StreamParams video_stream2;
558 video_stream2.id = kVideoTrackId2;
559 video_stream2.cname = kStream1Cname;
560 video_stream2.sync_label = kStreamLabel1;
561 video_stream2.ssrcs.push_back(kVideoTrack2Ssrc);
562 video->AddStream(video_stream2);
563 StreamParams video_stream3;
564 video_stream3.id = kVideoTrackId3;
565 video_stream3.cname = kStream2Cname;
566 video_stream3.sync_label = kStreamLabel2;
567 video_stream3.ssrcs.push_back(kVideoTrack3Ssrc);
568 video_stream3.ssrcs.push_back(kVideoTrack4Ssrc);
569 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream3.ssrcs);
570 video_stream3.ssrc_groups.push_back(ssrc_group);
571 video->AddStream(video_stream3);
572 video->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
573 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
574 video->set_protocol(cricket::kMediaProtocolSavpf);
575 video->AddCodec(VideoCodec(
576 120,
577 JsepSessionDescription::kDefaultVideoCodecName,
578 JsepSessionDescription::kMaxVideoCodecWidth,
579 JsepSessionDescription::kMaxVideoCodecHeight,
580 JsepSessionDescription::kDefaultVideoCodecFramerate,
581 JsepSessionDescription::kDefaultVideoCodecPreference));
582
583 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP,
584 video.release());
585
586 // TransportInfo
587 EXPECT_TRUE(desc_.AddTransportInfo(
588 TransportInfo(kAudioContentName,
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700589 TransportDescription(kCandidateUfragVoice,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000590 kCandidatePwdVoice))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000591 EXPECT_TRUE(desc_.AddTransportInfo(
592 TransportInfo(kVideoContentName,
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700593 TransportDescription(kCandidateUfragVideo,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000594 kCandidatePwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000595
596 // v4 host
597 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000598 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000599 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000600 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
601 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000602 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000603 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000604 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
605 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000606 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000607 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "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 candidate4(ICE_CANDIDATE_COMPONENT_RTP, "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
615 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000616 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000617 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
618 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000619 cricket::LOCAL_PORT_TYPE,
620 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000621 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000622 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
623 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000624 cricket::LOCAL_PORT_TYPE,
625 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000626 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000627 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
628 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000629 cricket::LOCAL_PORT_TYPE,
630 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000631 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000632 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
633 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000634 cricket::LOCAL_PORT_TYPE,
635 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000636
637 // stun
638 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000639 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
640 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000641 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
642 address_stun, kCandidatePriority, "", "",
643 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000644 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000645 candidate9.set_related_address(rel_address_stun);
646
647 address_stun.SetPort(port_stun++);
648 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000649 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "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 candidate10.set_related_address(rel_address_stun);
654
655 // relay
656 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000657 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000658 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
659 address_relay, kCandidatePriority, "", "",
660 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000661 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000662 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000663 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
664 address_relay, kCandidatePriority, "", "",
665 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000666 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000667
668 // voice
669 candidates_.push_back(candidate1);
670 candidates_.push_back(candidate2);
671 candidates_.push_back(candidate5);
672 candidates_.push_back(candidate6);
673 candidates_.push_back(candidate9);
674 candidates_.push_back(candidate10);
675
676 // video
677 candidates_.push_back(candidate3);
678 candidates_.push_back(candidate4);
679 candidates_.push_back(candidate7);
680 candidates_.push_back(candidate8);
681 candidates_.push_back(candidate11);
682 candidates_.push_back(candidate12);
683
684 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"),
685 0, candidate1));
686
687 // Set up JsepSessionDescription.
688 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
689 std::string mline_id;
690 int mline_index = 0;
691 for (size_t i = 0; i< candidates_.size(); ++i) {
692 // In this test, the audio m line index will be 0, and the video m line
693 // will be 1.
694 bool is_video = (i > 5);
695 mline_id = is_video ? "video_content_name" : "audio_content_name";
696 mline_index = is_video ? 1 : 0;
697 JsepIceCandidate jice(mline_id,
698 mline_index,
699 candidates_.at(i));
700 jdesc_.AddCandidate(&jice);
701 }
702 }
703
704 AudioContentDescription* CreateAudioContentDescription() {
705 AudioContentDescription* audio = new AudioContentDescription();
706 audio->set_rtcp_mux(true);
707 StreamParams audio_stream1;
708 audio_stream1.id = kAudioTrackId1;
709 audio_stream1.cname = kStream1Cname;
710 audio_stream1.sync_label = kStreamLabel1;
711 audio_stream1.ssrcs.push_back(kAudioTrack1Ssrc);
712 audio->AddStream(audio_stream1);
713 StreamParams audio_stream2;
714 audio_stream2.id = kAudioTrackId2;
715 audio_stream2.cname = kStream2Cname;
716 audio_stream2.sync_label = kStreamLabel2;
717 audio_stream2.ssrcs.push_back(kAudioTrack2Ssrc);
718 audio->AddStream(audio_stream2);
719 audio->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_32",
720 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
721 "dummy_session_params"));
722 audio->set_protocol(cricket::kMediaProtocolSavpf);
723 return audio;
724 }
725
726 template <class MCD>
727 void CompareMediaContentDescription(const MCD* cd1,
728 const MCD* cd2) {
729 // type
730 EXPECT_EQ(cd1->type(), cd1->type());
731
732 // content direction
733 EXPECT_EQ(cd1->direction(), cd2->direction());
734
735 // rtcp_mux
736 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
737
738 // cryptos
739 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
740 if (cd1->cryptos().size() != cd2->cryptos().size()) {
741 ADD_FAILURE();
742 return;
743 }
744 for (size_t i = 0; i< cd1->cryptos().size(); ++i) {
745 const CryptoParams c1 = cd1->cryptos().at(i);
746 const CryptoParams c2 = cd2->cryptos().at(i);
747 EXPECT_TRUE(c1.Matches(c2));
748 EXPECT_EQ(c1.key_params, c2.key_params);
749 EXPECT_EQ(c1.session_params, c2.session_params);
750 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +0000751
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000752 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +0000753 // Use an equivalence class here, for old and new versions of the
754 // protocol description.
755 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:35 +0000756 || cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp
757 || cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
758 const bool cd2_is_also_dtls_sctp =
lally@webrtc.orgd7b61652015-02-24 20:18:55 +0000759 cd2->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:35 +0000760 || cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp
761 || cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
762 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +0000763 } else {
764 EXPECT_EQ(cd1->protocol(), cd2->protocol());
765 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000766
767 // codecs
768 EXPECT_EQ(cd1->codecs(), cd2->codecs());
769
770 // bandwidth
771 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
772
773 // streams
774 EXPECT_EQ(cd1->streams(), cd2->streams());
775
776 // extmap
777 ASSERT_EQ(cd1->rtp_header_extensions().size(),
778 cd2->rtp_header_extensions().size());
779 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) {
780 const RtpHeaderExtension ext1 = cd1->rtp_header_extensions().at(i);
781 const RtpHeaderExtension ext2 = cd2->rtp_header_extensions().at(i);
782 EXPECT_EQ(ext1.uri, ext2.uri);
783 EXPECT_EQ(ext1.id, ext2.id);
784 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000785 }
786
787
788 void CompareSessionDescription(const SessionDescription& desc1,
789 const SessionDescription& desc2) {
790 // Compare content descriptions.
791 if (desc1.contents().size() != desc2.contents().size()) {
792 ADD_FAILURE();
793 return;
794 }
795 for (size_t i = 0 ; i < desc1.contents().size(); ++i) {
796 const cricket::ContentInfo& c1 = desc1.contents().at(i);
797 const cricket::ContentInfo& c2 = desc2.contents().at(i);
798 // content name
799 EXPECT_EQ(c1.name, c2.name);
800 // content type
801 // Note, ASSERT will return from the function, but will not stop the test.
802 ASSERT_EQ(c1.type, c2.type);
803
804 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
805 if (IsAudioContent(&c1)) {
806 const AudioContentDescription* acd1 =
807 static_cast<const AudioContentDescription*>(c1.description);
808 const AudioContentDescription* acd2 =
809 static_cast<const AudioContentDescription*>(c2.description);
810 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
811 }
812
813 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
814 if (IsVideoContent(&c1)) {
815 const VideoContentDescription* vcd1 =
816 static_cast<const VideoContentDescription*>(c1.description);
817 const VideoContentDescription* vcd2 =
818 static_cast<const VideoContentDescription*>(c2.description);
819 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
820 }
821
822 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
823 if (IsDataContent(&c1)) {
824 const DataContentDescription* dcd1 =
825 static_cast<const DataContentDescription*>(c1.description);
826 const DataContentDescription* dcd2 =
827 static_cast<const DataContentDescription*>(c2.description);
828 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
829 }
830 }
831
832 // group
833 const cricket::ContentGroups groups1 = desc1.groups();
834 const cricket::ContentGroups groups2 = desc2.groups();
835 EXPECT_EQ(groups1.size(), groups1.size());
836 if (groups1.size() != groups2.size()) {
837 ADD_FAILURE();
838 return;
839 }
840 for (size_t i = 0; i < groups1.size(); ++i) {
841 const cricket::ContentGroup group1 = groups1.at(i);
842 const cricket::ContentGroup group2 = groups2.at(i);
843 EXPECT_EQ(group1.semantics(), group2.semantics());
844 const cricket::ContentNames names1 = group1.content_names();
845 const cricket::ContentNames names2 = group2.content_names();
846 EXPECT_EQ(names1.size(), names2.size());
847 if (names1.size() != names2.size()) {
848 ADD_FAILURE();
849 return;
850 }
851 cricket::ContentNames::const_iterator iter1 = names1.begin();
852 cricket::ContentNames::const_iterator iter2 = names2.begin();
853 while (iter1 != names1.end()) {
854 EXPECT_EQ(*iter1++, *iter2++);
855 }
856 }
857
858 // transport info
859 const cricket::TransportInfos transports1 = desc1.transport_infos();
860 const cricket::TransportInfos transports2 = desc2.transport_infos();
861 EXPECT_EQ(transports1.size(), transports2.size());
862 if (transports1.size() != transports2.size()) {
863 ADD_FAILURE();
864 return;
865 }
866 for (size_t i = 0; i < transports1.size(); ++i) {
867 const cricket::TransportInfo transport1 = transports1.at(i);
868 const cricket::TransportInfo transport2 = transports2.at(i);
869 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000870 EXPECT_EQ(transport1.description.ice_ufrag,
871 transport2.description.ice_ufrag);
872 EXPECT_EQ(transport1.description.ice_pwd,
873 transport2.description.ice_pwd);
874 if (transport1.description.identity_fingerprint) {
875 EXPECT_EQ(*transport1.description.identity_fingerprint,
876 *transport2.description.identity_fingerprint);
877 } else {
878 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
879 transport2.description.identity_fingerprint.get());
880 }
881 EXPECT_EQ(transport1.description.transport_options,
882 transport2.description.transport_options);
883 EXPECT_TRUE(CompareCandidates(transport1.description.candidates,
884 transport2.description.candidates));
885 }
deadbeefc80741f2015-10-22 13:14:45 -0700886
887 // global attributes
888 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000889 }
890
891 bool CompareCandidates(const Candidates& cs1, const Candidates& cs2) {
892 EXPECT_EQ(cs1.size(), cs2.size());
893 if (cs1.size() != cs2.size())
894 return false;
895 for (size_t i = 0; i< cs1.size(); ++i) {
896 const Candidate c1 = cs1.at(i);
897 const Candidate c2 = cs2.at(i);
898 EXPECT_TRUE(c1.IsEquivalent(c2));
899 }
900 return true;
901 }
902
903 bool CompareSessionDescription(
904 const JsepSessionDescription& desc1,
905 const JsepSessionDescription& desc2) {
906 EXPECT_EQ(desc1.session_id(), desc2.session_id());
907 EXPECT_EQ(desc1.session_version(), desc2.session_version());
908 CompareSessionDescription(*desc1.description(), *desc2.description());
909 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
910 return false;
911 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
912 const IceCandidateCollection* cc1 = desc1.candidates(i);
913 const IceCandidateCollection* cc2 = desc2.candidates(i);
914 if (cc1->count() != cc2->count())
915 return false;
916 for (size_t j = 0; j < cc1->count(); ++j) {
917 const IceCandidateInterface* c1 = cc1->at(j);
918 const IceCandidateInterface* c2 = cc2->at(j);
919 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
920 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
921 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
922 }
923 }
924 return true;
925 }
926
927 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
928 // them with invalid keywords so that the parser will just ignore them.
929 bool RemoveCandidateUfragPwd(std::string* sdp) {
930 const char ice_ufrag[] = "a=ice-ufrag";
931 const char ice_ufragx[] = "a=xice-ufrag";
932 const char ice_pwd[] = "a=ice-pwd";
933 const char ice_pwdx[] = "a=xice-pwd";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000934 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000935 ice_ufragx, strlen(ice_ufragx), sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000936 rtc::replace_substrs(ice_pwd, strlen(ice_pwd),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000937 ice_pwdx, strlen(ice_pwdx), sdp);
938 return true;
939 }
940
941 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
942 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, int mline_index,
943 const std::string& ufrag, const std::string& pwd) {
944 std::string content_name;
945 if (mline_index == 0) {
946 content_name = kAudioContentName;
947 } else if (mline_index == 1) {
948 content_name = kVideoContentName;
949 } else {
950 ASSERT(false);
951 }
952 TransportInfo transport_info(
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700953 content_name, TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000954 SessionDescription* desc =
955 const_cast<SessionDescription*>(jdesc->description());
956 desc->RemoveTransportInfoByName(content_name);
957 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
958 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
959 const IceCandidateCollection* cc = jdesc_.candidates(i);
960 for (size_t j = 0; j < cc->count(); ++j) {
961 if (cc->at(j)->sdp_mline_index() == mline_index) {
962 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(
963 ufrag);
964 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(
965 pwd);
966 }
967 }
968 }
969 return true;
970 }
971
972 void AddIceOptions(const std::string& content_name,
973 const std::vector<std::string>& transport_options) {
974 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
975 cricket::TransportInfo transport_info =
976 *(desc_.GetTransportInfoByName(content_name));
977 desc_.RemoveTransportInfoByName(content_name);
978 transport_info.description.transport_options = transport_options;
979 desc_.AddTransportInfo(transport_info);
980 }
981
982 void AddFingerprint() {
983 desc_.RemoveTransportInfoByName(kAudioContentName);
984 desc_.RemoveTransportInfoByName(kVideoContentName);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000985 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000986 kIdentityDigest,
987 sizeof(kIdentityDigest));
988 EXPECT_TRUE(desc_.AddTransportInfo(
989 TransportInfo(kAudioContentName,
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700990 TransportDescription(std::vector<std::string>(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000991 kCandidateUfragVoice,
992 kCandidatePwdVoice,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000993 cricket::ICEMODE_FULL,
994 cricket::CONNECTIONROLE_NONE,
995 &fingerprint, Candidates()))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000996 EXPECT_TRUE(desc_.AddTransportInfo(
997 TransportInfo(kVideoContentName,
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700998 TransportDescription(std::vector<std::string>(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000999 kCandidateUfragVideo,
1000 kCandidatePwdVideo,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001001 cricket::ICEMODE_FULL,
1002 cricket::CONNECTIONROLE_NONE,
1003 &fingerprint, Candidates()))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001004 }
1005
1006 void AddExtmap() {
1007 audio_desc_ = static_cast<AudioContentDescription*>(
1008 audio_desc_->Copy());
1009 video_desc_ = static_cast<VideoContentDescription*>(
1010 video_desc_->Copy());
1011 audio_desc_->AddRtpHeaderExtension(
1012 RtpHeaderExtension(kExtmapUri, kExtmapId));
1013 video_desc_->AddRtpHeaderExtension(
1014 RtpHeaderExtension(kExtmapUri, kExtmapId));
1015 desc_.RemoveContentByName(kAudioContentName);
1016 desc_.RemoveContentByName(kVideoContentName);
1017 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1018 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1019 }
1020
1021 void RemoveCryptos() {
1022 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1023 video_desc_->set_cryptos(std::vector<CryptoParams>());
1024 }
1025
1026 bool TestSerializeDirection(cricket::MediaContentDirection direction) {
1027 audio_desc_->set_direction(direction);
1028 video_desc_->set_direction(direction);
1029 std::string new_sdp = kSdpFullString;
1030 ReplaceDirection(direction, &new_sdp);
1031
1032 if (!jdesc_.Initialize(desc_.Copy(),
1033 jdesc_.session_id(),
1034 jdesc_.session_version())) {
1035 return false;
1036 }
1037 std::string message = webrtc::SdpSerialize(jdesc_);
1038 EXPECT_EQ(new_sdp, message);
1039 return true;
1040 }
1041
1042 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
1043 audio_desc_ = static_cast<AudioContentDescription*>(
1044 audio_desc_->Copy());
1045 video_desc_ = static_cast<VideoContentDescription*>(
1046 video_desc_->Copy());
1047 desc_.RemoveContentByName(kAudioContentName);
1048 desc_.RemoveContentByName(kVideoContentName);
1049 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1050 audio_desc_);
1051 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1052 video_desc_);
1053 std::string new_sdp = kSdpFullString;
1054 ReplaceRejected(audio_rejected, video_rejected, &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 void AddSctpDataChannel() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001067 rtc::scoped_ptr<DataContentDescription> data(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001068 new DataContentDescription());
1069 data_desc_ = data.get();
1070 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
wu@webrtc.org78187522013-10-07 23:32:02 +00001071 DataCodec codec(cricket::kGoogleSctpDataCodecId,
1072 cricket::kGoogleSctpDataCodecName, 0);
1073 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1074 data_desc_->AddCodec(codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001075 desc_.AddContent(kDataContentName, NS_JINGLE_DRAFT_SCTP, data.release());
1076 EXPECT_TRUE(desc_.AddTransportInfo(
1077 TransportInfo(kDataContentName,
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001078 TransportDescription(kCandidateUfragData,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001079 kCandidatePwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001080 }
1081
1082 void AddRtpDataChannel() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001083 rtc::scoped_ptr<DataContentDescription> data(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001084 new DataContentDescription());
1085 data_desc_ = data.get();
1086
1087 data_desc_->AddCodec(DataCodec(101, "google-data", 1));
1088 StreamParams data_stream;
1089 data_stream.id = kDataChannelMsid;
1090 data_stream.cname = kDataChannelCname;
1091 data_stream.sync_label = kDataChannelLabel;
1092 data_stream.ssrcs.push_back(kDataChannelSsrc);
1093 data_desc_->AddStream(data_stream);
1094 data_desc_->AddCrypto(CryptoParams(
1095 1, "AES_CM_128_HMAC_SHA1_80",
1096 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
1097 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
1098 desc_.AddContent(kDataContentName, NS_JINGLE_RTP, data.release());
1099 EXPECT_TRUE(desc_.AddTransportInfo(
1100 TransportInfo(kDataContentName,
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001101 TransportDescription(kCandidateUfragData,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001102 kCandidatePwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001103 }
1104
1105 bool TestDeserializeDirection(cricket::MediaContentDirection direction) {
1106 std::string new_sdp = kSdpFullString;
1107 ReplaceDirection(direction, &new_sdp);
1108 JsepSessionDescription new_jdesc(kDummyString);
1109
1110 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1111
1112 audio_desc_->set_direction(direction);
1113 video_desc_->set_direction(direction);
1114 if (!jdesc_.Initialize(desc_.Copy(),
1115 jdesc_.session_id(),
1116 jdesc_.session_version())) {
1117 return false;
1118 }
1119 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1120 return true;
1121 }
1122
1123 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
1124 std::string new_sdp = kSdpFullString;
1125 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1126 JsepSessionDescription new_jdesc(JsepSessionDescription::kOffer);
1127
1128 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1129 audio_desc_ = static_cast<AudioContentDescription*>(
1130 audio_desc_->Copy());
1131 video_desc_ = static_cast<VideoContentDescription*>(
1132 video_desc_->Copy());
1133 desc_.RemoveContentByName(kAudioContentName);
1134 desc_.RemoveContentByName(kVideoContentName);
1135 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1136 audio_desc_);
1137 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1138 video_desc_);
1139 if (!jdesc_.Initialize(desc_.Copy(),
1140 jdesc_.session_id(),
1141 jdesc_.session_version())) {
1142 return false;
1143 }
1144 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1145 return true;
1146 }
1147
1148 void TestDeserializeExtmap(bool session_level, bool media_level) {
1149 AddExtmap();
1150 JsepSessionDescription new_jdesc("dummy");
1151 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1152 jdesc_.session_id(),
1153 jdesc_.session_version()));
1154 JsepSessionDescription jdesc_with_extmap("dummy");
1155 std::string sdp_with_extmap = kSdpString;
1156 if (session_level) {
1157 InjectAfter(kSessionTime, kExtmapWithDirectionAndAttribute,
1158 &sdp_with_extmap);
1159 }
1160 if (media_level) {
1161 InjectAfter(kAttributeIcePwdVoice, kExtmapWithDirectionAndAttribute,
1162 &sdp_with_extmap);
1163 InjectAfter(kAttributeIcePwdVideo, kExtmapWithDirectionAndAttribute,
1164 &sdp_with_extmap);
1165 }
1166 // The extmap can't be present at the same time in both session level and
1167 // media level.
1168 if (session_level && media_level) {
1169 SdpParseError error;
1170 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap,
1171 &jdesc_with_extmap, &error));
1172 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1173 } else {
1174 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1175 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1176 }
1177 }
1178
1179 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
1180 const std::string& name, int expected_value) {
1181 cricket::CodecParameterMap::const_iterator found = params.find(name);
1182 ASSERT_TRUE(found != params.end());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001183 EXPECT_EQ(found->second, rtc::ToString<int>(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001184 }
1185
1186 void TestDeserializeCodecParams(const CodecParams& params,
1187 JsepSessionDescription* jdesc_output) {
1188 std::string sdp =
1189 "v=0\r\n"
1190 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1191 "s=-\r\n"
1192 "t=0 0\r\n"
1193 // Include semantics for WebRTC Media Streams since it is supported by
1194 // this parser, and will be added to the SDP when serializing a session
1195 // description.
1196 "a=msid-semantic: WMS\r\n"
1197 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001198 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001199 // Pltype 111 listed before 103 and 104 in the map.
1200 "a=rtpmap:111 opus/48000/2\r\n"
1201 // Pltype 103 listed before 104.
1202 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001203 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001204 "a=fmtp:111 0-15,66,70\r\n"
1205 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001206 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001207 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001208 << "; sprop-stereo=" << params.sprop_stereo
1209 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001210 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001211 << "a=ptime:" << params.ptime << "\r\n"
1212 << "a=maxptime:" << params.max_ptime << "\r\n";
1213 sdp += os.str();
1214
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001215 os.clear();
1216 os.str("");
1217 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001218 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001219 << "a=rtpmap:99 VP8/90000\r\n"
1220 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001221 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001222 sdp += os.str();
1223
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001224 // Deserialize
1225 SdpParseError error;
1226 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1227
1228 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1229 ASSERT_TRUE(ac != NULL);
1230 const AudioContentDescription* acd =
1231 static_cast<const AudioContentDescription*>(ac->description);
1232 ASSERT_FALSE(acd->codecs().empty());
1233 cricket::AudioCodec opus = acd->codecs()[0];
1234 EXPECT_EQ("opus", opus.name);
1235 EXPECT_EQ(111, opus.id);
1236 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1237 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1238 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1239 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001240 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1241 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001242 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1243 cricket::AudioCodec codec = acd->codecs()[i];
1244 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1245 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
1246 if (codec.name == "ISAC") {
1247 if (codec.clockrate == 16000) {
1248 EXPECT_EQ(32000, codec.bitrate);
1249 } else {
1250 EXPECT_EQ(56000, codec.bitrate);
1251 }
1252 }
1253 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001254
1255 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1256 ASSERT_TRUE(vc != NULL);
1257 const VideoContentDescription* vcd =
1258 static_cast<const VideoContentDescription*>(vc->description);
1259 ASSERT_FALSE(vcd->codecs().empty());
1260 cricket::VideoCodec vp8 = vcd->codecs()[0];
1261 EXPECT_EQ("VP8", vp8.name);
1262 EXPECT_EQ(99, vp8.id);
1263 cricket::VideoCodec rtx = vcd->codecs()[1];
1264 EXPECT_EQ("RTX", rtx.name);
1265 EXPECT_EQ(95, rtx.id);
1266 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001267 }
1268
1269 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1270 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001271 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001272 "v=0\r\n"
1273 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1274 "s=-\r\n"
1275 "t=0 0\r\n"
1276 // Include semantics for WebRTC Media Streams since it is supported by
1277 // this parser, and will be added to the SDP when serializing a session
1278 // description.
1279 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001280 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001281 "a=rtpmap:111 opus/48000/2\r\n";
1282 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001283 "m=video 3457 RTP/SAVPF 101\r\n"
1284 "a=rtpmap:101 VP8/90000\r\n"
1285 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001286 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001287 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001288 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001289 os << sdp_session_and_audio;
1290 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
1291 os << sdp_video;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001292 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001293 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001294 // Deserialize
1295 SdpParseError error;
1296 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1297 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1298 ASSERT_TRUE(ac != NULL);
1299 const AudioContentDescription* acd =
1300 static_cast<const AudioContentDescription*>(ac->description);
1301 ASSERT_FALSE(acd->codecs().empty());
1302 cricket::AudioCodec opus = acd->codecs()[0];
1303 EXPECT_EQ(111, opus.id);
1304 EXPECT_TRUE(opus.HasFeedbackParam(
1305 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1306 cricket::kParamValueEmpty)));
1307
1308 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1309 ASSERT_TRUE(vc != NULL);
1310 const VideoContentDescription* vcd =
1311 static_cast<const VideoContentDescription*>(vc->description);
1312 ASSERT_FALSE(vcd->codecs().empty());
1313 cricket::VideoCodec vp8 = vcd->codecs()[0];
1314 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1315 vp8.name.c_str());
1316 EXPECT_EQ(101, vp8.id);
1317 EXPECT_TRUE(vp8.HasFeedbackParam(
1318 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1319 cricket::kParamValueEmpty)));
1320 EXPECT_TRUE(vp8.HasFeedbackParam(
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001321 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1322 cricket::kRtcpFbNackParamPli)));
1323 EXPECT_TRUE(vp8.HasFeedbackParam(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001324 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
1325 cricket::kParamValueEmpty)));
1326 EXPECT_TRUE(vp8.HasFeedbackParam(
1327 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
1328 cricket::kRtcpFbCcmParamFir)));
1329 }
1330
1331 // Two SDP messages can mean the same thing but be different strings, e.g.
1332 // some of the lines can be serialized in different order.
1333 // However, a deserialized description can be compared field by field and has
1334 // no order. If deserializer has already been tested, serializing then
1335 // deserializing and comparing JsepSessionDescription will test
1336 // the serializer sufficiently.
1337 void TestSerialize(const JsepSessionDescription& jdesc) {
1338 std::string message = webrtc::SdpSerialize(jdesc);
1339 JsepSessionDescription jdesc_output_des(kDummyString);
1340 SdpParseError error;
1341 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1342 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1343 }
1344
1345 protected:
1346 SessionDescription desc_;
1347 AudioContentDescription* audio_desc_;
1348 VideoContentDescription* video_desc_;
1349 DataContentDescription* data_desc_;
1350 Candidates candidates_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001351 rtc::scoped_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001352 JsepSessionDescription jdesc_;
1353};
1354
1355void TestMismatch(const std::string& string1, const std::string& string2) {
1356 int position = 0;
1357 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1358 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001359 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001360 break;
1361 }
1362 }
1363 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1364 << " character\n"
1365 << " 1: " << string1.substr(position, 20) << "\n"
1366 << " 2: " << string2.substr(position, 20) << "\n";
1367}
1368
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001369TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1370 // SessionDescription with desc and candidates.
1371 std::string message = webrtc::SdpSerialize(jdesc_);
1372 TestMismatch(std::string(kSdpFullString), message);
1373}
1374
1375TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
1376 JsepSessionDescription jdesc_empty(kDummyString);
1377 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
1378}
1379
guoweis@webrtc.org57ac2c82015-02-06 00:45:13 +00001380// This tests serialization of SDP with only IPv6 candidates and verifies that
1381// IPv6 is used as default address in c line according to preference.
1382TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIPv6Only) {
1383 // Only test 1 m line.
1384 desc_.RemoveContentByName("video_content_name");
1385 // Stun has a high preference than local host.
1386 cricket::Candidate candidate1(
1387 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1388 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1389 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1390 cricket::Candidate candidate2(
1391 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1392 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
1393 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1394 JsepSessionDescription jdesc(kDummyString);
1395 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1396
1397 // Only add the candidates to audio m line.
1398 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1399 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1400 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1401 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
1402 std::string message = webrtc::SdpSerialize(jdesc);
1403
1404 // Audio line should have a c line like this one.
1405 EXPECT_NE(message.find("c=IN IP6 ::1"), std::string::npos);
1406 // Shouldn't have a IP4 c line.
1407 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
1408}
1409
1410// This tests serialization of SDP with both IPv4 and IPv6 candidates and
1411// verifies that IPv4 is used as default address in c line even if the
1412// preference of IPv4 is lower.
1413TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothIPFamilies) {
1414 // Only test 1 m line.
1415 desc_.RemoveContentByName("video_content_name");
1416 cricket::Candidate candidate_v4(
1417 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1418 rtc::SocketAddress("192.168.1.5", 1234), kCandidatePriority, "", "",
1419 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1420 cricket::Candidate candidate_v6(
1421 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1422 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1423 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1424 JsepSessionDescription jdesc(kDummyString);
1425 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1426
1427 // Only add the candidates to audio m line.
1428 JsepIceCandidate jice_v4("audio_content_name", 0, candidate_v4);
1429 JsepIceCandidate jice_v6("audio_content_name", 0, candidate_v6);
1430 ASSERT_TRUE(jdesc.AddCandidate(&jice_v4));
1431 ASSERT_TRUE(jdesc.AddCandidate(&jice_v6));
1432 std::string message = webrtc::SdpSerialize(jdesc);
1433
1434 // Audio line should have a c line like this one.
1435 EXPECT_NE(message.find("c=IN IP4 192.168.1.5"), std::string::npos);
1436 // Shouldn't have a IP6 c line.
1437 EXPECT_EQ(message.find("c=IN IP6"), std::string::npos);
1438}
1439
1440// This tests serialization of SDP with both UDP and TCP candidates and
1441// verifies that UDP is used as default address in c line even if the
1442// preference of UDP is lower.
1443TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothProtocols) {
1444 // Only test 1 m line.
1445 desc_.RemoveContentByName("video_content_name");
1446 // Stun has a high preference than local host.
1447 cricket::Candidate candidate1(
1448 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1449 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1450 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1451 cricket::Candidate candidate2(
1452 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1453 rtc::SocketAddress("fe80::1234:5678:abcd:ef12", 1235), kCandidatePriority,
1454 "", "", cricket::LOCAL_PORT_TYPE, kCandidateGeneration,
1455 kCandidateFoundation1);
1456 JsepSessionDescription jdesc(kDummyString);
1457 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1458
1459 // Only add the candidates to audio m line.
1460 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1461 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1462 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1463 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
1464 std::string message = webrtc::SdpSerialize(jdesc);
1465
1466 // Audio line should have a c line like this one.
1467 EXPECT_NE(message.find("c=IN IP6 fe80::1234:5678:abcd:ef12"),
1468 std::string::npos);
1469 // Shouldn't have a IP4 c line.
1470 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
1471}
1472
1473// This tests serialization of SDP with only TCP candidates and verifies that
1474// null IPv4 is used as default address in c line.
1475TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithTCPOnly) {
1476 // Only test 1 m line.
1477 desc_.RemoveContentByName("video_content_name");
1478 // Stun has a high preference than local host.
1479 cricket::Candidate candidate1(
1480 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1481 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1482 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1483 cricket::Candidate candidate2(
1484 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1485 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
1486 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1487 JsepSessionDescription jdesc(kDummyString);
1488 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1489
1490 // Only add the candidates to audio m line.
1491 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1492 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1493 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1494 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
1495 std::string message = webrtc::SdpSerialize(jdesc);
1496
1497 // Audio line should have a c line like this one when no any default exists.
1498 EXPECT_NE(message.find("c=IN IP4 0.0.0.0"), std::string::npos);
1499}
1500
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001501// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1502// the case in a DTLS offer.
1503TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1504 AddFingerprint();
1505 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1506 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1507 kSessionId, kSessionVersion));
1508 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
1509
1510 std::string sdp_with_fingerprint = kSdpString;
1511 InjectAfter(kAttributeIcePwdVoice,
1512 kFingerprint, &sdp_with_fingerprint);
1513 InjectAfter(kAttributeIcePwdVideo,
1514 kFingerprint, &sdp_with_fingerprint);
1515
1516 EXPECT_EQ(sdp_with_fingerprint, message);
1517}
1518
1519// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1520// be the case in a DTLS answer.
1521TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1522 AddFingerprint();
1523 RemoveCryptos();
1524 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1525 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1526 kSessionId, kSessionVersion));
1527 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
1528
1529 std::string sdp_with_fingerprint = kSdpString;
1530 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1531 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
1532 InjectAfter(kAttributeIcePwdVoice,
1533 kFingerprint, &sdp_with_fingerprint);
1534 InjectAfter(kAttributeIcePwdVideo,
1535 kFingerprint, &sdp_with_fingerprint);
1536
1537 EXPECT_EQ(sdp_with_fingerprint, message);
1538}
1539
1540TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1541 // JsepSessionDescription with desc but without candidates.
1542 JsepSessionDescription jdesc_no_candidates(kDummyString);
1543 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
1544 kSessionId, kSessionVersion));
1545 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
1546 EXPECT_EQ(std::string(kSdpString), message);
1547}
1548
1549TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1550 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1551 group.AddContentName(kAudioContentName);
1552 group.AddContentName(kVideoContentName);
1553 desc_.AddGroup(group);
1554 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1555 jdesc_.session_id(),
1556 jdesc_.session_version()));
1557 std::string message = webrtc::SdpSerialize(jdesc_);
1558 std::string sdp_with_bundle = kSdpFullString;
1559 InjectAfter(kSessionTime,
1560 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1561 &sdp_with_bundle);
1562 EXPECT_EQ(sdp_with_bundle, message);
1563}
1564
1565TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
1566 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1567 GetFirstVideoContent(&desc_)->description);
1568 vcd->set_bandwidth(100 * 1000);
1569 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1570 GetFirstAudioContent(&desc_)->description);
1571 acd->set_bandwidth(50 * 1000);
1572 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1573 jdesc_.session_id(),
1574 jdesc_.session_version()));
1575 std::string message = webrtc::SdpSerialize(jdesc_);
1576 std::string sdp_with_bandwidth = kSdpFullString;
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001577 InjectAfter("c=IN IP4 74.125.224.39\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001578 "b=AS:100\r\n",
1579 &sdp_with_bandwidth);
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001580 InjectAfter("c=IN IP4 74.125.127.126\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001581 "b=AS:50\r\n",
1582 &sdp_with_bandwidth);
1583 EXPECT_EQ(sdp_with_bandwidth, message);
1584}
1585
1586TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1587 std::vector<std::string> transport_options;
1588 transport_options.push_back(kIceOption1);
1589 transport_options.push_back(kIceOption3);
1590 AddIceOptions(kAudioContentName, transport_options);
1591 transport_options.clear();
1592 transport_options.push_back(kIceOption2);
1593 transport_options.push_back(kIceOption3);
1594 AddIceOptions(kVideoContentName, transport_options);
1595 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1596 jdesc_.session_id(),
1597 jdesc_.session_version()));
1598 std::string message = webrtc::SdpSerialize(jdesc_);
1599 std::string sdp_with_ice_options = kSdpFullString;
1600 InjectAfter(kAttributeIcePwdVoice,
1601 "a=ice-options:iceoption1 iceoption3\r\n",
1602 &sdp_with_ice_options);
1603 InjectAfter(kAttributeIcePwdVideo,
1604 "a=ice-options:iceoption2 iceoption3\r\n",
1605 &sdp_with_ice_options);
1606 EXPECT_EQ(sdp_with_ice_options, message);
1607}
1608
1609TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
1610 EXPECT_TRUE(TestSerializeDirection(cricket::MD_RECVONLY));
1611}
1612
1613TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
1614 EXPECT_TRUE(TestSerializeDirection(cricket::MD_SENDONLY));
1615}
1616
1617TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
1618 EXPECT_TRUE(TestSerializeDirection(cricket::MD_INACTIVE));
1619}
1620
1621TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
1622 EXPECT_TRUE(TestSerializeRejected(true, false));
1623}
1624
1625TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
1626 EXPECT_TRUE(TestSerializeRejected(false, true));
1627}
1628
1629TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
1630 EXPECT_TRUE(TestSerializeRejected(true, true));
1631}
1632
1633TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
1634 AddRtpDataChannel();
1635 JsepSessionDescription jsep_desc(kDummyString);
1636
1637 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1638 std::string message = webrtc::SdpSerialize(jsep_desc);
1639
1640 std::string expected_sdp = kSdpString;
1641 expected_sdp.append(kSdpRtpDataChannelString);
1642 EXPECT_EQ(expected_sdp, message);
1643}
1644
1645TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
1646 AddSctpDataChannel();
1647 JsepSessionDescription jsep_desc(kDummyString);
1648
1649 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1650 std::string message = webrtc::SdpSerialize(jsep_desc);
1651
1652 std::string expected_sdp = kSdpString;
1653 expected_sdp.append(kSdpSctpDataChannelString);
1654 EXPECT_EQ(message, expected_sdp);
1655}
1656
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001657TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
1658 AddSctpDataChannel();
1659 JsepSessionDescription jsep_desc(kDummyString);
1660
1661 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1662 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
1663 jsep_desc.description()->GetContentDescriptionByName(kDataContentName));
1664
1665 const int kNewPort = 1234;
1666 cricket::DataCodec codec(
1667 cricket::kGoogleSctpDataCodecId, cricket::kGoogleSctpDataCodecName, 0);
1668 codec.SetParam(cricket::kCodecParamPort, kNewPort);
1669 dcdesc->AddOrReplaceCodec(codec);
1670
1671 std::string message = webrtc::SdpSerialize(jsep_desc);
1672
1673 std::string expected_sdp = kSdpString;
1674 expected_sdp.append(kSdpSctpDataChannelString);
1675
1676 char default_portstr[16];
1677 char new_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001678 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001679 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001680 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
1681 rtc::replace_substrs(default_portstr, strlen(default_portstr),
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001682 new_portstr, strlen(new_portstr),
1683 &expected_sdp);
1684
1685 EXPECT_EQ(expected_sdp, message);
1686}
1687
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001688TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
1689 AddRtpDataChannel();
1690 data_desc_->set_bandwidth(100*1000);
1691 JsepSessionDescription jsep_desc(kDummyString);
1692
1693 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1694 std::string message = webrtc::SdpSerialize(jsep_desc);
1695
1696 std::string expected_sdp = kSdpString;
1697 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07001698 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00001699 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 +00001700 "b=AS:100\r\n",
1701 &expected_sdp);
1702 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001703}
1704
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001705TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
1706 AddExtmap();
1707 JsepSessionDescription desc_with_extmap("dummy");
1708 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(),
1709 kSessionId, kSessionVersion));
1710 std::string message = webrtc::SdpSerialize(desc_with_extmap);
1711
1712 std::string sdp_with_extmap = kSdpString;
1713 InjectAfter("a=mid:audio_content_name\r\n",
1714 kExtmap, &sdp_with_extmap);
1715 InjectAfter("a=mid:video_content_name\r\n",
1716 kExtmap, &sdp_with_extmap);
1717
1718 EXPECT_EQ(sdp_with_extmap, message);
1719}
1720
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001721TEST_F(WebRtcSdpTest, SerializeCandidates) {
1722 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00001723 EXPECT_EQ(std::string(kRawCandidate), message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001724}
1725
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00001726// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
1727// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00001728TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001729 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001730 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
1731 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
1732 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00001733 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
1734 rtc::scoped_ptr<IceCandidateInterface> jcandidate(
1735 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
1736
1737 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
1738 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
1739}
1740
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001741TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
1742 JsepSessionDescription jdesc(kDummyString);
1743 // Deserialize
1744 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
1745 // Verify
1746 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1747}
1748
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001749TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
1750 JsepSessionDescription jdesc(kDummyString);
1751 const char kSdpWithoutMline[] =
1752 "v=0\r\n"
1753 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1754 "s=-\r\n"
1755 "t=0 0\r\n"
1756 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
1757 // Deserialize
1758 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
1759 EXPECT_EQ(0u, jdesc.description()->contents().size());
1760}
1761
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001762TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
1763 JsepSessionDescription jdesc(kDummyString);
1764 std::string sdp_without_carriage_return = kSdpFullString;
1765 Replace("\r\n", "\n", &sdp_without_carriage_return);
1766 // Deserialize
1767 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
1768 // Verify
1769 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1770}
1771
1772TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
1773 // SessionDescription with desc but without candidates.
1774 JsepSessionDescription jdesc_no_candidates(kDummyString);
1775 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
1776 kSessionId, kSessionVersion));
1777 JsepSessionDescription new_jdesc(kDummyString);
1778 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
1779 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
1780}
1781
1782TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
1783 static const char kSdpNoRtpmapString[] =
1784 "v=0\r\n"
1785 "o=- 11 22 IN IP4 127.0.0.1\r\n"
1786 "s=-\r\n"
1787 "t=0 0\r\n"
1788 "m=audio 49232 RTP/AVP 0 18 103\r\n"
1789 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001790 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001791 // The rtpmap line for static payload codec is optional.
1792 "a=rtpmap:18 G729/16000\r\n"
1793 "a=rtpmap:103 ISAC/16000\r\n";
1794
1795 JsepSessionDescription jdesc(kDummyString);
1796 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
1797 cricket::AudioContentDescription* audio =
1798 static_cast<AudioContentDescription*>(
1799 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
1800 AudioCodecs ref_codecs;
1801 // The codecs in the AudioContentDescription will be sorted by preference.
1802 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1, 3));
1803 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1, 2));
1804 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 32000, 1, 1));
1805 EXPECT_EQ(ref_codecs, audio->codecs());
1806}
1807
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001808TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
1809 static const char kSdpNoRtpmapString[] =
1810 "v=0\r\n"
1811 "o=- 11 22 IN IP4 127.0.0.1\r\n"
1812 "s=-\r\n"
1813 "t=0 0\r\n"
1814 "m=audio 49232 RTP/AVP 18 103\r\n"
1815 "a=fmtp:18 annexb=yes\r\n"
1816 "a=rtpmap:103 ISAC/16000\r\n";
1817
1818 JsepSessionDescription jdesc(kDummyString);
1819 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
1820 cricket::AudioContentDescription* audio =
1821 static_cast<AudioContentDescription*>(
1822 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
1823
1824 cricket::AudioCodec g729 = audio->codecs()[0];
1825 EXPECT_EQ("G729", g729.name);
1826 EXPECT_EQ(8000, g729.clockrate);
1827 EXPECT_EQ(18, g729.id);
1828 cricket::CodecParameterMap::iterator found =
1829 g729.params.find("annexb");
1830 ASSERT_TRUE(found != g729.params.end());
1831 EXPECT_EQ(found->second, "yes");
1832
1833 cricket::AudioCodec isac = audio->codecs()[1];
1834 EXPECT_EQ("ISAC", isac.name);
1835 EXPECT_EQ(103, isac.id);
1836 EXPECT_EQ(16000, isac.clockrate);
1837}
1838
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001839// Ensure that we can deserialize SDP with a=fingerprint properly.
1840TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
1841 // Add a DTLS a=fingerprint attribute to our session description.
1842 AddFingerprint();
1843 JsepSessionDescription new_jdesc(kDummyString);
1844 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1845 jdesc_.session_id(),
1846 jdesc_.session_version()));
1847
1848 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1849 std::string sdp_with_fingerprint = kSdpString;
1850 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1851 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
1852 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
1853 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
1854}
1855
1856TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
1857 JsepSessionDescription jdesc_with_bundle(kDummyString);
1858 std::string sdp_with_bundle = kSdpFullString;
1859 InjectAfter(kSessionTime,
1860 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1861 &sdp_with_bundle);
1862 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
1863 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1864 group.AddContentName(kAudioContentName);
1865 group.AddContentName(kVideoContentName);
1866 desc_.AddGroup(group);
1867 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1868 jdesc_.session_id(),
1869 jdesc_.session_version()));
1870 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
1871}
1872
1873TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
1874 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
1875 std::string sdp_with_bandwidth = kSdpFullString;
1876 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
1877 "b=AS:100\r\n",
1878 &sdp_with_bandwidth);
1879 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
1880 "b=AS:50\r\n",
1881 &sdp_with_bandwidth);
1882 EXPECT_TRUE(
1883 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
1884 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1885 GetFirstVideoContent(&desc_)->description);
1886 vcd->set_bandwidth(100 * 1000);
1887 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1888 GetFirstAudioContent(&desc_)->description);
1889 acd->set_bandwidth(50 * 1000);
1890 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1891 jdesc_.session_id(),
1892 jdesc_.session_version()));
1893 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
1894}
1895
1896TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
1897 JsepSessionDescription jdesc_with_ice_options(kDummyString);
1898 std::string sdp_with_ice_options = kSdpFullString;
1899 InjectAfter(kSessionTime,
1900 "a=ice-options:iceoption3\r\n",
1901 &sdp_with_ice_options);
1902 InjectAfter(kAttributeIcePwdVoice,
1903 "a=ice-options:iceoption1\r\n",
1904 &sdp_with_ice_options);
1905 InjectAfter(kAttributeIcePwdVideo,
1906 "a=ice-options:iceoption2\r\n",
1907 &sdp_with_ice_options);
1908 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
1909 std::vector<std::string> transport_options;
1910 transport_options.push_back(kIceOption3);
1911 transport_options.push_back(kIceOption1);
1912 AddIceOptions(kAudioContentName, transport_options);
1913 transport_options.clear();
1914 transport_options.push_back(kIceOption3);
1915 transport_options.push_back(kIceOption2);
1916 AddIceOptions(kVideoContentName, transport_options);
1917 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1918 jdesc_.session_id(),
1919 jdesc_.session_version()));
1920 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
1921}
1922
1923TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
1924 // Remove the original ice-ufrag and ice-pwd
1925 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyString);
1926 std::string sdp_with_ufrag_pwd = kSdpFullString;
1927 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
1928 // Add session level ufrag and pwd
1929 InjectAfter(kSessionTime,
1930 "a=ice-pwd:session+level+icepwd\r\n"
1931 "a=ice-ufrag:session+level+iceufrag\r\n",
1932 &sdp_with_ufrag_pwd);
1933 // Add media level ufrag and pwd for audio
1934 InjectAfter("a=mid:audio_content_name\r\n",
1935 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
1936 &sdp_with_ufrag_pwd);
1937 // Update the candidate ufrag and pwd to the expected ones.
1938 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0,
1939 "media+level+iceufrag", "media+level+icepwd"));
1940 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1,
1941 "session+level+iceufrag", "session+level+icepwd"));
1942 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
1943 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
1944}
1945
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001946TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
1947 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_RECVONLY));
1948}
1949
1950TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
1951 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_SENDONLY));
1952}
1953
1954TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
1955 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_INACTIVE));
1956}
1957
1958TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
1959 EXPECT_TRUE(TestDeserializeRejected(true, false));
1960}
1961
1962TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
1963 EXPECT_TRUE(TestDeserializeRejected(false, true));
1964}
1965
1966TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
1967 EXPECT_TRUE(TestDeserializeRejected(true, true));
1968}
1969
1970// Tests that we can still handle the sdp uses mslabel and label instead of
1971// msid for backward compatibility.
1972TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07001973 jdesc_.description()->set_msid_supported(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001974 JsepSessionDescription jdesc(kDummyString);
1975 std::string sdp_without_msid = kSdpFullString;
1976 Replace("msid", "xmsid", &sdp_without_msid);
1977 // Deserialize
1978 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
1979 // Verify
1980 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1981}
1982
1983TEST_F(WebRtcSdpTest, DeserializeCandidate) {
1984 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
1985
1986 std::string sdp = kSdpOneCandidate;
1987 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
1988 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
1989 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
1990 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
1991
1992 // Candidate line without generation extension.
1993 sdp = kSdpOneCandidate;
1994 Replace(" generation 2", "", &sdp);
1995 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
1996 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
1997 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
1998 Candidate expected = jcandidate_->candidate();
1999 expected.set_generation(0);
2000 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2001
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002002 sdp = kSdpTcpActiveCandidate;
2003 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2004 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002005 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002006 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2007 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2008 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002009 rtc::scoped_ptr<IceCandidateInterface> jcandidate_template(
2010 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
2011 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(
2012 jcandidate_template->candidate()));
2013 sdp = kSdpTcpPassiveCandidate;
2014 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2015 sdp = kSdpTcpSOCandidate;
2016 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002017}
2018
2019// This test verifies the deserialization of candidate-attribute
2020// as per RFC 5245. Candiate-attribute will be of the format
2021// candidate:<blah>. This format will be used when candidates
2022// are trickled.
2023TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2024 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2025
2026 std::string candidate_attribute = kRawCandidate;
2027 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2028 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2029 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2030 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2031 EXPECT_EQ(2u, jcandidate.candidate().generation());
2032
2033 // Candidate line without generation extension.
2034 candidate_attribute = kRawCandidate;
2035 Replace(" generation 2", "", &candidate_attribute);
2036 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2037 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2038 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2039 Candidate expected = jcandidate_->candidate();
2040 expected.set_generation(0);
2041 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2042
2043 // Candidate line without candidate:
2044 candidate_attribute = kRawCandidate;
2045 Replace("candidate:", "", &candidate_attribute);
2046 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2047
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002048 // Candidate line with IPV6 address.
2049 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
2050}
2051
2052// This test verifies that the deserialization of an invalid candidate string
2053// fails.
2054TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
2055 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2056
2057 std::string candidate_attribute = kRawCandidate;
2058 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002059 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002060
2061 candidate_attribute = kSdpOneCandidate;
2062 candidate_attribute.replace(0, 1, "x");
2063 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2064
2065 candidate_attribute = kRawCandidate;
2066 candidate_attribute.append("\r\n");
2067 candidate_attribute.append(kRawCandidate);
2068 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2069
2070 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002071}
2072
2073TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2074 AddRtpDataChannel();
2075 JsepSessionDescription jdesc(kDummyString);
2076 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2077
2078 std::string sdp_with_data = kSdpString;
2079 sdp_with_data.append(kSdpRtpDataChannelString);
2080 JsepSessionDescription jdesc_output(kDummyString);
2081
2082 // Deserialize
2083 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2084 // Verify
2085 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2086}
2087
2088TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
2089 AddSctpDataChannel();
2090 JsepSessionDescription jdesc(kDummyString);
2091 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2092
2093 std::string sdp_with_data = kSdpString;
2094 sdp_with_data.append(kSdpSctpDataChannelString);
2095 JsepSessionDescription jdesc_output(kDummyString);
2096
lally@webrtc.org36300852015-02-24 20:19:35 +00002097 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2098 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2099 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2100
2101 // Verify with UDP/DTLS/SCTP.
2102 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2103 strlen(kDtlsSctp), kUdpDtlsSctp);
2104 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2105 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2106
2107 // Verify with TCP/DTLS/SCTP.
2108 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2109 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002110 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2111 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2112}
2113
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002114TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
2115 AddSctpDataChannel();
2116 JsepSessionDescription jdesc(kDummyString);
2117 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2118
2119 std::string sdp_with_data = kSdpString;
2120 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2121 JsepSessionDescription jdesc_output(kDummyString);
2122
lally@webrtc.org36300852015-02-24 20:19:35 +00002123 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002124 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2125 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002126
lally@webrtc.org36300852015-02-24 20:19:35 +00002127 // Verify with UDP/DTLS/SCTP.
2128 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2129 strlen(kDtlsSctp), kUdpDtlsSctp);
2130 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2131 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002132
lally@webrtc.org36300852015-02-24 20:19:35 +00002133 // Verify with TCP/DTLS/SCTP.
2134 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2135 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002136 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2137 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2138}
2139
lally69f57602015-10-08 10:15:04 -07002140TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
2141 AddSctpDataChannel();
2142 JsepSessionDescription jdesc(kDummyString);
2143 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2144
2145 std::string sdp_with_data = kSdpString;
2146 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
2147 JsepSessionDescription jdesc_output(kDummyString);
2148
2149 // Verify with DTLS/SCTP.
2150 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2151 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2152
2153 // Verify with UDP/DTLS/SCTP.
2154 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2155 strlen(kDtlsSctp), kUdpDtlsSctp);
2156 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2157 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2158
2159 // Verify with TCP/DTLS/SCTP.
2160 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2161 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
2162 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2163 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2164}
2165
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002166// Test to check the behaviour if sctp-port is specified
2167// on the m= line and in a=sctp-port.
2168TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
2169 AddSctpDataChannel();
2170 JsepSessionDescription jdesc(kDummyString);
2171 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2172
2173 std::string sdp_with_data = kSdpString;
2174 // Append m= attributes
2175 sdp_with_data.append(kSdpSctpDataChannelString);
2176 // Append a=sctp-port attribute
2177 sdp_with_data.append("a=sctp-port 5000\r\n");
2178 JsepSessionDescription jdesc_output(kDummyString);
2179
2180 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2181}
2182
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002183// For crbug/344475.
2184TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2185 std::string sdp_with_data = kSdpString;
2186 sdp_with_data.append(kSdpSctpDataChannelString);
2187 // Remove the "\n" at the end.
2188 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
2189 JsepSessionDescription jdesc_output(kDummyString);
2190
2191 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2192 // No crash is a pass.
2193}
2194
wu@webrtc.org78187522013-10-07 23:32:02 +00002195TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndNewPort) {
2196 AddSctpDataChannel();
Peter Boström0c4e06b2015-10-07 12:23:21 +02002197 const uint16_t kUnusualSctpPort = 9556;
wu@webrtc.org78187522013-10-07 23:32:02 +00002198 char default_portstr[16];
2199 char unusual_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002200 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
wu@webrtc.org78187522013-10-07 23:32:02 +00002201 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002202 rtc::sprintfn(unusual_portstr, sizeof(unusual_portstr), "%d",
wu@webrtc.org78187522013-10-07 23:32:02 +00002203 kUnusualSctpPort);
2204
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002205 // First setup the expected JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002206 JsepSessionDescription jdesc(kDummyString);
2207 // take our pre-built session description and change the SCTP port.
2208 cricket::SessionDescription* mutant = desc_.Copy();
2209 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
2210 mutant->GetContentDescriptionByName(kDataContentName));
2211 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002212 EXPECT_EQ(1U, codecs.size());
2213 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002214 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002215 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002216
2217 // note: mutant's owned by jdesc now.
2218 ASSERT_TRUE(jdesc.Initialize(mutant, kSessionId, kSessionVersion));
2219 mutant = NULL;
2220
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002221 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002222 std::string sdp_with_data = kSdpString;
2223 sdp_with_data.append(kSdpSctpDataChannelString);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002224 rtc::replace_substrs(default_portstr, strlen(default_portstr),
wu@webrtc.org78187522013-10-07 23:32:02 +00002225 unusual_portstr, strlen(unusual_portstr),
2226 &sdp_with_data);
2227 JsepSessionDescription jdesc_output(kDummyString);
2228
2229 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2230 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002231
2232 // We need to test the deserialized JsepSessionDescription from
2233 // kSdpSctpDataChannelStringWithSctpPort for
2234 // draft-ietf-mmusic-sctp-sdp-07
2235 // a=sctp-port
2236 sdp_with_data = kSdpString;
2237 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2238 rtc::replace_substrs(default_portstr, strlen(default_portstr),
2239 unusual_portstr, strlen(unusual_portstr),
2240 &sdp_with_data);
2241
2242 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2243 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002244}
2245
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002246TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002247 // We want to test that deserializing data content limits bandwidth
2248 // settings (it should never be greater than the default).
2249 // This should prevent someone from using unlimited data bandwidth through
2250 // JS and "breaking the Internet".
2251 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002252 std::string sdp_with_bandwidth = kSdpString;
2253 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
2254 InjectAfter("a=mid:data_content_name\r\n",
2255 "b=AS:100\r\n",
2256 &sdp_with_bandwidth);
2257 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2258
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002259 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2260}
2261
2262TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
2263 AddSctpDataChannel();
2264 JsepSessionDescription jdesc(kDummyString);
2265 DataContentDescription* dcd = static_cast<DataContentDescription*>(
2266 GetFirstDataContent(&desc_)->description);
2267 dcd->set_bandwidth(100 * 1000);
2268 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2269
2270 std::string sdp_with_bandwidth = kSdpString;
2271 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
2272 InjectAfter("a=mid:data_content_name\r\n",
2273 "b=AS:100\r\n",
2274 &sdp_with_bandwidth);
2275 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2276
2277 // SCTP has congestion control, so we shouldn't limit the bandwidth
2278 // as we do for RTP.
2279 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002280 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2281}
2282
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002283TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSessionLevelExtmap) {
2284 TestDeserializeExtmap(true, false);
2285}
2286
2287TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
2288 TestDeserializeExtmap(false, true);
2289}
2290
2291TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInvalidExtmap) {
2292 TestDeserializeExtmap(true, true);
2293}
2294
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002295TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
2296 JsepSessionDescription jdesc(kDummyString);
2297 std::string sdp = kSdpFullString;
2298 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2299 // Deserialize
2300 SdpParseError error;
2301 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
2302 const std::string lastline = "a=ssrc:6 label:video_track_id_3";
2303 EXPECT_EQ(lastline, error.line);
2304 EXPECT_EQ("Invalid SDP line.", error.description);
2305}
2306
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002307TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2308 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2309 std::string new_sdp = kSdpOneCandidate;
2310 Replace("udp", "unsupported_transport", &new_sdp);
2311 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2312 new_sdp = kSdpOneCandidate;
2313 Replace("udp", "uDP", &new_sdp);
2314 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2315 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2316 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2317 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2318}
2319
2320TEST_F(WebRtcSdpTest, DeserializeCandidateOldFormat) {
2321 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2322 EXPECT_TRUE(SdpDeserializeCandidate(kSdpOneCandidateOldFormat,&jcandidate));
2323 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2324 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2325 Candidate ref_candidate = jcandidate_->candidate();
2326 ref_candidate.set_username("user_rtp");
2327 ref_candidate.set_password("password_rtp");
2328 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2329}
2330
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002331TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
2332 JsepSessionDescription jdesc(kDummyString);
2333
2334 // Deserialize
2335 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2336
2337 // Verify
2338 cricket::AudioContentDescription* audio =
2339 static_cast<AudioContentDescription*>(
2340 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2341 EXPECT_TRUE(audio->conference_mode());
2342
2343 cricket::VideoContentDescription* video =
2344 static_cast<VideoContentDescription*>(
2345 jdesc.description()->GetContentDescriptionByName(cricket::CN_VIDEO));
2346 EXPECT_TRUE(video->conference_mode());
2347}
2348
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002349TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2350 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002351 const char kSdpEmptyType[] = " =candidate";
2352 const char kSdpEqualAsPlus[] = "a+candidate";
2353 const char kSdpSpaceAfterEqual[] = "a= candidate";
2354 const char kSdpUpperType[] = "A=candidate";
2355 const char kSdpEmptyLine[] = "";
2356 const char kSdpMissingValue[] = "a=";
2357
2358 const char kSdpBrokenFingerprint[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002359 "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 +00002360 const char kSdpExtraField[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002361 "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 +00002362 const char kSdpMissingSpace[] = "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002363 "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 +00002364 // MD5 is not allowed in fingerprints.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002365 const char kSdpMd5[] = "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002366 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002367
2368 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002369 ExpectParseFailure("v=", kSdpDestroyer);
2370 ExpectParseFailure("o=", kSdpDestroyer);
2371 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002372 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002373 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002374
2375 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002376 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2377 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002378
2379 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002380 ExpectParseFailure("a=candidate", kSdpEmptyType);
2381 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2382 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
2383 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002384
2385 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2386 // because it's orthogonal to what we are replacing and hence
2387 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002388 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
2389 ExpectParseFailure("a=sendrecv", kSdpExtraField);
2390 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
2391 ExpectParseFailure("a=sendrecv", kSdpMd5);
2392
2393 // Empty Line
2394 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
2395 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002396}
2397
2398TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2399 // ssrc
2400 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
2401 ExpectParseFailure("a=ssrc-group:FEC 5 6", "a=ssrc-group:FEC badvalue 6");
2402 // crypto
2403 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
2404 // rtpmap
2405 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
2406 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
2407 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
2408 // candidate
2409 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
2410 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
2411 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
2412 ExpectParseFailure("rport 2346", "rport badvalue");
2413 ExpectParseFailure("rport 2346 generation 2",
2414 "rport 2346 generation badvalue");
2415 // m line
2416 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
2417 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
2418
2419 // bandwidth
2420 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2421 "b=AS:badvalue\r\n",
2422 "b=AS:badvalue");
2423 // rtcp-fb
2424 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2425 "a=rtcp-fb:badvalue nack\r\n",
2426 "a=rtcp-fb:badvalue nack");
2427 // extmap
2428 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2429 "a=extmap:badvalue http://example.com\r\n",
2430 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002431}
2432
2433TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
2434 JsepSessionDescription jdesc_output(kDummyString);
2435
2436 const char kSdpWithReorderedPlTypesString[] =
2437 "v=0\r\n"
2438 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2439 "s=-\r\n"
2440 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00002441 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002442 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
2443 // in the map.
2444 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002445 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002446
2447 // Deserialize
2448 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
2449
2450 const ContentInfo* ac = GetFirstAudioContent(jdesc_output.description());
2451 ASSERT_TRUE(ac != NULL);
2452 const AudioContentDescription* acd =
2453 static_cast<const AudioContentDescription*>(ac->description);
2454 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002455 EXPECT_EQ("ISAC", acd->codecs()[0].name);
2456 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002457 EXPECT_EQ(104, acd->codecs()[0].id);
2458}
2459
2460TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
2461 JsepSessionDescription jdesc_output(kDummyString);
2462 CodecParams params;
2463 params.max_ptime = 40;
2464 params.ptime = 30;
2465 params.min_ptime = 10;
2466 params.sprop_stereo = 1;
2467 params.stereo = 1;
2468 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002469 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002470 TestDeserializeCodecParams(params, &jdesc_output);
2471 TestSerialize(jdesc_output);
2472}
2473
2474TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
2475 const bool kUseWildcard = false;
2476 JsepSessionDescription jdesc_output(kDummyString);
2477 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
2478 TestSerialize(jdesc_output);
2479}
2480
2481TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
2482 const bool kUseWildcard = true;
2483 JsepSessionDescription jdesc_output(kDummyString);
2484 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
2485 TestSerialize(jdesc_output);
2486}
2487
2488TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
2489 JsepSessionDescription jdesc_output(kDummyString);
2490
2491 const char kSdpWithFmtpString[] =
2492 "v=0\r\n"
2493 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2494 "s=-\r\n"
2495 "t=0 0\r\n"
2496 "m=video 3457 RTP/SAVPF 120\r\n"
2497 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07002498 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
2499
2500 // Deserialize
2501 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07002502 EXPECT_TRUE(
2503 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07002504
2505 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2506 ASSERT_TRUE(vc != NULL);
2507 const VideoContentDescription* vcd =
2508 static_cast<const VideoContentDescription*>(vc->description);
2509 ASSERT_FALSE(vcd->codecs().empty());
2510 cricket::VideoCodec vp8 = vcd->codecs()[0];
2511 EXPECT_EQ("VP8", vp8.name);
2512 EXPECT_EQ(120, vp8.id);
2513 cricket::CodecParameterMap::iterator found =
2514 vp8.params.find("x-google-min-bitrate");
2515 ASSERT_TRUE(found != vp8.params.end());
2516 EXPECT_EQ(found->second, "10");
2517 found = vp8.params.find("x-google-max-quantization");
2518 ASSERT_TRUE(found != vp8.params.end());
2519 EXPECT_EQ(found->second, "40");
2520}
2521
2522TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
2523 JsepSessionDescription jdesc_output(kDummyString);
2524
2525 const char kSdpWithFmtpString[] =
2526 "v=0\r\n"
2527 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2528 "s=-\r\n"
2529 "t=0 0\r\n"
2530 "m=video 3457 RTP/SAVPF 120\r\n"
2531 "a=rtpmap:120 VP8/90000\r\n"
2532 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002533
2534 // Deserialize
2535 SdpParseError error;
2536 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output,
2537 &error));
2538
2539 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2540 ASSERT_TRUE(vc != NULL);
2541 const VideoContentDescription* vcd =
2542 static_cast<const VideoContentDescription*>(vc->description);
2543 ASSERT_FALSE(vcd->codecs().empty());
2544 cricket::VideoCodec vp8 = vcd->codecs()[0];
2545 EXPECT_EQ("VP8", vp8.name);
2546 EXPECT_EQ(120, vp8.id);
2547 cricket::CodecParameterMap::iterator found =
2548 vp8.params.find("x-google-min-bitrate");
2549 ASSERT_TRUE(found != vp8.params.end());
2550 EXPECT_EQ(found->second, "10");
2551 found = vp8.params.find("x-google-max-quantization");
2552 ASSERT_TRUE(found != vp8.params.end());
2553 EXPECT_EQ(found->second, "40");
2554}
2555
2556TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
2557 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
2558 GetFirstVideoContent(&desc_)->description);
2559
2560 cricket::VideoCodecs codecs = vcd->codecs();
2561 codecs[0].params["x-google-min-bitrate"] = "10";
2562 vcd->set_codecs(codecs);
2563
2564 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2565 jdesc_.session_id(),
2566 jdesc_.session_version()));
2567 std::string message = webrtc::SdpSerialize(jdesc_);
2568 std::string sdp_with_fmtp = kSdpFullString;
2569 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
2570 "a=fmtp:120 x-google-min-bitrate=10\r\n",
2571 &sdp_with_fmtp);
2572 EXPECT_EQ(sdp_with_fmtp, message);
2573}
2574
2575TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) {
2576 JsepSessionDescription jdesc_with_icelite(kDummyString);
2577 std::string sdp_with_icelite = kSdpFullString;
2578 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
2579 cricket::SessionDescription* desc = jdesc_with_icelite.description();
2580 const cricket::TransportInfo* tinfo1 =
2581 desc->GetTransportInfoByName("audio_content_name");
2582 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
2583 const cricket::TransportInfo* tinfo2 =
2584 desc->GetTransportInfoByName("video_content_name");
2585 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
2586 InjectAfter(kSessionTime,
2587 "a=ice-lite\r\n",
2588 &sdp_with_icelite);
2589 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
2590 desc = jdesc_with_icelite.description();
2591 const cricket::TransportInfo* atinfo =
2592 desc->GetTransportInfoByName("audio_content_name");
2593 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
2594 const cricket::TransportInfo* vtinfo =
2595 desc->GetTransportInfoByName("video_content_name");
2596 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
2597}
2598
2599// Verifies that the candidates in the input SDP are parsed and serialized
2600// correctly in the output SDP.
2601TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
2602 std::string sdp_with_data = kSdpString;
2603 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
2604 JsepSessionDescription jdesc_output(kDummyString);
2605
2606 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2607 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
2608}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00002609
2610TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
2611 AddFingerprint();
2612 TransportInfo audio_transport_info =
2613 *(desc_.GetTransportInfoByName(kAudioContentName));
2614 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
2615 audio_transport_info.description.connection_role);
2616 audio_transport_info.description.connection_role =
2617 cricket::CONNECTIONROLE_ACTIVE;
2618
2619 TransportInfo video_transport_info =
2620 *(desc_.GetTransportInfoByName(kVideoContentName));
2621 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
2622 video_transport_info.description.connection_role);
2623 video_transport_info.description.connection_role =
2624 cricket::CONNECTIONROLE_ACTIVE;
2625
2626 desc_.RemoveTransportInfoByName(kAudioContentName);
2627 desc_.RemoveTransportInfoByName(kVideoContentName);
2628
2629 desc_.AddTransportInfo(audio_transport_info);
2630 desc_.AddTransportInfo(video_transport_info);
2631
2632 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2633 jdesc_.session_id(),
2634 jdesc_.session_version()));
2635 std::string message = webrtc::SdpSerialize(jdesc_);
2636 std::string sdp_with_dtlssetup = kSdpFullString;
2637
2638 // Fingerprint attribute is necessary to add DTLS setup attribute.
2639 InjectAfter(kAttributeIcePwdVoice,
2640 kFingerprint, &sdp_with_dtlssetup);
2641 InjectAfter(kAttributeIcePwdVideo,
2642 kFingerprint, &sdp_with_dtlssetup);
2643 // Now adding |setup| attribute.
2644 InjectAfter(kFingerprint,
2645 "a=setup:active\r\n", &sdp_with_dtlssetup);
2646 EXPECT_EQ(sdp_with_dtlssetup, message);
2647}
2648
2649TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
2650 JsepSessionDescription jdesc_with_dtlssetup(kDummyString);
2651 std::string sdp_with_dtlssetup = kSdpFullString;
2652 InjectAfter(kSessionTime,
2653 "a=setup:actpass\r\n",
2654 &sdp_with_dtlssetup);
2655 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
2656 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
2657 const cricket::TransportInfo* atinfo =
2658 desc->GetTransportInfoByName("audio_content_name");
2659 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
2660 atinfo->description.connection_role);
2661 const cricket::TransportInfo* vtinfo =
2662 desc->GetTransportInfoByName("video_content_name");
2663 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
2664 vtinfo->description.connection_role);
2665}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00002666
2667// Verifies that the order of the serialized m-lines follows the order of the
2668// ContentInfo in SessionDescription, and vise versa for deserialization.
2669TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
2670 JsepSessionDescription jdesc(kDummyString);
2671 const std::string media_content_sdps[3] = {
2672 kSdpAudioString,
2673 kSdpVideoString,
2674 kSdpSctpDataChannelString
2675 };
2676 const cricket::MediaType media_types[3] = {
2677 cricket::MEDIA_TYPE_AUDIO,
2678 cricket::MEDIA_TYPE_VIDEO,
2679 cricket::MEDIA_TYPE_DATA
2680 };
2681
2682 // Verifies all 6 permutations.
2683 for (size_t i = 0; i < 6; ++i) {
2684 size_t media_content_in_sdp[3];
2685 // The index of the first media content.
2686 media_content_in_sdp[0] = i / 2;
2687 // The index of the second media content.
2688 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
2689 // The index of the third media content.
2690 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
2691
2692 std::string sdp_string = kSdpSessionString;
2693 for (size_t i = 0; i < 3; ++i)
2694 sdp_string += media_content_sdps[media_content_in_sdp[i]];
2695
2696 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
2697 cricket::SessionDescription* desc = jdesc.description();
2698 EXPECT_EQ(3u, desc->contents().size());
2699
2700 for (size_t i = 0; i < 3; ++i) {
2701 const cricket::MediaContentDescription* mdesc =
2702 static_cast<const cricket::MediaContentDescription*>(
2703 desc->contents()[i].description);
2704 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
2705 }
2706
2707 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
2708 EXPECT_EQ(sdp_string, serialized_sdp);
2709 }
2710}