blob: a534c23920748138cb98d5eb03c3da47c0b3fb99 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 * Copyright 2011 Google Inc.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <set>
29#include <string>
30#include <vector>
31
32#include "talk/app/webrtc/jsepsessiondescription.h"
33#include "talk/app/webrtc/webrtcsdp.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000034#include "talk/media/base/constants.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000035#include "webrtc/p2p/base/constants.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000036#include "talk/session/media/mediasession.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000037#include "webrtc/base/gunit.h"
38#include "webrtc/base/logging.h"
39#include "webrtc/base/messagedigest.h"
40#include "webrtc/base/scoped_ptr.h"
41#include "webrtc/base/sslfingerprint.h"
42#include "webrtc/base/stringencode.h"
43#include "webrtc/base/stringutils.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044
45using cricket::AudioCodec;
46using cricket::AudioContentDescription;
47using cricket::Candidate;
48using cricket::ContentInfo;
49using cricket::CryptoParams;
50using cricket::ContentGroup;
51using cricket::DataCodec;
52using cricket::DataContentDescription;
53using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
54using cricket::ICE_CANDIDATE_COMPONENT_RTP;
55using cricket::kFecSsrcGroupSemantics;
56using cricket::LOCAL_PORT_TYPE;
57using cricket::NS_JINGLE_DRAFT_SCTP;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058using cricket::NS_JINGLE_RTP;
59using cricket::RtpHeaderExtension;
60using cricket::RELAY_PORT_TYPE;
61using cricket::SessionDescription;
62using cricket::StreamParams;
63using cricket::STUN_PORT_TYPE;
64using cricket::TransportDescription;
65using cricket::TransportInfo;
66using cricket::VideoCodec;
67using cricket::VideoContentDescription;
68using webrtc::IceCandidateCollection;
69using webrtc::IceCandidateInterface;
70using webrtc::JsepIceCandidate;
71using webrtc::JsepSessionDescription;
72using webrtc::SdpParseError;
73using webrtc::SessionDescriptionInterface;
74
75typedef std::vector<AudioCodec> AudioCodecs;
76typedef std::vector<Candidate> Candidates;
77
wu@webrtc.org78187522013-10-07 23:32:02 +000078static const uint32 kDefaultSctpPort = 5000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079static const char kSessionTime[] = "t=0 0\r\n";
80static const uint32 kCandidatePriority = 2130706432U; // pref = 1.0
81static const char kCandidateUfragVoice[] = "ufrag_voice";
82static const char kCandidatePwdVoice[] = "pwd_voice";
83static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
84static const char kCandidateUfragVideo[] = "ufrag_video";
85static const char kCandidatePwdVideo[] = "pwd_video";
86static const char kCandidateUfragData[] = "ufrag_data";
87static const char kCandidatePwdData[] = "pwd_data";
88static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
89static const uint32 kCandidateGeneration = 2;
90static const char kCandidateFoundation1[] = "a0+B/1";
91static const char kCandidateFoundation2[] = "a0+B/2";
92static const char kCandidateFoundation3[] = "a0+B/3";
93static const char kCandidateFoundation4[] = "a0+B/4";
94static const char kAttributeCryptoVoice[] =
95 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
96 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
97 "dummy_session_params\r\n";
98static const char kAttributeCryptoVideo[] =
99 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
100 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
101static const char kFingerprint[] = "a=fingerprint:sha-1 "
102 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n";
103static const int kExtmapId = 1;
104static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
105static const char kExtmap[] =
106 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
107static const char kExtmapWithDirectionAndAttribute[] =
108 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
109
110static const uint8 kIdentityDigest[] = {0x4A, 0xAD, 0xB9, 0xB1,
111 0x3F, 0x82, 0x18, 0x3B,
112 0x54, 0x02, 0x12, 0xDF,
113 0x3E, 0x5D, 0x49, 0x6B,
114 0x19, 0xE5, 0x7C, 0xAB};
115
lally@webrtc.org34807282015-02-24 20:19:39 +0000116static const char kDtlsSctp[] = "DTLS/SCTP";
117static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
118static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +0000119
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120struct CodecParams {
121 int max_ptime;
122 int ptime;
123 int min_ptime;
124 int sprop_stereo;
125 int stereo;
126 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000127 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000128};
129
130// Reference sdp string
131static const char kSdpFullString[] =
132 "v=0\r\n"
133 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
134 "s=-\r\n"
135 "t=0 0\r\n"
136 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
137 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
138 "c=IN IP4 74.125.127.126\r\n"
139 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
140 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
141 "generation 2\r\n"
142 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
143 "generation 2\r\n"
144 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
145 "generation 2\r\n"
146 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
147 "generation 2\r\n"
148 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
149 "raddr 192.168.1.5 rport 2346 "
150 "generation 2\r\n"
151 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
152 "raddr 192.168.1.5 rport 2348 "
153 "generation 2\r\n"
154 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
155 "a=mid:audio_content_name\r\n"
156 "a=sendrecv\r\n"
157 "a=rtcp-mux\r\n"
158 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
159 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
160 "dummy_session_params\r\n"
161 "a=rtpmap:111 opus/48000/2\r\n"
162 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000163 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000164 "a=ssrc:1 cname:stream_1_cname\r\n"
165 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
166 "a=ssrc:1 mslabel:local_stream_1\r\n"
167 "a=ssrc:1 label:audio_track_id_1\r\n"
168 "a=ssrc:4 cname:stream_2_cname\r\n"
169 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
170 "a=ssrc:4 mslabel:local_stream_2\r\n"
171 "a=ssrc:4 label:audio_track_id_2\r\n"
172 "m=video 3457 RTP/SAVPF 120\r\n"
173 "c=IN IP4 74.125.224.39\r\n"
174 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
175 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
176 "generation 2\r\n"
177 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
178 "generation 2\r\n"
179 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
180 "generation 2\r\n"
181 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
182 "generation 2\r\n"
183 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
184 "generation 2\r\n"
185 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
186 "generation 2\r\n"
187 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
188 "a=mid:video_content_name\r\n"
189 "a=sendrecv\r\n"
190 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
191 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
192 "a=rtpmap:120 VP8/90000\r\n"
193 "a=ssrc:2 cname:stream_1_cname\r\n"
194 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
195 "a=ssrc:2 mslabel:local_stream_1\r\n"
196 "a=ssrc:2 label:video_track_id_1\r\n"
197 "a=ssrc:3 cname:stream_1_cname\r\n"
198 "a=ssrc:3 msid:local_stream_1 video_track_id_2\r\n"
199 "a=ssrc:3 mslabel:local_stream_1\r\n"
200 "a=ssrc:3 label:video_track_id_2\r\n"
201 "a=ssrc-group:FEC 5 6\r\n"
202 "a=ssrc:5 cname:stream_2_cname\r\n"
203 "a=ssrc:5 msid:local_stream_2 video_track_id_3\r\n"
204 "a=ssrc:5 mslabel:local_stream_2\r\n"
205 "a=ssrc:5 label:video_track_id_3\r\n"
206 "a=ssrc:6 cname:stream_2_cname\r\n"
207 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
208 "a=ssrc:6 mslabel:local_stream_2\r\n"
209 "a=ssrc:6 label:video_track_id_3\r\n";
210
211// SDP reference string without the candidates.
212static const char kSdpString[] =
213 "v=0\r\n"
214 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
215 "s=-\r\n"
216 "t=0 0\r\n"
217 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000218 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000219 "c=IN IP4 0.0.0.0\r\n"
220 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000221 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
222 "a=mid:audio_content_name\r\n"
223 "a=sendrecv\r\n"
224 "a=rtcp-mux\r\n"
225 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
226 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
227 "dummy_session_params\r\n"
228 "a=rtpmap:111 opus/48000/2\r\n"
229 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000230 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000231 "a=ssrc:1 cname:stream_1_cname\r\n"
232 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
233 "a=ssrc:1 mslabel:local_stream_1\r\n"
234 "a=ssrc:1 label:audio_track_id_1\r\n"
235 "a=ssrc:4 cname:stream_2_cname\r\n"
236 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
237 "a=ssrc:4 mslabel:local_stream_2\r\n"
238 "a=ssrc:4 label:audio_track_id_2\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000239 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000240 "c=IN IP4 0.0.0.0\r\n"
241 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000242 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
243 "a=mid:video_content_name\r\n"
244 "a=sendrecv\r\n"
245 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
246 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
247 "a=rtpmap:120 VP8/90000\r\n"
248 "a=ssrc:2 cname:stream_1_cname\r\n"
249 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
250 "a=ssrc:2 mslabel:local_stream_1\r\n"
251 "a=ssrc:2 label:video_track_id_1\r\n"
252 "a=ssrc:3 cname:stream_1_cname\r\n"
253 "a=ssrc:3 msid:local_stream_1 video_track_id_2\r\n"
254 "a=ssrc:3 mslabel:local_stream_1\r\n"
255 "a=ssrc:3 label:video_track_id_2\r\n"
256 "a=ssrc-group:FEC 5 6\r\n"
257 "a=ssrc:5 cname:stream_2_cname\r\n"
258 "a=ssrc:5 msid:local_stream_2 video_track_id_3\r\n"
259 "a=ssrc:5 mslabel:local_stream_2\r\n"
260 "a=ssrc:5 label:video_track_id_3\r\n"
261 "a=ssrc:6 cname:stream_2_cname\r\n"
262 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
263 "a=ssrc:6 mslabel:local_stream_2\r\n"
264 "a=ssrc:6 label:video_track_id_3\r\n";
265
266static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000267 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000268 "c=IN IP4 0.0.0.0\r\n"
269 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000270 "a=ice-ufrag:ufrag_data\r\n"
271 "a=ice-pwd:pwd_data\r\n"
272 "a=mid:data_content_name\r\n"
273 "a=sendrecv\r\n"
274 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
275 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
276 "a=rtpmap:101 google-data/90000\r\n"
277 "a=ssrc:10 cname:data_channel_cname\r\n"
278 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
279 "a=ssrc:10 mslabel:data_channel\r\n"
280 "a=ssrc:10 label:data_channeld0\r\n";
281
282static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000283 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000284 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000285 "a=ice-ufrag:ufrag_data\r\n"
286 "a=ice-pwd:pwd_data\r\n"
287 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000288 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000289
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000290// draft-ietf-mmusic-sctp-sdp-12
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000291static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000292 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
293 "a=max-message-size=100000\r\n"
294 "a=sctp-port 5000\r\n"
295 "c=IN IP4 0.0.0.0\r\n"
296 "a=ice-ufrag:ufrag_data\r\n"
297 "a=ice-pwd:pwd_data\r\n"
298 "a=mid:data_content_name\r\n";
299
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000300static const char kSdpSctpDataChannelWithCandidatesString[] =
301 "m=application 2345 DTLS/SCTP 5000\r\n"
302 "c=IN IP4 74.125.127.126\r\n"
303 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
304 "generation 2\r\n"
305 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
306 "generation 2\r\n"
307 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
308 "raddr 192.168.1.5 rport 2346 "
309 "generation 2\r\n"
310 "a=ice-ufrag:ufrag_data\r\n"
311 "a=ice-pwd:pwd_data\r\n"
312 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000313 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000314
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000315static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000316 "v=0\r\n"
317 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
318 "s=-\r\n"
319 "t=0 0\r\n"
320 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000321 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000322 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000323 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000324 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000325 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000326 "a=x-google-flag:conference\r\n";
327
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000328static const char kSdpSessionString[] =
329 "v=0\r\n"
330 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
331 "s=-\r\n"
332 "t=0 0\r\n"
333 "a=msid-semantic: WMS local_stream\r\n";
334
335static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000336 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000337 "c=IN IP4 0.0.0.0\r\n"
338 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000339 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
340 "a=mid:audio_content_name\r\n"
341 "a=sendrecv\r\n"
342 "a=rtpmap:111 opus/48000/2\r\n"
343 "a=ssrc:1 cname:stream_1_cname\r\n"
344 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
345 "a=ssrc:1 mslabel:local_stream\r\n"
346 "a=ssrc:1 label:audio_track_id_1\r\n";
347
348static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000349 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000350 "c=IN IP4 0.0.0.0\r\n"
351 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000352 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
353 "a=mid:video_content_name\r\n"
354 "a=sendrecv\r\n"
355 "a=rtpmap:120 VP8/90000\r\n"
356 "a=ssrc:2 cname:stream_1_cname\r\n"
357 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
358 "a=ssrc:2 mslabel:local_stream\r\n"
359 "a=ssrc:2 label:video_track_id_1\r\n";
360
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000361
362// One candidate reference string as per W3c spec.
363// candidate:<blah> not a=candidate:<blah>CRLF
364static const char kRawCandidate[] =
365 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
366// One candidate reference string.
367static const char kSdpOneCandidate[] =
368 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
369 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000370
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000371static const char kSdpTcpActiveCandidate[] =
372 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
373 "tcptype active generation 2";
374static const char kSdpTcpPassiveCandidate[] =
375 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
376 "tcptype passive generation 2";
377static const char kSdpTcpSOCandidate[] =
378 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
379 "tcptype so generation 2";
380static const char kSdpTcpInvalidCandidate[] =
381 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
382 "tcptype invalid generation 2";
383
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000384// One candidate reference string with IPV6 address.
385static const char kRawIPV6Candidate[] =
386 "candidate:a0+B/1 1 udp 2130706432 "
387 "abcd::abcd::abcd::abcd::abcd::abcd::abcd::abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000388
389// One candidate reference string.
390static const char kSdpOneCandidateOldFormat[] =
391 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
392 " eth0 username user_rtp password password_rtp generation 2\r\n";
393
394// Session id and version
395static const char kSessionId[] = "18446744069414584320";
396static const char kSessionVersion[] = "18446462598732840960";
397
398// Ice options
399static const char kIceOption1[] = "iceoption1";
400static const char kIceOption2[] = "iceoption2";
401static const char kIceOption3[] = "iceoption3";
402
403// Content name
404static const char kAudioContentName[] = "audio_content_name";
405static const char kVideoContentName[] = "video_content_name";
406static const char kDataContentName[] = "data_content_name";
407
408// MediaStream 1
409static const char kStreamLabel1[] = "local_stream_1";
410static const char kStream1Cname[] = "stream_1_cname";
411static const char kAudioTrackId1[] = "audio_track_id_1";
412static const uint32 kAudioTrack1Ssrc = 1;
413static const char kVideoTrackId1[] = "video_track_id_1";
414static const uint32 kVideoTrack1Ssrc = 2;
415static const char kVideoTrackId2[] = "video_track_id_2";
416static const uint32 kVideoTrack2Ssrc = 3;
417
418// MediaStream 2
419static const char kStreamLabel2[] = "local_stream_2";
420static const char kStream2Cname[] = "stream_2_cname";
421static const char kAudioTrackId2[] = "audio_track_id_2";
422static const uint32 kAudioTrack2Ssrc = 4;
423static const char kVideoTrackId3[] = "video_track_id_3";
424static const uint32 kVideoTrack3Ssrc = 5;
425static const uint32 kVideoTrack4Ssrc = 6;
426
427// DataChannel
428static const char kDataChannelLabel[] = "data_channel";
429static const char kDataChannelMsid[] = "data_channeld0";
430static const char kDataChannelCname[] = "data_channel_cname";
431static const uint32 kDataChannelSsrc = 10;
432
433// Candidate
434static const char kDummyMid[] = "dummy_mid";
435static const int kDummyIndex = 123;
436
437// Misc
438static const char kDummyString[] = "dummy";
439
440// Helper functions
441
442static bool SdpDeserialize(const std::string& message,
443 JsepSessionDescription* jdesc) {
444 return webrtc::SdpDeserialize(message, jdesc, NULL);
445}
446
447static bool SdpDeserializeCandidate(const std::string& message,
448 JsepIceCandidate* candidate) {
449 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
450}
451
452// Add some extra |newlines| to the |message| after |line|.
453static void InjectAfter(const std::string& line,
454 const std::string& newlines,
455 std::string* message) {
456 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000457 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000458 tmp.c_str(), tmp.length(), message);
459}
460
461static void Replace(const std::string& line,
462 const std::string& newlines,
463 std::string* message) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000464 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000465 newlines.c_str(), newlines.length(), message);
466}
467
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000468// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
469// message.
470static void ExpectParseFailure(const std::string& bad_sdp,
471 const std::string& bad_part) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000472 JsepSessionDescription desc(kDummyString);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000473 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000474 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000475 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000476 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
477}
478
479// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
480static void ExpectParseFailure(const char* good_part, const char* bad_part) {
481 std::string bad_sdp = kSdpFullString;
482 Replace(good_part, bad_part, &bad_sdp);
483 ExpectParseFailure(bad_sdp, bad_part);
484}
485
486// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
487static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
488 const std::string& newlines,
489 const std::string& bad_part) {
490 std::string bad_sdp = kSdpFullString;
491 InjectAfter(injectpoint, newlines, &bad_sdp);
492 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000493}
494
495static void ReplaceDirection(cricket::MediaContentDirection direction,
496 std::string* message) {
497 std::string new_direction;
498 switch (direction) {
499 case cricket::MD_INACTIVE:
500 new_direction = "a=inactive";
501 break;
502 case cricket::MD_SENDONLY:
503 new_direction = "a=sendonly";
504 break;
505 case cricket::MD_RECVONLY:
506 new_direction = "a=recvonly";
507 break;
508 case cricket::MD_SENDRECV:
509 default:
510 new_direction = "a=sendrecv";
511 break;
512 }
513 Replace("a=sendrecv", new_direction, message);
514}
515
516static void ReplaceRejected(bool audio_rejected, bool video_rejected,
517 std::string* message) {
518 if (audio_rejected) {
519 Replace("m=audio 2345", "m=audio 0", message);
520 }
521 if (video_rejected) {
522 Replace("m=video 3457", "m=video 0", message);
523 }
524}
525
526// WebRtcSdpTest
527
528class WebRtcSdpTest : public testing::Test {
529 public:
530 WebRtcSdpTest()
531 : jdesc_(kDummyString) {
532 // AudioContentDescription
533 audio_desc_ = CreateAudioContentDescription();
534 AudioCodec opus(111, "opus", 48000, 0, 2, 3);
535 audio_desc_->AddCodec(opus);
536 audio_desc_->AddCodec(AudioCodec(103, "ISAC", 16000, 32000, 1, 2));
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000537 audio_desc_->AddCodec(AudioCodec(104, "ISAC", 32000, 56000, 1, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000538 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
539
540 // VideoContentDescription
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000541 rtc::scoped_ptr<VideoContentDescription> video(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000542 new VideoContentDescription());
543 video_desc_ = video.get();
544 StreamParams video_stream1;
545 video_stream1.id = kVideoTrackId1;
546 video_stream1.cname = kStream1Cname;
547 video_stream1.sync_label = kStreamLabel1;
548 video_stream1.ssrcs.push_back(kVideoTrack1Ssrc);
549 video->AddStream(video_stream1);
550 StreamParams video_stream2;
551 video_stream2.id = kVideoTrackId2;
552 video_stream2.cname = kStream1Cname;
553 video_stream2.sync_label = kStreamLabel1;
554 video_stream2.ssrcs.push_back(kVideoTrack2Ssrc);
555 video->AddStream(video_stream2);
556 StreamParams video_stream3;
557 video_stream3.id = kVideoTrackId3;
558 video_stream3.cname = kStream2Cname;
559 video_stream3.sync_label = kStreamLabel2;
560 video_stream3.ssrcs.push_back(kVideoTrack3Ssrc);
561 video_stream3.ssrcs.push_back(kVideoTrack4Ssrc);
562 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream3.ssrcs);
563 video_stream3.ssrc_groups.push_back(ssrc_group);
564 video->AddStream(video_stream3);
565 video->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
566 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
567 video->set_protocol(cricket::kMediaProtocolSavpf);
568 video->AddCodec(VideoCodec(
569 120,
570 JsepSessionDescription::kDefaultVideoCodecName,
571 JsepSessionDescription::kMaxVideoCodecWidth,
572 JsepSessionDescription::kMaxVideoCodecHeight,
573 JsepSessionDescription::kDefaultVideoCodecFramerate,
574 JsepSessionDescription::kDefaultVideoCodecPreference));
575
576 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP,
577 video.release());
578
579 // TransportInfo
580 EXPECT_TRUE(desc_.AddTransportInfo(
581 TransportInfo(kAudioContentName,
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700582 TransportDescription(kCandidateUfragVoice,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000583 kCandidatePwdVoice))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000584 EXPECT_TRUE(desc_.AddTransportInfo(
585 TransportInfo(kVideoContentName,
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700586 TransportDescription(kCandidateUfragVideo,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000587 kCandidatePwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000588
589 // v4 host
590 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000591 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000592 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000593 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
594 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000595 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000596 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000597 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
598 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000599 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000600 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000601 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
602 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000603 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000604 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000605 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
606 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000607
608 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000609 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000610 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
611 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000612 cricket::LOCAL_PORT_TYPE,
613 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000614 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000615 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
616 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000617 cricket::LOCAL_PORT_TYPE,
618 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000619 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000620 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
621 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000622 cricket::LOCAL_PORT_TYPE,
623 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000624 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000625 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
626 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000627 cricket::LOCAL_PORT_TYPE,
628 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000629
630 // stun
631 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000632 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
633 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000634 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
635 address_stun, kCandidatePriority, "", "",
636 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000637 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000638 candidate9.set_related_address(rel_address_stun);
639
640 address_stun.SetPort(port_stun++);
641 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000642 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
643 address_stun, kCandidatePriority, "", "",
644 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000645 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000646 candidate10.set_related_address(rel_address_stun);
647
648 // relay
649 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000650 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000651 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
652 address_relay, kCandidatePriority, "", "",
653 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000654 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000655 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000656 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
657 address_relay, kCandidatePriority, "", "",
658 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000659 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000660
661 // voice
662 candidates_.push_back(candidate1);
663 candidates_.push_back(candidate2);
664 candidates_.push_back(candidate5);
665 candidates_.push_back(candidate6);
666 candidates_.push_back(candidate9);
667 candidates_.push_back(candidate10);
668
669 // video
670 candidates_.push_back(candidate3);
671 candidates_.push_back(candidate4);
672 candidates_.push_back(candidate7);
673 candidates_.push_back(candidate8);
674 candidates_.push_back(candidate11);
675 candidates_.push_back(candidate12);
676
677 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"),
678 0, candidate1));
679
680 // Set up JsepSessionDescription.
681 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
682 std::string mline_id;
683 int mline_index = 0;
684 for (size_t i = 0; i< candidates_.size(); ++i) {
685 // In this test, the audio m line index will be 0, and the video m line
686 // will be 1.
687 bool is_video = (i > 5);
688 mline_id = is_video ? "video_content_name" : "audio_content_name";
689 mline_index = is_video ? 1 : 0;
690 JsepIceCandidate jice(mline_id,
691 mline_index,
692 candidates_.at(i));
693 jdesc_.AddCandidate(&jice);
694 }
695 }
696
697 AudioContentDescription* CreateAudioContentDescription() {
698 AudioContentDescription* audio = new AudioContentDescription();
699 audio->set_rtcp_mux(true);
700 StreamParams audio_stream1;
701 audio_stream1.id = kAudioTrackId1;
702 audio_stream1.cname = kStream1Cname;
703 audio_stream1.sync_label = kStreamLabel1;
704 audio_stream1.ssrcs.push_back(kAudioTrack1Ssrc);
705 audio->AddStream(audio_stream1);
706 StreamParams audio_stream2;
707 audio_stream2.id = kAudioTrackId2;
708 audio_stream2.cname = kStream2Cname;
709 audio_stream2.sync_label = kStreamLabel2;
710 audio_stream2.ssrcs.push_back(kAudioTrack2Ssrc);
711 audio->AddStream(audio_stream2);
712 audio->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_32",
713 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
714 "dummy_session_params"));
715 audio->set_protocol(cricket::kMediaProtocolSavpf);
716 return audio;
717 }
718
719 template <class MCD>
720 void CompareMediaContentDescription(const MCD* cd1,
721 const MCD* cd2) {
722 // type
723 EXPECT_EQ(cd1->type(), cd1->type());
724
725 // content direction
726 EXPECT_EQ(cd1->direction(), cd2->direction());
727
728 // rtcp_mux
729 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
730
731 // cryptos
732 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
733 if (cd1->cryptos().size() != cd2->cryptos().size()) {
734 ADD_FAILURE();
735 return;
736 }
737 for (size_t i = 0; i< cd1->cryptos().size(); ++i) {
738 const CryptoParams c1 = cd1->cryptos().at(i);
739 const CryptoParams c2 = cd2->cryptos().at(i);
740 EXPECT_TRUE(c1.Matches(c2));
741 EXPECT_EQ(c1.key_params, c2.key_params);
742 EXPECT_EQ(c1.session_params, c2.session_params);
743 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +0000744
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000745 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +0000746 // Use an equivalence class here, for old and new versions of the
747 // protocol description.
748 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:35 +0000749 || cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp
750 || cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
751 const bool cd2_is_also_dtls_sctp =
lally@webrtc.orgd7b61652015-02-24 20:18:55 +0000752 cd2->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:35 +0000753 || cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp
754 || cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
755 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +0000756 } else {
757 EXPECT_EQ(cd1->protocol(), cd2->protocol());
758 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000759
760 // codecs
761 EXPECT_EQ(cd1->codecs(), cd2->codecs());
762
763 // bandwidth
764 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
765
766 // streams
767 EXPECT_EQ(cd1->streams(), cd2->streams());
768
769 // extmap
770 ASSERT_EQ(cd1->rtp_header_extensions().size(),
771 cd2->rtp_header_extensions().size());
772 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) {
773 const RtpHeaderExtension ext1 = cd1->rtp_header_extensions().at(i);
774 const RtpHeaderExtension ext2 = cd2->rtp_header_extensions().at(i);
775 EXPECT_EQ(ext1.uri, ext2.uri);
776 EXPECT_EQ(ext1.id, ext2.id);
777 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000778 }
779
780
781 void CompareSessionDescription(const SessionDescription& desc1,
782 const SessionDescription& desc2) {
783 // Compare content descriptions.
784 if (desc1.contents().size() != desc2.contents().size()) {
785 ADD_FAILURE();
786 return;
787 }
788 for (size_t i = 0 ; i < desc1.contents().size(); ++i) {
789 const cricket::ContentInfo& c1 = desc1.contents().at(i);
790 const cricket::ContentInfo& c2 = desc2.contents().at(i);
791 // content name
792 EXPECT_EQ(c1.name, c2.name);
793 // content type
794 // Note, ASSERT will return from the function, but will not stop the test.
795 ASSERT_EQ(c1.type, c2.type);
796
797 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
798 if (IsAudioContent(&c1)) {
799 const AudioContentDescription* acd1 =
800 static_cast<const AudioContentDescription*>(c1.description);
801 const AudioContentDescription* acd2 =
802 static_cast<const AudioContentDescription*>(c2.description);
803 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
804 }
805
806 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
807 if (IsVideoContent(&c1)) {
808 const VideoContentDescription* vcd1 =
809 static_cast<const VideoContentDescription*>(c1.description);
810 const VideoContentDescription* vcd2 =
811 static_cast<const VideoContentDescription*>(c2.description);
812 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
813 }
814
815 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
816 if (IsDataContent(&c1)) {
817 const DataContentDescription* dcd1 =
818 static_cast<const DataContentDescription*>(c1.description);
819 const DataContentDescription* dcd2 =
820 static_cast<const DataContentDescription*>(c2.description);
821 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
822 }
823 }
824
825 // group
826 const cricket::ContentGroups groups1 = desc1.groups();
827 const cricket::ContentGroups groups2 = desc2.groups();
828 EXPECT_EQ(groups1.size(), groups1.size());
829 if (groups1.size() != groups2.size()) {
830 ADD_FAILURE();
831 return;
832 }
833 for (size_t i = 0; i < groups1.size(); ++i) {
834 const cricket::ContentGroup group1 = groups1.at(i);
835 const cricket::ContentGroup group2 = groups2.at(i);
836 EXPECT_EQ(group1.semantics(), group2.semantics());
837 const cricket::ContentNames names1 = group1.content_names();
838 const cricket::ContentNames names2 = group2.content_names();
839 EXPECT_EQ(names1.size(), names2.size());
840 if (names1.size() != names2.size()) {
841 ADD_FAILURE();
842 return;
843 }
844 cricket::ContentNames::const_iterator iter1 = names1.begin();
845 cricket::ContentNames::const_iterator iter2 = names2.begin();
846 while (iter1 != names1.end()) {
847 EXPECT_EQ(*iter1++, *iter2++);
848 }
849 }
850
851 // transport info
852 const cricket::TransportInfos transports1 = desc1.transport_infos();
853 const cricket::TransportInfos transports2 = desc2.transport_infos();
854 EXPECT_EQ(transports1.size(), transports2.size());
855 if (transports1.size() != transports2.size()) {
856 ADD_FAILURE();
857 return;
858 }
859 for (size_t i = 0; i < transports1.size(); ++i) {
860 const cricket::TransportInfo transport1 = transports1.at(i);
861 const cricket::TransportInfo transport2 = transports2.at(i);
862 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000863 EXPECT_EQ(transport1.description.ice_ufrag,
864 transport2.description.ice_ufrag);
865 EXPECT_EQ(transport1.description.ice_pwd,
866 transport2.description.ice_pwd);
867 if (transport1.description.identity_fingerprint) {
868 EXPECT_EQ(*transport1.description.identity_fingerprint,
869 *transport2.description.identity_fingerprint);
870 } else {
871 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
872 transport2.description.identity_fingerprint.get());
873 }
874 EXPECT_EQ(transport1.description.transport_options,
875 transport2.description.transport_options);
876 EXPECT_TRUE(CompareCandidates(transport1.description.candidates,
877 transport2.description.candidates));
878 }
879 }
880
881 bool CompareCandidates(const Candidates& cs1, const Candidates& cs2) {
882 EXPECT_EQ(cs1.size(), cs2.size());
883 if (cs1.size() != cs2.size())
884 return false;
885 for (size_t i = 0; i< cs1.size(); ++i) {
886 const Candidate c1 = cs1.at(i);
887 const Candidate c2 = cs2.at(i);
888 EXPECT_TRUE(c1.IsEquivalent(c2));
889 }
890 return true;
891 }
892
893 bool CompareSessionDescription(
894 const JsepSessionDescription& desc1,
895 const JsepSessionDescription& desc2) {
896 EXPECT_EQ(desc1.session_id(), desc2.session_id());
897 EXPECT_EQ(desc1.session_version(), desc2.session_version());
898 CompareSessionDescription(*desc1.description(), *desc2.description());
899 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
900 return false;
901 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
902 const IceCandidateCollection* cc1 = desc1.candidates(i);
903 const IceCandidateCollection* cc2 = desc2.candidates(i);
904 if (cc1->count() != cc2->count())
905 return false;
906 for (size_t j = 0; j < cc1->count(); ++j) {
907 const IceCandidateInterface* c1 = cc1->at(j);
908 const IceCandidateInterface* c2 = cc2->at(j);
909 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
910 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
911 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
912 }
913 }
914 return true;
915 }
916
917 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
918 // them with invalid keywords so that the parser will just ignore them.
919 bool RemoveCandidateUfragPwd(std::string* sdp) {
920 const char ice_ufrag[] = "a=ice-ufrag";
921 const char ice_ufragx[] = "a=xice-ufrag";
922 const char ice_pwd[] = "a=ice-pwd";
923 const char ice_pwdx[] = "a=xice-pwd";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000924 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000925 ice_ufragx, strlen(ice_ufragx), sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000926 rtc::replace_substrs(ice_pwd, strlen(ice_pwd),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000927 ice_pwdx, strlen(ice_pwdx), sdp);
928 return true;
929 }
930
931 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
932 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, int mline_index,
933 const std::string& ufrag, const std::string& pwd) {
934 std::string content_name;
935 if (mline_index == 0) {
936 content_name = kAudioContentName;
937 } else if (mline_index == 1) {
938 content_name = kVideoContentName;
939 } else {
940 ASSERT(false);
941 }
942 TransportInfo transport_info(
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700943 content_name, TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000944 SessionDescription* desc =
945 const_cast<SessionDescription*>(jdesc->description());
946 desc->RemoveTransportInfoByName(content_name);
947 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
948 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
949 const IceCandidateCollection* cc = jdesc_.candidates(i);
950 for (size_t j = 0; j < cc->count(); ++j) {
951 if (cc->at(j)->sdp_mline_index() == mline_index) {
952 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(
953 ufrag);
954 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(
955 pwd);
956 }
957 }
958 }
959 return true;
960 }
961
962 void AddIceOptions(const std::string& content_name,
963 const std::vector<std::string>& transport_options) {
964 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
965 cricket::TransportInfo transport_info =
966 *(desc_.GetTransportInfoByName(content_name));
967 desc_.RemoveTransportInfoByName(content_name);
968 transport_info.description.transport_options = transport_options;
969 desc_.AddTransportInfo(transport_info);
970 }
971
972 void AddFingerprint() {
973 desc_.RemoveTransportInfoByName(kAudioContentName);
974 desc_.RemoveTransportInfoByName(kVideoContentName);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000975 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000976 kIdentityDigest,
977 sizeof(kIdentityDigest));
978 EXPECT_TRUE(desc_.AddTransportInfo(
979 TransportInfo(kAudioContentName,
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700980 TransportDescription(std::vector<std::string>(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000981 kCandidateUfragVoice,
982 kCandidatePwdVoice,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000983 cricket::ICEMODE_FULL,
984 cricket::CONNECTIONROLE_NONE,
985 &fingerprint, Candidates()))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000986 EXPECT_TRUE(desc_.AddTransportInfo(
987 TransportInfo(kVideoContentName,
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700988 TransportDescription(std::vector<std::string>(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000989 kCandidateUfragVideo,
990 kCandidatePwdVideo,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000991 cricket::ICEMODE_FULL,
992 cricket::CONNECTIONROLE_NONE,
993 &fingerprint, Candidates()))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000994 }
995
996 void AddExtmap() {
997 audio_desc_ = static_cast<AudioContentDescription*>(
998 audio_desc_->Copy());
999 video_desc_ = static_cast<VideoContentDescription*>(
1000 video_desc_->Copy());
1001 audio_desc_->AddRtpHeaderExtension(
1002 RtpHeaderExtension(kExtmapUri, kExtmapId));
1003 video_desc_->AddRtpHeaderExtension(
1004 RtpHeaderExtension(kExtmapUri, kExtmapId));
1005 desc_.RemoveContentByName(kAudioContentName);
1006 desc_.RemoveContentByName(kVideoContentName);
1007 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1008 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1009 }
1010
1011 void RemoveCryptos() {
1012 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1013 video_desc_->set_cryptos(std::vector<CryptoParams>());
1014 }
1015
1016 bool TestSerializeDirection(cricket::MediaContentDirection direction) {
1017 audio_desc_->set_direction(direction);
1018 video_desc_->set_direction(direction);
1019 std::string new_sdp = kSdpFullString;
1020 ReplaceDirection(direction, &new_sdp);
1021
1022 if (!jdesc_.Initialize(desc_.Copy(),
1023 jdesc_.session_id(),
1024 jdesc_.session_version())) {
1025 return false;
1026 }
1027 std::string message = webrtc::SdpSerialize(jdesc_);
1028 EXPECT_EQ(new_sdp, message);
1029 return true;
1030 }
1031
1032 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
1033 audio_desc_ = static_cast<AudioContentDescription*>(
1034 audio_desc_->Copy());
1035 video_desc_ = static_cast<VideoContentDescription*>(
1036 video_desc_->Copy());
1037 desc_.RemoveContentByName(kAudioContentName);
1038 desc_.RemoveContentByName(kVideoContentName);
1039 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1040 audio_desc_);
1041 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1042 video_desc_);
1043 std::string new_sdp = kSdpFullString;
1044 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1045
1046 if (!jdesc_.Initialize(desc_.Copy(),
1047 jdesc_.session_id(),
1048 jdesc_.session_version())) {
1049 return false;
1050 }
1051 std::string message = webrtc::SdpSerialize(jdesc_);
1052 EXPECT_EQ(new_sdp, message);
1053 return true;
1054 }
1055
1056 void AddSctpDataChannel() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001057 rtc::scoped_ptr<DataContentDescription> data(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001058 new DataContentDescription());
1059 data_desc_ = data.get();
1060 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
wu@webrtc.org78187522013-10-07 23:32:02 +00001061 DataCodec codec(cricket::kGoogleSctpDataCodecId,
1062 cricket::kGoogleSctpDataCodecName, 0);
1063 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1064 data_desc_->AddCodec(codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001065 desc_.AddContent(kDataContentName, NS_JINGLE_DRAFT_SCTP, data.release());
1066 EXPECT_TRUE(desc_.AddTransportInfo(
1067 TransportInfo(kDataContentName,
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001068 TransportDescription(kCandidateUfragData,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001069 kCandidatePwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001070 }
1071
1072 void AddRtpDataChannel() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001073 rtc::scoped_ptr<DataContentDescription> data(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001074 new DataContentDescription());
1075 data_desc_ = data.get();
1076
1077 data_desc_->AddCodec(DataCodec(101, "google-data", 1));
1078 StreamParams data_stream;
1079 data_stream.id = kDataChannelMsid;
1080 data_stream.cname = kDataChannelCname;
1081 data_stream.sync_label = kDataChannelLabel;
1082 data_stream.ssrcs.push_back(kDataChannelSsrc);
1083 data_desc_->AddStream(data_stream);
1084 data_desc_->AddCrypto(CryptoParams(
1085 1, "AES_CM_128_HMAC_SHA1_80",
1086 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
1087 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
1088 desc_.AddContent(kDataContentName, NS_JINGLE_RTP, data.release());
1089 EXPECT_TRUE(desc_.AddTransportInfo(
1090 TransportInfo(kDataContentName,
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001091 TransportDescription(kCandidateUfragData,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001092 kCandidatePwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001093 }
1094
1095 bool TestDeserializeDirection(cricket::MediaContentDirection direction) {
1096 std::string new_sdp = kSdpFullString;
1097 ReplaceDirection(direction, &new_sdp);
1098 JsepSessionDescription new_jdesc(kDummyString);
1099
1100 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1101
1102 audio_desc_->set_direction(direction);
1103 video_desc_->set_direction(direction);
1104 if (!jdesc_.Initialize(desc_.Copy(),
1105 jdesc_.session_id(),
1106 jdesc_.session_version())) {
1107 return false;
1108 }
1109 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1110 return true;
1111 }
1112
1113 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
1114 std::string new_sdp = kSdpFullString;
1115 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1116 JsepSessionDescription new_jdesc(JsepSessionDescription::kOffer);
1117
1118 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1119 audio_desc_ = static_cast<AudioContentDescription*>(
1120 audio_desc_->Copy());
1121 video_desc_ = static_cast<VideoContentDescription*>(
1122 video_desc_->Copy());
1123 desc_.RemoveContentByName(kAudioContentName);
1124 desc_.RemoveContentByName(kVideoContentName);
1125 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1126 audio_desc_);
1127 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1128 video_desc_);
1129 if (!jdesc_.Initialize(desc_.Copy(),
1130 jdesc_.session_id(),
1131 jdesc_.session_version())) {
1132 return false;
1133 }
1134 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1135 return true;
1136 }
1137
1138 void TestDeserializeExtmap(bool session_level, bool media_level) {
1139 AddExtmap();
1140 JsepSessionDescription new_jdesc("dummy");
1141 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1142 jdesc_.session_id(),
1143 jdesc_.session_version()));
1144 JsepSessionDescription jdesc_with_extmap("dummy");
1145 std::string sdp_with_extmap = kSdpString;
1146 if (session_level) {
1147 InjectAfter(kSessionTime, kExtmapWithDirectionAndAttribute,
1148 &sdp_with_extmap);
1149 }
1150 if (media_level) {
1151 InjectAfter(kAttributeIcePwdVoice, kExtmapWithDirectionAndAttribute,
1152 &sdp_with_extmap);
1153 InjectAfter(kAttributeIcePwdVideo, kExtmapWithDirectionAndAttribute,
1154 &sdp_with_extmap);
1155 }
1156 // The extmap can't be present at the same time in both session level and
1157 // media level.
1158 if (session_level && media_level) {
1159 SdpParseError error;
1160 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap,
1161 &jdesc_with_extmap, &error));
1162 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1163 } else {
1164 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1165 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1166 }
1167 }
1168
1169 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
1170 const std::string& name, int expected_value) {
1171 cricket::CodecParameterMap::const_iterator found = params.find(name);
1172 ASSERT_TRUE(found != params.end());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001173 EXPECT_EQ(found->second, rtc::ToString<int>(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001174 }
1175
1176 void TestDeserializeCodecParams(const CodecParams& params,
1177 JsepSessionDescription* jdesc_output) {
1178 std::string sdp =
1179 "v=0\r\n"
1180 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1181 "s=-\r\n"
1182 "t=0 0\r\n"
1183 // Include semantics for WebRTC Media Streams since it is supported by
1184 // this parser, and will be added to the SDP when serializing a session
1185 // description.
1186 "a=msid-semantic: WMS\r\n"
1187 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001188 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001189 // Pltype 111 listed before 103 and 104 in the map.
1190 "a=rtpmap:111 opus/48000/2\r\n"
1191 // Pltype 103 listed before 104.
1192 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001193 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001194 "a=fmtp:111 0-15,66,70\r\n"
1195 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001196 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001197 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001198 << "; sprop-stereo=" << params.sprop_stereo
1199 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001200 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001201 << "a=ptime:" << params.ptime << "\r\n"
1202 << "a=maxptime:" << params.max_ptime << "\r\n";
1203 sdp += os.str();
1204
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001205 os.clear();
1206 os.str("");
1207 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001208 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001209 << "a=rtpmap:99 VP8/90000\r\n"
1210 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001211 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001212 sdp += os.str();
1213
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001214 // Deserialize
1215 SdpParseError error;
1216 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1217
1218 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1219 ASSERT_TRUE(ac != NULL);
1220 const AudioContentDescription* acd =
1221 static_cast<const AudioContentDescription*>(ac->description);
1222 ASSERT_FALSE(acd->codecs().empty());
1223 cricket::AudioCodec opus = acd->codecs()[0];
1224 EXPECT_EQ("opus", opus.name);
1225 EXPECT_EQ(111, opus.id);
1226 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1227 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1228 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1229 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001230 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1231 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001232 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1233 cricket::AudioCodec codec = acd->codecs()[i];
1234 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1235 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
1236 if (codec.name == "ISAC") {
1237 if (codec.clockrate == 16000) {
1238 EXPECT_EQ(32000, codec.bitrate);
1239 } else {
1240 EXPECT_EQ(56000, codec.bitrate);
1241 }
1242 }
1243 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001244
1245 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1246 ASSERT_TRUE(vc != NULL);
1247 const VideoContentDescription* vcd =
1248 static_cast<const VideoContentDescription*>(vc->description);
1249 ASSERT_FALSE(vcd->codecs().empty());
1250 cricket::VideoCodec vp8 = vcd->codecs()[0];
1251 EXPECT_EQ("VP8", vp8.name);
1252 EXPECT_EQ(99, vp8.id);
1253 cricket::VideoCodec rtx = vcd->codecs()[1];
1254 EXPECT_EQ("RTX", rtx.name);
1255 EXPECT_EQ(95, rtx.id);
1256 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001257 }
1258
1259 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1260 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001261 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001262 "v=0\r\n"
1263 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1264 "s=-\r\n"
1265 "t=0 0\r\n"
1266 // Include semantics for WebRTC Media Streams since it is supported by
1267 // this parser, and will be added to the SDP when serializing a session
1268 // description.
1269 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001270 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001271 "a=rtpmap:111 opus/48000/2\r\n";
1272 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001273 "m=video 3457 RTP/SAVPF 101\r\n"
1274 "a=rtpmap:101 VP8/90000\r\n"
1275 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001276 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001277 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001278 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001279 os << sdp_session_and_audio;
1280 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
1281 os << sdp_video;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001282 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001283 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001284 // Deserialize
1285 SdpParseError error;
1286 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1287 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1288 ASSERT_TRUE(ac != NULL);
1289 const AudioContentDescription* acd =
1290 static_cast<const AudioContentDescription*>(ac->description);
1291 ASSERT_FALSE(acd->codecs().empty());
1292 cricket::AudioCodec opus = acd->codecs()[0];
1293 EXPECT_EQ(111, opus.id);
1294 EXPECT_TRUE(opus.HasFeedbackParam(
1295 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1296 cricket::kParamValueEmpty)));
1297
1298 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1299 ASSERT_TRUE(vc != NULL);
1300 const VideoContentDescription* vcd =
1301 static_cast<const VideoContentDescription*>(vc->description);
1302 ASSERT_FALSE(vcd->codecs().empty());
1303 cricket::VideoCodec vp8 = vcd->codecs()[0];
1304 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1305 vp8.name.c_str());
1306 EXPECT_EQ(101, vp8.id);
1307 EXPECT_TRUE(vp8.HasFeedbackParam(
1308 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1309 cricket::kParamValueEmpty)));
1310 EXPECT_TRUE(vp8.HasFeedbackParam(
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001311 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1312 cricket::kRtcpFbNackParamPli)));
1313 EXPECT_TRUE(vp8.HasFeedbackParam(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001314 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
1315 cricket::kParamValueEmpty)));
1316 EXPECT_TRUE(vp8.HasFeedbackParam(
1317 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
1318 cricket::kRtcpFbCcmParamFir)));
1319 }
1320
1321 // Two SDP messages can mean the same thing but be different strings, e.g.
1322 // some of the lines can be serialized in different order.
1323 // However, a deserialized description can be compared field by field and has
1324 // no order. If deserializer has already been tested, serializing then
1325 // deserializing and comparing JsepSessionDescription will test
1326 // the serializer sufficiently.
1327 void TestSerialize(const JsepSessionDescription& jdesc) {
1328 std::string message = webrtc::SdpSerialize(jdesc);
1329 JsepSessionDescription jdesc_output_des(kDummyString);
1330 SdpParseError error;
1331 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1332 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1333 }
1334
1335 protected:
1336 SessionDescription desc_;
1337 AudioContentDescription* audio_desc_;
1338 VideoContentDescription* video_desc_;
1339 DataContentDescription* data_desc_;
1340 Candidates candidates_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001341 rtc::scoped_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001342 JsepSessionDescription jdesc_;
1343};
1344
1345void TestMismatch(const std::string& string1, const std::string& string2) {
1346 int position = 0;
1347 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1348 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001349 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001350 break;
1351 }
1352 }
1353 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1354 << " character\n"
1355 << " 1: " << string1.substr(position, 20) << "\n"
1356 << " 2: " << string2.substr(position, 20) << "\n";
1357}
1358
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001359TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1360 // SessionDescription with desc and candidates.
1361 std::string message = webrtc::SdpSerialize(jdesc_);
1362 TestMismatch(std::string(kSdpFullString), message);
1363}
1364
1365TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
1366 JsepSessionDescription jdesc_empty(kDummyString);
1367 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
1368}
1369
guoweis@webrtc.org57ac2c82015-02-06 00:45:13 +00001370// This tests serialization of SDP with only IPv6 candidates and verifies that
1371// IPv6 is used as default address in c line according to preference.
1372TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIPv6Only) {
1373 // Only test 1 m line.
1374 desc_.RemoveContentByName("video_content_name");
1375 // Stun has a high preference than local host.
1376 cricket::Candidate candidate1(
1377 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1378 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1379 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1380 cricket::Candidate candidate2(
1381 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1382 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
1383 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1384 JsepSessionDescription jdesc(kDummyString);
1385 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1386
1387 // Only add the candidates to audio m line.
1388 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1389 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1390 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1391 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
1392 std::string message = webrtc::SdpSerialize(jdesc);
1393
1394 // Audio line should have a c line like this one.
1395 EXPECT_NE(message.find("c=IN IP6 ::1"), std::string::npos);
1396 // Shouldn't have a IP4 c line.
1397 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
1398}
1399
1400// This tests serialization of SDP with both IPv4 and IPv6 candidates and
1401// verifies that IPv4 is used as default address in c line even if the
1402// preference of IPv4 is lower.
1403TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothIPFamilies) {
1404 // Only test 1 m line.
1405 desc_.RemoveContentByName("video_content_name");
1406 cricket::Candidate candidate_v4(
1407 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1408 rtc::SocketAddress("192.168.1.5", 1234), kCandidatePriority, "", "",
1409 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1410 cricket::Candidate candidate_v6(
1411 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1412 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1413 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1414 JsepSessionDescription jdesc(kDummyString);
1415 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1416
1417 // Only add the candidates to audio m line.
1418 JsepIceCandidate jice_v4("audio_content_name", 0, candidate_v4);
1419 JsepIceCandidate jice_v6("audio_content_name", 0, candidate_v6);
1420 ASSERT_TRUE(jdesc.AddCandidate(&jice_v4));
1421 ASSERT_TRUE(jdesc.AddCandidate(&jice_v6));
1422 std::string message = webrtc::SdpSerialize(jdesc);
1423
1424 // Audio line should have a c line like this one.
1425 EXPECT_NE(message.find("c=IN IP4 192.168.1.5"), std::string::npos);
1426 // Shouldn't have a IP6 c line.
1427 EXPECT_EQ(message.find("c=IN IP6"), std::string::npos);
1428}
1429
1430// This tests serialization of SDP with both UDP and TCP candidates and
1431// verifies that UDP is used as default address in c line even if the
1432// preference of UDP is lower.
1433TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothProtocols) {
1434 // Only test 1 m line.
1435 desc_.RemoveContentByName("video_content_name");
1436 // Stun has a high preference than local host.
1437 cricket::Candidate candidate1(
1438 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1439 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1440 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1441 cricket::Candidate candidate2(
1442 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1443 rtc::SocketAddress("fe80::1234:5678:abcd:ef12", 1235), kCandidatePriority,
1444 "", "", cricket::LOCAL_PORT_TYPE, kCandidateGeneration,
1445 kCandidateFoundation1);
1446 JsepSessionDescription jdesc(kDummyString);
1447 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1448
1449 // Only add the candidates to audio m line.
1450 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1451 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1452 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1453 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
1454 std::string message = webrtc::SdpSerialize(jdesc);
1455
1456 // Audio line should have a c line like this one.
1457 EXPECT_NE(message.find("c=IN IP6 fe80::1234:5678:abcd:ef12"),
1458 std::string::npos);
1459 // Shouldn't have a IP4 c line.
1460 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
1461}
1462
1463// This tests serialization of SDP with only TCP candidates and verifies that
1464// null IPv4 is used as default address in c line.
1465TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithTCPOnly) {
1466 // Only test 1 m line.
1467 desc_.RemoveContentByName("video_content_name");
1468 // Stun has a high preference than local host.
1469 cricket::Candidate candidate1(
1470 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1471 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1472 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1473 cricket::Candidate candidate2(
1474 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1475 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
1476 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1477 JsepSessionDescription jdesc(kDummyString);
1478 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1479
1480 // Only add the candidates to audio m line.
1481 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1482 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1483 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1484 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
1485 std::string message = webrtc::SdpSerialize(jdesc);
1486
1487 // Audio line should have a c line like this one when no any default exists.
1488 EXPECT_NE(message.find("c=IN IP4 0.0.0.0"), std::string::npos);
1489}
1490
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001491// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1492// the case in a DTLS offer.
1493TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1494 AddFingerprint();
1495 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1496 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1497 kSessionId, kSessionVersion));
1498 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
1499
1500 std::string sdp_with_fingerprint = kSdpString;
1501 InjectAfter(kAttributeIcePwdVoice,
1502 kFingerprint, &sdp_with_fingerprint);
1503 InjectAfter(kAttributeIcePwdVideo,
1504 kFingerprint, &sdp_with_fingerprint);
1505
1506 EXPECT_EQ(sdp_with_fingerprint, message);
1507}
1508
1509// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1510// be the case in a DTLS answer.
1511TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1512 AddFingerprint();
1513 RemoveCryptos();
1514 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1515 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1516 kSessionId, kSessionVersion));
1517 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
1518
1519 std::string sdp_with_fingerprint = kSdpString;
1520 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1521 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
1522 InjectAfter(kAttributeIcePwdVoice,
1523 kFingerprint, &sdp_with_fingerprint);
1524 InjectAfter(kAttributeIcePwdVideo,
1525 kFingerprint, &sdp_with_fingerprint);
1526
1527 EXPECT_EQ(sdp_with_fingerprint, message);
1528}
1529
1530TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1531 // JsepSessionDescription with desc but without candidates.
1532 JsepSessionDescription jdesc_no_candidates(kDummyString);
1533 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
1534 kSessionId, kSessionVersion));
1535 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
1536 EXPECT_EQ(std::string(kSdpString), message);
1537}
1538
1539TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1540 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1541 group.AddContentName(kAudioContentName);
1542 group.AddContentName(kVideoContentName);
1543 desc_.AddGroup(group);
1544 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1545 jdesc_.session_id(),
1546 jdesc_.session_version()));
1547 std::string message = webrtc::SdpSerialize(jdesc_);
1548 std::string sdp_with_bundle = kSdpFullString;
1549 InjectAfter(kSessionTime,
1550 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1551 &sdp_with_bundle);
1552 EXPECT_EQ(sdp_with_bundle, message);
1553}
1554
1555TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
1556 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1557 GetFirstVideoContent(&desc_)->description);
1558 vcd->set_bandwidth(100 * 1000);
1559 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1560 GetFirstAudioContent(&desc_)->description);
1561 acd->set_bandwidth(50 * 1000);
1562 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1563 jdesc_.session_id(),
1564 jdesc_.session_version()));
1565 std::string message = webrtc::SdpSerialize(jdesc_);
1566 std::string sdp_with_bandwidth = kSdpFullString;
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001567 InjectAfter("c=IN IP4 74.125.224.39\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001568 "b=AS:100\r\n",
1569 &sdp_with_bandwidth);
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001570 InjectAfter("c=IN IP4 74.125.127.126\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001571 "b=AS:50\r\n",
1572 &sdp_with_bandwidth);
1573 EXPECT_EQ(sdp_with_bandwidth, message);
1574}
1575
1576TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1577 std::vector<std::string> transport_options;
1578 transport_options.push_back(kIceOption1);
1579 transport_options.push_back(kIceOption3);
1580 AddIceOptions(kAudioContentName, transport_options);
1581 transport_options.clear();
1582 transport_options.push_back(kIceOption2);
1583 transport_options.push_back(kIceOption3);
1584 AddIceOptions(kVideoContentName, transport_options);
1585 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1586 jdesc_.session_id(),
1587 jdesc_.session_version()));
1588 std::string message = webrtc::SdpSerialize(jdesc_);
1589 std::string sdp_with_ice_options = kSdpFullString;
1590 InjectAfter(kAttributeIcePwdVoice,
1591 "a=ice-options:iceoption1 iceoption3\r\n",
1592 &sdp_with_ice_options);
1593 InjectAfter(kAttributeIcePwdVideo,
1594 "a=ice-options:iceoption2 iceoption3\r\n",
1595 &sdp_with_ice_options);
1596 EXPECT_EQ(sdp_with_ice_options, message);
1597}
1598
1599TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
1600 EXPECT_TRUE(TestSerializeDirection(cricket::MD_RECVONLY));
1601}
1602
1603TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
1604 EXPECT_TRUE(TestSerializeDirection(cricket::MD_SENDONLY));
1605}
1606
1607TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
1608 EXPECT_TRUE(TestSerializeDirection(cricket::MD_INACTIVE));
1609}
1610
1611TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
1612 EXPECT_TRUE(TestSerializeRejected(true, false));
1613}
1614
1615TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
1616 EXPECT_TRUE(TestSerializeRejected(false, true));
1617}
1618
1619TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
1620 EXPECT_TRUE(TestSerializeRejected(true, true));
1621}
1622
1623TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
1624 AddRtpDataChannel();
1625 JsepSessionDescription jsep_desc(kDummyString);
1626
1627 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1628 std::string message = webrtc::SdpSerialize(jsep_desc);
1629
1630 std::string expected_sdp = kSdpString;
1631 expected_sdp.append(kSdpRtpDataChannelString);
1632 EXPECT_EQ(expected_sdp, message);
1633}
1634
1635TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
1636 AddSctpDataChannel();
1637 JsepSessionDescription jsep_desc(kDummyString);
1638
1639 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1640 std::string message = webrtc::SdpSerialize(jsep_desc);
1641
1642 std::string expected_sdp = kSdpString;
1643 expected_sdp.append(kSdpSctpDataChannelString);
1644 EXPECT_EQ(message, expected_sdp);
1645}
1646
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001647TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
1648 AddSctpDataChannel();
1649 JsepSessionDescription jsep_desc(kDummyString);
1650
1651 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1652 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
1653 jsep_desc.description()->GetContentDescriptionByName(kDataContentName));
1654
1655 const int kNewPort = 1234;
1656 cricket::DataCodec codec(
1657 cricket::kGoogleSctpDataCodecId, cricket::kGoogleSctpDataCodecName, 0);
1658 codec.SetParam(cricket::kCodecParamPort, kNewPort);
1659 dcdesc->AddOrReplaceCodec(codec);
1660
1661 std::string message = webrtc::SdpSerialize(jsep_desc);
1662
1663 std::string expected_sdp = kSdpString;
1664 expected_sdp.append(kSdpSctpDataChannelString);
1665
1666 char default_portstr[16];
1667 char new_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001668 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001669 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001670 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
1671 rtc::replace_substrs(default_portstr, strlen(default_portstr),
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001672 new_portstr, strlen(new_portstr),
1673 &expected_sdp);
1674
1675 EXPECT_EQ(expected_sdp, message);
1676}
1677
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001678TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
1679 AddRtpDataChannel();
1680 data_desc_->set_bandwidth(100*1000);
1681 JsepSessionDescription jsep_desc(kDummyString);
1682
1683 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1684 std::string message = webrtc::SdpSerialize(jsep_desc);
1685
1686 std::string expected_sdp = kSdpString;
1687 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07001688 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00001689 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 +00001690 "b=AS:100\r\n",
1691 &expected_sdp);
1692 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001693}
1694
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001695TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
1696 AddExtmap();
1697 JsepSessionDescription desc_with_extmap("dummy");
1698 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(),
1699 kSessionId, kSessionVersion));
1700 std::string message = webrtc::SdpSerialize(desc_with_extmap);
1701
1702 std::string sdp_with_extmap = kSdpString;
1703 InjectAfter("a=mid:audio_content_name\r\n",
1704 kExtmap, &sdp_with_extmap);
1705 InjectAfter("a=mid:video_content_name\r\n",
1706 kExtmap, &sdp_with_extmap);
1707
1708 EXPECT_EQ(sdp_with_extmap, message);
1709}
1710
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001711TEST_F(WebRtcSdpTest, SerializeCandidates) {
1712 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00001713 EXPECT_EQ(std::string(kRawCandidate), message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001714}
1715
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00001716// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
1717// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00001718TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001719 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001720 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
1721 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
1722 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00001723 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
1724 rtc::scoped_ptr<IceCandidateInterface> jcandidate(
1725 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
1726
1727 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
1728 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
1729}
1730
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001731TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
1732 JsepSessionDescription jdesc(kDummyString);
1733 // Deserialize
1734 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
1735 // Verify
1736 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1737}
1738
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001739TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
1740 JsepSessionDescription jdesc(kDummyString);
1741 const char kSdpWithoutMline[] =
1742 "v=0\r\n"
1743 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1744 "s=-\r\n"
1745 "t=0 0\r\n"
1746 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
1747 // Deserialize
1748 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
1749 EXPECT_EQ(0u, jdesc.description()->contents().size());
1750}
1751
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001752TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
1753 JsepSessionDescription jdesc(kDummyString);
1754 std::string sdp_without_carriage_return = kSdpFullString;
1755 Replace("\r\n", "\n", &sdp_without_carriage_return);
1756 // Deserialize
1757 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
1758 // Verify
1759 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1760}
1761
1762TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
1763 // SessionDescription with desc but without candidates.
1764 JsepSessionDescription jdesc_no_candidates(kDummyString);
1765 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
1766 kSessionId, kSessionVersion));
1767 JsepSessionDescription new_jdesc(kDummyString);
1768 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
1769 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
1770}
1771
1772TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
1773 static const char kSdpNoRtpmapString[] =
1774 "v=0\r\n"
1775 "o=- 11 22 IN IP4 127.0.0.1\r\n"
1776 "s=-\r\n"
1777 "t=0 0\r\n"
1778 "m=audio 49232 RTP/AVP 0 18 103\r\n"
1779 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001780 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001781 // The rtpmap line for static payload codec is optional.
1782 "a=rtpmap:18 G729/16000\r\n"
1783 "a=rtpmap:103 ISAC/16000\r\n";
1784
1785 JsepSessionDescription jdesc(kDummyString);
1786 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
1787 cricket::AudioContentDescription* audio =
1788 static_cast<AudioContentDescription*>(
1789 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
1790 AudioCodecs ref_codecs;
1791 // The codecs in the AudioContentDescription will be sorted by preference.
1792 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1, 3));
1793 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1, 2));
1794 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 32000, 1, 1));
1795 EXPECT_EQ(ref_codecs, audio->codecs());
1796}
1797
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001798TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
1799 static const char kSdpNoRtpmapString[] =
1800 "v=0\r\n"
1801 "o=- 11 22 IN IP4 127.0.0.1\r\n"
1802 "s=-\r\n"
1803 "t=0 0\r\n"
1804 "m=audio 49232 RTP/AVP 18 103\r\n"
1805 "a=fmtp:18 annexb=yes\r\n"
1806 "a=rtpmap:103 ISAC/16000\r\n";
1807
1808 JsepSessionDescription jdesc(kDummyString);
1809 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
1810 cricket::AudioContentDescription* audio =
1811 static_cast<AudioContentDescription*>(
1812 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
1813
1814 cricket::AudioCodec g729 = audio->codecs()[0];
1815 EXPECT_EQ("G729", g729.name);
1816 EXPECT_EQ(8000, g729.clockrate);
1817 EXPECT_EQ(18, g729.id);
1818 cricket::CodecParameterMap::iterator found =
1819 g729.params.find("annexb");
1820 ASSERT_TRUE(found != g729.params.end());
1821 EXPECT_EQ(found->second, "yes");
1822
1823 cricket::AudioCodec isac = audio->codecs()[1];
1824 EXPECT_EQ("ISAC", isac.name);
1825 EXPECT_EQ(103, isac.id);
1826 EXPECT_EQ(16000, isac.clockrate);
1827}
1828
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001829// Ensure that we can deserialize SDP with a=fingerprint properly.
1830TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
1831 // Add a DTLS a=fingerprint attribute to our session description.
1832 AddFingerprint();
1833 JsepSessionDescription new_jdesc(kDummyString);
1834 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1835 jdesc_.session_id(),
1836 jdesc_.session_version()));
1837
1838 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1839 std::string sdp_with_fingerprint = kSdpString;
1840 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1841 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
1842 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
1843 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
1844}
1845
1846TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
1847 JsepSessionDescription jdesc_with_bundle(kDummyString);
1848 std::string sdp_with_bundle = kSdpFullString;
1849 InjectAfter(kSessionTime,
1850 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1851 &sdp_with_bundle);
1852 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
1853 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1854 group.AddContentName(kAudioContentName);
1855 group.AddContentName(kVideoContentName);
1856 desc_.AddGroup(group);
1857 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1858 jdesc_.session_id(),
1859 jdesc_.session_version()));
1860 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
1861}
1862
1863TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
1864 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
1865 std::string sdp_with_bandwidth = kSdpFullString;
1866 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
1867 "b=AS:100\r\n",
1868 &sdp_with_bandwidth);
1869 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
1870 "b=AS:50\r\n",
1871 &sdp_with_bandwidth);
1872 EXPECT_TRUE(
1873 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
1874 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1875 GetFirstVideoContent(&desc_)->description);
1876 vcd->set_bandwidth(100 * 1000);
1877 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1878 GetFirstAudioContent(&desc_)->description);
1879 acd->set_bandwidth(50 * 1000);
1880 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1881 jdesc_.session_id(),
1882 jdesc_.session_version()));
1883 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
1884}
1885
1886TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
1887 JsepSessionDescription jdesc_with_ice_options(kDummyString);
1888 std::string sdp_with_ice_options = kSdpFullString;
1889 InjectAfter(kSessionTime,
1890 "a=ice-options:iceoption3\r\n",
1891 &sdp_with_ice_options);
1892 InjectAfter(kAttributeIcePwdVoice,
1893 "a=ice-options:iceoption1\r\n",
1894 &sdp_with_ice_options);
1895 InjectAfter(kAttributeIcePwdVideo,
1896 "a=ice-options:iceoption2\r\n",
1897 &sdp_with_ice_options);
1898 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
1899 std::vector<std::string> transport_options;
1900 transport_options.push_back(kIceOption3);
1901 transport_options.push_back(kIceOption1);
1902 AddIceOptions(kAudioContentName, transport_options);
1903 transport_options.clear();
1904 transport_options.push_back(kIceOption3);
1905 transport_options.push_back(kIceOption2);
1906 AddIceOptions(kVideoContentName, transport_options);
1907 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1908 jdesc_.session_id(),
1909 jdesc_.session_version()));
1910 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
1911}
1912
1913TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
1914 // Remove the original ice-ufrag and ice-pwd
1915 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyString);
1916 std::string sdp_with_ufrag_pwd = kSdpFullString;
1917 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
1918 // Add session level ufrag and pwd
1919 InjectAfter(kSessionTime,
1920 "a=ice-pwd:session+level+icepwd\r\n"
1921 "a=ice-ufrag:session+level+iceufrag\r\n",
1922 &sdp_with_ufrag_pwd);
1923 // Add media level ufrag and pwd for audio
1924 InjectAfter("a=mid:audio_content_name\r\n",
1925 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
1926 &sdp_with_ufrag_pwd);
1927 // Update the candidate ufrag and pwd to the expected ones.
1928 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0,
1929 "media+level+iceufrag", "media+level+icepwd"));
1930 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1,
1931 "session+level+iceufrag", "session+level+icepwd"));
1932 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
1933 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
1934}
1935
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001936TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
1937 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_RECVONLY));
1938}
1939
1940TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
1941 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_SENDONLY));
1942}
1943
1944TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
1945 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_INACTIVE));
1946}
1947
1948TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
1949 EXPECT_TRUE(TestDeserializeRejected(true, false));
1950}
1951
1952TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
1953 EXPECT_TRUE(TestDeserializeRejected(false, true));
1954}
1955
1956TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
1957 EXPECT_TRUE(TestDeserializeRejected(true, true));
1958}
1959
1960// Tests that we can still handle the sdp uses mslabel and label instead of
1961// msid for backward compatibility.
1962TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
1963 JsepSessionDescription jdesc(kDummyString);
1964 std::string sdp_without_msid = kSdpFullString;
1965 Replace("msid", "xmsid", &sdp_without_msid);
1966 // Deserialize
1967 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
1968 // Verify
1969 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1970}
1971
1972TEST_F(WebRtcSdpTest, DeserializeCandidate) {
1973 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
1974
1975 std::string sdp = kSdpOneCandidate;
1976 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
1977 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
1978 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
1979 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
1980
1981 // Candidate line without generation extension.
1982 sdp = kSdpOneCandidate;
1983 Replace(" generation 2", "", &sdp);
1984 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
1985 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
1986 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
1987 Candidate expected = jcandidate_->candidate();
1988 expected.set_generation(0);
1989 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
1990
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00001991 sdp = kSdpTcpActiveCandidate;
1992 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
1993 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001994 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001995 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
1996 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
1997 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00001998 rtc::scoped_ptr<IceCandidateInterface> jcandidate_template(
1999 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
2000 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(
2001 jcandidate_template->candidate()));
2002 sdp = kSdpTcpPassiveCandidate;
2003 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2004 sdp = kSdpTcpSOCandidate;
2005 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002006}
2007
2008// This test verifies the deserialization of candidate-attribute
2009// as per RFC 5245. Candiate-attribute will be of the format
2010// candidate:<blah>. This format will be used when candidates
2011// are trickled.
2012TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2013 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2014
2015 std::string candidate_attribute = kRawCandidate;
2016 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2017 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2018 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2019 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2020 EXPECT_EQ(2u, jcandidate.candidate().generation());
2021
2022 // Candidate line without generation extension.
2023 candidate_attribute = kRawCandidate;
2024 Replace(" generation 2", "", &candidate_attribute);
2025 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2026 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2027 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2028 Candidate expected = jcandidate_->candidate();
2029 expected.set_generation(0);
2030 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2031
2032 // Candidate line without candidate:
2033 candidate_attribute = kRawCandidate;
2034 Replace("candidate:", "", &candidate_attribute);
2035 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2036
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002037 // Candidate line with IPV6 address.
2038 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
2039}
2040
2041// This test verifies that the deserialization of an invalid candidate string
2042// fails.
2043TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
2044 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2045
2046 std::string candidate_attribute = kRawCandidate;
2047 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002048 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002049
2050 candidate_attribute = kSdpOneCandidate;
2051 candidate_attribute.replace(0, 1, "x");
2052 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2053
2054 candidate_attribute = kRawCandidate;
2055 candidate_attribute.append("\r\n");
2056 candidate_attribute.append(kRawCandidate);
2057 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2058
2059 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002060}
2061
2062TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2063 AddRtpDataChannel();
2064 JsepSessionDescription jdesc(kDummyString);
2065 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2066
2067 std::string sdp_with_data = kSdpString;
2068 sdp_with_data.append(kSdpRtpDataChannelString);
2069 JsepSessionDescription jdesc_output(kDummyString);
2070
2071 // Deserialize
2072 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2073 // Verify
2074 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2075}
2076
2077TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
2078 AddSctpDataChannel();
2079 JsepSessionDescription jdesc(kDummyString);
2080 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2081
2082 std::string sdp_with_data = kSdpString;
2083 sdp_with_data.append(kSdpSctpDataChannelString);
2084 JsepSessionDescription jdesc_output(kDummyString);
2085
lally@webrtc.org36300852015-02-24 20:19:35 +00002086 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2087 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2088 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2089
2090 // Verify with UDP/DTLS/SCTP.
2091 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2092 strlen(kDtlsSctp), kUdpDtlsSctp);
2093 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2094 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2095
2096 // Verify with TCP/DTLS/SCTP.
2097 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2098 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002099 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2100 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2101}
2102
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002103TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
2104 AddSctpDataChannel();
2105 JsepSessionDescription jdesc(kDummyString);
2106 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2107
2108 std::string sdp_with_data = kSdpString;
2109 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2110 JsepSessionDescription jdesc_output(kDummyString);
2111
lally@webrtc.org36300852015-02-24 20:19:35 +00002112 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002113 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2114 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002115
lally@webrtc.org36300852015-02-24 20:19:35 +00002116 // Verify with UDP/DTLS/SCTP.
2117 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2118 strlen(kDtlsSctp), kUdpDtlsSctp);
2119 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2120 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002121
lally@webrtc.org36300852015-02-24 20:19:35 +00002122 // Verify with TCP/DTLS/SCTP.
2123 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2124 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002125 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2126 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2127}
2128
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002129// Test to check the behaviour if sctp-port is specified
2130// on the m= line and in a=sctp-port.
2131TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
2132 AddSctpDataChannel();
2133 JsepSessionDescription jdesc(kDummyString);
2134 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2135
2136 std::string sdp_with_data = kSdpString;
2137 // Append m= attributes
2138 sdp_with_data.append(kSdpSctpDataChannelString);
2139 // Append a=sctp-port attribute
2140 sdp_with_data.append("a=sctp-port 5000\r\n");
2141 JsepSessionDescription jdesc_output(kDummyString);
2142
2143 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2144}
2145
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002146// For crbug/344475.
2147TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2148 std::string sdp_with_data = kSdpString;
2149 sdp_with_data.append(kSdpSctpDataChannelString);
2150 // Remove the "\n" at the end.
2151 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
2152 JsepSessionDescription jdesc_output(kDummyString);
2153
2154 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2155 // No crash is a pass.
2156}
2157
wu@webrtc.org78187522013-10-07 23:32:02 +00002158TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndNewPort) {
2159 AddSctpDataChannel();
2160 const uint16 kUnusualSctpPort = 9556;
2161 char default_portstr[16];
2162 char unusual_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002163 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
wu@webrtc.org78187522013-10-07 23:32:02 +00002164 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002165 rtc::sprintfn(unusual_portstr, sizeof(unusual_portstr), "%d",
wu@webrtc.org78187522013-10-07 23:32:02 +00002166 kUnusualSctpPort);
2167
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002168 // First setup the expected JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002169 JsepSessionDescription jdesc(kDummyString);
2170 // take our pre-built session description and change the SCTP port.
2171 cricket::SessionDescription* mutant = desc_.Copy();
2172 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
2173 mutant->GetContentDescriptionByName(kDataContentName));
2174 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002175 EXPECT_EQ(1U, codecs.size());
2176 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002177 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002178 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002179
2180 // note: mutant's owned by jdesc now.
2181 ASSERT_TRUE(jdesc.Initialize(mutant, kSessionId, kSessionVersion));
2182 mutant = NULL;
2183
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002184 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002185 std::string sdp_with_data = kSdpString;
2186 sdp_with_data.append(kSdpSctpDataChannelString);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002187 rtc::replace_substrs(default_portstr, strlen(default_portstr),
wu@webrtc.org78187522013-10-07 23:32:02 +00002188 unusual_portstr, strlen(unusual_portstr),
2189 &sdp_with_data);
2190 JsepSessionDescription jdesc_output(kDummyString);
2191
2192 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2193 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002194
2195 // We need to test the deserialized JsepSessionDescription from
2196 // kSdpSctpDataChannelStringWithSctpPort for
2197 // draft-ietf-mmusic-sctp-sdp-07
2198 // a=sctp-port
2199 sdp_with_data = kSdpString;
2200 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2201 rtc::replace_substrs(default_portstr, strlen(default_portstr),
2202 unusual_portstr, strlen(unusual_portstr),
2203 &sdp_with_data);
2204
2205 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2206 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002207}
2208
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002209TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002210 // We want to test that deserializing data content limits bandwidth
2211 // settings (it should never be greater than the default).
2212 // This should prevent someone from using unlimited data bandwidth through
2213 // JS and "breaking the Internet".
2214 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002215 std::string sdp_with_bandwidth = kSdpString;
2216 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
2217 InjectAfter("a=mid:data_content_name\r\n",
2218 "b=AS:100\r\n",
2219 &sdp_with_bandwidth);
2220 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2221
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002222 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2223}
2224
2225TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
2226 AddSctpDataChannel();
2227 JsepSessionDescription jdesc(kDummyString);
2228 DataContentDescription* dcd = static_cast<DataContentDescription*>(
2229 GetFirstDataContent(&desc_)->description);
2230 dcd->set_bandwidth(100 * 1000);
2231 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2232
2233 std::string sdp_with_bandwidth = kSdpString;
2234 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
2235 InjectAfter("a=mid:data_content_name\r\n",
2236 "b=AS:100\r\n",
2237 &sdp_with_bandwidth);
2238 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2239
2240 // SCTP has congestion control, so we shouldn't limit the bandwidth
2241 // as we do for RTP.
2242 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002243 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2244}
2245
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002246TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSessionLevelExtmap) {
2247 TestDeserializeExtmap(true, false);
2248}
2249
2250TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
2251 TestDeserializeExtmap(false, true);
2252}
2253
2254TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInvalidExtmap) {
2255 TestDeserializeExtmap(true, true);
2256}
2257
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002258TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
2259 JsepSessionDescription jdesc(kDummyString);
2260 std::string sdp = kSdpFullString;
2261 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2262 // Deserialize
2263 SdpParseError error;
2264 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
2265 const std::string lastline = "a=ssrc:6 label:video_track_id_3";
2266 EXPECT_EQ(lastline, error.line);
2267 EXPECT_EQ("Invalid SDP line.", error.description);
2268}
2269
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002270TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2271 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2272 std::string new_sdp = kSdpOneCandidate;
2273 Replace("udp", "unsupported_transport", &new_sdp);
2274 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2275 new_sdp = kSdpOneCandidate;
2276 Replace("udp", "uDP", &new_sdp);
2277 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2278 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2279 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2280 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2281}
2282
2283TEST_F(WebRtcSdpTest, DeserializeCandidateOldFormat) {
2284 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2285 EXPECT_TRUE(SdpDeserializeCandidate(kSdpOneCandidateOldFormat,&jcandidate));
2286 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2287 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2288 Candidate ref_candidate = jcandidate_->candidate();
2289 ref_candidate.set_username("user_rtp");
2290 ref_candidate.set_password("password_rtp");
2291 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2292}
2293
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002294TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
2295 JsepSessionDescription jdesc(kDummyString);
2296
2297 // Deserialize
2298 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2299
2300 // Verify
2301 cricket::AudioContentDescription* audio =
2302 static_cast<AudioContentDescription*>(
2303 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2304 EXPECT_TRUE(audio->conference_mode());
2305
2306 cricket::VideoContentDescription* video =
2307 static_cast<VideoContentDescription*>(
2308 jdesc.description()->GetContentDescriptionByName(cricket::CN_VIDEO));
2309 EXPECT_TRUE(video->conference_mode());
2310}
2311
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002312TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2313 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002314 const char kSdpEmptyType[] = " =candidate";
2315 const char kSdpEqualAsPlus[] = "a+candidate";
2316 const char kSdpSpaceAfterEqual[] = "a= candidate";
2317 const char kSdpUpperType[] = "A=candidate";
2318 const char kSdpEmptyLine[] = "";
2319 const char kSdpMissingValue[] = "a=";
2320
2321 const char kSdpBrokenFingerprint[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002322 "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 +00002323 const char kSdpExtraField[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002324 "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 +00002325 const char kSdpMissingSpace[] = "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002326 "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 +00002327 // MD5 is not allowed in fingerprints.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002328 const char kSdpMd5[] = "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002329 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002330
2331 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002332 ExpectParseFailure("v=", kSdpDestroyer);
2333 ExpectParseFailure("o=", kSdpDestroyer);
2334 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002335 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002336 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002337
2338 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002339 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2340 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002341
2342 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002343 ExpectParseFailure("a=candidate", kSdpEmptyType);
2344 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2345 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
2346 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002347
2348 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2349 // because it's orthogonal to what we are replacing and hence
2350 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002351 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
2352 ExpectParseFailure("a=sendrecv", kSdpExtraField);
2353 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
2354 ExpectParseFailure("a=sendrecv", kSdpMd5);
2355
2356 // Empty Line
2357 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
2358 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002359}
2360
2361TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2362 // ssrc
2363 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
2364 ExpectParseFailure("a=ssrc-group:FEC 5 6", "a=ssrc-group:FEC badvalue 6");
2365 // crypto
2366 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
2367 // rtpmap
2368 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
2369 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
2370 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
2371 // candidate
2372 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
2373 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
2374 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
2375 ExpectParseFailure("rport 2346", "rport badvalue");
2376 ExpectParseFailure("rport 2346 generation 2",
2377 "rport 2346 generation badvalue");
2378 // m line
2379 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
2380 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
2381
2382 // bandwidth
2383 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2384 "b=AS:badvalue\r\n",
2385 "b=AS:badvalue");
2386 // rtcp-fb
2387 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2388 "a=rtcp-fb:badvalue nack\r\n",
2389 "a=rtcp-fb:badvalue nack");
2390 // extmap
2391 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2392 "a=extmap:badvalue http://example.com\r\n",
2393 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002394}
2395
2396TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
2397 JsepSessionDescription jdesc_output(kDummyString);
2398
2399 const char kSdpWithReorderedPlTypesString[] =
2400 "v=0\r\n"
2401 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2402 "s=-\r\n"
2403 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00002404 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002405 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
2406 // in the map.
2407 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002408 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002409
2410 // Deserialize
2411 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
2412
2413 const ContentInfo* ac = GetFirstAudioContent(jdesc_output.description());
2414 ASSERT_TRUE(ac != NULL);
2415 const AudioContentDescription* acd =
2416 static_cast<const AudioContentDescription*>(ac->description);
2417 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002418 EXPECT_EQ("ISAC", acd->codecs()[0].name);
2419 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002420 EXPECT_EQ(104, acd->codecs()[0].id);
2421}
2422
2423TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
2424 JsepSessionDescription jdesc_output(kDummyString);
2425 CodecParams params;
2426 params.max_ptime = 40;
2427 params.ptime = 30;
2428 params.min_ptime = 10;
2429 params.sprop_stereo = 1;
2430 params.stereo = 1;
2431 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002432 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002433 TestDeserializeCodecParams(params, &jdesc_output);
2434 TestSerialize(jdesc_output);
2435}
2436
2437TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
2438 const bool kUseWildcard = false;
2439 JsepSessionDescription jdesc_output(kDummyString);
2440 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
2441 TestSerialize(jdesc_output);
2442}
2443
2444TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
2445 const bool kUseWildcard = true;
2446 JsepSessionDescription jdesc_output(kDummyString);
2447 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
2448 TestSerialize(jdesc_output);
2449}
2450
2451TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
2452 JsepSessionDescription jdesc_output(kDummyString);
2453
2454 const char kSdpWithFmtpString[] =
2455 "v=0\r\n"
2456 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2457 "s=-\r\n"
2458 "t=0 0\r\n"
2459 "m=video 3457 RTP/SAVPF 120\r\n"
2460 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07002461 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
2462
2463 // Deserialize
2464 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07002465 EXPECT_TRUE(
2466 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07002467
2468 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2469 ASSERT_TRUE(vc != NULL);
2470 const VideoContentDescription* vcd =
2471 static_cast<const VideoContentDescription*>(vc->description);
2472 ASSERT_FALSE(vcd->codecs().empty());
2473 cricket::VideoCodec vp8 = vcd->codecs()[0];
2474 EXPECT_EQ("VP8", vp8.name);
2475 EXPECT_EQ(120, vp8.id);
2476 cricket::CodecParameterMap::iterator found =
2477 vp8.params.find("x-google-min-bitrate");
2478 ASSERT_TRUE(found != vp8.params.end());
2479 EXPECT_EQ(found->second, "10");
2480 found = vp8.params.find("x-google-max-quantization");
2481 ASSERT_TRUE(found != vp8.params.end());
2482 EXPECT_EQ(found->second, "40");
2483}
2484
2485TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
2486 JsepSessionDescription jdesc_output(kDummyString);
2487
2488 const char kSdpWithFmtpString[] =
2489 "v=0\r\n"
2490 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2491 "s=-\r\n"
2492 "t=0 0\r\n"
2493 "m=video 3457 RTP/SAVPF 120\r\n"
2494 "a=rtpmap:120 VP8/90000\r\n"
2495 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002496
2497 // Deserialize
2498 SdpParseError error;
2499 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output,
2500 &error));
2501
2502 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2503 ASSERT_TRUE(vc != NULL);
2504 const VideoContentDescription* vcd =
2505 static_cast<const VideoContentDescription*>(vc->description);
2506 ASSERT_FALSE(vcd->codecs().empty());
2507 cricket::VideoCodec vp8 = vcd->codecs()[0];
2508 EXPECT_EQ("VP8", vp8.name);
2509 EXPECT_EQ(120, vp8.id);
2510 cricket::CodecParameterMap::iterator found =
2511 vp8.params.find("x-google-min-bitrate");
2512 ASSERT_TRUE(found != vp8.params.end());
2513 EXPECT_EQ(found->second, "10");
2514 found = vp8.params.find("x-google-max-quantization");
2515 ASSERT_TRUE(found != vp8.params.end());
2516 EXPECT_EQ(found->second, "40");
2517}
2518
2519TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
2520 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
2521 GetFirstVideoContent(&desc_)->description);
2522
2523 cricket::VideoCodecs codecs = vcd->codecs();
2524 codecs[0].params["x-google-min-bitrate"] = "10";
2525 vcd->set_codecs(codecs);
2526
2527 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2528 jdesc_.session_id(),
2529 jdesc_.session_version()));
2530 std::string message = webrtc::SdpSerialize(jdesc_);
2531 std::string sdp_with_fmtp = kSdpFullString;
2532 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
2533 "a=fmtp:120 x-google-min-bitrate=10\r\n",
2534 &sdp_with_fmtp);
2535 EXPECT_EQ(sdp_with_fmtp, message);
2536}
2537
2538TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) {
2539 JsepSessionDescription jdesc_with_icelite(kDummyString);
2540 std::string sdp_with_icelite = kSdpFullString;
2541 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
2542 cricket::SessionDescription* desc = jdesc_with_icelite.description();
2543 const cricket::TransportInfo* tinfo1 =
2544 desc->GetTransportInfoByName("audio_content_name");
2545 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
2546 const cricket::TransportInfo* tinfo2 =
2547 desc->GetTransportInfoByName("video_content_name");
2548 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
2549 InjectAfter(kSessionTime,
2550 "a=ice-lite\r\n",
2551 &sdp_with_icelite);
2552 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
2553 desc = jdesc_with_icelite.description();
2554 const cricket::TransportInfo* atinfo =
2555 desc->GetTransportInfoByName("audio_content_name");
2556 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
2557 const cricket::TransportInfo* vtinfo =
2558 desc->GetTransportInfoByName("video_content_name");
2559 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
2560}
2561
2562// Verifies that the candidates in the input SDP are parsed and serialized
2563// correctly in the output SDP.
2564TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
2565 std::string sdp_with_data = kSdpString;
2566 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
2567 JsepSessionDescription jdesc_output(kDummyString);
2568
2569 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2570 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
2571}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00002572
2573TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
2574 AddFingerprint();
2575 TransportInfo audio_transport_info =
2576 *(desc_.GetTransportInfoByName(kAudioContentName));
2577 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
2578 audio_transport_info.description.connection_role);
2579 audio_transport_info.description.connection_role =
2580 cricket::CONNECTIONROLE_ACTIVE;
2581
2582 TransportInfo video_transport_info =
2583 *(desc_.GetTransportInfoByName(kVideoContentName));
2584 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
2585 video_transport_info.description.connection_role);
2586 video_transport_info.description.connection_role =
2587 cricket::CONNECTIONROLE_ACTIVE;
2588
2589 desc_.RemoveTransportInfoByName(kAudioContentName);
2590 desc_.RemoveTransportInfoByName(kVideoContentName);
2591
2592 desc_.AddTransportInfo(audio_transport_info);
2593 desc_.AddTransportInfo(video_transport_info);
2594
2595 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2596 jdesc_.session_id(),
2597 jdesc_.session_version()));
2598 std::string message = webrtc::SdpSerialize(jdesc_);
2599 std::string sdp_with_dtlssetup = kSdpFullString;
2600
2601 // Fingerprint attribute is necessary to add DTLS setup attribute.
2602 InjectAfter(kAttributeIcePwdVoice,
2603 kFingerprint, &sdp_with_dtlssetup);
2604 InjectAfter(kAttributeIcePwdVideo,
2605 kFingerprint, &sdp_with_dtlssetup);
2606 // Now adding |setup| attribute.
2607 InjectAfter(kFingerprint,
2608 "a=setup:active\r\n", &sdp_with_dtlssetup);
2609 EXPECT_EQ(sdp_with_dtlssetup, message);
2610}
2611
2612TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
2613 JsepSessionDescription jdesc_with_dtlssetup(kDummyString);
2614 std::string sdp_with_dtlssetup = kSdpFullString;
2615 InjectAfter(kSessionTime,
2616 "a=setup:actpass\r\n",
2617 &sdp_with_dtlssetup);
2618 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
2619 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
2620 const cricket::TransportInfo* atinfo =
2621 desc->GetTransportInfoByName("audio_content_name");
2622 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
2623 atinfo->description.connection_role);
2624 const cricket::TransportInfo* vtinfo =
2625 desc->GetTransportInfoByName("video_content_name");
2626 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
2627 vtinfo->description.connection_role);
2628}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00002629
2630// Verifies that the order of the serialized m-lines follows the order of the
2631// ContentInfo in SessionDescription, and vise versa for deserialization.
2632TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
2633 JsepSessionDescription jdesc(kDummyString);
2634 const std::string media_content_sdps[3] = {
2635 kSdpAudioString,
2636 kSdpVideoString,
2637 kSdpSctpDataChannelString
2638 };
2639 const cricket::MediaType media_types[3] = {
2640 cricket::MEDIA_TYPE_AUDIO,
2641 cricket::MEDIA_TYPE_VIDEO,
2642 cricket::MEDIA_TYPE_DATA
2643 };
2644
2645 // Verifies all 6 permutations.
2646 for (size_t i = 0; i < 6; ++i) {
2647 size_t media_content_in_sdp[3];
2648 // The index of the first media content.
2649 media_content_in_sdp[0] = i / 2;
2650 // The index of the second media content.
2651 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
2652 // The index of the third media content.
2653 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
2654
2655 std::string sdp_string = kSdpSessionString;
2656 for (size_t i = 0; i < 3; ++i)
2657 sdp_string += media_content_sdps[media_content_in_sdp[i]];
2658
2659 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
2660 cricket::SessionDescription* desc = jdesc.description();
2661 EXPECT_EQ(3u, desc->contents().size());
2662
2663 for (size_t i = 0; i < 3; ++i) {
2664 const cricket::MediaContentDescription* mdesc =
2665 static_cast<const cricket::MediaContentDescription*>(
2666 desc->contents()[i].description);
2667 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
2668 }
2669
2670 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
2671 EXPECT_EQ(sdp_string, serialized_sdp);
2672 }
2673}