blob: 7f54a9dab30d0d98ad4ab945a29597547c16d85d [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2011 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
11#include <set>
12#include <string>
13#include <vector>
14
Henrik Kjellander15583c12016-02-10 10:53:12 +010015#include "webrtc/api/jsepsessiondescription.h"
16#ifdef WEBRTC_ANDROID
17#include "webrtc/api/test/androidtestinitializer.h"
18#endif
19#include "webrtc/api/webrtcsdp.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000020#include "webrtc/base/gunit.h"
21#include "webrtc/base/logging.h"
22#include "webrtc/base/messagedigest.h"
23#include "webrtc/base/scoped_ptr.h"
24#include "webrtc/base/sslfingerprint.h"
25#include "webrtc/base/stringencode.h"
26#include "webrtc/base/stringutils.h"
kjellandera96e2d72016-02-04 23:52:28 -080027#include "webrtc/media/base/constants.h"
28#include "webrtc/p2p/base/constants.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010029#include "webrtc/pc/mediasession.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030
31using cricket::AudioCodec;
32using cricket::AudioContentDescription;
33using cricket::Candidate;
34using cricket::ContentInfo;
35using cricket::CryptoParams;
36using cricket::ContentGroup;
37using cricket::DataCodec;
38using cricket::DataContentDescription;
39using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
40using cricket::ICE_CANDIDATE_COMPONENT_RTP;
41using cricket::kFecSsrcGroupSemantics;
42using cricket::LOCAL_PORT_TYPE;
43using cricket::NS_JINGLE_DRAFT_SCTP;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044using cricket::NS_JINGLE_RTP;
45using cricket::RtpHeaderExtension;
46using cricket::RELAY_PORT_TYPE;
47using cricket::SessionDescription;
48using cricket::StreamParams;
49using cricket::STUN_PORT_TYPE;
50using cricket::TransportDescription;
51using cricket::TransportInfo;
52using cricket::VideoCodec;
53using cricket::VideoContentDescription;
54using webrtc::IceCandidateCollection;
55using webrtc::IceCandidateInterface;
56using webrtc::JsepIceCandidate;
57using webrtc::JsepSessionDescription;
58using webrtc::SdpParseError;
59using webrtc::SessionDescriptionInterface;
60
61typedef std::vector<AudioCodec> AudioCodecs;
62typedef std::vector<Candidate> Candidates;
63
Peter Boström0c4e06b2015-10-07 12:23:21 +020064static const uint32_t kDefaultSctpPort = 5000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000065static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020066static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
henrike@webrtc.org28e20752013-07-10 00:45:36 +000067static const char kCandidateUfragVoice[] = "ufrag_voice";
68static const char kCandidatePwdVoice[] = "pwd_voice";
deadbeef3f7219b2015-12-28 15:17:14 -080069static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
71static const char kCandidateUfragVideo[] = "ufrag_video";
72static const char kCandidatePwdVideo[] = "pwd_video";
73static const char kCandidateUfragData[] = "ufrag_data";
74static const char kCandidatePwdData[] = "pwd_data";
deadbeef3f7219b2015-12-28 15:17:14 -080075static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020077static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078static const char kCandidateFoundation1[] = "a0+B/1";
79static const char kCandidateFoundation2[] = "a0+B/2";
80static const char kCandidateFoundation3[] = "a0+B/3";
81static const char kCandidateFoundation4[] = "a0+B/4";
82static const char kAttributeCryptoVoice[] =
83 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
84 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
85 "dummy_session_params\r\n";
86static const char kAttributeCryptoVideo[] =
87 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
88 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
89static const char kFingerprint[] = "a=fingerprint:sha-1 "
90 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n";
91static const int kExtmapId = 1;
92static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
93static const char kExtmap[] =
94 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
95static const char kExtmapWithDirectionAndAttribute[] =
96 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
97
Peter Boström0c4e06b2015-10-07 12:23:21 +020098static const uint8_t kIdentityDigest[] = {
99 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
100 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000101
lally@webrtc.org34807282015-02-24 20:19:39 +0000102static const char kDtlsSctp[] = "DTLS/SCTP";
103static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
104static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +0000105
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000106struct CodecParams {
107 int max_ptime;
108 int ptime;
109 int min_ptime;
110 int sprop_stereo;
111 int stereo;
112 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000113 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000114};
115
116// Reference sdp string
117static const char kSdpFullString[] =
118 "v=0\r\n"
119 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
120 "s=-\r\n"
121 "t=0 0\r\n"
122 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
123 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
124 "c=IN IP4 74.125.127.126\r\n"
125 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
126 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
127 "generation 2\r\n"
128 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
129 "generation 2\r\n"
130 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
131 "generation 2\r\n"
132 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
133 "generation 2\r\n"
134 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
135 "raddr 192.168.1.5 rport 2346 "
136 "generation 2\r\n"
137 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
138 "raddr 192.168.1.5 rport 2348 "
139 "generation 2\r\n"
140 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
141 "a=mid:audio_content_name\r\n"
142 "a=sendrecv\r\n"
143 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800144 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000145 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
146 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
147 "dummy_session_params\r\n"
148 "a=rtpmap:111 opus/48000/2\r\n"
149 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000150 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000151 "a=ssrc:1 cname:stream_1_cname\r\n"
152 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
153 "a=ssrc:1 mslabel:local_stream_1\r\n"
154 "a=ssrc:1 label:audio_track_id_1\r\n"
155 "a=ssrc:4 cname:stream_2_cname\r\n"
156 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
157 "a=ssrc:4 mslabel:local_stream_2\r\n"
158 "a=ssrc:4 label:audio_track_id_2\r\n"
159 "m=video 3457 RTP/SAVPF 120\r\n"
160 "c=IN IP4 74.125.224.39\r\n"
161 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
162 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
163 "generation 2\r\n"
164 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
165 "generation 2\r\n"
166 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
167 "generation 2\r\n"
168 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
169 "generation 2\r\n"
170 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
171 "generation 2\r\n"
172 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
173 "generation 2\r\n"
174 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
175 "a=mid:video_content_name\r\n"
176 "a=sendrecv\r\n"
177 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
178 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
179 "a=rtpmap:120 VP8/90000\r\n"
180 "a=ssrc:2 cname:stream_1_cname\r\n"
181 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
182 "a=ssrc:2 mslabel:local_stream_1\r\n"
183 "a=ssrc:2 label:video_track_id_1\r\n"
184 "a=ssrc:3 cname:stream_1_cname\r\n"
185 "a=ssrc:3 msid:local_stream_1 video_track_id_2\r\n"
186 "a=ssrc:3 mslabel:local_stream_1\r\n"
187 "a=ssrc:3 label:video_track_id_2\r\n"
188 "a=ssrc-group:FEC 5 6\r\n"
189 "a=ssrc:5 cname:stream_2_cname\r\n"
190 "a=ssrc:5 msid:local_stream_2 video_track_id_3\r\n"
191 "a=ssrc:5 mslabel:local_stream_2\r\n"
192 "a=ssrc:5 label:video_track_id_3\r\n"
193 "a=ssrc:6 cname:stream_2_cname\r\n"
194 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
195 "a=ssrc:6 mslabel:local_stream_2\r\n"
196 "a=ssrc:6 label:video_track_id_3\r\n";
197
198// SDP reference string without the candidates.
199static const char kSdpString[] =
200 "v=0\r\n"
201 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
202 "s=-\r\n"
203 "t=0 0\r\n"
204 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000205 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000206 "c=IN IP4 0.0.0.0\r\n"
207 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000208 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
209 "a=mid:audio_content_name\r\n"
210 "a=sendrecv\r\n"
211 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800212 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
214 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
215 "dummy_session_params\r\n"
216 "a=rtpmap:111 opus/48000/2\r\n"
217 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000218 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000219 "a=ssrc:1 cname:stream_1_cname\r\n"
220 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
221 "a=ssrc:1 mslabel:local_stream_1\r\n"
222 "a=ssrc:1 label:audio_track_id_1\r\n"
223 "a=ssrc:4 cname:stream_2_cname\r\n"
224 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
225 "a=ssrc:4 mslabel:local_stream_2\r\n"
226 "a=ssrc:4 label:audio_track_id_2\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000227 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000228 "c=IN IP4 0.0.0.0\r\n"
229 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000230 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
231 "a=mid:video_content_name\r\n"
232 "a=sendrecv\r\n"
233 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
234 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
235 "a=rtpmap:120 VP8/90000\r\n"
236 "a=ssrc:2 cname:stream_1_cname\r\n"
237 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
238 "a=ssrc:2 mslabel:local_stream_1\r\n"
239 "a=ssrc:2 label:video_track_id_1\r\n"
240 "a=ssrc:3 cname:stream_1_cname\r\n"
241 "a=ssrc:3 msid:local_stream_1 video_track_id_2\r\n"
242 "a=ssrc:3 mslabel:local_stream_1\r\n"
243 "a=ssrc:3 label:video_track_id_2\r\n"
244 "a=ssrc-group:FEC 5 6\r\n"
245 "a=ssrc:5 cname:stream_2_cname\r\n"
246 "a=ssrc:5 msid:local_stream_2 video_track_id_3\r\n"
247 "a=ssrc:5 mslabel:local_stream_2\r\n"
248 "a=ssrc:5 label:video_track_id_3\r\n"
249 "a=ssrc:6 cname:stream_2_cname\r\n"
250 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
251 "a=ssrc:6 mslabel:local_stream_2\r\n"
252 "a=ssrc:6 label:video_track_id_3\r\n";
253
254static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000255 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000256 "c=IN IP4 0.0.0.0\r\n"
257 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000258 "a=ice-ufrag:ufrag_data\r\n"
259 "a=ice-pwd:pwd_data\r\n"
260 "a=mid:data_content_name\r\n"
261 "a=sendrecv\r\n"
262 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
263 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
264 "a=rtpmap:101 google-data/90000\r\n"
265 "a=ssrc:10 cname:data_channel_cname\r\n"
266 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
267 "a=ssrc:10 mslabel:data_channel\r\n"
268 "a=ssrc:10 label:data_channeld0\r\n";
269
270static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000271 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000272 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000273 "a=ice-ufrag:ufrag_data\r\n"
274 "a=ice-pwd:pwd_data\r\n"
275 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000276 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000277
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000278// draft-ietf-mmusic-sctp-sdp-12
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000279static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000280 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
281 "a=max-message-size=100000\r\n"
282 "a=sctp-port 5000\r\n"
283 "c=IN IP4 0.0.0.0\r\n"
284 "a=ice-ufrag:ufrag_data\r\n"
285 "a=ice-pwd:pwd_data\r\n"
286 "a=mid:data_content_name\r\n";
287
lally69f57602015-10-08 10:15:04 -0700288static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
289 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
290 "a=max-message-size=100000\r\n"
291 "a=sctp-port:5000\r\n"
292 "c=IN IP4 0.0.0.0\r\n"
293 "a=ice-ufrag:ufrag_data\r\n"
294 "a=ice-pwd:pwd_data\r\n"
295 "a=mid:data_content_name\r\n";
296
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000297static const char kSdpSctpDataChannelWithCandidatesString[] =
298 "m=application 2345 DTLS/SCTP 5000\r\n"
299 "c=IN IP4 74.125.127.126\r\n"
300 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
301 "generation 2\r\n"
302 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
303 "generation 2\r\n"
304 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
305 "raddr 192.168.1.5 rport 2346 "
306 "generation 2\r\n"
307 "a=ice-ufrag:ufrag_data\r\n"
308 "a=ice-pwd:pwd_data\r\n"
309 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000310 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000312static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000313 "v=0\r\n"
314 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
315 "s=-\r\n"
316 "t=0 0\r\n"
317 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000318 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000319 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000320 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000321 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000322 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000323 "a=x-google-flag:conference\r\n";
324
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000325static const char kSdpSessionString[] =
326 "v=0\r\n"
327 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
328 "s=-\r\n"
329 "t=0 0\r\n"
330 "a=msid-semantic: WMS local_stream\r\n";
331
332static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000333 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000334 "c=IN IP4 0.0.0.0\r\n"
335 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000336 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
337 "a=mid:audio_content_name\r\n"
338 "a=sendrecv\r\n"
339 "a=rtpmap:111 opus/48000/2\r\n"
340 "a=ssrc:1 cname:stream_1_cname\r\n"
341 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
342 "a=ssrc:1 mslabel:local_stream\r\n"
343 "a=ssrc:1 label:audio_track_id_1\r\n";
344
345static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000346 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000347 "c=IN IP4 0.0.0.0\r\n"
348 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000349 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
350 "a=mid:video_content_name\r\n"
351 "a=sendrecv\r\n"
352 "a=rtpmap:120 VP8/90000\r\n"
353 "a=ssrc:2 cname:stream_1_cname\r\n"
354 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
355 "a=ssrc:2 mslabel:local_stream\r\n"
356 "a=ssrc:2 label:video_track_id_1\r\n";
357
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000358
359// One candidate reference string as per W3c spec.
360// candidate:<blah> not a=candidate:<blah>CRLF
361static const char kRawCandidate[] =
362 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
363// One candidate reference string.
364static const char kSdpOneCandidate[] =
365 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
366 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000367
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000368static const char kSdpTcpActiveCandidate[] =
369 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
370 "tcptype active generation 2";
371static const char kSdpTcpPassiveCandidate[] =
372 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
373 "tcptype passive generation 2";
374static const char kSdpTcpSOCandidate[] =
375 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
376 "tcptype so generation 2";
377static const char kSdpTcpInvalidCandidate[] =
378 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
379 "tcptype invalid generation 2";
380
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000381// One candidate reference string with IPV6 address.
382static const char kRawIPV6Candidate[] =
383 "candidate:a0+B/1 1 udp 2130706432 "
384 "abcd::abcd::abcd::abcd::abcd::abcd::abcd::abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000385
386// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800387static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000388 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800389 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000390
391// Session id and version
392static const char kSessionId[] = "18446744069414584320";
393static const char kSessionVersion[] = "18446462598732840960";
394
395// Ice options
396static const char kIceOption1[] = "iceoption1";
397static const char kIceOption2[] = "iceoption2";
398static const char kIceOption3[] = "iceoption3";
399
400// Content name
401static const char kAudioContentName[] = "audio_content_name";
402static const char kVideoContentName[] = "video_content_name";
403static const char kDataContentName[] = "data_content_name";
404
405// MediaStream 1
406static const char kStreamLabel1[] = "local_stream_1";
407static const char kStream1Cname[] = "stream_1_cname";
408static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200409static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000410static const char kVideoTrackId1[] = "video_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200411static const uint32_t kVideoTrack1Ssrc = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000412static const char kVideoTrackId2[] = "video_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200413static const uint32_t kVideoTrack2Ssrc = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000414
415// MediaStream 2
416static const char kStreamLabel2[] = "local_stream_2";
417static const char kStream2Cname[] = "stream_2_cname";
418static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200419static const uint32_t kAudioTrack2Ssrc = 4;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000420static const char kVideoTrackId3[] = "video_track_id_3";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200421static const uint32_t kVideoTrack3Ssrc = 5;
422static const uint32_t kVideoTrack4Ssrc = 6;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000423
424// DataChannel
425static const char kDataChannelLabel[] = "data_channel";
426static const char kDataChannelMsid[] = "data_channeld0";
427static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200428static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000429
430// Candidate
431static const char kDummyMid[] = "dummy_mid";
432static const int kDummyIndex = 123;
433
434// Misc
435static const char kDummyString[] = "dummy";
436
437// Helper functions
438
439static bool SdpDeserialize(const std::string& message,
440 JsepSessionDescription* jdesc) {
441 return webrtc::SdpDeserialize(message, jdesc, NULL);
442}
443
444static bool SdpDeserializeCandidate(const std::string& message,
445 JsepIceCandidate* candidate) {
446 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
447}
448
449// Add some extra |newlines| to the |message| after |line|.
450static void InjectAfter(const std::string& line,
451 const std::string& newlines,
452 std::string* message) {
453 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000454 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000455 tmp.c_str(), tmp.length(), message);
456}
457
458static void Replace(const std::string& line,
459 const std::string& newlines,
460 std::string* message) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000461 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000462 newlines.c_str(), newlines.length(), message);
463}
464
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000465// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
466// message.
467static void ExpectParseFailure(const std::string& bad_sdp,
468 const std::string& bad_part) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000469 JsepSessionDescription desc(kDummyString);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000470 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000471 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000472 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000473 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
474}
475
476// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
477static void ExpectParseFailure(const char* good_part, const char* bad_part) {
478 std::string bad_sdp = kSdpFullString;
479 Replace(good_part, bad_part, &bad_sdp);
480 ExpectParseFailure(bad_sdp, bad_part);
481}
482
483// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
484static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
485 const std::string& newlines,
486 const std::string& bad_part) {
487 std::string bad_sdp = kSdpFullString;
488 InjectAfter(injectpoint, newlines, &bad_sdp);
489 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000490}
491
492static void ReplaceDirection(cricket::MediaContentDirection direction,
493 std::string* message) {
494 std::string new_direction;
495 switch (direction) {
496 case cricket::MD_INACTIVE:
497 new_direction = "a=inactive";
498 break;
499 case cricket::MD_SENDONLY:
500 new_direction = "a=sendonly";
501 break;
502 case cricket::MD_RECVONLY:
503 new_direction = "a=recvonly";
504 break;
505 case cricket::MD_SENDRECV:
506 default:
507 new_direction = "a=sendrecv";
508 break;
509 }
510 Replace("a=sendrecv", new_direction, message);
511}
512
513static void ReplaceRejected(bool audio_rejected, bool video_rejected,
514 std::string* message) {
515 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800516 Replace("m=audio 9", "m=audio 0", message);
517 Replace(kAttributeIceUfragVoice, "", message);
518 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000519 }
520 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800521 Replace("m=video 9", "m=video 0", message);
522 Replace(kAttributeIceUfragVideo, "", message);
523 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000524 }
525}
526
527// WebRtcSdpTest
528
529class WebRtcSdpTest : public testing::Test {
530 public:
531 WebRtcSdpTest()
532 : jdesc_(kDummyString) {
phoglund37ebcf02016-01-08 05:04:57 -0800533#ifdef WEBRTC_ANDROID
534 webrtc::InitializeAndroidObjects();
535#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000536 // AudioContentDescription
537 audio_desc_ = CreateAudioContentDescription();
538 AudioCodec opus(111, "opus", 48000, 0, 2, 3);
539 audio_desc_->AddCodec(opus);
540 audio_desc_->AddCodec(AudioCodec(103, "ISAC", 16000, 32000, 1, 2));
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000541 audio_desc_->AddCodec(AudioCodec(104, "ISAC", 32000, 56000, 1, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000542 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
543
544 // VideoContentDescription
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000545 rtc::scoped_ptr<VideoContentDescription> video(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000546 new VideoContentDescription());
547 video_desc_ = video.get();
548 StreamParams video_stream1;
549 video_stream1.id = kVideoTrackId1;
550 video_stream1.cname = kStream1Cname;
551 video_stream1.sync_label = kStreamLabel1;
552 video_stream1.ssrcs.push_back(kVideoTrack1Ssrc);
553 video->AddStream(video_stream1);
554 StreamParams video_stream2;
555 video_stream2.id = kVideoTrackId2;
556 video_stream2.cname = kStream1Cname;
557 video_stream2.sync_label = kStreamLabel1;
558 video_stream2.ssrcs.push_back(kVideoTrack2Ssrc);
559 video->AddStream(video_stream2);
560 StreamParams video_stream3;
561 video_stream3.id = kVideoTrackId3;
562 video_stream3.cname = kStream2Cname;
563 video_stream3.sync_label = kStreamLabel2;
564 video_stream3.ssrcs.push_back(kVideoTrack3Ssrc);
565 video_stream3.ssrcs.push_back(kVideoTrack4Ssrc);
566 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream3.ssrcs);
567 video_stream3.ssrc_groups.push_back(ssrc_group);
568 video->AddStream(video_stream3);
569 video->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
570 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
571 video->set_protocol(cricket::kMediaProtocolSavpf);
572 video->AddCodec(VideoCodec(
573 120,
574 JsepSessionDescription::kDefaultVideoCodecName,
575 JsepSessionDescription::kMaxVideoCodecWidth,
576 JsepSessionDescription::kMaxVideoCodecHeight,
577 JsepSessionDescription::kDefaultVideoCodecFramerate,
578 JsepSessionDescription::kDefaultVideoCodecPreference));
579
580 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP,
581 video.release());
582
583 // TransportInfo
584 EXPECT_TRUE(desc_.AddTransportInfo(
585 TransportInfo(kAudioContentName,
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700586 TransportDescription(kCandidateUfragVoice,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000587 kCandidatePwdVoice))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000588 EXPECT_TRUE(desc_.AddTransportInfo(
589 TransportInfo(kVideoContentName,
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700590 TransportDescription(kCandidateUfragVideo,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000591 kCandidatePwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000592
593 // v4 host
594 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000595 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000596 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000597 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
598 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000599 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000600 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000601 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
602 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000603 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000604 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000605 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
606 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000607 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000608 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000609 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
610 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000611
612 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000613 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000614 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
615 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000616 cricket::LOCAL_PORT_TYPE,
617 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000618 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000619 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
620 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000621 cricket::LOCAL_PORT_TYPE,
622 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000623 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000624 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
625 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000626 cricket::LOCAL_PORT_TYPE,
627 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000628 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000629 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
630 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000631 cricket::LOCAL_PORT_TYPE,
632 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000633
634 // stun
635 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000636 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
637 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000638 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
639 address_stun, kCandidatePriority, "", "",
640 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000641 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000642 candidate9.set_related_address(rel_address_stun);
643
644 address_stun.SetPort(port_stun++);
645 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000646 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
647 address_stun, kCandidatePriority, "", "",
648 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000649 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000650 candidate10.set_related_address(rel_address_stun);
651
652 // relay
653 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000654 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000655 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
656 address_relay, kCandidatePriority, "", "",
657 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000658 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000659 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000660 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
661 address_relay, kCandidatePriority, "", "",
662 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000663 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000664
665 // voice
666 candidates_.push_back(candidate1);
667 candidates_.push_back(candidate2);
668 candidates_.push_back(candidate5);
669 candidates_.push_back(candidate6);
670 candidates_.push_back(candidate9);
671 candidates_.push_back(candidate10);
672
673 // video
674 candidates_.push_back(candidate3);
675 candidates_.push_back(candidate4);
676 candidates_.push_back(candidate7);
677 candidates_.push_back(candidate8);
678 candidates_.push_back(candidate11);
679 candidates_.push_back(candidate12);
680
681 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"),
682 0, candidate1));
683
684 // Set up JsepSessionDescription.
685 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
686 std::string mline_id;
687 int mline_index = 0;
688 for (size_t i = 0; i< candidates_.size(); ++i) {
689 // In this test, the audio m line index will be 0, and the video m line
690 // will be 1.
691 bool is_video = (i > 5);
692 mline_id = is_video ? "video_content_name" : "audio_content_name";
693 mline_index = is_video ? 1 : 0;
694 JsepIceCandidate jice(mline_id,
695 mline_index,
696 candidates_.at(i));
697 jdesc_.AddCandidate(&jice);
698 }
699 }
700
701 AudioContentDescription* CreateAudioContentDescription() {
702 AudioContentDescription* audio = new AudioContentDescription();
703 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -0800704 audio->set_rtcp_reduced_size(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000705 StreamParams audio_stream1;
706 audio_stream1.id = kAudioTrackId1;
707 audio_stream1.cname = kStream1Cname;
708 audio_stream1.sync_label = kStreamLabel1;
709 audio_stream1.ssrcs.push_back(kAudioTrack1Ssrc);
710 audio->AddStream(audio_stream1);
711 StreamParams audio_stream2;
712 audio_stream2.id = kAudioTrackId2;
713 audio_stream2.cname = kStream2Cname;
714 audio_stream2.sync_label = kStreamLabel2;
715 audio_stream2.ssrcs.push_back(kAudioTrack2Ssrc);
716 audio->AddStream(audio_stream2);
717 audio->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_32",
718 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
719 "dummy_session_params"));
720 audio->set_protocol(cricket::kMediaProtocolSavpf);
721 return audio;
722 }
723
724 template <class MCD>
725 void CompareMediaContentDescription(const MCD* cd1,
726 const MCD* cd2) {
727 // type
728 EXPECT_EQ(cd1->type(), cd1->type());
729
730 // content direction
731 EXPECT_EQ(cd1->direction(), cd2->direction());
732
733 // rtcp_mux
734 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
735
deadbeef13871492015-12-09 12:37:51 -0800736 // rtcp_reduced_size
737 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
738
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000739 // cryptos
740 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
741 if (cd1->cryptos().size() != cd2->cryptos().size()) {
742 ADD_FAILURE();
743 return;
744 }
745 for (size_t i = 0; i< cd1->cryptos().size(); ++i) {
746 const CryptoParams c1 = cd1->cryptos().at(i);
747 const CryptoParams c2 = cd2->cryptos().at(i);
748 EXPECT_TRUE(c1.Matches(c2));
749 EXPECT_EQ(c1.key_params, c2.key_params);
750 EXPECT_EQ(c1.session_params, c2.session_params);
751 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +0000752
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000753 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +0000754 // Use an equivalence class here, for old and new versions of the
755 // protocol description.
756 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:35 +0000757 || cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp
758 || cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
759 const bool cd2_is_also_dtls_sctp =
lally@webrtc.orgd7b61652015-02-24 20:18:55 +0000760 cd2->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:35 +0000761 || cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp
762 || cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
763 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +0000764 } else {
765 EXPECT_EQ(cd1->protocol(), cd2->protocol());
766 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000767
768 // codecs
769 EXPECT_EQ(cd1->codecs(), cd2->codecs());
770
771 // bandwidth
772 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
773
774 // streams
775 EXPECT_EQ(cd1->streams(), cd2->streams());
776
777 // extmap
778 ASSERT_EQ(cd1->rtp_header_extensions().size(),
779 cd2->rtp_header_extensions().size());
780 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) {
781 const RtpHeaderExtension ext1 = cd1->rtp_header_extensions().at(i);
782 const RtpHeaderExtension ext2 = cd2->rtp_header_extensions().at(i);
783 EXPECT_EQ(ext1.uri, ext2.uri);
784 EXPECT_EQ(ext1.id, ext2.id);
785 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000786 }
787
788
789 void CompareSessionDescription(const SessionDescription& desc1,
790 const SessionDescription& desc2) {
791 // Compare content descriptions.
792 if (desc1.contents().size() != desc2.contents().size()) {
793 ADD_FAILURE();
794 return;
795 }
796 for (size_t i = 0 ; i < desc1.contents().size(); ++i) {
797 const cricket::ContentInfo& c1 = desc1.contents().at(i);
798 const cricket::ContentInfo& c2 = desc2.contents().at(i);
799 // content name
800 EXPECT_EQ(c1.name, c2.name);
801 // content type
802 // Note, ASSERT will return from the function, but will not stop the test.
803 ASSERT_EQ(c1.type, c2.type);
804
805 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
806 if (IsAudioContent(&c1)) {
807 const AudioContentDescription* acd1 =
808 static_cast<const AudioContentDescription*>(c1.description);
809 const AudioContentDescription* acd2 =
810 static_cast<const AudioContentDescription*>(c2.description);
811 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
812 }
813
814 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
815 if (IsVideoContent(&c1)) {
816 const VideoContentDescription* vcd1 =
817 static_cast<const VideoContentDescription*>(c1.description);
818 const VideoContentDescription* vcd2 =
819 static_cast<const VideoContentDescription*>(c2.description);
820 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
821 }
822
823 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
824 if (IsDataContent(&c1)) {
825 const DataContentDescription* dcd1 =
826 static_cast<const DataContentDescription*>(c1.description);
827 const DataContentDescription* dcd2 =
828 static_cast<const DataContentDescription*>(c2.description);
829 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
830 }
831 }
832
833 // group
834 const cricket::ContentGroups groups1 = desc1.groups();
835 const cricket::ContentGroups groups2 = desc2.groups();
836 EXPECT_EQ(groups1.size(), groups1.size());
837 if (groups1.size() != groups2.size()) {
838 ADD_FAILURE();
839 return;
840 }
841 for (size_t i = 0; i < groups1.size(); ++i) {
842 const cricket::ContentGroup group1 = groups1.at(i);
843 const cricket::ContentGroup group2 = groups2.at(i);
844 EXPECT_EQ(group1.semantics(), group2.semantics());
845 const cricket::ContentNames names1 = group1.content_names();
846 const cricket::ContentNames names2 = group2.content_names();
847 EXPECT_EQ(names1.size(), names2.size());
848 if (names1.size() != names2.size()) {
849 ADD_FAILURE();
850 return;
851 }
852 cricket::ContentNames::const_iterator iter1 = names1.begin();
853 cricket::ContentNames::const_iterator iter2 = names2.begin();
854 while (iter1 != names1.end()) {
855 EXPECT_EQ(*iter1++, *iter2++);
856 }
857 }
858
859 // transport info
860 const cricket::TransportInfos transports1 = desc1.transport_infos();
861 const cricket::TransportInfos transports2 = desc2.transport_infos();
862 EXPECT_EQ(transports1.size(), transports2.size());
863 if (transports1.size() != transports2.size()) {
864 ADD_FAILURE();
865 return;
866 }
867 for (size_t i = 0; i < transports1.size(); ++i) {
868 const cricket::TransportInfo transport1 = transports1.at(i);
869 const cricket::TransportInfo transport2 = transports2.at(i);
870 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000871 EXPECT_EQ(transport1.description.ice_ufrag,
872 transport2.description.ice_ufrag);
873 EXPECT_EQ(transport1.description.ice_pwd,
874 transport2.description.ice_pwd);
875 if (transport1.description.identity_fingerprint) {
876 EXPECT_EQ(*transport1.description.identity_fingerprint,
877 *transport2.description.identity_fingerprint);
878 } else {
879 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
880 transport2.description.identity_fingerprint.get());
881 }
882 EXPECT_EQ(transport1.description.transport_options,
883 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000884 }
deadbeefc80741f2015-10-22 13:14:45 -0700885
886 // global attributes
887 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000888 }
889
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890 bool CompareSessionDescription(
891 const JsepSessionDescription& desc1,
892 const JsepSessionDescription& desc2) {
893 EXPECT_EQ(desc1.session_id(), desc2.session_id());
894 EXPECT_EQ(desc1.session_version(), desc2.session_version());
895 CompareSessionDescription(*desc1.description(), *desc2.description());
896 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
897 return false;
898 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
899 const IceCandidateCollection* cc1 = desc1.candidates(i);
900 const IceCandidateCollection* cc2 = desc2.candidates(i);
901 if (cc1->count() != cc2->count())
902 return false;
903 for (size_t j = 0; j < cc1->count(); ++j) {
904 const IceCandidateInterface* c1 = cc1->at(j);
905 const IceCandidateInterface* c2 = cc2->at(j);
906 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
907 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
908 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
909 }
910 }
911 return true;
912 }
913
914 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
915 // them with invalid keywords so that the parser will just ignore them.
916 bool RemoveCandidateUfragPwd(std::string* sdp) {
917 const char ice_ufrag[] = "a=ice-ufrag";
918 const char ice_ufragx[] = "a=xice-ufrag";
919 const char ice_pwd[] = "a=ice-pwd";
920 const char ice_pwdx[] = "a=xice-pwd";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000921 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000922 ice_ufragx, strlen(ice_ufragx), sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000923 rtc::replace_substrs(ice_pwd, strlen(ice_pwd),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000924 ice_pwdx, strlen(ice_pwdx), sdp);
925 return true;
926 }
927
928 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
929 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, int mline_index,
930 const std::string& ufrag, const std::string& pwd) {
931 std::string content_name;
932 if (mline_index == 0) {
933 content_name = kAudioContentName;
934 } else if (mline_index == 1) {
935 content_name = kVideoContentName;
936 } else {
937 ASSERT(false);
938 }
939 TransportInfo transport_info(
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700940 content_name, TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000941 SessionDescription* desc =
942 const_cast<SessionDescription*>(jdesc->description());
943 desc->RemoveTransportInfoByName(content_name);
944 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
945 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
946 const IceCandidateCollection* cc = jdesc_.candidates(i);
947 for (size_t j = 0; j < cc->count(); ++j) {
948 if (cc->at(j)->sdp_mline_index() == mline_index) {
949 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(
950 ufrag);
951 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(
952 pwd);
953 }
954 }
955 }
956 return true;
957 }
958
959 void AddIceOptions(const std::string& content_name,
960 const std::vector<std::string>& transport_options) {
961 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
962 cricket::TransportInfo transport_info =
963 *(desc_.GetTransportInfoByName(content_name));
964 desc_.RemoveTransportInfoByName(content_name);
965 transport_info.description.transport_options = transport_options;
966 desc_.AddTransportInfo(transport_info);
967 }
968
deadbeef3f7219b2015-12-28 15:17:14 -0800969 void SetIceUfragPwd(const std::string& content_name,
970 const std::string& ice_ufrag,
971 const std::string& ice_pwd) {
972 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
973 cricket::TransportInfo transport_info =
974 *(desc_.GetTransportInfoByName(content_name));
975 desc_.RemoveTransportInfoByName(content_name);
976 transport_info.description.ice_ufrag = ice_ufrag;
977 transport_info.description.ice_pwd = ice_pwd;
978 desc_.AddTransportInfo(transport_info);
979 }
980
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000981 void AddFingerprint() {
982 desc_.RemoveTransportInfoByName(kAudioContentName);
983 desc_.RemoveTransportInfoByName(kVideoContentName);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000984 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000985 kIdentityDigest,
986 sizeof(kIdentityDigest));
deadbeef46eed762016-01-28 13:24:37 -0800987 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
988 kAudioContentName,
989 TransportDescription(std::vector<std::string>(), kCandidateUfragVoice,
990 kCandidatePwdVoice, cricket::ICEMODE_FULL,
991 cricket::CONNECTIONROLE_NONE, &fingerprint))));
992 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
993 kVideoContentName,
994 TransportDescription(std::vector<std::string>(), kCandidateUfragVideo,
995 kCandidatePwdVideo, cricket::ICEMODE_FULL,
996 cricket::CONNECTIONROLE_NONE, &fingerprint))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000997 }
998
999 void AddExtmap() {
1000 audio_desc_ = static_cast<AudioContentDescription*>(
1001 audio_desc_->Copy());
1002 video_desc_ = static_cast<VideoContentDescription*>(
1003 video_desc_->Copy());
1004 audio_desc_->AddRtpHeaderExtension(
1005 RtpHeaderExtension(kExtmapUri, kExtmapId));
1006 video_desc_->AddRtpHeaderExtension(
1007 RtpHeaderExtension(kExtmapUri, kExtmapId));
1008 desc_.RemoveContentByName(kAudioContentName);
1009 desc_.RemoveContentByName(kVideoContentName);
1010 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1011 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1012 }
1013
1014 void RemoveCryptos() {
1015 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1016 video_desc_->set_cryptos(std::vector<CryptoParams>());
1017 }
1018
1019 bool TestSerializeDirection(cricket::MediaContentDirection direction) {
1020 audio_desc_->set_direction(direction);
1021 video_desc_->set_direction(direction);
1022 std::string new_sdp = kSdpFullString;
1023 ReplaceDirection(direction, &new_sdp);
1024
1025 if (!jdesc_.Initialize(desc_.Copy(),
1026 jdesc_.session_id(),
1027 jdesc_.session_version())) {
1028 return false;
1029 }
1030 std::string message = webrtc::SdpSerialize(jdesc_);
1031 EXPECT_EQ(new_sdp, message);
1032 return true;
1033 }
1034
1035 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
1036 audio_desc_ = static_cast<AudioContentDescription*>(
1037 audio_desc_->Copy());
1038 video_desc_ = static_cast<VideoContentDescription*>(
1039 video_desc_->Copy());
1040 desc_.RemoveContentByName(kAudioContentName);
1041 desc_.RemoveContentByName(kVideoContentName);
1042 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1043 audio_desc_);
1044 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1045 video_desc_);
deadbeef3f7219b2015-12-28 15:17:14 -08001046 SetIceUfragPwd(kAudioContentName,
1047 audio_rejected ? "" : kCandidateUfragVoice,
1048 audio_rejected ? "" : kCandidatePwdVoice);
1049 SetIceUfragPwd(kVideoContentName,
1050 video_rejected ? "" : kCandidateUfragVideo,
1051 video_rejected ? "" : kCandidatePwdVideo);
1052
1053 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001054 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1055
deadbeef3f7219b2015-12-28 15:17:14 -08001056 JsepSessionDescription jdesc_no_candidates(kDummyString);
1057 if (!jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
1058 kSessionVersion)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001059 return false;
1060 }
deadbeef3f7219b2015-12-28 15:17:14 -08001061 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001062 EXPECT_EQ(new_sdp, message);
1063 return true;
1064 }
1065
1066 void AddSctpDataChannel() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001067 rtc::scoped_ptr<DataContentDescription> data(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001068 new DataContentDescription());
1069 data_desc_ = data.get();
1070 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
wu@webrtc.org78187522013-10-07 23:32:02 +00001071 DataCodec codec(cricket::kGoogleSctpDataCodecId,
1072 cricket::kGoogleSctpDataCodecName, 0);
1073 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1074 data_desc_->AddCodec(codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001075 desc_.AddContent(kDataContentName, NS_JINGLE_DRAFT_SCTP, data.release());
1076 EXPECT_TRUE(desc_.AddTransportInfo(
1077 TransportInfo(kDataContentName,
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001078 TransportDescription(kCandidateUfragData,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001079 kCandidatePwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001080 }
1081
1082 void AddRtpDataChannel() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001083 rtc::scoped_ptr<DataContentDescription> data(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001084 new DataContentDescription());
1085 data_desc_ = data.get();
1086
1087 data_desc_->AddCodec(DataCodec(101, "google-data", 1));
1088 StreamParams data_stream;
1089 data_stream.id = kDataChannelMsid;
1090 data_stream.cname = kDataChannelCname;
1091 data_stream.sync_label = kDataChannelLabel;
1092 data_stream.ssrcs.push_back(kDataChannelSsrc);
1093 data_desc_->AddStream(data_stream);
1094 data_desc_->AddCrypto(CryptoParams(
1095 1, "AES_CM_128_HMAC_SHA1_80",
1096 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
1097 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
1098 desc_.AddContent(kDataContentName, NS_JINGLE_RTP, data.release());
1099 EXPECT_TRUE(desc_.AddTransportInfo(
1100 TransportInfo(kDataContentName,
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001101 TransportDescription(kCandidateUfragData,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001102 kCandidatePwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001103 }
1104
1105 bool TestDeserializeDirection(cricket::MediaContentDirection direction) {
1106 std::string new_sdp = kSdpFullString;
1107 ReplaceDirection(direction, &new_sdp);
1108 JsepSessionDescription new_jdesc(kDummyString);
1109
1110 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1111
1112 audio_desc_->set_direction(direction);
1113 video_desc_->set_direction(direction);
1114 if (!jdesc_.Initialize(desc_.Copy(),
1115 jdesc_.session_id(),
1116 jdesc_.session_version())) {
1117 return false;
1118 }
1119 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1120 return true;
1121 }
1122
1123 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001124 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001125 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1126 JsepSessionDescription new_jdesc(JsepSessionDescription::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001127 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001128
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001129 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_);
deadbeef3f7219b2015-12-28 15:17:14 -08001139 SetIceUfragPwd(kAudioContentName,
1140 audio_rejected ? "" : kCandidateUfragVoice,
1141 audio_rejected ? "" : kCandidatePwdVoice);
1142 SetIceUfragPwd(kVideoContentName,
1143 video_rejected ? "" : kCandidateUfragVideo,
1144 video_rejected ? "" : kCandidatePwdVideo);
1145 JsepSessionDescription jdesc_no_candidates(kDummyString);
1146 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1147 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001148 return false;
1149 }
deadbeef3f7219b2015-12-28 15:17:14 -08001150 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001151 return true;
1152 }
1153
1154 void TestDeserializeExtmap(bool session_level, bool media_level) {
1155 AddExtmap();
1156 JsepSessionDescription new_jdesc("dummy");
1157 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1158 jdesc_.session_id(),
1159 jdesc_.session_version()));
1160 JsepSessionDescription jdesc_with_extmap("dummy");
1161 std::string sdp_with_extmap = kSdpString;
1162 if (session_level) {
1163 InjectAfter(kSessionTime, kExtmapWithDirectionAndAttribute,
1164 &sdp_with_extmap);
1165 }
1166 if (media_level) {
1167 InjectAfter(kAttributeIcePwdVoice, kExtmapWithDirectionAndAttribute,
1168 &sdp_with_extmap);
1169 InjectAfter(kAttributeIcePwdVideo, kExtmapWithDirectionAndAttribute,
1170 &sdp_with_extmap);
1171 }
1172 // The extmap can't be present at the same time in both session level and
1173 // media level.
1174 if (session_level && media_level) {
1175 SdpParseError error;
1176 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap,
1177 &jdesc_with_extmap, &error));
1178 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1179 } else {
1180 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1181 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1182 }
1183 }
1184
1185 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
1186 const std::string& name, int expected_value) {
1187 cricket::CodecParameterMap::const_iterator found = params.find(name);
1188 ASSERT_TRUE(found != params.end());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001189 EXPECT_EQ(found->second, rtc::ToString<int>(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001190 }
1191
1192 void TestDeserializeCodecParams(const CodecParams& params,
1193 JsepSessionDescription* jdesc_output) {
1194 std::string sdp =
1195 "v=0\r\n"
1196 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1197 "s=-\r\n"
1198 "t=0 0\r\n"
1199 // Include semantics for WebRTC Media Streams since it is supported by
1200 // this parser, and will be added to the SDP when serializing a session
1201 // description.
1202 "a=msid-semantic: WMS\r\n"
1203 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001204 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001205 // Pltype 111 listed before 103 and 104 in the map.
1206 "a=rtpmap:111 opus/48000/2\r\n"
1207 // Pltype 103 listed before 104.
1208 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001209 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001210 "a=fmtp:111 0-15,66,70\r\n"
1211 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001212 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001213 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001214 << "; sprop-stereo=" << params.sprop_stereo
1215 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001216 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001217 << "a=ptime:" << params.ptime << "\r\n"
1218 << "a=maxptime:" << params.max_ptime << "\r\n";
1219 sdp += os.str();
1220
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001221 os.clear();
1222 os.str("");
1223 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001224 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001225 << "a=rtpmap:99 VP8/90000\r\n"
1226 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001227 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001228 sdp += os.str();
1229
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001230 // Deserialize
1231 SdpParseError error;
1232 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1233
1234 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1235 ASSERT_TRUE(ac != NULL);
1236 const AudioContentDescription* acd =
1237 static_cast<const AudioContentDescription*>(ac->description);
1238 ASSERT_FALSE(acd->codecs().empty());
1239 cricket::AudioCodec opus = acd->codecs()[0];
1240 EXPECT_EQ("opus", opus.name);
1241 EXPECT_EQ(111, opus.id);
1242 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1243 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1244 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1245 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001246 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1247 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001248 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1249 cricket::AudioCodec codec = acd->codecs()[i];
1250 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1251 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
1252 if (codec.name == "ISAC") {
1253 if (codec.clockrate == 16000) {
1254 EXPECT_EQ(32000, codec.bitrate);
1255 } else {
1256 EXPECT_EQ(56000, codec.bitrate);
1257 }
1258 }
1259 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001260
1261 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1262 ASSERT_TRUE(vc != NULL);
1263 const VideoContentDescription* vcd =
1264 static_cast<const VideoContentDescription*>(vc->description);
1265 ASSERT_FALSE(vcd->codecs().empty());
1266 cricket::VideoCodec vp8 = vcd->codecs()[0];
1267 EXPECT_EQ("VP8", vp8.name);
1268 EXPECT_EQ(99, vp8.id);
1269 cricket::VideoCodec rtx = vcd->codecs()[1];
1270 EXPECT_EQ("RTX", rtx.name);
1271 EXPECT_EQ(95, rtx.id);
1272 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001273 }
1274
1275 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1276 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001277 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001278 "v=0\r\n"
1279 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1280 "s=-\r\n"
1281 "t=0 0\r\n"
1282 // Include semantics for WebRTC Media Streams since it is supported by
1283 // this parser, and will be added to the SDP when serializing a session
1284 // description.
1285 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001286 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001287 "a=rtpmap:111 opus/48000/2\r\n";
1288 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001289 "m=video 3457 RTP/SAVPF 101\r\n"
1290 "a=rtpmap:101 VP8/90000\r\n"
1291 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001292 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001293 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001294 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001295 os << sdp_session_and_audio;
1296 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
1297 os << sdp_video;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001298 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001299 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001300 // Deserialize
1301 SdpParseError error;
1302 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1303 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1304 ASSERT_TRUE(ac != NULL);
1305 const AudioContentDescription* acd =
1306 static_cast<const AudioContentDescription*>(ac->description);
1307 ASSERT_FALSE(acd->codecs().empty());
1308 cricket::AudioCodec opus = acd->codecs()[0];
1309 EXPECT_EQ(111, opus.id);
1310 EXPECT_TRUE(opus.HasFeedbackParam(
1311 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1312 cricket::kParamValueEmpty)));
1313
1314 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1315 ASSERT_TRUE(vc != NULL);
1316 const VideoContentDescription* vcd =
1317 static_cast<const VideoContentDescription*>(vc->description);
1318 ASSERT_FALSE(vcd->codecs().empty());
1319 cricket::VideoCodec vp8 = vcd->codecs()[0];
1320 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1321 vp8.name.c_str());
1322 EXPECT_EQ(101, vp8.id);
1323 EXPECT_TRUE(vp8.HasFeedbackParam(
1324 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1325 cricket::kParamValueEmpty)));
1326 EXPECT_TRUE(vp8.HasFeedbackParam(
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001327 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1328 cricket::kRtcpFbNackParamPli)));
1329 EXPECT_TRUE(vp8.HasFeedbackParam(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001330 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
1331 cricket::kParamValueEmpty)));
1332 EXPECT_TRUE(vp8.HasFeedbackParam(
1333 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
1334 cricket::kRtcpFbCcmParamFir)));
1335 }
1336
1337 // Two SDP messages can mean the same thing but be different strings, e.g.
1338 // some of the lines can be serialized in different order.
1339 // However, a deserialized description can be compared field by field and has
1340 // no order. If deserializer has already been tested, serializing then
1341 // deserializing and comparing JsepSessionDescription will test
1342 // the serializer sufficiently.
1343 void TestSerialize(const JsepSessionDescription& jdesc) {
1344 std::string message = webrtc::SdpSerialize(jdesc);
1345 JsepSessionDescription jdesc_output_des(kDummyString);
1346 SdpParseError error;
1347 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1348 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1349 }
1350
1351 protected:
1352 SessionDescription desc_;
1353 AudioContentDescription* audio_desc_;
1354 VideoContentDescription* video_desc_;
1355 DataContentDescription* data_desc_;
1356 Candidates candidates_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001357 rtc::scoped_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001358 JsepSessionDescription jdesc_;
1359};
1360
1361void TestMismatch(const std::string& string1, const std::string& string2) {
1362 int position = 0;
1363 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1364 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001365 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001366 break;
1367 }
1368 }
1369 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1370 << " character\n"
1371 << " 1: " << string1.substr(position, 20) << "\n"
1372 << " 2: " << string2.substr(position, 20) << "\n";
1373}
1374
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001375TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1376 // SessionDescription with desc and candidates.
1377 std::string message = webrtc::SdpSerialize(jdesc_);
1378 TestMismatch(std::string(kSdpFullString), message);
1379}
1380
1381TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
1382 JsepSessionDescription jdesc_empty(kDummyString);
1383 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
1384}
1385
guoweis@webrtc.org57ac2c82015-02-06 00:45:13 +00001386// This tests serialization of SDP with only IPv6 candidates and verifies that
1387// IPv6 is used as default address in c line according to preference.
1388TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIPv6Only) {
1389 // Only test 1 m line.
1390 desc_.RemoveContentByName("video_content_name");
1391 // Stun has a high preference than local host.
1392 cricket::Candidate candidate1(
1393 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1394 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1395 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1396 cricket::Candidate candidate2(
1397 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1398 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
1399 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1400 JsepSessionDescription jdesc(kDummyString);
1401 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1402
1403 // Only add the candidates to audio m line.
1404 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1405 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1406 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1407 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
1408 std::string message = webrtc::SdpSerialize(jdesc);
1409
1410 // Audio line should have a c line like this one.
1411 EXPECT_NE(message.find("c=IN IP6 ::1"), std::string::npos);
1412 // Shouldn't have a IP4 c line.
1413 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
1414}
1415
1416// This tests serialization of SDP with both IPv4 and IPv6 candidates and
1417// verifies that IPv4 is used as default address in c line even if the
1418// preference of IPv4 is lower.
1419TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothIPFamilies) {
1420 // Only test 1 m line.
1421 desc_.RemoveContentByName("video_content_name");
1422 cricket::Candidate candidate_v4(
1423 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1424 rtc::SocketAddress("192.168.1.5", 1234), kCandidatePriority, "", "",
1425 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1426 cricket::Candidate candidate_v6(
1427 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1428 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1429 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1430 JsepSessionDescription jdesc(kDummyString);
1431 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1432
1433 // Only add the candidates to audio m line.
1434 JsepIceCandidate jice_v4("audio_content_name", 0, candidate_v4);
1435 JsepIceCandidate jice_v6("audio_content_name", 0, candidate_v6);
1436 ASSERT_TRUE(jdesc.AddCandidate(&jice_v4));
1437 ASSERT_TRUE(jdesc.AddCandidate(&jice_v6));
1438 std::string message = webrtc::SdpSerialize(jdesc);
1439
1440 // Audio line should have a c line like this one.
1441 EXPECT_NE(message.find("c=IN IP4 192.168.1.5"), std::string::npos);
1442 // Shouldn't have a IP6 c line.
1443 EXPECT_EQ(message.find("c=IN IP6"), std::string::npos);
1444}
1445
1446// This tests serialization of SDP with both UDP and TCP candidates and
1447// verifies that UDP is used as default address in c line even if the
1448// preference of UDP is lower.
1449TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothProtocols) {
1450 // Only test 1 m line.
1451 desc_.RemoveContentByName("video_content_name");
1452 // Stun has a high preference than local host.
1453 cricket::Candidate candidate1(
1454 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1455 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1456 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1457 cricket::Candidate candidate2(
1458 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1459 rtc::SocketAddress("fe80::1234:5678:abcd:ef12", 1235), kCandidatePriority,
1460 "", "", cricket::LOCAL_PORT_TYPE, kCandidateGeneration,
1461 kCandidateFoundation1);
1462 JsepSessionDescription jdesc(kDummyString);
1463 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1464
1465 // Only add the candidates to audio m line.
1466 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1467 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1468 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1469 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
1470 std::string message = webrtc::SdpSerialize(jdesc);
1471
1472 // Audio line should have a c line like this one.
1473 EXPECT_NE(message.find("c=IN IP6 fe80::1234:5678:abcd:ef12"),
1474 std::string::npos);
1475 // Shouldn't have a IP4 c line.
1476 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
1477}
1478
1479// This tests serialization of SDP with only TCP candidates and verifies that
1480// null IPv4 is used as default address in c line.
1481TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithTCPOnly) {
1482 // Only test 1 m line.
1483 desc_.RemoveContentByName("video_content_name");
1484 // Stun has a high preference than local host.
1485 cricket::Candidate candidate1(
1486 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1487 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1488 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1489 cricket::Candidate candidate2(
1490 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1491 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
1492 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1493 JsepSessionDescription jdesc(kDummyString);
1494 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1495
1496 // Only add the candidates to audio m line.
1497 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1498 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1499 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1500 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
1501 std::string message = webrtc::SdpSerialize(jdesc);
1502
1503 // Audio line should have a c line like this one when no any default exists.
1504 EXPECT_NE(message.find("c=IN IP4 0.0.0.0"), std::string::npos);
1505}
1506
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001507// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1508// the case in a DTLS offer.
1509TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1510 AddFingerprint();
1511 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1512 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1513 kSessionId, kSessionVersion));
1514 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
1515
1516 std::string sdp_with_fingerprint = kSdpString;
1517 InjectAfter(kAttributeIcePwdVoice,
1518 kFingerprint, &sdp_with_fingerprint);
1519 InjectAfter(kAttributeIcePwdVideo,
1520 kFingerprint, &sdp_with_fingerprint);
1521
1522 EXPECT_EQ(sdp_with_fingerprint, message);
1523}
1524
1525// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1526// be the case in a DTLS answer.
1527TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1528 AddFingerprint();
1529 RemoveCryptos();
1530 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1531 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1532 kSessionId, kSessionVersion));
1533 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
1534
1535 std::string sdp_with_fingerprint = kSdpString;
1536 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1537 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
1538 InjectAfter(kAttributeIcePwdVoice,
1539 kFingerprint, &sdp_with_fingerprint);
1540 InjectAfter(kAttributeIcePwdVideo,
1541 kFingerprint, &sdp_with_fingerprint);
1542
1543 EXPECT_EQ(sdp_with_fingerprint, message);
1544}
1545
1546TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1547 // JsepSessionDescription with desc but without candidates.
1548 JsepSessionDescription jdesc_no_candidates(kDummyString);
deadbeef3f7219b2015-12-28 15:17:14 -08001549 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
1550 kSessionVersion));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001551 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
1552 EXPECT_EQ(std::string(kSdpString), message);
1553}
1554
1555TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1556 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1557 group.AddContentName(kAudioContentName);
1558 group.AddContentName(kVideoContentName);
1559 desc_.AddGroup(group);
1560 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1561 jdesc_.session_id(),
1562 jdesc_.session_version()));
1563 std::string message = webrtc::SdpSerialize(jdesc_);
1564 std::string sdp_with_bundle = kSdpFullString;
1565 InjectAfter(kSessionTime,
1566 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1567 &sdp_with_bundle);
1568 EXPECT_EQ(sdp_with_bundle, message);
1569}
1570
1571TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
1572 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1573 GetFirstVideoContent(&desc_)->description);
1574 vcd->set_bandwidth(100 * 1000);
1575 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1576 GetFirstAudioContent(&desc_)->description);
1577 acd->set_bandwidth(50 * 1000);
1578 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1579 jdesc_.session_id(),
1580 jdesc_.session_version()));
1581 std::string message = webrtc::SdpSerialize(jdesc_);
1582 std::string sdp_with_bandwidth = kSdpFullString;
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001583 InjectAfter("c=IN IP4 74.125.224.39\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001584 "b=AS:100\r\n",
1585 &sdp_with_bandwidth);
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001586 InjectAfter("c=IN IP4 74.125.127.126\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001587 "b=AS:50\r\n",
1588 &sdp_with_bandwidth);
1589 EXPECT_EQ(sdp_with_bandwidth, message);
1590}
1591
1592TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1593 std::vector<std::string> transport_options;
1594 transport_options.push_back(kIceOption1);
1595 transport_options.push_back(kIceOption3);
1596 AddIceOptions(kAudioContentName, transport_options);
1597 transport_options.clear();
1598 transport_options.push_back(kIceOption2);
1599 transport_options.push_back(kIceOption3);
1600 AddIceOptions(kVideoContentName, transport_options);
1601 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1602 jdesc_.session_id(),
1603 jdesc_.session_version()));
1604 std::string message = webrtc::SdpSerialize(jdesc_);
1605 std::string sdp_with_ice_options = kSdpFullString;
1606 InjectAfter(kAttributeIcePwdVoice,
1607 "a=ice-options:iceoption1 iceoption3\r\n",
1608 &sdp_with_ice_options);
1609 InjectAfter(kAttributeIcePwdVideo,
1610 "a=ice-options:iceoption2 iceoption3\r\n",
1611 &sdp_with_ice_options);
1612 EXPECT_EQ(sdp_with_ice_options, message);
1613}
1614
1615TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
1616 EXPECT_TRUE(TestSerializeDirection(cricket::MD_RECVONLY));
1617}
1618
1619TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
1620 EXPECT_TRUE(TestSerializeDirection(cricket::MD_SENDONLY));
1621}
1622
1623TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
1624 EXPECT_TRUE(TestSerializeDirection(cricket::MD_INACTIVE));
1625}
1626
1627TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
1628 EXPECT_TRUE(TestSerializeRejected(true, false));
1629}
1630
1631TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
1632 EXPECT_TRUE(TestSerializeRejected(false, true));
1633}
1634
1635TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
1636 EXPECT_TRUE(TestSerializeRejected(true, true));
1637}
1638
1639TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
1640 AddRtpDataChannel();
1641 JsepSessionDescription jsep_desc(kDummyString);
1642
1643 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1644 std::string message = webrtc::SdpSerialize(jsep_desc);
1645
1646 std::string expected_sdp = kSdpString;
1647 expected_sdp.append(kSdpRtpDataChannelString);
1648 EXPECT_EQ(expected_sdp, message);
1649}
1650
1651TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
1652 AddSctpDataChannel();
1653 JsepSessionDescription jsep_desc(kDummyString);
1654
1655 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1656 std::string message = webrtc::SdpSerialize(jsep_desc);
1657
1658 std::string expected_sdp = kSdpString;
1659 expected_sdp.append(kSdpSctpDataChannelString);
1660 EXPECT_EQ(message, expected_sdp);
1661}
1662
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001663TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
1664 AddSctpDataChannel();
1665 JsepSessionDescription jsep_desc(kDummyString);
1666
1667 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1668 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
1669 jsep_desc.description()->GetContentDescriptionByName(kDataContentName));
1670
1671 const int kNewPort = 1234;
1672 cricket::DataCodec codec(
1673 cricket::kGoogleSctpDataCodecId, cricket::kGoogleSctpDataCodecName, 0);
1674 codec.SetParam(cricket::kCodecParamPort, kNewPort);
1675 dcdesc->AddOrReplaceCodec(codec);
1676
1677 std::string message = webrtc::SdpSerialize(jsep_desc);
1678
1679 std::string expected_sdp = kSdpString;
1680 expected_sdp.append(kSdpSctpDataChannelString);
1681
1682 char default_portstr[16];
1683 char new_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001684 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001685 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001686 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
1687 rtc::replace_substrs(default_portstr, strlen(default_portstr),
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001688 new_portstr, strlen(new_portstr),
1689 &expected_sdp);
1690
1691 EXPECT_EQ(expected_sdp, message);
1692}
1693
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001694TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
1695 AddRtpDataChannel();
1696 data_desc_->set_bandwidth(100*1000);
1697 JsepSessionDescription jsep_desc(kDummyString);
1698
1699 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1700 std::string message = webrtc::SdpSerialize(jsep_desc);
1701
1702 std::string expected_sdp = kSdpString;
1703 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07001704 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00001705 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 +00001706 "b=AS:100\r\n",
1707 &expected_sdp);
1708 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001709}
1710
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001711TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
1712 AddExtmap();
1713 JsepSessionDescription desc_with_extmap("dummy");
1714 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(),
1715 kSessionId, kSessionVersion));
1716 std::string message = webrtc::SdpSerialize(desc_with_extmap);
1717
1718 std::string sdp_with_extmap = kSdpString;
1719 InjectAfter("a=mid:audio_content_name\r\n",
1720 kExtmap, &sdp_with_extmap);
1721 InjectAfter("a=mid:video_content_name\r\n",
1722 kExtmap, &sdp_with_extmap);
1723
1724 EXPECT_EQ(sdp_with_extmap, message);
1725}
1726
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001727TEST_F(WebRtcSdpTest, SerializeCandidates) {
1728 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00001729 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08001730
1731 Candidate candidate_with_ufrag(candidates_.front());
1732 candidate_with_ufrag.set_username("ABC");
1733 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
1734 candidate_with_ufrag));
1735 message = webrtc::SdpSerializeCandidate(*jcandidate_);
1736 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001737}
1738
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00001739// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
1740// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00001741TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001742 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001743 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
1744 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
1745 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00001746 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
1747 rtc::scoped_ptr<IceCandidateInterface> jcandidate(
1748 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
1749
1750 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
1751 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
1752}
1753
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001754TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
1755 JsepSessionDescription jdesc(kDummyString);
1756 // Deserialize
1757 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
1758 // Verify
1759 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1760}
1761
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001762TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
1763 JsepSessionDescription jdesc(kDummyString);
1764 const char kSdpWithoutMline[] =
1765 "v=0\r\n"
1766 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1767 "s=-\r\n"
1768 "t=0 0\r\n"
1769 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
1770 // Deserialize
1771 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
1772 EXPECT_EQ(0u, jdesc.description()->contents().size());
1773}
1774
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001775TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
1776 JsepSessionDescription jdesc(kDummyString);
1777 std::string sdp_without_carriage_return = kSdpFullString;
1778 Replace("\r\n", "\n", &sdp_without_carriage_return);
1779 // Deserialize
1780 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
1781 // Verify
1782 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1783}
1784
1785TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
1786 // SessionDescription with desc but without candidates.
1787 JsepSessionDescription jdesc_no_candidates(kDummyString);
1788 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
1789 kSessionId, kSessionVersion));
1790 JsepSessionDescription new_jdesc(kDummyString);
1791 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
1792 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
1793}
1794
1795TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
1796 static const char kSdpNoRtpmapString[] =
1797 "v=0\r\n"
1798 "o=- 11 22 IN IP4 127.0.0.1\r\n"
1799 "s=-\r\n"
1800 "t=0 0\r\n"
1801 "m=audio 49232 RTP/AVP 0 18 103\r\n"
1802 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001803 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001804 // The rtpmap line for static payload codec is optional.
1805 "a=rtpmap:18 G729/16000\r\n"
1806 "a=rtpmap:103 ISAC/16000\r\n";
1807
1808 JsepSessionDescription jdesc(kDummyString);
1809 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
1810 cricket::AudioContentDescription* audio =
1811 static_cast<AudioContentDescription*>(
1812 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
1813 AudioCodecs ref_codecs;
1814 // The codecs in the AudioContentDescription will be sorted by preference.
1815 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1, 3));
1816 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1, 2));
1817 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 32000, 1, 1));
1818 EXPECT_EQ(ref_codecs, audio->codecs());
1819}
1820
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001821TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
1822 static const char kSdpNoRtpmapString[] =
1823 "v=0\r\n"
1824 "o=- 11 22 IN IP4 127.0.0.1\r\n"
1825 "s=-\r\n"
1826 "t=0 0\r\n"
1827 "m=audio 49232 RTP/AVP 18 103\r\n"
1828 "a=fmtp:18 annexb=yes\r\n"
1829 "a=rtpmap:103 ISAC/16000\r\n";
1830
1831 JsepSessionDescription jdesc(kDummyString);
1832 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
1833 cricket::AudioContentDescription* audio =
1834 static_cast<AudioContentDescription*>(
1835 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
1836
1837 cricket::AudioCodec g729 = audio->codecs()[0];
1838 EXPECT_EQ("G729", g729.name);
1839 EXPECT_EQ(8000, g729.clockrate);
1840 EXPECT_EQ(18, g729.id);
1841 cricket::CodecParameterMap::iterator found =
1842 g729.params.find("annexb");
1843 ASSERT_TRUE(found != g729.params.end());
1844 EXPECT_EQ(found->second, "yes");
1845
1846 cricket::AudioCodec isac = audio->codecs()[1];
1847 EXPECT_EQ("ISAC", isac.name);
1848 EXPECT_EQ(103, isac.id);
1849 EXPECT_EQ(16000, isac.clockrate);
1850}
1851
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001852// Ensure that we can deserialize SDP with a=fingerprint properly.
1853TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
1854 // Add a DTLS a=fingerprint attribute to our session description.
1855 AddFingerprint();
1856 JsepSessionDescription new_jdesc(kDummyString);
1857 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1858 jdesc_.session_id(),
1859 jdesc_.session_version()));
1860
1861 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1862 std::string sdp_with_fingerprint = kSdpString;
1863 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1864 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
1865 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
1866 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
1867}
1868
1869TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
1870 JsepSessionDescription jdesc_with_bundle(kDummyString);
1871 std::string sdp_with_bundle = kSdpFullString;
1872 InjectAfter(kSessionTime,
1873 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1874 &sdp_with_bundle);
1875 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
1876 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1877 group.AddContentName(kAudioContentName);
1878 group.AddContentName(kVideoContentName);
1879 desc_.AddGroup(group);
1880 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1881 jdesc_.session_id(),
1882 jdesc_.session_version()));
1883 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
1884}
1885
1886TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
1887 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
1888 std::string sdp_with_bandwidth = kSdpFullString;
1889 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
1890 "b=AS:100\r\n",
1891 &sdp_with_bandwidth);
1892 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
1893 "b=AS:50\r\n",
1894 &sdp_with_bandwidth);
1895 EXPECT_TRUE(
1896 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
1897 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1898 GetFirstVideoContent(&desc_)->description);
1899 vcd->set_bandwidth(100 * 1000);
1900 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1901 GetFirstAudioContent(&desc_)->description);
1902 acd->set_bandwidth(50 * 1000);
1903 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1904 jdesc_.session_id(),
1905 jdesc_.session_version()));
1906 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
1907}
1908
1909TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
1910 JsepSessionDescription jdesc_with_ice_options(kDummyString);
1911 std::string sdp_with_ice_options = kSdpFullString;
1912 InjectAfter(kSessionTime,
1913 "a=ice-options:iceoption3\r\n",
1914 &sdp_with_ice_options);
1915 InjectAfter(kAttributeIcePwdVoice,
1916 "a=ice-options:iceoption1\r\n",
1917 &sdp_with_ice_options);
1918 InjectAfter(kAttributeIcePwdVideo,
1919 "a=ice-options:iceoption2\r\n",
1920 &sdp_with_ice_options);
1921 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
1922 std::vector<std::string> transport_options;
1923 transport_options.push_back(kIceOption3);
1924 transport_options.push_back(kIceOption1);
1925 AddIceOptions(kAudioContentName, transport_options);
1926 transport_options.clear();
1927 transport_options.push_back(kIceOption3);
1928 transport_options.push_back(kIceOption2);
1929 AddIceOptions(kVideoContentName, transport_options);
1930 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1931 jdesc_.session_id(),
1932 jdesc_.session_version()));
1933 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
1934}
1935
1936TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
1937 // Remove the original ice-ufrag and ice-pwd
1938 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyString);
1939 std::string sdp_with_ufrag_pwd = kSdpFullString;
1940 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
1941 // Add session level ufrag and pwd
1942 InjectAfter(kSessionTime,
1943 "a=ice-pwd:session+level+icepwd\r\n"
1944 "a=ice-ufrag:session+level+iceufrag\r\n",
1945 &sdp_with_ufrag_pwd);
1946 // Add media level ufrag and pwd for audio
1947 InjectAfter("a=mid:audio_content_name\r\n",
1948 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
1949 &sdp_with_ufrag_pwd);
1950 // Update the candidate ufrag and pwd to the expected ones.
1951 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0,
1952 "media+level+iceufrag", "media+level+icepwd"));
1953 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1,
1954 "session+level+iceufrag", "session+level+icepwd"));
1955 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
1956 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
1957}
1958
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001959TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
1960 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_RECVONLY));
1961}
1962
1963TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
1964 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_SENDONLY));
1965}
1966
1967TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
1968 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_INACTIVE));
1969}
1970
1971TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
1972 EXPECT_TRUE(TestDeserializeRejected(true, false));
1973}
1974
1975TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
1976 EXPECT_TRUE(TestDeserializeRejected(false, true));
1977}
1978
1979TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
1980 EXPECT_TRUE(TestDeserializeRejected(true, true));
1981}
1982
1983// Tests that we can still handle the sdp uses mslabel and label instead of
1984// msid for backward compatibility.
1985TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07001986 jdesc_.description()->set_msid_supported(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001987 JsepSessionDescription jdesc(kDummyString);
1988 std::string sdp_without_msid = kSdpFullString;
1989 Replace("msid", "xmsid", &sdp_without_msid);
1990 // Deserialize
1991 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
1992 // Verify
1993 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1994}
1995
1996TEST_F(WebRtcSdpTest, DeserializeCandidate) {
1997 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
1998
1999 std::string sdp = kSdpOneCandidate;
2000 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2001 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2002 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2003 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2004
2005 // Candidate line without generation extension.
2006 sdp = kSdpOneCandidate;
2007 Replace(" generation 2", "", &sdp);
2008 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2009 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2010 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2011 Candidate expected = jcandidate_->candidate();
2012 expected.set_generation(0);
2013 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2014
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002015 sdp = kSdpTcpActiveCandidate;
2016 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2017 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002018 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002019 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2020 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2021 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002022 rtc::scoped_ptr<IceCandidateInterface> jcandidate_template(
2023 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
2024 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(
2025 jcandidate_template->candidate()));
2026 sdp = kSdpTcpPassiveCandidate;
2027 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2028 sdp = kSdpTcpSOCandidate;
2029 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002030}
2031
2032// This test verifies the deserialization of candidate-attribute
2033// as per RFC 5245. Candiate-attribute will be of the format
2034// candidate:<blah>. This format will be used when candidates
2035// are trickled.
2036TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2037 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2038
2039 std::string candidate_attribute = kRawCandidate;
2040 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2041 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2042 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2043 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2044 EXPECT_EQ(2u, jcandidate.candidate().generation());
2045
2046 // Candidate line without generation extension.
2047 candidate_attribute = kRawCandidate;
2048 Replace(" generation 2", "", &candidate_attribute);
2049 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2050 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2051 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2052 Candidate expected = jcandidate_->candidate();
2053 expected.set_generation(0);
2054 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2055
2056 // Candidate line without candidate:
2057 candidate_attribute = kRawCandidate;
2058 Replace("candidate:", "", &candidate_attribute);
2059 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2060
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002061 // Candidate line with IPV6 address.
2062 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
2063}
2064
2065// This test verifies that the deserialization of an invalid candidate string
2066// fails.
2067TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
2068 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2069
2070 std::string candidate_attribute = kRawCandidate;
2071 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002072 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002073
2074 candidate_attribute = kSdpOneCandidate;
2075 candidate_attribute.replace(0, 1, "x");
2076 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2077
2078 candidate_attribute = kRawCandidate;
2079 candidate_attribute.append("\r\n");
2080 candidate_attribute.append(kRawCandidate);
2081 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2082
2083 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002084}
2085
2086TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2087 AddRtpDataChannel();
2088 JsepSessionDescription jdesc(kDummyString);
2089 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2090
2091 std::string sdp_with_data = kSdpString;
2092 sdp_with_data.append(kSdpRtpDataChannelString);
2093 JsepSessionDescription jdesc_output(kDummyString);
2094
2095 // Deserialize
2096 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2097 // Verify
2098 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2099}
2100
2101TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
2102 AddSctpDataChannel();
2103 JsepSessionDescription jdesc(kDummyString);
2104 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2105
2106 std::string sdp_with_data = kSdpString;
2107 sdp_with_data.append(kSdpSctpDataChannelString);
2108 JsepSessionDescription jdesc_output(kDummyString);
2109
lally@webrtc.org36300852015-02-24 20:19:35 +00002110 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2111 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2112 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2113
2114 // Verify with UDP/DTLS/SCTP.
2115 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2116 strlen(kDtlsSctp), kUdpDtlsSctp);
2117 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2118 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2119
2120 // Verify with TCP/DTLS/SCTP.
2121 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2122 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002123 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2124 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2125}
2126
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002127TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
2128 AddSctpDataChannel();
2129 JsepSessionDescription jdesc(kDummyString);
2130 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2131
2132 std::string sdp_with_data = kSdpString;
2133 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2134 JsepSessionDescription jdesc_output(kDummyString);
2135
lally@webrtc.org36300852015-02-24 20:19:35 +00002136 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002137 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2138 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002139
lally@webrtc.org36300852015-02-24 20:19:35 +00002140 // Verify with UDP/DTLS/SCTP.
2141 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2142 strlen(kDtlsSctp), kUdpDtlsSctp);
2143 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2144 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002145
lally@webrtc.org36300852015-02-24 20:19:35 +00002146 // Verify with TCP/DTLS/SCTP.
2147 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2148 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002149 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2150 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2151}
2152
lally69f57602015-10-08 10:15:04 -07002153TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
2154 AddSctpDataChannel();
2155 JsepSessionDescription jdesc(kDummyString);
2156 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2157
2158 std::string sdp_with_data = kSdpString;
2159 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
2160 JsepSessionDescription jdesc_output(kDummyString);
2161
2162 // Verify with DTLS/SCTP.
2163 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2164 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2165
2166 // Verify with UDP/DTLS/SCTP.
2167 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2168 strlen(kDtlsSctp), kUdpDtlsSctp);
2169 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2170 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2171
2172 // Verify with TCP/DTLS/SCTP.
2173 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2174 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
2175 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2176 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2177}
2178
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002179// Test to check the behaviour if sctp-port is specified
2180// on the m= line and in a=sctp-port.
2181TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
2182 AddSctpDataChannel();
2183 JsepSessionDescription jdesc(kDummyString);
2184 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2185
2186 std::string sdp_with_data = kSdpString;
2187 // Append m= attributes
2188 sdp_with_data.append(kSdpSctpDataChannelString);
2189 // Append a=sctp-port attribute
2190 sdp_with_data.append("a=sctp-port 5000\r\n");
2191 JsepSessionDescription jdesc_output(kDummyString);
2192
2193 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2194}
2195
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002196// For crbug/344475.
2197TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2198 std::string sdp_with_data = kSdpString;
2199 sdp_with_data.append(kSdpSctpDataChannelString);
2200 // Remove the "\n" at the end.
2201 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
2202 JsepSessionDescription jdesc_output(kDummyString);
2203
2204 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2205 // No crash is a pass.
2206}
2207
wu@webrtc.org78187522013-10-07 23:32:02 +00002208TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndNewPort) {
2209 AddSctpDataChannel();
Peter Boström0c4e06b2015-10-07 12:23:21 +02002210 const uint16_t kUnusualSctpPort = 9556;
wu@webrtc.org78187522013-10-07 23:32:02 +00002211 char default_portstr[16];
2212 char unusual_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002213 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
wu@webrtc.org78187522013-10-07 23:32:02 +00002214 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002215 rtc::sprintfn(unusual_portstr, sizeof(unusual_portstr), "%d",
wu@webrtc.org78187522013-10-07 23:32:02 +00002216 kUnusualSctpPort);
2217
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002218 // First setup the expected JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002219 JsepSessionDescription jdesc(kDummyString);
2220 // take our pre-built session description and change the SCTP port.
2221 cricket::SessionDescription* mutant = desc_.Copy();
2222 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
2223 mutant->GetContentDescriptionByName(kDataContentName));
2224 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002225 EXPECT_EQ(1U, codecs.size());
2226 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002227 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002228 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002229
2230 // note: mutant's owned by jdesc now.
2231 ASSERT_TRUE(jdesc.Initialize(mutant, kSessionId, kSessionVersion));
2232 mutant = NULL;
2233
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002234 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002235 std::string sdp_with_data = kSdpString;
2236 sdp_with_data.append(kSdpSctpDataChannelString);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002237 rtc::replace_substrs(default_portstr, strlen(default_portstr),
wu@webrtc.org78187522013-10-07 23:32:02 +00002238 unusual_portstr, strlen(unusual_portstr),
2239 &sdp_with_data);
2240 JsepSessionDescription jdesc_output(kDummyString);
2241
2242 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2243 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002244
2245 // We need to test the deserialized JsepSessionDescription from
2246 // kSdpSctpDataChannelStringWithSctpPort for
2247 // draft-ietf-mmusic-sctp-sdp-07
2248 // a=sctp-port
2249 sdp_with_data = kSdpString;
2250 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2251 rtc::replace_substrs(default_portstr, strlen(default_portstr),
2252 unusual_portstr, strlen(unusual_portstr),
2253 &sdp_with_data);
2254
2255 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2256 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002257}
2258
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002259TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002260 // We want to test that deserializing data content limits bandwidth
2261 // settings (it should never be greater than the default).
2262 // This should prevent someone from using unlimited data bandwidth through
2263 // JS and "breaking the Internet".
2264 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002265 std::string sdp_with_bandwidth = kSdpString;
2266 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
2267 InjectAfter("a=mid:data_content_name\r\n",
2268 "b=AS:100\r\n",
2269 &sdp_with_bandwidth);
2270 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2271
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002272 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2273}
2274
2275TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
2276 AddSctpDataChannel();
2277 JsepSessionDescription jdesc(kDummyString);
2278 DataContentDescription* dcd = static_cast<DataContentDescription*>(
2279 GetFirstDataContent(&desc_)->description);
2280 dcd->set_bandwidth(100 * 1000);
2281 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2282
2283 std::string sdp_with_bandwidth = kSdpString;
2284 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
2285 InjectAfter("a=mid:data_content_name\r\n",
2286 "b=AS:100\r\n",
2287 &sdp_with_bandwidth);
2288 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2289
2290 // SCTP has congestion control, so we shouldn't limit the bandwidth
2291 // as we do for RTP.
2292 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002293 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2294}
2295
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002296TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSessionLevelExtmap) {
2297 TestDeserializeExtmap(true, false);
2298}
2299
2300TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
2301 TestDeserializeExtmap(false, true);
2302}
2303
2304TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInvalidExtmap) {
2305 TestDeserializeExtmap(true, true);
2306}
2307
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002308TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
2309 JsepSessionDescription jdesc(kDummyString);
2310 std::string sdp = kSdpFullString;
2311 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2312 // Deserialize
2313 SdpParseError error;
2314 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
2315 const std::string lastline = "a=ssrc:6 label:video_track_id_3";
2316 EXPECT_EQ(lastline, error.line);
2317 EXPECT_EQ("Invalid SDP line.", error.description);
2318}
2319
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002320TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2321 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2322 std::string new_sdp = kSdpOneCandidate;
2323 Replace("udp", "unsupported_transport", &new_sdp);
2324 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2325 new_sdp = kSdpOneCandidate;
2326 Replace("udp", "uDP", &new_sdp);
2327 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2328 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2329 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2330 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2331}
2332
honghaiza54a0802015-12-16 18:37:23 -08002333TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002334 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08002335 EXPECT_TRUE(
2336 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002337 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2338 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2339 Candidate ref_candidate = jcandidate_->candidate();
2340 ref_candidate.set_username("user_rtp");
2341 ref_candidate.set_password("password_rtp");
2342 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2343}
2344
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002345TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
2346 JsepSessionDescription jdesc(kDummyString);
2347
2348 // Deserialize
2349 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2350
2351 // Verify
2352 cricket::AudioContentDescription* audio =
2353 static_cast<AudioContentDescription*>(
2354 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2355 EXPECT_TRUE(audio->conference_mode());
2356
2357 cricket::VideoContentDescription* video =
2358 static_cast<VideoContentDescription*>(
2359 jdesc.description()->GetContentDescriptionByName(cricket::CN_VIDEO));
2360 EXPECT_TRUE(video->conference_mode());
2361}
2362
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002363TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2364 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002365 const char kSdpEmptyType[] = " =candidate";
2366 const char kSdpEqualAsPlus[] = "a+candidate";
2367 const char kSdpSpaceAfterEqual[] = "a= candidate";
2368 const char kSdpUpperType[] = "A=candidate";
2369 const char kSdpEmptyLine[] = "";
2370 const char kSdpMissingValue[] = "a=";
2371
2372 const char kSdpBrokenFingerprint[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002373 "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 +00002374 const char kSdpExtraField[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002375 "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 +00002376 const char kSdpMissingSpace[] = "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002377 "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 +00002378 // MD5 is not allowed in fingerprints.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002379 const char kSdpMd5[] = "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002380 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002381
2382 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002383 ExpectParseFailure("v=", kSdpDestroyer);
2384 ExpectParseFailure("o=", kSdpDestroyer);
2385 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002386 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002387 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002388
2389 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002390 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2391 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002392
2393 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002394 ExpectParseFailure("a=candidate", kSdpEmptyType);
2395 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2396 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
2397 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002398
2399 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2400 // because it's orthogonal to what we are replacing and hence
2401 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002402 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
2403 ExpectParseFailure("a=sendrecv", kSdpExtraField);
2404 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
2405 ExpectParseFailure("a=sendrecv", kSdpMd5);
2406
2407 // Empty Line
2408 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
2409 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002410}
2411
2412TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2413 // ssrc
2414 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
2415 ExpectParseFailure("a=ssrc-group:FEC 5 6", "a=ssrc-group:FEC badvalue 6");
2416 // crypto
2417 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
2418 // rtpmap
2419 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
2420 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
2421 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
2422 // candidate
2423 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
2424 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
2425 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
2426 ExpectParseFailure("rport 2346", "rport badvalue");
2427 ExpectParseFailure("rport 2346 generation 2",
2428 "rport 2346 generation badvalue");
2429 // m line
2430 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
2431 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
2432
2433 // bandwidth
2434 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2435 "b=AS:badvalue\r\n",
2436 "b=AS:badvalue");
2437 // rtcp-fb
2438 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2439 "a=rtcp-fb:badvalue nack\r\n",
2440 "a=rtcp-fb:badvalue nack");
2441 // extmap
2442 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2443 "a=extmap:badvalue http://example.com\r\n",
2444 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002445}
2446
2447TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
2448 JsepSessionDescription jdesc_output(kDummyString);
2449
2450 const char kSdpWithReorderedPlTypesString[] =
2451 "v=0\r\n"
2452 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2453 "s=-\r\n"
2454 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00002455 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002456 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
2457 // in the map.
2458 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002459 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002460
2461 // Deserialize
2462 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
2463
2464 const ContentInfo* ac = GetFirstAudioContent(jdesc_output.description());
2465 ASSERT_TRUE(ac != NULL);
2466 const AudioContentDescription* acd =
2467 static_cast<const AudioContentDescription*>(ac->description);
2468 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002469 EXPECT_EQ("ISAC", acd->codecs()[0].name);
2470 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002471 EXPECT_EQ(104, acd->codecs()[0].id);
2472}
2473
2474TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
2475 JsepSessionDescription jdesc_output(kDummyString);
2476 CodecParams params;
2477 params.max_ptime = 40;
2478 params.ptime = 30;
2479 params.min_ptime = 10;
2480 params.sprop_stereo = 1;
2481 params.stereo = 1;
2482 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002483 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002484 TestDeserializeCodecParams(params, &jdesc_output);
2485 TestSerialize(jdesc_output);
2486}
2487
2488TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
2489 const bool kUseWildcard = false;
2490 JsepSessionDescription jdesc_output(kDummyString);
2491 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
2492 TestSerialize(jdesc_output);
2493}
2494
2495TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
2496 const bool kUseWildcard = true;
2497 JsepSessionDescription jdesc_output(kDummyString);
2498 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
2499 TestSerialize(jdesc_output);
2500}
2501
2502TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
2503 JsepSessionDescription jdesc_output(kDummyString);
2504
2505 const char kSdpWithFmtpString[] =
2506 "v=0\r\n"
2507 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2508 "s=-\r\n"
2509 "t=0 0\r\n"
2510 "m=video 3457 RTP/SAVPF 120\r\n"
2511 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07002512 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
2513
2514 // Deserialize
2515 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07002516 EXPECT_TRUE(
2517 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07002518
2519 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2520 ASSERT_TRUE(vc != NULL);
2521 const VideoContentDescription* vcd =
2522 static_cast<const VideoContentDescription*>(vc->description);
2523 ASSERT_FALSE(vcd->codecs().empty());
2524 cricket::VideoCodec vp8 = vcd->codecs()[0];
2525 EXPECT_EQ("VP8", vp8.name);
2526 EXPECT_EQ(120, vp8.id);
2527 cricket::CodecParameterMap::iterator found =
2528 vp8.params.find("x-google-min-bitrate");
2529 ASSERT_TRUE(found != vp8.params.end());
2530 EXPECT_EQ(found->second, "10");
2531 found = vp8.params.find("x-google-max-quantization");
2532 ASSERT_TRUE(found != vp8.params.end());
2533 EXPECT_EQ(found->second, "40");
2534}
2535
2536TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
2537 JsepSessionDescription jdesc_output(kDummyString);
2538
2539 const char kSdpWithFmtpString[] =
2540 "v=0\r\n"
2541 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2542 "s=-\r\n"
2543 "t=0 0\r\n"
2544 "m=video 3457 RTP/SAVPF 120\r\n"
2545 "a=rtpmap:120 VP8/90000\r\n"
2546 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002547
2548 // Deserialize
2549 SdpParseError error;
2550 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output,
2551 &error));
2552
2553 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2554 ASSERT_TRUE(vc != NULL);
2555 const VideoContentDescription* vcd =
2556 static_cast<const VideoContentDescription*>(vc->description);
2557 ASSERT_FALSE(vcd->codecs().empty());
2558 cricket::VideoCodec vp8 = vcd->codecs()[0];
2559 EXPECT_EQ("VP8", vp8.name);
2560 EXPECT_EQ(120, vp8.id);
2561 cricket::CodecParameterMap::iterator found =
2562 vp8.params.find("x-google-min-bitrate");
2563 ASSERT_TRUE(found != vp8.params.end());
2564 EXPECT_EQ(found->second, "10");
2565 found = vp8.params.find("x-google-max-quantization");
2566 ASSERT_TRUE(found != vp8.params.end());
2567 EXPECT_EQ(found->second, "40");
2568}
2569
2570TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
2571 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
2572 GetFirstVideoContent(&desc_)->description);
2573
2574 cricket::VideoCodecs codecs = vcd->codecs();
2575 codecs[0].params["x-google-min-bitrate"] = "10";
2576 vcd->set_codecs(codecs);
2577
2578 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2579 jdesc_.session_id(),
2580 jdesc_.session_version()));
2581 std::string message = webrtc::SdpSerialize(jdesc_);
2582 std::string sdp_with_fmtp = kSdpFullString;
2583 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
2584 "a=fmtp:120 x-google-min-bitrate=10\r\n",
2585 &sdp_with_fmtp);
2586 EXPECT_EQ(sdp_with_fmtp, message);
2587}
2588
2589TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) {
2590 JsepSessionDescription jdesc_with_icelite(kDummyString);
2591 std::string sdp_with_icelite = kSdpFullString;
2592 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
2593 cricket::SessionDescription* desc = jdesc_with_icelite.description();
2594 const cricket::TransportInfo* tinfo1 =
2595 desc->GetTransportInfoByName("audio_content_name");
2596 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
2597 const cricket::TransportInfo* tinfo2 =
2598 desc->GetTransportInfoByName("video_content_name");
2599 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
2600 InjectAfter(kSessionTime,
2601 "a=ice-lite\r\n",
2602 &sdp_with_icelite);
2603 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
2604 desc = jdesc_with_icelite.description();
2605 const cricket::TransportInfo* atinfo =
2606 desc->GetTransportInfoByName("audio_content_name");
2607 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
2608 const cricket::TransportInfo* vtinfo =
2609 desc->GetTransportInfoByName("video_content_name");
2610 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
2611}
2612
2613// Verifies that the candidates in the input SDP are parsed and serialized
2614// correctly in the output SDP.
2615TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
2616 std::string sdp_with_data = kSdpString;
2617 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
2618 JsepSessionDescription jdesc_output(kDummyString);
2619
2620 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2621 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
2622}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00002623
2624TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
2625 AddFingerprint();
2626 TransportInfo audio_transport_info =
2627 *(desc_.GetTransportInfoByName(kAudioContentName));
2628 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
2629 audio_transport_info.description.connection_role);
2630 audio_transport_info.description.connection_role =
2631 cricket::CONNECTIONROLE_ACTIVE;
2632
2633 TransportInfo video_transport_info =
2634 *(desc_.GetTransportInfoByName(kVideoContentName));
2635 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
2636 video_transport_info.description.connection_role);
2637 video_transport_info.description.connection_role =
2638 cricket::CONNECTIONROLE_ACTIVE;
2639
2640 desc_.RemoveTransportInfoByName(kAudioContentName);
2641 desc_.RemoveTransportInfoByName(kVideoContentName);
2642
2643 desc_.AddTransportInfo(audio_transport_info);
2644 desc_.AddTransportInfo(video_transport_info);
2645
2646 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2647 jdesc_.session_id(),
2648 jdesc_.session_version()));
2649 std::string message = webrtc::SdpSerialize(jdesc_);
2650 std::string sdp_with_dtlssetup = kSdpFullString;
2651
2652 // Fingerprint attribute is necessary to add DTLS setup attribute.
2653 InjectAfter(kAttributeIcePwdVoice,
2654 kFingerprint, &sdp_with_dtlssetup);
2655 InjectAfter(kAttributeIcePwdVideo,
2656 kFingerprint, &sdp_with_dtlssetup);
2657 // Now adding |setup| attribute.
2658 InjectAfter(kFingerprint,
2659 "a=setup:active\r\n", &sdp_with_dtlssetup);
2660 EXPECT_EQ(sdp_with_dtlssetup, message);
2661}
2662
2663TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
2664 JsepSessionDescription jdesc_with_dtlssetup(kDummyString);
2665 std::string sdp_with_dtlssetup = kSdpFullString;
2666 InjectAfter(kSessionTime,
2667 "a=setup:actpass\r\n",
2668 &sdp_with_dtlssetup);
2669 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
2670 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
2671 const cricket::TransportInfo* atinfo =
2672 desc->GetTransportInfoByName("audio_content_name");
2673 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
2674 atinfo->description.connection_role);
2675 const cricket::TransportInfo* vtinfo =
2676 desc->GetTransportInfoByName("video_content_name");
2677 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
2678 vtinfo->description.connection_role);
2679}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00002680
2681// Verifies that the order of the serialized m-lines follows the order of the
2682// ContentInfo in SessionDescription, and vise versa for deserialization.
2683TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
2684 JsepSessionDescription jdesc(kDummyString);
2685 const std::string media_content_sdps[3] = {
2686 kSdpAudioString,
2687 kSdpVideoString,
2688 kSdpSctpDataChannelString
2689 };
2690 const cricket::MediaType media_types[3] = {
2691 cricket::MEDIA_TYPE_AUDIO,
2692 cricket::MEDIA_TYPE_VIDEO,
2693 cricket::MEDIA_TYPE_DATA
2694 };
2695
2696 // Verifies all 6 permutations.
2697 for (size_t i = 0; i < 6; ++i) {
2698 size_t media_content_in_sdp[3];
2699 // The index of the first media content.
2700 media_content_in_sdp[0] = i / 2;
2701 // The index of the second media content.
2702 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
2703 // The index of the third media content.
2704 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
2705
2706 std::string sdp_string = kSdpSessionString;
2707 for (size_t i = 0; i < 3; ++i)
2708 sdp_string += media_content_sdps[media_content_in_sdp[i]];
2709
2710 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
2711 cricket::SessionDescription* desc = jdesc.description();
2712 EXPECT_EQ(3u, desc->contents().size());
2713
2714 for (size_t i = 0; i < 3; ++i) {
2715 const cricket::MediaContentDescription* mdesc =
2716 static_cast<const cricket::MediaContentDescription*>(
2717 desc->contents()[i].description);
2718 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
2719 }
2720
2721 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
2722 EXPECT_EQ(sdp_string, serialized_sdp);
2723 }
2724}