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