blob: b6577682041c8d305ecd69fb4754706370cf7698 [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;
58using cricket::NS_JINGLE_ICE_UDP;
59using cricket::NS_JINGLE_RTP;
60using cricket::RtpHeaderExtension;
61using cricket::RELAY_PORT_TYPE;
62using cricket::SessionDescription;
63using cricket::StreamParams;
64using cricket::STUN_PORT_TYPE;
65using cricket::TransportDescription;
66using cricket::TransportInfo;
67using cricket::VideoCodec;
68using cricket::VideoContentDescription;
69using webrtc::IceCandidateCollection;
70using webrtc::IceCandidateInterface;
71using webrtc::JsepIceCandidate;
72using webrtc::JsepSessionDescription;
73using webrtc::SdpParseError;
74using webrtc::SessionDescriptionInterface;
75
76typedef std::vector<AudioCodec> AudioCodecs;
77typedef std::vector<Candidate> Candidates;
78
wu@webrtc.org78187522013-10-07 23:32:02 +000079static const uint32 kDefaultSctpPort = 5000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080static const char kSessionTime[] = "t=0 0\r\n";
81static const uint32 kCandidatePriority = 2130706432U; // pref = 1.0
82static const char kCandidateUfragVoice[] = "ufrag_voice";
83static const char kCandidatePwdVoice[] = "pwd_voice";
84static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
85static const char kCandidateUfragVideo[] = "ufrag_video";
86static const char kCandidatePwdVideo[] = "pwd_video";
87static const char kCandidateUfragData[] = "ufrag_data";
88static const char kCandidatePwdData[] = "pwd_data";
89static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
90static const uint32 kCandidateGeneration = 2;
91static const char kCandidateFoundation1[] = "a0+B/1";
92static const char kCandidateFoundation2[] = "a0+B/2";
93static const char kCandidateFoundation3[] = "a0+B/3";
94static const char kCandidateFoundation4[] = "a0+B/4";
95static const char kAttributeCryptoVoice[] =
96 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
97 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
98 "dummy_session_params\r\n";
99static const char kAttributeCryptoVideo[] =
100 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
101 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
102static const char kFingerprint[] = "a=fingerprint:sha-1 "
103 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n";
104static const int kExtmapId = 1;
105static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
106static const char kExtmap[] =
107 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
108static const char kExtmapWithDirectionAndAttribute[] =
109 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
110
111static const uint8 kIdentityDigest[] = {0x4A, 0xAD, 0xB9, 0xB1,
112 0x3F, 0x82, 0x18, 0x3B,
113 0x54, 0x02, 0x12, 0xDF,
114 0x3E, 0x5D, 0x49, 0x6B,
115 0x19, 0xE5, 0x7C, 0xAB};
116
lally@webrtc.org34807282015-02-24 20:19:39 +0000117static const char kDtlsSctp[] = "DTLS/SCTP";
118static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
119static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +0000120
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121struct CodecParams {
122 int max_ptime;
123 int ptime;
124 int min_ptime;
125 int sprop_stereo;
126 int stereo;
127 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000128 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000129};
130
131// Reference sdp string
132static const char kSdpFullString[] =
133 "v=0\r\n"
134 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
135 "s=-\r\n"
136 "t=0 0\r\n"
137 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
138 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
139 "c=IN IP4 74.125.127.126\r\n"
140 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
141 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
142 "generation 2\r\n"
143 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
144 "generation 2\r\n"
145 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
146 "generation 2\r\n"
147 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
148 "generation 2\r\n"
149 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
150 "raddr 192.168.1.5 rport 2346 "
151 "generation 2\r\n"
152 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
153 "raddr 192.168.1.5 rport 2348 "
154 "generation 2\r\n"
155 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
156 "a=mid:audio_content_name\r\n"
157 "a=sendrecv\r\n"
158 "a=rtcp-mux\r\n"
159 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
160 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
161 "dummy_session_params\r\n"
162 "a=rtpmap:111 opus/48000/2\r\n"
163 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000164 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000165 "a=ssrc:1 cname:stream_1_cname\r\n"
166 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
167 "a=ssrc:1 mslabel:local_stream_1\r\n"
168 "a=ssrc:1 label:audio_track_id_1\r\n"
169 "a=ssrc:4 cname:stream_2_cname\r\n"
170 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
171 "a=ssrc:4 mslabel:local_stream_2\r\n"
172 "a=ssrc:4 label:audio_track_id_2\r\n"
173 "m=video 3457 RTP/SAVPF 120\r\n"
174 "c=IN IP4 74.125.224.39\r\n"
175 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
176 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
177 "generation 2\r\n"
178 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
179 "generation 2\r\n"
180 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
181 "generation 2\r\n"
182 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
183 "generation 2\r\n"
184 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
185 "generation 2\r\n"
186 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
187 "generation 2\r\n"
188 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
189 "a=mid:video_content_name\r\n"
190 "a=sendrecv\r\n"
191 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
192 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
193 "a=rtpmap:120 VP8/90000\r\n"
194 "a=ssrc:2 cname:stream_1_cname\r\n"
195 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
196 "a=ssrc:2 mslabel:local_stream_1\r\n"
197 "a=ssrc:2 label:video_track_id_1\r\n"
198 "a=ssrc:3 cname:stream_1_cname\r\n"
199 "a=ssrc:3 msid:local_stream_1 video_track_id_2\r\n"
200 "a=ssrc:3 mslabel:local_stream_1\r\n"
201 "a=ssrc:3 label:video_track_id_2\r\n"
202 "a=ssrc-group:FEC 5 6\r\n"
203 "a=ssrc:5 cname:stream_2_cname\r\n"
204 "a=ssrc:5 msid:local_stream_2 video_track_id_3\r\n"
205 "a=ssrc:5 mslabel:local_stream_2\r\n"
206 "a=ssrc:5 label:video_track_id_3\r\n"
207 "a=ssrc:6 cname:stream_2_cname\r\n"
208 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
209 "a=ssrc:6 mslabel:local_stream_2\r\n"
210 "a=ssrc:6 label:video_track_id_3\r\n";
211
212// SDP reference string without the candidates.
213static const char kSdpString[] =
214 "v=0\r\n"
215 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
216 "s=-\r\n"
217 "t=0 0\r\n"
218 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000219 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000220 "c=IN IP4 0.0.0.0\r\n"
221 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000222 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
223 "a=mid:audio_content_name\r\n"
224 "a=sendrecv\r\n"
225 "a=rtcp-mux\r\n"
226 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
227 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
228 "dummy_session_params\r\n"
229 "a=rtpmap:111 opus/48000/2\r\n"
230 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000231 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000232 "a=ssrc:1 cname:stream_1_cname\r\n"
233 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
234 "a=ssrc:1 mslabel:local_stream_1\r\n"
235 "a=ssrc:1 label:audio_track_id_1\r\n"
236 "a=ssrc:4 cname:stream_2_cname\r\n"
237 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
238 "a=ssrc:4 mslabel:local_stream_2\r\n"
239 "a=ssrc:4 label:audio_track_id_2\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000240 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000241 "c=IN IP4 0.0.0.0\r\n"
242 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000243 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
244 "a=mid:video_content_name\r\n"
245 "a=sendrecv\r\n"
246 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
247 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
248 "a=rtpmap:120 VP8/90000\r\n"
249 "a=ssrc:2 cname:stream_1_cname\r\n"
250 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
251 "a=ssrc:2 mslabel:local_stream_1\r\n"
252 "a=ssrc:2 label:video_track_id_1\r\n"
253 "a=ssrc:3 cname:stream_1_cname\r\n"
254 "a=ssrc:3 msid:local_stream_1 video_track_id_2\r\n"
255 "a=ssrc:3 mslabel:local_stream_1\r\n"
256 "a=ssrc:3 label:video_track_id_2\r\n"
257 "a=ssrc-group:FEC 5 6\r\n"
258 "a=ssrc:5 cname:stream_2_cname\r\n"
259 "a=ssrc:5 msid:local_stream_2 video_track_id_3\r\n"
260 "a=ssrc:5 mslabel:local_stream_2\r\n"
261 "a=ssrc:5 label:video_track_id_3\r\n"
262 "a=ssrc:6 cname:stream_2_cname\r\n"
263 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
264 "a=ssrc:6 mslabel:local_stream_2\r\n"
265 "a=ssrc:6 label:video_track_id_3\r\n";
266
267static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000268 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000269 "c=IN IP4 0.0.0.0\r\n"
270 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000271 "a=ice-ufrag:ufrag_data\r\n"
272 "a=ice-pwd:pwd_data\r\n"
273 "a=mid:data_content_name\r\n"
274 "a=sendrecv\r\n"
275 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
276 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
277 "a=rtpmap:101 google-data/90000\r\n"
278 "a=ssrc:10 cname:data_channel_cname\r\n"
279 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
280 "a=ssrc:10 mslabel:data_channel\r\n"
281 "a=ssrc:10 label:data_channeld0\r\n";
282
283static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000284 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000285 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000286 "a=ice-ufrag:ufrag_data\r\n"
287 "a=ice-pwd:pwd_data\r\n"
288 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000289 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000290
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000291// draft-ietf-mmusic-sctp-sdp-12
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000292static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000293 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
294 "a=max-message-size=100000\r\n"
295 "a=sctp-port 5000\r\n"
296 "c=IN IP4 0.0.0.0\r\n"
297 "a=ice-ufrag:ufrag_data\r\n"
298 "a=ice-pwd:pwd_data\r\n"
299 "a=mid:data_content_name\r\n";
300
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000301static const char kSdpSctpDataChannelWithCandidatesString[] =
302 "m=application 2345 DTLS/SCTP 5000\r\n"
303 "c=IN IP4 74.125.127.126\r\n"
304 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
305 "generation 2\r\n"
306 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
307 "generation 2\r\n"
308 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
309 "raddr 192.168.1.5 rport 2346 "
310 "generation 2\r\n"
311 "a=ice-ufrag:ufrag_data\r\n"
312 "a=ice-pwd:pwd_data\r\n"
313 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000314 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000315
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000316static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000317 "v=0\r\n"
318 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
319 "s=-\r\n"
320 "t=0 0\r\n"
321 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000322 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000323 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000324 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000325 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000326 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000327 "a=x-google-flag:conference\r\n";
328
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000329static const char kSdpSessionString[] =
330 "v=0\r\n"
331 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
332 "s=-\r\n"
333 "t=0 0\r\n"
334 "a=msid-semantic: WMS local_stream\r\n";
335
336static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000337 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000338 "c=IN IP4 0.0.0.0\r\n"
339 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000340 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
341 "a=mid:audio_content_name\r\n"
342 "a=sendrecv\r\n"
343 "a=rtpmap:111 opus/48000/2\r\n"
344 "a=ssrc:1 cname:stream_1_cname\r\n"
345 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
346 "a=ssrc:1 mslabel:local_stream\r\n"
347 "a=ssrc:1 label:audio_track_id_1\r\n";
348
349static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000350 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000351 "c=IN IP4 0.0.0.0\r\n"
352 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000353 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
354 "a=mid:video_content_name\r\n"
355 "a=sendrecv\r\n"
356 "a=rtpmap:120 VP8/90000\r\n"
357 "a=ssrc:2 cname:stream_1_cname\r\n"
358 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
359 "a=ssrc:2 mslabel:local_stream\r\n"
360 "a=ssrc:2 label:video_track_id_1\r\n";
361
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000362
363// One candidate reference string as per W3c spec.
364// candidate:<blah> not a=candidate:<blah>CRLF
365static const char kRawCandidate[] =
366 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
367// One candidate reference string.
368static const char kSdpOneCandidate[] =
369 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
370 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000371
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000372static const char kSdpTcpActiveCandidate[] =
373 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
374 "tcptype active generation 2";
375static const char kSdpTcpPassiveCandidate[] =
376 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
377 "tcptype passive generation 2";
378static const char kSdpTcpSOCandidate[] =
379 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
380 "tcptype so generation 2";
381static const char kSdpTcpInvalidCandidate[] =
382 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
383 "tcptype invalid generation 2";
384
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000385// One candidate reference string with IPV6 address.
386static const char kRawIPV6Candidate[] =
387 "candidate:a0+B/1 1 udp 2130706432 "
388 "abcd::abcd::abcd::abcd::abcd::abcd::abcd::abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000389
390// One candidate reference string.
391static const char kSdpOneCandidateOldFormat[] =
392 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
393 " eth0 username user_rtp password password_rtp generation 2\r\n";
394
395// Session id and version
396static const char kSessionId[] = "18446744069414584320";
397static const char kSessionVersion[] = "18446462598732840960";
398
399// Ice options
400static const char kIceOption1[] = "iceoption1";
401static const char kIceOption2[] = "iceoption2";
402static const char kIceOption3[] = "iceoption3";
403
404// Content name
405static const char kAudioContentName[] = "audio_content_name";
406static const char kVideoContentName[] = "video_content_name";
407static const char kDataContentName[] = "data_content_name";
408
409// MediaStream 1
410static const char kStreamLabel1[] = "local_stream_1";
411static const char kStream1Cname[] = "stream_1_cname";
412static const char kAudioTrackId1[] = "audio_track_id_1";
413static const uint32 kAudioTrack1Ssrc = 1;
414static const char kVideoTrackId1[] = "video_track_id_1";
415static const uint32 kVideoTrack1Ssrc = 2;
416static const char kVideoTrackId2[] = "video_track_id_2";
417static const uint32 kVideoTrack2Ssrc = 3;
418
419// MediaStream 2
420static const char kStreamLabel2[] = "local_stream_2";
421static const char kStream2Cname[] = "stream_2_cname";
422static const char kAudioTrackId2[] = "audio_track_id_2";
423static const uint32 kAudioTrack2Ssrc = 4;
424static const char kVideoTrackId3[] = "video_track_id_3";
425static const uint32 kVideoTrack3Ssrc = 5;
426static const uint32 kVideoTrack4Ssrc = 6;
427
428// DataChannel
429static const char kDataChannelLabel[] = "data_channel";
430static const char kDataChannelMsid[] = "data_channeld0";
431static const char kDataChannelCname[] = "data_channel_cname";
432static const uint32 kDataChannelSsrc = 10;
433
434// Candidate
435static const char kDummyMid[] = "dummy_mid";
436static const int kDummyIndex = 123;
437
438// Misc
439static const char kDummyString[] = "dummy";
440
441// Helper functions
442
443static bool SdpDeserialize(const std::string& message,
444 JsepSessionDescription* jdesc) {
445 return webrtc::SdpDeserialize(message, jdesc, NULL);
446}
447
448static bool SdpDeserializeCandidate(const std::string& message,
449 JsepIceCandidate* candidate) {
450 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
451}
452
453// Add some extra |newlines| to the |message| after |line|.
454static void InjectAfter(const std::string& line,
455 const std::string& newlines,
456 std::string* message) {
457 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000458 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000459 tmp.c_str(), tmp.length(), message);
460}
461
462static void Replace(const std::string& line,
463 const std::string& newlines,
464 std::string* message) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000465 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000466 newlines.c_str(), newlines.length(), message);
467}
468
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000469// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
470// message.
471static void ExpectParseFailure(const std::string& bad_sdp,
472 const std::string& bad_part) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000473 JsepSessionDescription desc(kDummyString);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000474 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000475 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000476 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000477 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
478}
479
480// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
481static void ExpectParseFailure(const char* good_part, const char* bad_part) {
482 std::string bad_sdp = kSdpFullString;
483 Replace(good_part, bad_part, &bad_sdp);
484 ExpectParseFailure(bad_sdp, bad_part);
485}
486
487// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
488static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
489 const std::string& newlines,
490 const std::string& bad_part) {
491 std::string bad_sdp = kSdpFullString;
492 InjectAfter(injectpoint, newlines, &bad_sdp);
493 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000494}
495
496static void ReplaceDirection(cricket::MediaContentDirection direction,
497 std::string* message) {
498 std::string new_direction;
499 switch (direction) {
500 case cricket::MD_INACTIVE:
501 new_direction = "a=inactive";
502 break;
503 case cricket::MD_SENDONLY:
504 new_direction = "a=sendonly";
505 break;
506 case cricket::MD_RECVONLY:
507 new_direction = "a=recvonly";
508 break;
509 case cricket::MD_SENDRECV:
510 default:
511 new_direction = "a=sendrecv";
512 break;
513 }
514 Replace("a=sendrecv", new_direction, message);
515}
516
517static void ReplaceRejected(bool audio_rejected, bool video_rejected,
518 std::string* message) {
519 if (audio_rejected) {
520 Replace("m=audio 2345", "m=audio 0", message);
521 }
522 if (video_rejected) {
523 Replace("m=video 3457", "m=video 0", message);
524 }
525}
526
527// WebRtcSdpTest
528
529class WebRtcSdpTest : public testing::Test {
530 public:
531 WebRtcSdpTest()
532 : jdesc_(kDummyString) {
533 // AudioContentDescription
534 audio_desc_ = CreateAudioContentDescription();
535 AudioCodec opus(111, "opus", 48000, 0, 2, 3);
536 audio_desc_->AddCodec(opus);
537 audio_desc_->AddCodec(AudioCodec(103, "ISAC", 16000, 32000, 1, 2));
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000538 audio_desc_->AddCodec(AudioCodec(104, "ISAC", 32000, 56000, 1, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000539 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
540
541 // VideoContentDescription
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000542 rtc::scoped_ptr<VideoContentDescription> video(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000543 new VideoContentDescription());
544 video_desc_ = video.get();
545 StreamParams video_stream1;
546 video_stream1.id = kVideoTrackId1;
547 video_stream1.cname = kStream1Cname;
548 video_stream1.sync_label = kStreamLabel1;
549 video_stream1.ssrcs.push_back(kVideoTrack1Ssrc);
550 video->AddStream(video_stream1);
551 StreamParams video_stream2;
552 video_stream2.id = kVideoTrackId2;
553 video_stream2.cname = kStream1Cname;
554 video_stream2.sync_label = kStreamLabel1;
555 video_stream2.ssrcs.push_back(kVideoTrack2Ssrc);
556 video->AddStream(video_stream2);
557 StreamParams video_stream3;
558 video_stream3.id = kVideoTrackId3;
559 video_stream3.cname = kStream2Cname;
560 video_stream3.sync_label = kStreamLabel2;
561 video_stream3.ssrcs.push_back(kVideoTrack3Ssrc);
562 video_stream3.ssrcs.push_back(kVideoTrack4Ssrc);
563 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream3.ssrcs);
564 video_stream3.ssrc_groups.push_back(ssrc_group);
565 video->AddStream(video_stream3);
566 video->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
567 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
568 video->set_protocol(cricket::kMediaProtocolSavpf);
569 video->AddCodec(VideoCodec(
570 120,
571 JsepSessionDescription::kDefaultVideoCodecName,
572 JsepSessionDescription::kMaxVideoCodecWidth,
573 JsepSessionDescription::kMaxVideoCodecHeight,
574 JsepSessionDescription::kDefaultVideoCodecFramerate,
575 JsepSessionDescription::kDefaultVideoCodecPreference));
576
577 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP,
578 video.release());
579
580 // TransportInfo
581 EXPECT_TRUE(desc_.AddTransportInfo(
582 TransportInfo(kAudioContentName,
583 TransportDescription(NS_JINGLE_ICE_UDP,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000584 kCandidateUfragVoice,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000585 kCandidatePwdVoice))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000586 EXPECT_TRUE(desc_.AddTransportInfo(
587 TransportInfo(kVideoContentName,
588 TransportDescription(NS_JINGLE_ICE_UDP,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000589 kCandidateUfragVideo,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000590 kCandidatePwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000591
592 // v4 host
593 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000594 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000595 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000596 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
597 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000598 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000599 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "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 candidate3(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 candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000608 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
609 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000610
611 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000612 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000613 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
614 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000615 cricket::LOCAL_PORT_TYPE,
616 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000617 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000618 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
619 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000620 cricket::LOCAL_PORT_TYPE,
621 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000622 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000623 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
624 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000625 cricket::LOCAL_PORT_TYPE,
626 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000627 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000628 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
629 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000630 cricket::LOCAL_PORT_TYPE,
631 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000632
633 // stun
634 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000635 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
636 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000637 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
638 address_stun, kCandidatePriority, "", "",
639 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000640 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000641 candidate9.set_related_address(rel_address_stun);
642
643 address_stun.SetPort(port_stun++);
644 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000645 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
646 address_stun, kCandidatePriority, "", "",
647 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000648 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000649 candidate10.set_related_address(rel_address_stun);
650
651 // relay
652 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000653 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000654 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
655 address_relay, kCandidatePriority, "", "",
656 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000657 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000658 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000659 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
660 address_relay, kCandidatePriority, "", "",
661 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000662 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000663
664 // voice
665 candidates_.push_back(candidate1);
666 candidates_.push_back(candidate2);
667 candidates_.push_back(candidate5);
668 candidates_.push_back(candidate6);
669 candidates_.push_back(candidate9);
670 candidates_.push_back(candidate10);
671
672 // video
673 candidates_.push_back(candidate3);
674 candidates_.push_back(candidate4);
675 candidates_.push_back(candidate7);
676 candidates_.push_back(candidate8);
677 candidates_.push_back(candidate11);
678 candidates_.push_back(candidate12);
679
680 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"),
681 0, candidate1));
682
683 // Set up JsepSessionDescription.
684 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
685 std::string mline_id;
686 int mline_index = 0;
687 for (size_t i = 0; i< candidates_.size(); ++i) {
688 // In this test, the audio m line index will be 0, and the video m line
689 // will be 1.
690 bool is_video = (i > 5);
691 mline_id = is_video ? "video_content_name" : "audio_content_name";
692 mline_index = is_video ? 1 : 0;
693 JsepIceCandidate jice(mline_id,
694 mline_index,
695 candidates_.at(i));
696 jdesc_.AddCandidate(&jice);
697 }
698 }
699
700 AudioContentDescription* CreateAudioContentDescription() {
701 AudioContentDescription* audio = new AudioContentDescription();
702 audio->set_rtcp_mux(true);
703 StreamParams audio_stream1;
704 audio_stream1.id = kAudioTrackId1;
705 audio_stream1.cname = kStream1Cname;
706 audio_stream1.sync_label = kStreamLabel1;
707 audio_stream1.ssrcs.push_back(kAudioTrack1Ssrc);
708 audio->AddStream(audio_stream1);
709 StreamParams audio_stream2;
710 audio_stream2.id = kAudioTrackId2;
711 audio_stream2.cname = kStream2Cname;
712 audio_stream2.sync_label = kStreamLabel2;
713 audio_stream2.ssrcs.push_back(kAudioTrack2Ssrc);
714 audio->AddStream(audio_stream2);
715 audio->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_32",
716 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
717 "dummy_session_params"));
718 audio->set_protocol(cricket::kMediaProtocolSavpf);
719 return audio;
720 }
721
722 template <class MCD>
723 void CompareMediaContentDescription(const MCD* cd1,
724 const MCD* cd2) {
725 // type
726 EXPECT_EQ(cd1->type(), cd1->type());
727
728 // content direction
729 EXPECT_EQ(cd1->direction(), cd2->direction());
730
731 // rtcp_mux
732 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
733
734 // cryptos
735 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
736 if (cd1->cryptos().size() != cd2->cryptos().size()) {
737 ADD_FAILURE();
738 return;
739 }
740 for (size_t i = 0; i< cd1->cryptos().size(); ++i) {
741 const CryptoParams c1 = cd1->cryptos().at(i);
742 const CryptoParams c2 = cd2->cryptos().at(i);
743 EXPECT_TRUE(c1.Matches(c2));
744 EXPECT_EQ(c1.key_params, c2.key_params);
745 EXPECT_EQ(c1.session_params, c2.session_params);
746 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +0000747
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000748 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +0000749 // Use an equivalence class here, for old and new versions of the
750 // protocol description.
751 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:35 +0000752 || cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp
753 || cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
754 const bool cd2_is_also_dtls_sctp =
lally@webrtc.orgd7b61652015-02-24 20:18:55 +0000755 cd2->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:35 +0000756 || cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp
757 || cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
758 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +0000759 } else {
760 EXPECT_EQ(cd1->protocol(), cd2->protocol());
761 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000762
763 // codecs
764 EXPECT_EQ(cd1->codecs(), cd2->codecs());
765
766 // bandwidth
767 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
768
769 // streams
770 EXPECT_EQ(cd1->streams(), cd2->streams());
771
772 // extmap
773 ASSERT_EQ(cd1->rtp_header_extensions().size(),
774 cd2->rtp_header_extensions().size());
775 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) {
776 const RtpHeaderExtension ext1 = cd1->rtp_header_extensions().at(i);
777 const RtpHeaderExtension ext2 = cd2->rtp_header_extensions().at(i);
778 EXPECT_EQ(ext1.uri, ext2.uri);
779 EXPECT_EQ(ext1.id, ext2.id);
780 }
781
782 // buffered mode latency
783 EXPECT_EQ(cd1->buffered_mode_latency(), cd2->buffered_mode_latency());
784 }
785
786
787 void CompareSessionDescription(const SessionDescription& desc1,
788 const SessionDescription& desc2) {
789 // Compare content descriptions.
790 if (desc1.contents().size() != desc2.contents().size()) {
791 ADD_FAILURE();
792 return;
793 }
794 for (size_t i = 0 ; i < desc1.contents().size(); ++i) {
795 const cricket::ContentInfo& c1 = desc1.contents().at(i);
796 const cricket::ContentInfo& c2 = desc2.contents().at(i);
797 // content name
798 EXPECT_EQ(c1.name, c2.name);
799 // content type
800 // Note, ASSERT will return from the function, but will not stop the test.
801 ASSERT_EQ(c1.type, c2.type);
802
803 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
804 if (IsAudioContent(&c1)) {
805 const AudioContentDescription* acd1 =
806 static_cast<const AudioContentDescription*>(c1.description);
807 const AudioContentDescription* acd2 =
808 static_cast<const AudioContentDescription*>(c2.description);
809 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
810 }
811
812 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
813 if (IsVideoContent(&c1)) {
814 const VideoContentDescription* vcd1 =
815 static_cast<const VideoContentDescription*>(c1.description);
816 const VideoContentDescription* vcd2 =
817 static_cast<const VideoContentDescription*>(c2.description);
818 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
819 }
820
821 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
822 if (IsDataContent(&c1)) {
823 const DataContentDescription* dcd1 =
824 static_cast<const DataContentDescription*>(c1.description);
825 const DataContentDescription* dcd2 =
826 static_cast<const DataContentDescription*>(c2.description);
827 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
828 }
829 }
830
831 // group
832 const cricket::ContentGroups groups1 = desc1.groups();
833 const cricket::ContentGroups groups2 = desc2.groups();
834 EXPECT_EQ(groups1.size(), groups1.size());
835 if (groups1.size() != groups2.size()) {
836 ADD_FAILURE();
837 return;
838 }
839 for (size_t i = 0; i < groups1.size(); ++i) {
840 const cricket::ContentGroup group1 = groups1.at(i);
841 const cricket::ContentGroup group2 = groups2.at(i);
842 EXPECT_EQ(group1.semantics(), group2.semantics());
843 const cricket::ContentNames names1 = group1.content_names();
844 const cricket::ContentNames names2 = group2.content_names();
845 EXPECT_EQ(names1.size(), names2.size());
846 if (names1.size() != names2.size()) {
847 ADD_FAILURE();
848 return;
849 }
850 cricket::ContentNames::const_iterator iter1 = names1.begin();
851 cricket::ContentNames::const_iterator iter2 = names2.begin();
852 while (iter1 != names1.end()) {
853 EXPECT_EQ(*iter1++, *iter2++);
854 }
855 }
856
857 // transport info
858 const cricket::TransportInfos transports1 = desc1.transport_infos();
859 const cricket::TransportInfos transports2 = desc2.transport_infos();
860 EXPECT_EQ(transports1.size(), transports2.size());
861 if (transports1.size() != transports2.size()) {
862 ADD_FAILURE();
863 return;
864 }
865 for (size_t i = 0; i < transports1.size(); ++i) {
866 const cricket::TransportInfo transport1 = transports1.at(i);
867 const cricket::TransportInfo transport2 = transports2.at(i);
868 EXPECT_EQ(transport1.content_name, transport2.content_name);
869 EXPECT_EQ(transport1.description.transport_type,
870 transport2.description.transport_type);
871 EXPECT_EQ(transport1.description.ice_ufrag,
872 transport2.description.ice_ufrag);
873 EXPECT_EQ(transport1.description.ice_pwd,
874 transport2.description.ice_pwd);
875 if (transport1.description.identity_fingerprint) {
876 EXPECT_EQ(*transport1.description.identity_fingerprint,
877 *transport2.description.identity_fingerprint);
878 } else {
879 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
880 transport2.description.identity_fingerprint.get());
881 }
882 EXPECT_EQ(transport1.description.transport_options,
883 transport2.description.transport_options);
884 EXPECT_TRUE(CompareCandidates(transport1.description.candidates,
885 transport2.description.candidates));
886 }
887 }
888
889 bool CompareCandidates(const Candidates& cs1, const Candidates& cs2) {
890 EXPECT_EQ(cs1.size(), cs2.size());
891 if (cs1.size() != cs2.size())
892 return false;
893 for (size_t i = 0; i< cs1.size(); ++i) {
894 const Candidate c1 = cs1.at(i);
895 const Candidate c2 = cs2.at(i);
896 EXPECT_TRUE(c1.IsEquivalent(c2));
897 }
898 return true;
899 }
900
901 bool CompareSessionDescription(
902 const JsepSessionDescription& desc1,
903 const JsepSessionDescription& desc2) {
904 EXPECT_EQ(desc1.session_id(), desc2.session_id());
905 EXPECT_EQ(desc1.session_version(), desc2.session_version());
906 CompareSessionDescription(*desc1.description(), *desc2.description());
907 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
908 return false;
909 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
910 const IceCandidateCollection* cc1 = desc1.candidates(i);
911 const IceCandidateCollection* cc2 = desc2.candidates(i);
912 if (cc1->count() != cc2->count())
913 return false;
914 for (size_t j = 0; j < cc1->count(); ++j) {
915 const IceCandidateInterface* c1 = cc1->at(j);
916 const IceCandidateInterface* c2 = cc2->at(j);
917 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
918 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
919 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
920 }
921 }
922 return true;
923 }
924
925 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
926 // them with invalid keywords so that the parser will just ignore them.
927 bool RemoveCandidateUfragPwd(std::string* sdp) {
928 const char ice_ufrag[] = "a=ice-ufrag";
929 const char ice_ufragx[] = "a=xice-ufrag";
930 const char ice_pwd[] = "a=ice-pwd";
931 const char ice_pwdx[] = "a=xice-pwd";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000932 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933 ice_ufragx, strlen(ice_ufragx), sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000934 rtc::replace_substrs(ice_pwd, strlen(ice_pwd),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000935 ice_pwdx, strlen(ice_pwdx), sdp);
936 return true;
937 }
938
939 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
940 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, int mline_index,
941 const std::string& ufrag, const std::string& pwd) {
942 std::string content_name;
943 if (mline_index == 0) {
944 content_name = kAudioContentName;
945 } else if (mline_index == 1) {
946 content_name = kVideoContentName;
947 } else {
948 ASSERT(false);
949 }
950 TransportInfo transport_info(
951 content_name, TransportDescription(NS_JINGLE_ICE_UDP,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000952 ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000953 SessionDescription* desc =
954 const_cast<SessionDescription*>(jdesc->description());
955 desc->RemoveTransportInfoByName(content_name);
956 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
957 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
958 const IceCandidateCollection* cc = jdesc_.candidates(i);
959 for (size_t j = 0; j < cc->count(); ++j) {
960 if (cc->at(j)->sdp_mline_index() == mline_index) {
961 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(
962 ufrag);
963 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(
964 pwd);
965 }
966 }
967 }
968 return true;
969 }
970
971 void AddIceOptions(const std::string& content_name,
972 const std::vector<std::string>& transport_options) {
973 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
974 cricket::TransportInfo transport_info =
975 *(desc_.GetTransportInfoByName(content_name));
976 desc_.RemoveTransportInfoByName(content_name);
977 transport_info.description.transport_options = transport_options;
978 desc_.AddTransportInfo(transport_info);
979 }
980
981 void AddFingerprint() {
982 desc_.RemoveTransportInfoByName(kAudioContentName);
983 desc_.RemoveTransportInfoByName(kVideoContentName);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000984 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000985 kIdentityDigest,
986 sizeof(kIdentityDigest));
987 EXPECT_TRUE(desc_.AddTransportInfo(
988 TransportInfo(kAudioContentName,
989 TransportDescription(NS_JINGLE_ICE_UDP,
990 std::vector<std::string>(),
991 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,
998 TransportDescription(NS_JINGLE_ICE_UDP,
999 std::vector<std::string>(),
1000 kCandidateUfragVideo,
1001 kCandidatePwdVideo,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001002 cricket::ICEMODE_FULL,
1003 cricket::CONNECTIONROLE_NONE,
1004 &fingerprint, Candidates()))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001005 }
1006
1007 void AddExtmap() {
1008 audio_desc_ = static_cast<AudioContentDescription*>(
1009 audio_desc_->Copy());
1010 video_desc_ = static_cast<VideoContentDescription*>(
1011 video_desc_->Copy());
1012 audio_desc_->AddRtpHeaderExtension(
1013 RtpHeaderExtension(kExtmapUri, kExtmapId));
1014 video_desc_->AddRtpHeaderExtension(
1015 RtpHeaderExtension(kExtmapUri, kExtmapId));
1016 desc_.RemoveContentByName(kAudioContentName);
1017 desc_.RemoveContentByName(kVideoContentName);
1018 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1019 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1020 }
1021
1022 void RemoveCryptos() {
1023 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1024 video_desc_->set_cryptos(std::vector<CryptoParams>());
1025 }
1026
1027 bool TestSerializeDirection(cricket::MediaContentDirection direction) {
1028 audio_desc_->set_direction(direction);
1029 video_desc_->set_direction(direction);
1030 std::string new_sdp = kSdpFullString;
1031 ReplaceDirection(direction, &new_sdp);
1032
1033 if (!jdesc_.Initialize(desc_.Copy(),
1034 jdesc_.session_id(),
1035 jdesc_.session_version())) {
1036 return false;
1037 }
1038 std::string message = webrtc::SdpSerialize(jdesc_);
1039 EXPECT_EQ(new_sdp, message);
1040 return true;
1041 }
1042
1043 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
1044 audio_desc_ = static_cast<AudioContentDescription*>(
1045 audio_desc_->Copy());
1046 video_desc_ = static_cast<VideoContentDescription*>(
1047 video_desc_->Copy());
1048 desc_.RemoveContentByName(kAudioContentName);
1049 desc_.RemoveContentByName(kVideoContentName);
1050 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1051 audio_desc_);
1052 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1053 video_desc_);
1054 std::string new_sdp = kSdpFullString;
1055 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1056
1057 if (!jdesc_.Initialize(desc_.Copy(),
1058 jdesc_.session_id(),
1059 jdesc_.session_version())) {
1060 return false;
1061 }
1062 std::string message = webrtc::SdpSerialize(jdesc_);
1063 EXPECT_EQ(new_sdp, message);
1064 return true;
1065 }
1066
1067 void AddSctpDataChannel() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001068 rtc::scoped_ptr<DataContentDescription> data(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001069 new DataContentDescription());
1070 data_desc_ = data.get();
1071 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
wu@webrtc.org78187522013-10-07 23:32:02 +00001072 DataCodec codec(cricket::kGoogleSctpDataCodecId,
1073 cricket::kGoogleSctpDataCodecName, 0);
1074 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1075 data_desc_->AddCodec(codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001076 desc_.AddContent(kDataContentName, NS_JINGLE_DRAFT_SCTP, data.release());
1077 EXPECT_TRUE(desc_.AddTransportInfo(
1078 TransportInfo(kDataContentName,
1079 TransportDescription(NS_JINGLE_ICE_UDP,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001080 kCandidateUfragData,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001081 kCandidatePwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001082 }
1083
1084 void AddRtpDataChannel() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001085 rtc::scoped_ptr<DataContentDescription> data(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001086 new DataContentDescription());
1087 data_desc_ = data.get();
1088
1089 data_desc_->AddCodec(DataCodec(101, "google-data", 1));
1090 StreamParams data_stream;
1091 data_stream.id = kDataChannelMsid;
1092 data_stream.cname = kDataChannelCname;
1093 data_stream.sync_label = kDataChannelLabel;
1094 data_stream.ssrcs.push_back(kDataChannelSsrc);
1095 data_desc_->AddStream(data_stream);
1096 data_desc_->AddCrypto(CryptoParams(
1097 1, "AES_CM_128_HMAC_SHA1_80",
1098 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
1099 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
1100 desc_.AddContent(kDataContentName, NS_JINGLE_RTP, data.release());
1101 EXPECT_TRUE(desc_.AddTransportInfo(
1102 TransportInfo(kDataContentName,
1103 TransportDescription(NS_JINGLE_ICE_UDP,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001104 kCandidateUfragData,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001105 kCandidatePwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001106 }
1107
1108 bool TestDeserializeDirection(cricket::MediaContentDirection direction) {
1109 std::string new_sdp = kSdpFullString;
1110 ReplaceDirection(direction, &new_sdp);
1111 JsepSessionDescription new_jdesc(kDummyString);
1112
1113 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1114
1115 audio_desc_->set_direction(direction);
1116 video_desc_->set_direction(direction);
1117 if (!jdesc_.Initialize(desc_.Copy(),
1118 jdesc_.session_id(),
1119 jdesc_.session_version())) {
1120 return false;
1121 }
1122 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1123 return true;
1124 }
1125
1126 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
1127 std::string new_sdp = kSdpFullString;
1128 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1129 JsepSessionDescription new_jdesc(JsepSessionDescription::kOffer);
1130
1131 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1132 audio_desc_ = static_cast<AudioContentDescription*>(
1133 audio_desc_->Copy());
1134 video_desc_ = static_cast<VideoContentDescription*>(
1135 video_desc_->Copy());
1136 desc_.RemoveContentByName(kAudioContentName);
1137 desc_.RemoveContentByName(kVideoContentName);
1138 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1139 audio_desc_);
1140 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1141 video_desc_);
1142 if (!jdesc_.Initialize(desc_.Copy(),
1143 jdesc_.session_id(),
1144 jdesc_.session_version())) {
1145 return false;
1146 }
1147 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1148 return true;
1149 }
1150
1151 void TestDeserializeExtmap(bool session_level, bool media_level) {
1152 AddExtmap();
1153 JsepSessionDescription new_jdesc("dummy");
1154 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1155 jdesc_.session_id(),
1156 jdesc_.session_version()));
1157 JsepSessionDescription jdesc_with_extmap("dummy");
1158 std::string sdp_with_extmap = kSdpString;
1159 if (session_level) {
1160 InjectAfter(kSessionTime, kExtmapWithDirectionAndAttribute,
1161 &sdp_with_extmap);
1162 }
1163 if (media_level) {
1164 InjectAfter(kAttributeIcePwdVoice, kExtmapWithDirectionAndAttribute,
1165 &sdp_with_extmap);
1166 InjectAfter(kAttributeIcePwdVideo, kExtmapWithDirectionAndAttribute,
1167 &sdp_with_extmap);
1168 }
1169 // The extmap can't be present at the same time in both session level and
1170 // media level.
1171 if (session_level && media_level) {
1172 SdpParseError error;
1173 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap,
1174 &jdesc_with_extmap, &error));
1175 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1176 } else {
1177 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1178 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1179 }
1180 }
1181
1182 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
1183 const std::string& name, int expected_value) {
1184 cricket::CodecParameterMap::const_iterator found = params.find(name);
1185 ASSERT_TRUE(found != params.end());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001186 EXPECT_EQ(found->second, rtc::ToString<int>(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001187 }
1188
1189 void TestDeserializeCodecParams(const CodecParams& params,
1190 JsepSessionDescription* jdesc_output) {
1191 std::string sdp =
1192 "v=0\r\n"
1193 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1194 "s=-\r\n"
1195 "t=0 0\r\n"
1196 // Include semantics for WebRTC Media Streams since it is supported by
1197 // this parser, and will be added to the SDP when serializing a session
1198 // description.
1199 "a=msid-semantic: WMS\r\n"
1200 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001201 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001202 // Pltype 111 listed before 103 and 104 in the map.
1203 "a=rtpmap:111 opus/48000/2\r\n"
1204 // Pltype 103 listed before 104.
1205 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001206 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001207 "a=fmtp:111 0-15,66,70\r\n"
1208 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001209 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001210 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001211 << "; sprop-stereo=" << params.sprop_stereo
1212 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001213 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001214 << "a=ptime:" << params.ptime << "\r\n"
1215 << "a=maxptime:" << params.max_ptime << "\r\n";
1216 sdp += os.str();
1217
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001218 os.clear();
1219 os.str("");
1220 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001221 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001222 << "a=rtpmap:99 VP8/90000\r\n"
1223 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001224 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001225 sdp += os.str();
1226
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001227 // Deserialize
1228 SdpParseError error;
1229 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1230
1231 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1232 ASSERT_TRUE(ac != NULL);
1233 const AudioContentDescription* acd =
1234 static_cast<const AudioContentDescription*>(ac->description);
1235 ASSERT_FALSE(acd->codecs().empty());
1236 cricket::AudioCodec opus = acd->codecs()[0];
1237 EXPECT_EQ("opus", opus.name);
1238 EXPECT_EQ(111, opus.id);
1239 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1240 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1241 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1242 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001243 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1244 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001245 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1246 cricket::AudioCodec codec = acd->codecs()[i];
1247 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1248 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
1249 if (codec.name == "ISAC") {
1250 if (codec.clockrate == 16000) {
1251 EXPECT_EQ(32000, codec.bitrate);
1252 } else {
1253 EXPECT_EQ(56000, codec.bitrate);
1254 }
1255 }
1256 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001257
1258 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1259 ASSERT_TRUE(vc != NULL);
1260 const VideoContentDescription* vcd =
1261 static_cast<const VideoContentDescription*>(vc->description);
1262 ASSERT_FALSE(vcd->codecs().empty());
1263 cricket::VideoCodec vp8 = vcd->codecs()[0];
1264 EXPECT_EQ("VP8", vp8.name);
1265 EXPECT_EQ(99, vp8.id);
1266 cricket::VideoCodec rtx = vcd->codecs()[1];
1267 EXPECT_EQ("RTX", rtx.name);
1268 EXPECT_EQ(95, rtx.id);
1269 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001270 }
1271
1272 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1273 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001274 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001275 "v=0\r\n"
1276 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1277 "s=-\r\n"
1278 "t=0 0\r\n"
1279 // Include semantics for WebRTC Media Streams since it is supported by
1280 // this parser, and will be added to the SDP when serializing a session
1281 // description.
1282 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001283 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001284 "a=rtpmap:111 opus/48000/2\r\n";
1285 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001286 "m=video 3457 RTP/SAVPF 101\r\n"
1287 "a=rtpmap:101 VP8/90000\r\n"
1288 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001289 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001290 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001291 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001292 os << sdp_session_and_audio;
1293 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
1294 os << sdp_video;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001295 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001296 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001297 // Deserialize
1298 SdpParseError error;
1299 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1300 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1301 ASSERT_TRUE(ac != NULL);
1302 const AudioContentDescription* acd =
1303 static_cast<const AudioContentDescription*>(ac->description);
1304 ASSERT_FALSE(acd->codecs().empty());
1305 cricket::AudioCodec opus = acd->codecs()[0];
1306 EXPECT_EQ(111, opus.id);
1307 EXPECT_TRUE(opus.HasFeedbackParam(
1308 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1309 cricket::kParamValueEmpty)));
1310
1311 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1312 ASSERT_TRUE(vc != NULL);
1313 const VideoContentDescription* vcd =
1314 static_cast<const VideoContentDescription*>(vc->description);
1315 ASSERT_FALSE(vcd->codecs().empty());
1316 cricket::VideoCodec vp8 = vcd->codecs()[0];
1317 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1318 vp8.name.c_str());
1319 EXPECT_EQ(101, vp8.id);
1320 EXPECT_TRUE(vp8.HasFeedbackParam(
1321 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1322 cricket::kParamValueEmpty)));
1323 EXPECT_TRUE(vp8.HasFeedbackParam(
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001324 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1325 cricket::kRtcpFbNackParamPli)));
1326 EXPECT_TRUE(vp8.HasFeedbackParam(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001327 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
1328 cricket::kParamValueEmpty)));
1329 EXPECT_TRUE(vp8.HasFeedbackParam(
1330 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
1331 cricket::kRtcpFbCcmParamFir)));
1332 }
1333
1334 // Two SDP messages can mean the same thing but be different strings, e.g.
1335 // some of the lines can be serialized in different order.
1336 // However, a deserialized description can be compared field by field and has
1337 // no order. If deserializer has already been tested, serializing then
1338 // deserializing and comparing JsepSessionDescription will test
1339 // the serializer sufficiently.
1340 void TestSerialize(const JsepSessionDescription& jdesc) {
1341 std::string message = webrtc::SdpSerialize(jdesc);
1342 JsepSessionDescription jdesc_output_des(kDummyString);
1343 SdpParseError error;
1344 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1345 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1346 }
1347
1348 protected:
1349 SessionDescription desc_;
1350 AudioContentDescription* audio_desc_;
1351 VideoContentDescription* video_desc_;
1352 DataContentDescription* data_desc_;
1353 Candidates candidates_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001354 rtc::scoped_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001355 JsepSessionDescription jdesc_;
1356};
1357
1358void TestMismatch(const std::string& string1, const std::string& string2) {
1359 int position = 0;
1360 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1361 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001362 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001363 break;
1364 }
1365 }
1366 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1367 << " character\n"
1368 << " 1: " << string1.substr(position, 20) << "\n"
1369 << " 2: " << string2.substr(position, 20) << "\n";
1370}
1371
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001372TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1373 // SessionDescription with desc and candidates.
1374 std::string message = webrtc::SdpSerialize(jdesc_);
1375 TestMismatch(std::string(kSdpFullString), message);
1376}
1377
1378TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
1379 JsepSessionDescription jdesc_empty(kDummyString);
1380 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
1381}
1382
guoweis@webrtc.org57ac2c82015-02-06 00:45:13 +00001383// This tests serialization of SDP with only IPv6 candidates and verifies that
1384// IPv6 is used as default address in c line according to preference.
1385TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIPv6Only) {
1386 // Only test 1 m line.
1387 desc_.RemoveContentByName("video_content_name");
1388 // Stun has a high preference than local host.
1389 cricket::Candidate candidate1(
1390 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1391 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1392 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1393 cricket::Candidate candidate2(
1394 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1395 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
1396 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1397 JsepSessionDescription jdesc(kDummyString);
1398 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1399
1400 // Only add the candidates to audio m line.
1401 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1402 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1403 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1404 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
1405 std::string message = webrtc::SdpSerialize(jdesc);
1406
1407 // Audio line should have a c line like this one.
1408 EXPECT_NE(message.find("c=IN IP6 ::1"), std::string::npos);
1409 // Shouldn't have a IP4 c line.
1410 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
1411}
1412
1413// This tests serialization of SDP with both IPv4 and IPv6 candidates and
1414// verifies that IPv4 is used as default address in c line even if the
1415// preference of IPv4 is lower.
1416TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothIPFamilies) {
1417 // Only test 1 m line.
1418 desc_.RemoveContentByName("video_content_name");
1419 cricket::Candidate candidate_v4(
1420 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1421 rtc::SocketAddress("192.168.1.5", 1234), kCandidatePriority, "", "",
1422 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1423 cricket::Candidate candidate_v6(
1424 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1425 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1426 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1427 JsepSessionDescription jdesc(kDummyString);
1428 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1429
1430 // Only add the candidates to audio m line.
1431 JsepIceCandidate jice_v4("audio_content_name", 0, candidate_v4);
1432 JsepIceCandidate jice_v6("audio_content_name", 0, candidate_v6);
1433 ASSERT_TRUE(jdesc.AddCandidate(&jice_v4));
1434 ASSERT_TRUE(jdesc.AddCandidate(&jice_v6));
1435 std::string message = webrtc::SdpSerialize(jdesc);
1436
1437 // Audio line should have a c line like this one.
1438 EXPECT_NE(message.find("c=IN IP4 192.168.1.5"), std::string::npos);
1439 // Shouldn't have a IP6 c line.
1440 EXPECT_EQ(message.find("c=IN IP6"), std::string::npos);
1441}
1442
1443// This tests serialization of SDP with both UDP and TCP candidates and
1444// verifies that UDP is used as default address in c line even if the
1445// preference of UDP is lower.
1446TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothProtocols) {
1447 // Only test 1 m line.
1448 desc_.RemoveContentByName("video_content_name");
1449 // Stun has a high preference than local host.
1450 cricket::Candidate candidate1(
1451 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1452 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1453 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1454 cricket::Candidate candidate2(
1455 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1456 rtc::SocketAddress("fe80::1234:5678:abcd:ef12", 1235), kCandidatePriority,
1457 "", "", cricket::LOCAL_PORT_TYPE, kCandidateGeneration,
1458 kCandidateFoundation1);
1459 JsepSessionDescription jdesc(kDummyString);
1460 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1461
1462 // Only add the candidates to audio m line.
1463 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1464 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1465 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1466 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
1467 std::string message = webrtc::SdpSerialize(jdesc);
1468
1469 // Audio line should have a c line like this one.
1470 EXPECT_NE(message.find("c=IN IP6 fe80::1234:5678:abcd:ef12"),
1471 std::string::npos);
1472 // Shouldn't have a IP4 c line.
1473 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
1474}
1475
1476// This tests serialization of SDP with only TCP candidates and verifies that
1477// null IPv4 is used as default address in c line.
1478TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithTCPOnly) {
1479 // Only test 1 m line.
1480 desc_.RemoveContentByName("video_content_name");
1481 // Stun has a high preference than local host.
1482 cricket::Candidate candidate1(
1483 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1484 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1485 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1486 cricket::Candidate candidate2(
1487 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1488 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
1489 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1490 JsepSessionDescription jdesc(kDummyString);
1491 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1492
1493 // Only add the candidates to audio m line.
1494 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1495 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1496 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1497 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
1498 std::string message = webrtc::SdpSerialize(jdesc);
1499
1500 // Audio line should have a c line like this one when no any default exists.
1501 EXPECT_NE(message.find("c=IN IP4 0.0.0.0"), std::string::npos);
1502}
1503
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001504// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1505// the case in a DTLS offer.
1506TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1507 AddFingerprint();
1508 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1509 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1510 kSessionId, kSessionVersion));
1511 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
1512
1513 std::string sdp_with_fingerprint = kSdpString;
1514 InjectAfter(kAttributeIcePwdVoice,
1515 kFingerprint, &sdp_with_fingerprint);
1516 InjectAfter(kAttributeIcePwdVideo,
1517 kFingerprint, &sdp_with_fingerprint);
1518
1519 EXPECT_EQ(sdp_with_fingerprint, message);
1520}
1521
1522// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1523// be the case in a DTLS answer.
1524TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1525 AddFingerprint();
1526 RemoveCryptos();
1527 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1528 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1529 kSessionId, kSessionVersion));
1530 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
1531
1532 std::string sdp_with_fingerprint = kSdpString;
1533 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1534 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
1535 InjectAfter(kAttributeIcePwdVoice,
1536 kFingerprint, &sdp_with_fingerprint);
1537 InjectAfter(kAttributeIcePwdVideo,
1538 kFingerprint, &sdp_with_fingerprint);
1539
1540 EXPECT_EQ(sdp_with_fingerprint, message);
1541}
1542
1543TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1544 // JsepSessionDescription with desc but without candidates.
1545 JsepSessionDescription jdesc_no_candidates(kDummyString);
1546 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
1547 kSessionId, kSessionVersion));
1548 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
1549 EXPECT_EQ(std::string(kSdpString), message);
1550}
1551
1552TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1553 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1554 group.AddContentName(kAudioContentName);
1555 group.AddContentName(kVideoContentName);
1556 desc_.AddGroup(group);
1557 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1558 jdesc_.session_id(),
1559 jdesc_.session_version()));
1560 std::string message = webrtc::SdpSerialize(jdesc_);
1561 std::string sdp_with_bundle = kSdpFullString;
1562 InjectAfter(kSessionTime,
1563 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1564 &sdp_with_bundle);
1565 EXPECT_EQ(sdp_with_bundle, message);
1566}
1567
1568TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
1569 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1570 GetFirstVideoContent(&desc_)->description);
1571 vcd->set_bandwidth(100 * 1000);
1572 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1573 GetFirstAudioContent(&desc_)->description);
1574 acd->set_bandwidth(50 * 1000);
1575 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1576 jdesc_.session_id(),
1577 jdesc_.session_version()));
1578 std::string message = webrtc::SdpSerialize(jdesc_);
1579 std::string sdp_with_bandwidth = kSdpFullString;
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001580 InjectAfter("c=IN IP4 74.125.224.39\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001581 "b=AS:100\r\n",
1582 &sdp_with_bandwidth);
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001583 InjectAfter("c=IN IP4 74.125.127.126\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001584 "b=AS:50\r\n",
1585 &sdp_with_bandwidth);
1586 EXPECT_EQ(sdp_with_bandwidth, message);
1587}
1588
1589TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1590 std::vector<std::string> transport_options;
1591 transport_options.push_back(kIceOption1);
1592 transport_options.push_back(kIceOption3);
1593 AddIceOptions(kAudioContentName, transport_options);
1594 transport_options.clear();
1595 transport_options.push_back(kIceOption2);
1596 transport_options.push_back(kIceOption3);
1597 AddIceOptions(kVideoContentName, transport_options);
1598 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1599 jdesc_.session_id(),
1600 jdesc_.session_version()));
1601 std::string message = webrtc::SdpSerialize(jdesc_);
1602 std::string sdp_with_ice_options = kSdpFullString;
1603 InjectAfter(kAttributeIcePwdVoice,
1604 "a=ice-options:iceoption1 iceoption3\r\n",
1605 &sdp_with_ice_options);
1606 InjectAfter(kAttributeIcePwdVideo,
1607 "a=ice-options:iceoption2 iceoption3\r\n",
1608 &sdp_with_ice_options);
1609 EXPECT_EQ(sdp_with_ice_options, message);
1610}
1611
1612TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
1613 EXPECT_TRUE(TestSerializeDirection(cricket::MD_RECVONLY));
1614}
1615
1616TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
1617 EXPECT_TRUE(TestSerializeDirection(cricket::MD_SENDONLY));
1618}
1619
1620TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
1621 EXPECT_TRUE(TestSerializeDirection(cricket::MD_INACTIVE));
1622}
1623
1624TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
1625 EXPECT_TRUE(TestSerializeRejected(true, false));
1626}
1627
1628TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
1629 EXPECT_TRUE(TestSerializeRejected(false, true));
1630}
1631
1632TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
1633 EXPECT_TRUE(TestSerializeRejected(true, true));
1634}
1635
1636TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
1637 AddRtpDataChannel();
1638 JsepSessionDescription jsep_desc(kDummyString);
1639
1640 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1641 std::string message = webrtc::SdpSerialize(jsep_desc);
1642
1643 std::string expected_sdp = kSdpString;
1644 expected_sdp.append(kSdpRtpDataChannelString);
1645 EXPECT_EQ(expected_sdp, message);
1646}
1647
1648TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
1649 AddSctpDataChannel();
1650 JsepSessionDescription jsep_desc(kDummyString);
1651
1652 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1653 std::string message = webrtc::SdpSerialize(jsep_desc);
1654
1655 std::string expected_sdp = kSdpString;
1656 expected_sdp.append(kSdpSctpDataChannelString);
1657 EXPECT_EQ(message, expected_sdp);
1658}
1659
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001660TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
1661 AddSctpDataChannel();
1662 JsepSessionDescription jsep_desc(kDummyString);
1663
1664 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1665 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
1666 jsep_desc.description()->GetContentDescriptionByName(kDataContentName));
1667
1668 const int kNewPort = 1234;
1669 cricket::DataCodec codec(
1670 cricket::kGoogleSctpDataCodecId, cricket::kGoogleSctpDataCodecName, 0);
1671 codec.SetParam(cricket::kCodecParamPort, kNewPort);
1672 dcdesc->AddOrReplaceCodec(codec);
1673
1674 std::string message = webrtc::SdpSerialize(jsep_desc);
1675
1676 std::string expected_sdp = kSdpString;
1677 expected_sdp.append(kSdpSctpDataChannelString);
1678
1679 char default_portstr[16];
1680 char new_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001681 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001682 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001683 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
1684 rtc::replace_substrs(default_portstr, strlen(default_portstr),
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001685 new_portstr, strlen(new_portstr),
1686 &expected_sdp);
1687
1688 EXPECT_EQ(expected_sdp, message);
1689}
1690
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001691TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
1692 AddRtpDataChannel();
1693 data_desc_->set_bandwidth(100*1000);
1694 JsepSessionDescription jsep_desc(kDummyString);
1695
1696 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1697 std::string message = webrtc::SdpSerialize(jsep_desc);
1698
1699 std::string expected_sdp = kSdpString;
1700 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07001701 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00001702 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 +00001703 "b=AS:100\r\n",
1704 &expected_sdp);
1705 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001706}
1707
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001708TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
1709 AddExtmap();
1710 JsepSessionDescription desc_with_extmap("dummy");
1711 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(),
1712 kSessionId, kSessionVersion));
1713 std::string message = webrtc::SdpSerialize(desc_with_extmap);
1714
1715 std::string sdp_with_extmap = kSdpString;
1716 InjectAfter("a=mid:audio_content_name\r\n",
1717 kExtmap, &sdp_with_extmap);
1718 InjectAfter("a=mid:video_content_name\r\n",
1719 kExtmap, &sdp_with_extmap);
1720
1721 EXPECT_EQ(sdp_with_extmap, message);
1722}
1723
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001724TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBufferLatency) {
1725 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1726 GetFirstVideoContent(&desc_)->description);
1727 vcd->set_buffered_mode_latency(128);
1728
1729 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1730 jdesc_.session_id(),
1731 jdesc_.session_version()));
1732 std::string message = webrtc::SdpSerialize(jdesc_);
1733 std::string sdp_with_buffer_latency = kSdpFullString;
1734 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
1735 "a=x-google-buffer-latency:128\r\n",
1736 &sdp_with_buffer_latency);
1737 EXPECT_EQ(sdp_with_buffer_latency, message);
1738}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001739
1740TEST_F(WebRtcSdpTest, SerializeCandidates) {
1741 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00001742 EXPECT_EQ(std::string(kRawCandidate), message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001743}
1744
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00001745// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
1746// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00001747TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001748 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001749 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
1750 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
1751 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00001752 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
1753 rtc::scoped_ptr<IceCandidateInterface> jcandidate(
1754 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
1755
1756 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
1757 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
1758}
1759
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001760TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
1761 JsepSessionDescription jdesc(kDummyString);
1762 // Deserialize
1763 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
1764 // Verify
1765 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1766}
1767
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001768TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
1769 JsepSessionDescription jdesc(kDummyString);
1770 const char kSdpWithoutMline[] =
1771 "v=0\r\n"
1772 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1773 "s=-\r\n"
1774 "t=0 0\r\n"
1775 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
1776 // Deserialize
1777 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
1778 EXPECT_EQ(0u, jdesc.description()->contents().size());
1779}
1780
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001781TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
1782 JsepSessionDescription jdesc(kDummyString);
1783 std::string sdp_without_carriage_return = kSdpFullString;
1784 Replace("\r\n", "\n", &sdp_without_carriage_return);
1785 // Deserialize
1786 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
1787 // Verify
1788 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1789}
1790
1791TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
1792 // SessionDescription with desc but without candidates.
1793 JsepSessionDescription jdesc_no_candidates(kDummyString);
1794 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
1795 kSessionId, kSessionVersion));
1796 JsepSessionDescription new_jdesc(kDummyString);
1797 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
1798 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
1799}
1800
1801TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
1802 static const char kSdpNoRtpmapString[] =
1803 "v=0\r\n"
1804 "o=- 11 22 IN IP4 127.0.0.1\r\n"
1805 "s=-\r\n"
1806 "t=0 0\r\n"
1807 "m=audio 49232 RTP/AVP 0 18 103\r\n"
1808 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001809 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001810 // The rtpmap line for static payload codec is optional.
1811 "a=rtpmap:18 G729/16000\r\n"
1812 "a=rtpmap:103 ISAC/16000\r\n";
1813
1814 JsepSessionDescription jdesc(kDummyString);
1815 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
1816 cricket::AudioContentDescription* audio =
1817 static_cast<AudioContentDescription*>(
1818 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
1819 AudioCodecs ref_codecs;
1820 // The codecs in the AudioContentDescription will be sorted by preference.
1821 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1, 3));
1822 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1, 2));
1823 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 32000, 1, 1));
1824 EXPECT_EQ(ref_codecs, audio->codecs());
1825}
1826
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001827TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
1828 static const char kSdpNoRtpmapString[] =
1829 "v=0\r\n"
1830 "o=- 11 22 IN IP4 127.0.0.1\r\n"
1831 "s=-\r\n"
1832 "t=0 0\r\n"
1833 "m=audio 49232 RTP/AVP 18 103\r\n"
1834 "a=fmtp:18 annexb=yes\r\n"
1835 "a=rtpmap:103 ISAC/16000\r\n";
1836
1837 JsepSessionDescription jdesc(kDummyString);
1838 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
1839 cricket::AudioContentDescription* audio =
1840 static_cast<AudioContentDescription*>(
1841 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
1842
1843 cricket::AudioCodec g729 = audio->codecs()[0];
1844 EXPECT_EQ("G729", g729.name);
1845 EXPECT_EQ(8000, g729.clockrate);
1846 EXPECT_EQ(18, g729.id);
1847 cricket::CodecParameterMap::iterator found =
1848 g729.params.find("annexb");
1849 ASSERT_TRUE(found != g729.params.end());
1850 EXPECT_EQ(found->second, "yes");
1851
1852 cricket::AudioCodec isac = audio->codecs()[1];
1853 EXPECT_EQ("ISAC", isac.name);
1854 EXPECT_EQ(103, isac.id);
1855 EXPECT_EQ(16000, isac.clockrate);
1856}
1857
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001858// Ensure that we can deserialize SDP with a=fingerprint properly.
1859TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
1860 // Add a DTLS a=fingerprint attribute to our session description.
1861 AddFingerprint();
1862 JsepSessionDescription new_jdesc(kDummyString);
1863 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1864 jdesc_.session_id(),
1865 jdesc_.session_version()));
1866
1867 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1868 std::string sdp_with_fingerprint = kSdpString;
1869 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1870 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
1871 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
1872 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
1873}
1874
1875TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
1876 JsepSessionDescription jdesc_with_bundle(kDummyString);
1877 std::string sdp_with_bundle = kSdpFullString;
1878 InjectAfter(kSessionTime,
1879 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1880 &sdp_with_bundle);
1881 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
1882 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1883 group.AddContentName(kAudioContentName);
1884 group.AddContentName(kVideoContentName);
1885 desc_.AddGroup(group);
1886 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1887 jdesc_.session_id(),
1888 jdesc_.session_version()));
1889 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
1890}
1891
1892TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
1893 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
1894 std::string sdp_with_bandwidth = kSdpFullString;
1895 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
1896 "b=AS:100\r\n",
1897 &sdp_with_bandwidth);
1898 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
1899 "b=AS:50\r\n",
1900 &sdp_with_bandwidth);
1901 EXPECT_TRUE(
1902 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
1903 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1904 GetFirstVideoContent(&desc_)->description);
1905 vcd->set_bandwidth(100 * 1000);
1906 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1907 GetFirstAudioContent(&desc_)->description);
1908 acd->set_bandwidth(50 * 1000);
1909 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1910 jdesc_.session_id(),
1911 jdesc_.session_version()));
1912 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
1913}
1914
1915TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
1916 JsepSessionDescription jdesc_with_ice_options(kDummyString);
1917 std::string sdp_with_ice_options = kSdpFullString;
1918 InjectAfter(kSessionTime,
1919 "a=ice-options:iceoption3\r\n",
1920 &sdp_with_ice_options);
1921 InjectAfter(kAttributeIcePwdVoice,
1922 "a=ice-options:iceoption1\r\n",
1923 &sdp_with_ice_options);
1924 InjectAfter(kAttributeIcePwdVideo,
1925 "a=ice-options:iceoption2\r\n",
1926 &sdp_with_ice_options);
1927 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
1928 std::vector<std::string> transport_options;
1929 transport_options.push_back(kIceOption3);
1930 transport_options.push_back(kIceOption1);
1931 AddIceOptions(kAudioContentName, transport_options);
1932 transport_options.clear();
1933 transport_options.push_back(kIceOption3);
1934 transport_options.push_back(kIceOption2);
1935 AddIceOptions(kVideoContentName, transport_options);
1936 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1937 jdesc_.session_id(),
1938 jdesc_.session_version()));
1939 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
1940}
1941
1942TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
1943 // Remove the original ice-ufrag and ice-pwd
1944 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyString);
1945 std::string sdp_with_ufrag_pwd = kSdpFullString;
1946 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
1947 // Add session level ufrag and pwd
1948 InjectAfter(kSessionTime,
1949 "a=ice-pwd:session+level+icepwd\r\n"
1950 "a=ice-ufrag:session+level+iceufrag\r\n",
1951 &sdp_with_ufrag_pwd);
1952 // Add media level ufrag and pwd for audio
1953 InjectAfter("a=mid:audio_content_name\r\n",
1954 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
1955 &sdp_with_ufrag_pwd);
1956 // Update the candidate ufrag and pwd to the expected ones.
1957 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0,
1958 "media+level+iceufrag", "media+level+icepwd"));
1959 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1,
1960 "session+level+iceufrag", "session+level+icepwd"));
1961 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
1962 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
1963}
1964
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001965TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBufferLatency) {
1966 JsepSessionDescription jdesc_with_buffer_latency(kDummyString);
1967 std::string sdp_with_buffer_latency = kSdpFullString;
1968 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
1969 "a=x-google-buffer-latency:128\r\n",
1970 &sdp_with_buffer_latency);
1971
1972 EXPECT_TRUE(
1973 SdpDeserialize(sdp_with_buffer_latency, &jdesc_with_buffer_latency));
1974 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1975 GetFirstVideoContent(&desc_)->description);
1976 vcd->set_buffered_mode_latency(128);
1977 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1978 jdesc_.session_id(),
1979 jdesc_.session_version()));
1980 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_buffer_latency));
1981}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001982
1983TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
1984 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_RECVONLY));
1985}
1986
1987TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
1988 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_SENDONLY));
1989}
1990
1991TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
1992 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_INACTIVE));
1993}
1994
1995TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
1996 EXPECT_TRUE(TestDeserializeRejected(true, false));
1997}
1998
1999TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2000 EXPECT_TRUE(TestDeserializeRejected(false, true));
2001}
2002
2003TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2004 EXPECT_TRUE(TestDeserializeRejected(true, true));
2005}
2006
2007// Tests that we can still handle the sdp uses mslabel and label instead of
2008// msid for backward compatibility.
2009TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
2010 JsepSessionDescription jdesc(kDummyString);
2011 std::string sdp_without_msid = kSdpFullString;
2012 Replace("msid", "xmsid", &sdp_without_msid);
2013 // Deserialize
2014 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2015 // Verify
2016 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2017}
2018
2019TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2020 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2021
2022 std::string sdp = kSdpOneCandidate;
2023 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2024 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2025 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2026 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2027
2028 // Candidate line without generation extension.
2029 sdp = kSdpOneCandidate;
2030 Replace(" generation 2", "", &sdp);
2031 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2032 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2033 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2034 Candidate expected = jcandidate_->candidate();
2035 expected.set_generation(0);
2036 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2037
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002038 sdp = kSdpTcpActiveCandidate;
2039 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2040 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002041 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002042 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2043 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2044 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002045 rtc::scoped_ptr<IceCandidateInterface> jcandidate_template(
2046 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
2047 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(
2048 jcandidate_template->candidate()));
2049 sdp = kSdpTcpPassiveCandidate;
2050 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2051 sdp = kSdpTcpSOCandidate;
2052 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002053}
2054
2055// This test verifies the deserialization of candidate-attribute
2056// as per RFC 5245. Candiate-attribute will be of the format
2057// candidate:<blah>. This format will be used when candidates
2058// are trickled.
2059TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2060 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2061
2062 std::string candidate_attribute = kRawCandidate;
2063 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2064 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2065 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2066 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2067 EXPECT_EQ(2u, jcandidate.candidate().generation());
2068
2069 // Candidate line without generation extension.
2070 candidate_attribute = kRawCandidate;
2071 Replace(" generation 2", "", &candidate_attribute);
2072 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2073 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2074 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2075 Candidate expected = jcandidate_->candidate();
2076 expected.set_generation(0);
2077 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2078
2079 // Candidate line without candidate:
2080 candidate_attribute = kRawCandidate;
2081 Replace("candidate:", "", &candidate_attribute);
2082 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2083
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002084 // Candidate line with IPV6 address.
2085 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
2086}
2087
2088// This test verifies that the deserialization of an invalid candidate string
2089// fails.
2090TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
2091 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2092
2093 std::string candidate_attribute = kRawCandidate;
2094 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002095 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002096
2097 candidate_attribute = kSdpOneCandidate;
2098 candidate_attribute.replace(0, 1, "x");
2099 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2100
2101 candidate_attribute = kRawCandidate;
2102 candidate_attribute.append("\r\n");
2103 candidate_attribute.append(kRawCandidate);
2104 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2105
2106 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002107}
2108
2109TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2110 AddRtpDataChannel();
2111 JsepSessionDescription jdesc(kDummyString);
2112 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2113
2114 std::string sdp_with_data = kSdpString;
2115 sdp_with_data.append(kSdpRtpDataChannelString);
2116 JsepSessionDescription jdesc_output(kDummyString);
2117
2118 // Deserialize
2119 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2120 // Verify
2121 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2122}
2123
2124TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
2125 AddSctpDataChannel();
2126 JsepSessionDescription jdesc(kDummyString);
2127 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2128
2129 std::string sdp_with_data = kSdpString;
2130 sdp_with_data.append(kSdpSctpDataChannelString);
2131 JsepSessionDescription jdesc_output(kDummyString);
2132
lally@webrtc.org36300852015-02-24 20:19:35 +00002133 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2134 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2135 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2136
2137 // Verify with UDP/DTLS/SCTP.
2138 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2139 strlen(kDtlsSctp), kUdpDtlsSctp);
2140 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2141 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2142
2143 // Verify with TCP/DTLS/SCTP.
2144 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2145 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002146 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2147 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2148}
2149
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002150TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
2151 AddSctpDataChannel();
2152 JsepSessionDescription jdesc(kDummyString);
2153 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2154
2155 std::string sdp_with_data = kSdpString;
2156 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2157 JsepSessionDescription jdesc_output(kDummyString);
2158
lally@webrtc.org36300852015-02-24 20:19:35 +00002159 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002160 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2161 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002162
lally@webrtc.org36300852015-02-24 20:19:35 +00002163 // Verify with UDP/DTLS/SCTP.
2164 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2165 strlen(kDtlsSctp), kUdpDtlsSctp);
2166 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2167 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002168
lally@webrtc.org36300852015-02-24 20:19:35 +00002169 // Verify with TCP/DTLS/SCTP.
2170 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2171 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002172 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2173 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2174}
2175
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002176// Test to check the behaviour if sctp-port is specified
2177// on the m= line and in a=sctp-port.
2178TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
2179 AddSctpDataChannel();
2180 JsepSessionDescription jdesc(kDummyString);
2181 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2182
2183 std::string sdp_with_data = kSdpString;
2184 // Append m= attributes
2185 sdp_with_data.append(kSdpSctpDataChannelString);
2186 // Append a=sctp-port attribute
2187 sdp_with_data.append("a=sctp-port 5000\r\n");
2188 JsepSessionDescription jdesc_output(kDummyString);
2189
2190 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2191}
2192
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002193// For crbug/344475.
2194TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2195 std::string sdp_with_data = kSdpString;
2196 sdp_with_data.append(kSdpSctpDataChannelString);
2197 // Remove the "\n" at the end.
2198 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
2199 JsepSessionDescription jdesc_output(kDummyString);
2200
2201 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2202 // No crash is a pass.
2203}
2204
wu@webrtc.org78187522013-10-07 23:32:02 +00002205TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndNewPort) {
2206 AddSctpDataChannel();
2207 const uint16 kUnusualSctpPort = 9556;
2208 char default_portstr[16];
2209 char unusual_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002210 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
wu@webrtc.org78187522013-10-07 23:32:02 +00002211 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002212 rtc::sprintfn(unusual_portstr, sizeof(unusual_portstr), "%d",
wu@webrtc.org78187522013-10-07 23:32:02 +00002213 kUnusualSctpPort);
2214
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002215 // First setup the expected JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002216 JsepSessionDescription jdesc(kDummyString);
2217 // take our pre-built session description and change the SCTP port.
2218 cricket::SessionDescription* mutant = desc_.Copy();
2219 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
2220 mutant->GetContentDescriptionByName(kDataContentName));
2221 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002222 EXPECT_EQ(1U, codecs.size());
2223 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002224 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002225 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002226
2227 // note: mutant's owned by jdesc now.
2228 ASSERT_TRUE(jdesc.Initialize(mutant, kSessionId, kSessionVersion));
2229 mutant = NULL;
2230
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002231 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002232 std::string sdp_with_data = kSdpString;
2233 sdp_with_data.append(kSdpSctpDataChannelString);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002234 rtc::replace_substrs(default_portstr, strlen(default_portstr),
wu@webrtc.org78187522013-10-07 23:32:02 +00002235 unusual_portstr, strlen(unusual_portstr),
2236 &sdp_with_data);
2237 JsepSessionDescription jdesc_output(kDummyString);
2238
2239 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2240 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002241
2242 // We need to test the deserialized JsepSessionDescription from
2243 // kSdpSctpDataChannelStringWithSctpPort for
2244 // draft-ietf-mmusic-sctp-sdp-07
2245 // a=sctp-port
2246 sdp_with_data = kSdpString;
2247 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2248 rtc::replace_substrs(default_portstr, strlen(default_portstr),
2249 unusual_portstr, strlen(unusual_portstr),
2250 &sdp_with_data);
2251
2252 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2253 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002254}
2255
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002256TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002257 // We want to test that deserializing data content limits bandwidth
2258 // settings (it should never be greater than the default).
2259 // This should prevent someone from using unlimited data bandwidth through
2260 // JS and "breaking the Internet".
2261 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002262 std::string sdp_with_bandwidth = kSdpString;
2263 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
2264 InjectAfter("a=mid:data_content_name\r\n",
2265 "b=AS:100\r\n",
2266 &sdp_with_bandwidth);
2267 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2268
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002269 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2270}
2271
2272TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
2273 AddSctpDataChannel();
2274 JsepSessionDescription jdesc(kDummyString);
2275 DataContentDescription* dcd = static_cast<DataContentDescription*>(
2276 GetFirstDataContent(&desc_)->description);
2277 dcd->set_bandwidth(100 * 1000);
2278 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2279
2280 std::string sdp_with_bandwidth = kSdpString;
2281 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
2282 InjectAfter("a=mid:data_content_name\r\n",
2283 "b=AS:100\r\n",
2284 &sdp_with_bandwidth);
2285 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2286
2287 // SCTP has congestion control, so we shouldn't limit the bandwidth
2288 // as we do for RTP.
2289 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002290 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2291}
2292
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002293TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSessionLevelExtmap) {
2294 TestDeserializeExtmap(true, false);
2295}
2296
2297TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
2298 TestDeserializeExtmap(false, true);
2299}
2300
2301TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInvalidExtmap) {
2302 TestDeserializeExtmap(true, true);
2303}
2304
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002305TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
2306 JsepSessionDescription jdesc(kDummyString);
2307 std::string sdp = kSdpFullString;
2308 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2309 // Deserialize
2310 SdpParseError error;
2311 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
2312 const std::string lastline = "a=ssrc:6 label:video_track_id_3";
2313 EXPECT_EQ(lastline, error.line);
2314 EXPECT_EQ("Invalid SDP line.", error.description);
2315}
2316
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002317TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2318 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2319 std::string new_sdp = kSdpOneCandidate;
2320 Replace("udp", "unsupported_transport", &new_sdp);
2321 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2322 new_sdp = kSdpOneCandidate;
2323 Replace("udp", "uDP", &new_sdp);
2324 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2325 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2326 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2327 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2328}
2329
2330TEST_F(WebRtcSdpTest, DeserializeCandidateOldFormat) {
2331 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2332 EXPECT_TRUE(SdpDeserializeCandidate(kSdpOneCandidateOldFormat,&jcandidate));
2333 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2334 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2335 Candidate ref_candidate = jcandidate_->candidate();
2336 ref_candidate.set_username("user_rtp");
2337 ref_candidate.set_password("password_rtp");
2338 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2339}
2340
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002341TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
2342 JsepSessionDescription jdesc(kDummyString);
2343
2344 // Deserialize
2345 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2346
2347 // Verify
2348 cricket::AudioContentDescription* audio =
2349 static_cast<AudioContentDescription*>(
2350 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2351 EXPECT_TRUE(audio->conference_mode());
2352
2353 cricket::VideoContentDescription* video =
2354 static_cast<VideoContentDescription*>(
2355 jdesc.description()->GetContentDescriptionByName(cricket::CN_VIDEO));
2356 EXPECT_TRUE(video->conference_mode());
2357}
2358
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002359TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2360 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002361 const char kSdpEmptyType[] = " =candidate";
2362 const char kSdpEqualAsPlus[] = "a+candidate";
2363 const char kSdpSpaceAfterEqual[] = "a= candidate";
2364 const char kSdpUpperType[] = "A=candidate";
2365 const char kSdpEmptyLine[] = "";
2366 const char kSdpMissingValue[] = "a=";
2367
2368 const char kSdpBrokenFingerprint[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002369 "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 +00002370 const char kSdpExtraField[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002371 "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 +00002372 const char kSdpMissingSpace[] = "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002373 "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 +00002374 // MD5 is not allowed in fingerprints.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002375 const char kSdpMd5[] = "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002376 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002377
2378 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002379 ExpectParseFailure("v=", kSdpDestroyer);
2380 ExpectParseFailure("o=", kSdpDestroyer);
2381 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002382 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002383 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002384
2385 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002386 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2387 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002388
2389 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002390 ExpectParseFailure("a=candidate", kSdpEmptyType);
2391 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2392 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
2393 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002394
2395 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2396 // because it's orthogonal to what we are replacing and hence
2397 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002398 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
2399 ExpectParseFailure("a=sendrecv", kSdpExtraField);
2400 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
2401 ExpectParseFailure("a=sendrecv", kSdpMd5);
2402
2403 // Empty Line
2404 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
2405 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002406}
2407
2408TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2409 // ssrc
2410 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
2411 ExpectParseFailure("a=ssrc-group:FEC 5 6", "a=ssrc-group:FEC badvalue 6");
2412 // crypto
2413 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
2414 // rtpmap
2415 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
2416 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
2417 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
2418 // candidate
2419 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
2420 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
2421 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
2422 ExpectParseFailure("rport 2346", "rport badvalue");
2423 ExpectParseFailure("rport 2346 generation 2",
2424 "rport 2346 generation badvalue");
2425 // m line
2426 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
2427 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
2428
2429 // bandwidth
2430 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2431 "b=AS:badvalue\r\n",
2432 "b=AS:badvalue");
2433 // rtcp-fb
2434 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2435 "a=rtcp-fb:badvalue nack\r\n",
2436 "a=rtcp-fb:badvalue nack");
2437 // extmap
2438 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2439 "a=extmap:badvalue http://example.com\r\n",
2440 "a=extmap:badvalue http://example.com");
2441 // x-google-buffer-latency
2442 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2443 "a=x-google-buffer-latency:badvalue\r\n",
2444 "a=x-google-buffer-latency:badvalue");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002445}
2446
2447TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
2448 JsepSessionDescription jdesc_output(kDummyString);
2449
2450 const char kSdpWithReorderedPlTypesString[] =
2451 "v=0\r\n"
2452 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2453 "s=-\r\n"
2454 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00002455 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002456 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
2457 // in the map.
2458 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002459 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002460
2461 // Deserialize
2462 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
2463
2464 const ContentInfo* ac = GetFirstAudioContent(jdesc_output.description());
2465 ASSERT_TRUE(ac != NULL);
2466 const AudioContentDescription* acd =
2467 static_cast<const AudioContentDescription*>(ac->description);
2468 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002469 EXPECT_EQ("ISAC", acd->codecs()[0].name);
2470 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002471 EXPECT_EQ(104, acd->codecs()[0].id);
2472}
2473
2474TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
2475 JsepSessionDescription jdesc_output(kDummyString);
2476 CodecParams params;
2477 params.max_ptime = 40;
2478 params.ptime = 30;
2479 params.min_ptime = 10;
2480 params.sprop_stereo = 1;
2481 params.stereo = 1;
2482 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002483 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002484 TestDeserializeCodecParams(params, &jdesc_output);
2485 TestSerialize(jdesc_output);
2486}
2487
2488TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
2489 const bool kUseWildcard = false;
2490 JsepSessionDescription jdesc_output(kDummyString);
2491 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
2492 TestSerialize(jdesc_output);
2493}
2494
2495TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
2496 const bool kUseWildcard = true;
2497 JsepSessionDescription jdesc_output(kDummyString);
2498 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
2499 TestSerialize(jdesc_output);
2500}
2501
2502TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
2503 JsepSessionDescription jdesc_output(kDummyString);
2504
2505 const char kSdpWithFmtpString[] =
2506 "v=0\r\n"
2507 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2508 "s=-\r\n"
2509 "t=0 0\r\n"
2510 "m=video 3457 RTP/SAVPF 120\r\n"
2511 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07002512 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
2513
2514 // Deserialize
2515 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07002516 EXPECT_TRUE(
2517 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07002518
2519 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2520 ASSERT_TRUE(vc != NULL);
2521 const VideoContentDescription* vcd =
2522 static_cast<const VideoContentDescription*>(vc->description);
2523 ASSERT_FALSE(vcd->codecs().empty());
2524 cricket::VideoCodec vp8 = vcd->codecs()[0];
2525 EXPECT_EQ("VP8", vp8.name);
2526 EXPECT_EQ(120, vp8.id);
2527 cricket::CodecParameterMap::iterator found =
2528 vp8.params.find("x-google-min-bitrate");
2529 ASSERT_TRUE(found != vp8.params.end());
2530 EXPECT_EQ(found->second, "10");
2531 found = vp8.params.find("x-google-max-quantization");
2532 ASSERT_TRUE(found != vp8.params.end());
2533 EXPECT_EQ(found->second, "40");
2534}
2535
2536TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
2537 JsepSessionDescription jdesc_output(kDummyString);
2538
2539 const char kSdpWithFmtpString[] =
2540 "v=0\r\n"
2541 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2542 "s=-\r\n"
2543 "t=0 0\r\n"
2544 "m=video 3457 RTP/SAVPF 120\r\n"
2545 "a=rtpmap:120 VP8/90000\r\n"
2546 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002547
2548 // Deserialize
2549 SdpParseError error;
2550 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output,
2551 &error));
2552
2553 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2554 ASSERT_TRUE(vc != NULL);
2555 const VideoContentDescription* vcd =
2556 static_cast<const VideoContentDescription*>(vc->description);
2557 ASSERT_FALSE(vcd->codecs().empty());
2558 cricket::VideoCodec vp8 = vcd->codecs()[0];
2559 EXPECT_EQ("VP8", vp8.name);
2560 EXPECT_EQ(120, vp8.id);
2561 cricket::CodecParameterMap::iterator found =
2562 vp8.params.find("x-google-min-bitrate");
2563 ASSERT_TRUE(found != vp8.params.end());
2564 EXPECT_EQ(found->second, "10");
2565 found = vp8.params.find("x-google-max-quantization");
2566 ASSERT_TRUE(found != vp8.params.end());
2567 EXPECT_EQ(found->second, "40");
2568}
2569
2570TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
2571 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
2572 GetFirstVideoContent(&desc_)->description);
2573
2574 cricket::VideoCodecs codecs = vcd->codecs();
2575 codecs[0].params["x-google-min-bitrate"] = "10";
2576 vcd->set_codecs(codecs);
2577
2578 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2579 jdesc_.session_id(),
2580 jdesc_.session_version()));
2581 std::string message = webrtc::SdpSerialize(jdesc_);
2582 std::string sdp_with_fmtp = kSdpFullString;
2583 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
2584 "a=fmtp:120 x-google-min-bitrate=10\r\n",
2585 &sdp_with_fmtp);
2586 EXPECT_EQ(sdp_with_fmtp, message);
2587}
2588
2589TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) {
2590 JsepSessionDescription jdesc_with_icelite(kDummyString);
2591 std::string sdp_with_icelite = kSdpFullString;
2592 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
2593 cricket::SessionDescription* desc = jdesc_with_icelite.description();
2594 const cricket::TransportInfo* tinfo1 =
2595 desc->GetTransportInfoByName("audio_content_name");
2596 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
2597 const cricket::TransportInfo* tinfo2 =
2598 desc->GetTransportInfoByName("video_content_name");
2599 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
2600 InjectAfter(kSessionTime,
2601 "a=ice-lite\r\n",
2602 &sdp_with_icelite);
2603 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
2604 desc = jdesc_with_icelite.description();
2605 const cricket::TransportInfo* atinfo =
2606 desc->GetTransportInfoByName("audio_content_name");
2607 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
2608 const cricket::TransportInfo* vtinfo =
2609 desc->GetTransportInfoByName("video_content_name");
2610 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
2611}
2612
2613// Verifies that the candidates in the input SDP are parsed and serialized
2614// correctly in the output SDP.
2615TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
2616 std::string sdp_with_data = kSdpString;
2617 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
2618 JsepSessionDescription jdesc_output(kDummyString);
2619
2620 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2621 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
2622}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00002623
2624TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
2625 AddFingerprint();
2626 TransportInfo audio_transport_info =
2627 *(desc_.GetTransportInfoByName(kAudioContentName));
2628 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
2629 audio_transport_info.description.connection_role);
2630 audio_transport_info.description.connection_role =
2631 cricket::CONNECTIONROLE_ACTIVE;
2632
2633 TransportInfo video_transport_info =
2634 *(desc_.GetTransportInfoByName(kVideoContentName));
2635 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
2636 video_transport_info.description.connection_role);
2637 video_transport_info.description.connection_role =
2638 cricket::CONNECTIONROLE_ACTIVE;
2639
2640 desc_.RemoveTransportInfoByName(kAudioContentName);
2641 desc_.RemoveTransportInfoByName(kVideoContentName);
2642
2643 desc_.AddTransportInfo(audio_transport_info);
2644 desc_.AddTransportInfo(video_transport_info);
2645
2646 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2647 jdesc_.session_id(),
2648 jdesc_.session_version()));
2649 std::string message = webrtc::SdpSerialize(jdesc_);
2650 std::string sdp_with_dtlssetup = kSdpFullString;
2651
2652 // Fingerprint attribute is necessary to add DTLS setup attribute.
2653 InjectAfter(kAttributeIcePwdVoice,
2654 kFingerprint, &sdp_with_dtlssetup);
2655 InjectAfter(kAttributeIcePwdVideo,
2656 kFingerprint, &sdp_with_dtlssetup);
2657 // Now adding |setup| attribute.
2658 InjectAfter(kFingerprint,
2659 "a=setup:active\r\n", &sdp_with_dtlssetup);
2660 EXPECT_EQ(sdp_with_dtlssetup, message);
2661}
2662
2663TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
2664 JsepSessionDescription jdesc_with_dtlssetup(kDummyString);
2665 std::string sdp_with_dtlssetup = kSdpFullString;
2666 InjectAfter(kSessionTime,
2667 "a=setup:actpass\r\n",
2668 &sdp_with_dtlssetup);
2669 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
2670 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
2671 const cricket::TransportInfo* atinfo =
2672 desc->GetTransportInfoByName("audio_content_name");
2673 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
2674 atinfo->description.connection_role);
2675 const cricket::TransportInfo* vtinfo =
2676 desc->GetTransportInfoByName("video_content_name");
2677 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
2678 vtinfo->description.connection_role);
2679}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00002680
2681// Verifies that the order of the serialized m-lines follows the order of the
2682// ContentInfo in SessionDescription, and vise versa for deserialization.
2683TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
2684 JsepSessionDescription jdesc(kDummyString);
2685 const std::string media_content_sdps[3] = {
2686 kSdpAudioString,
2687 kSdpVideoString,
2688 kSdpSctpDataChannelString
2689 };
2690 const cricket::MediaType media_types[3] = {
2691 cricket::MEDIA_TYPE_AUDIO,
2692 cricket::MEDIA_TYPE_VIDEO,
2693 cricket::MEDIA_TYPE_DATA
2694 };
2695
2696 // Verifies all 6 permutations.
2697 for (size_t i = 0; i < 6; ++i) {
2698 size_t media_content_in_sdp[3];
2699 // The index of the first media content.
2700 media_content_in_sdp[0] = i / 2;
2701 // The index of the second media content.
2702 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
2703 // The index of the third media content.
2704 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
2705
2706 std::string sdp_string = kSdpSessionString;
2707 for (size_t i = 0; i < 3; ++i)
2708 sdp_string += media_content_sdps[media_content_in_sdp[i]];
2709
2710 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
2711 cricket::SessionDescription* desc = jdesc.description();
2712 EXPECT_EQ(3u, desc->contents().size());
2713
2714 for (size_t i = 0; i < 3; ++i) {
2715 const cricket::MediaContentDescription* mdesc =
2716 static_cast<const cricket::MediaContentDescription*>(
2717 desc->contents()[i].description);
2718 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
2719 }
2720
2721 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
2722 EXPECT_EQ(sdp_string, serialized_sdp);
2723 }
2724}