blob: f5cac8921f3a3fddadf0672f372ce9f2c4713d1d [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
kwibergd1fe2812016-04-27 06:47:29 -070011#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000012#include <set>
13#include <string>
14#include <vector>
15
Henrik Kjellander15583c12016-02-10 10:53:12 +010016#include "webrtc/api/jsepsessiondescription.h"
nissec80e7412017-01-11 05:56:46 -080017#include "webrtc/base/checks.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000018#include "webrtc/base/gunit.h"
19#include "webrtc/base/logging.h"
20#include "webrtc/base/messagedigest.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000021#include "webrtc/base/sslfingerprint.h"
22#include "webrtc/base/stringencode.h"
23#include "webrtc/base/stringutils.h"
kjellanderf4752772016-03-02 05:42:30 -080024#include "webrtc/media/base/mediaconstants.h"
htaa6b99442016-04-12 10:29:17 -070025#include "webrtc/media/engine/webrtcvideoengine2.h"
26#include "webrtc/modules/video_coding/codecs/h264/include/h264.h"
kjellanderf4752772016-03-02 05:42:30 -080027#include "webrtc/p2p/base/p2pconstants.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010028#include "webrtc/pc/mediasession.h"
ossu7bb87ee2017-01-23 04:56:25 -080029#ifdef WEBRTC_ANDROID
30#include "webrtc/pc/test/androidtestinitializer.h"
31#endif
32#include "webrtc/pc/webrtcsdp.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000033
34using cricket::AudioCodec;
35using cricket::AudioContentDescription;
36using cricket::Candidate;
37using cricket::ContentInfo;
38using cricket::CryptoParams;
39using cricket::ContentGroup;
40using cricket::DataCodec;
41using cricket::DataContentDescription;
42using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
43using cricket::ICE_CANDIDATE_COMPONENT_RTP;
44using cricket::kFecSsrcGroupSemantics;
45using cricket::LOCAL_PORT_TYPE;
46using cricket::NS_JINGLE_DRAFT_SCTP;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047using cricket::NS_JINGLE_RTP;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000048using cricket::RELAY_PORT_TYPE;
49using cricket::SessionDescription;
50using cricket::StreamParams;
51using cricket::STUN_PORT_TYPE;
52using cricket::TransportDescription;
53using cricket::TransportInfo;
54using cricket::VideoCodec;
55using cricket::VideoContentDescription;
56using webrtc::IceCandidateCollection;
57using webrtc::IceCandidateInterface;
58using webrtc::JsepIceCandidate;
59using webrtc::JsepSessionDescription;
isheriff6f8d6862016-05-26 11:24:55 -070060using webrtc::RtpExtension;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061using webrtc::SdpParseError;
62using webrtc::SessionDescriptionInterface;
63
64typedef std::vector<AudioCodec> AudioCodecs;
65typedef std::vector<Candidate> Candidates;
66
Peter Boström0c4e06b2015-10-07 12:23:21 +020067static const uint32_t kDefaultSctpPort = 5000;
zstein4b2e0822017-02-17 19:48:38 -080068static const char kDefaultSctpPortStr[] = "5000";
69static const uint16_t kUnusualSctpPort = 9556;
70static const char kUnusualSctpPortStr[] = "9556";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020072static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 15:17:14 -080073static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
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
deadbeef9d3584c2016-02-16 17:54:10 -0800116// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
117// instead of "a=crypto", and have an explicit test for adding "a=crypto".
118// Currently it's the other way around.
119
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120// Reference sdp string
121static const char kSdpFullString[] =
122 "v=0\r\n"
123 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
124 "s=-\r\n"
125 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800126 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000127 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
128 "c=IN IP4 74.125.127.126\r\n"
129 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
130 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
131 "generation 2\r\n"
132 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
133 "generation 2\r\n"
134 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
135 "generation 2\r\n"
136 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
137 "generation 2\r\n"
138 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
139 "raddr 192.168.1.5 rport 2346 "
140 "generation 2\r\n"
141 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
142 "raddr 192.168.1.5 rport 2348 "
143 "generation 2\r\n"
144 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
145 "a=mid:audio_content_name\r\n"
146 "a=sendrecv\r\n"
147 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800148 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000149 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
150 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
151 "dummy_session_params\r\n"
152 "a=rtpmap:111 opus/48000/2\r\n"
153 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000154 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000155 "a=ssrc:1 cname:stream_1_cname\r\n"
156 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
157 "a=ssrc:1 mslabel:local_stream_1\r\n"
158 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000159 "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"
deadbeef9d3584c2016-02-16 17:54:10 -0800180 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000181 "a=ssrc:2 cname:stream_1_cname\r\n"
182 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
183 "a=ssrc:2 mslabel:local_stream_1\r\n"
184 "a=ssrc:2 label:video_track_id_1\r\n"
185 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800186 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800188 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000189
190// SDP reference string without the candidates.
191static const char kSdpString[] =
192 "v=0\r\n"
193 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
194 "s=-\r\n"
195 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800196 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000197 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000198 "c=IN IP4 0.0.0.0\r\n"
199 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000200 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
201 "a=mid:audio_content_name\r\n"
202 "a=sendrecv\r\n"
203 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800204 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000205 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
206 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
207 "dummy_session_params\r\n"
208 "a=rtpmap:111 opus/48000/2\r\n"
209 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000210 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 "a=ssrc:1 cname:stream_1_cname\r\n"
212 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
213 "a=ssrc:1 mslabel:local_stream_1\r\n"
214 "a=ssrc:1 label:audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000215 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000216 "c=IN IP4 0.0.0.0\r\n"
217 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000218 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
219 "a=mid:video_content_name\r\n"
220 "a=sendrecv\r\n"
221 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
222 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
223 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800224 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000225 "a=ssrc:2 cname:stream_1_cname\r\n"
226 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
227 "a=ssrc:2 mslabel:local_stream_1\r\n"
228 "a=ssrc:2 label:video_track_id_1\r\n"
229 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800230 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000231 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800232 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000233
234static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000235 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000236 "c=IN IP4 0.0.0.0\r\n"
237 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000238 "a=ice-ufrag:ufrag_data\r\n"
239 "a=ice-pwd:pwd_data\r\n"
240 "a=mid:data_content_name\r\n"
241 "a=sendrecv\r\n"
242 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
243 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
244 "a=rtpmap:101 google-data/90000\r\n"
245 "a=ssrc:10 cname:data_channel_cname\r\n"
246 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
247 "a=ssrc:10 mslabel:data_channel\r\n"
248 "a=ssrc:10 label:data_channeld0\r\n";
249
250static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000251 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000252 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000253 "a=ice-ufrag:ufrag_data\r\n"
254 "a=ice-pwd:pwd_data\r\n"
255 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000256 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000257
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000258// draft-ietf-mmusic-sctp-sdp-12
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000259static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000260 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
261 "a=max-message-size=100000\r\n"
262 "a=sctp-port 5000\r\n"
263 "c=IN IP4 0.0.0.0\r\n"
264 "a=ice-ufrag:ufrag_data\r\n"
265 "a=ice-pwd:pwd_data\r\n"
266 "a=mid:data_content_name\r\n";
267
lally69f57602015-10-08 10:15:04 -0700268static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
269 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
270 "a=max-message-size=100000\r\n"
271 "a=sctp-port:5000\r\n"
272 "c=IN IP4 0.0.0.0\r\n"
273 "a=ice-ufrag:ufrag_data\r\n"
274 "a=ice-pwd:pwd_data\r\n"
275 "a=mid:data_content_name\r\n";
276
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000277static const char kSdpSctpDataChannelWithCandidatesString[] =
278 "m=application 2345 DTLS/SCTP 5000\r\n"
279 "c=IN IP4 74.125.127.126\r\n"
280 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
281 "generation 2\r\n"
282 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
283 "generation 2\r\n"
284 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
285 "raddr 192.168.1.5 rport 2346 "
286 "generation 2\r\n"
287 "a=ice-ufrag:ufrag_data\r\n"
288 "a=ice-pwd:pwd_data\r\n"
289 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000290 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000291
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000292static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000293 "v=0\r\n"
294 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
295 "s=-\r\n"
296 "t=0 0\r\n"
297 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000298 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000299 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000300 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000301 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000302 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000303 "a=x-google-flag:conference\r\n";
304
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000305static const char kSdpSessionString[] =
306 "v=0\r\n"
307 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
308 "s=-\r\n"
309 "t=0 0\r\n"
310 "a=msid-semantic: WMS local_stream\r\n";
311
312static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000313 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000314 "c=IN IP4 0.0.0.0\r\n"
315 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000316 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
317 "a=mid:audio_content_name\r\n"
318 "a=sendrecv\r\n"
319 "a=rtpmap:111 opus/48000/2\r\n"
320 "a=ssrc:1 cname:stream_1_cname\r\n"
321 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
322 "a=ssrc:1 mslabel:local_stream\r\n"
323 "a=ssrc:1 label:audio_track_id_1\r\n";
324
325static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000326 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000327 "c=IN IP4 0.0.0.0\r\n"
328 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000329 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
330 "a=mid:video_content_name\r\n"
331 "a=sendrecv\r\n"
332 "a=rtpmap:120 VP8/90000\r\n"
333 "a=ssrc:2 cname:stream_1_cname\r\n"
334 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
335 "a=ssrc:2 mslabel:local_stream\r\n"
336 "a=ssrc:2 label:video_track_id_1\r\n";
337
deadbeef25ed4352016-12-12 18:37:36 -0800338// Reference sdp string using bundle-only.
339static const char kBundleOnlySdpFullString[] =
340 "v=0\r\n"
341 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
342 "s=-\r\n"
343 "t=0 0\r\n"
344 "a=group:BUNDLE audio_content_name video_content_name\r\n"
345 "a=msid-semantic: WMS local_stream_1\r\n"
346 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
347 "c=IN IP4 74.125.127.126\r\n"
348 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
349 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
350 "generation 2\r\n"
351 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
352 "generation 2\r\n"
353 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
354 "generation 2\r\n"
355 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
356 "generation 2\r\n"
357 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
358 "raddr 192.168.1.5 rport 2346 "
359 "generation 2\r\n"
360 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
361 "raddr 192.168.1.5 rport 2348 "
362 "generation 2\r\n"
363 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
364 "a=mid:audio_content_name\r\n"
365 "a=sendrecv\r\n"
366 "a=rtcp-mux\r\n"
367 "a=rtcp-rsize\r\n"
368 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
369 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
370 "dummy_session_params\r\n"
371 "a=rtpmap:111 opus/48000/2\r\n"
372 "a=rtpmap:103 ISAC/16000\r\n"
373 "a=rtpmap:104 ISAC/32000\r\n"
374 "a=ssrc:1 cname:stream_1_cname\r\n"
375 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
376 "a=ssrc:1 mslabel:local_stream_1\r\n"
377 "a=ssrc:1 label:audio_track_id_1\r\n"
378 "m=video 0 RTP/SAVPF 120\r\n"
379 "c=IN IP4 0.0.0.0\r\n"
380 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
381 "a=bundle-only\r\n"
382 "a=mid:video_content_name\r\n"
383 "a=sendrecv\r\n"
384 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
385 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
386 "a=rtpmap:120 VP8/90000\r\n"
387 "a=ssrc-group:FEC 2 3\r\n"
388 "a=ssrc:2 cname:stream_1_cname\r\n"
389 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
390 "a=ssrc:2 mslabel:local_stream_1\r\n"
391 "a=ssrc:2 label:video_track_id_1\r\n"
392 "a=ssrc:3 cname:stream_1_cname\r\n"
393 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
394 "a=ssrc:3 mslabel:local_stream_1\r\n"
395 "a=ssrc:3 label:video_track_id_1\r\n";
396
deadbeef9d3584c2016-02-16 17:54:10 -0800397// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
398// tracks.
399static const char kPlanBSdpFullString[] =
400 "v=0\r\n"
401 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
402 "s=-\r\n"
403 "t=0 0\r\n"
404 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
405 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
406 "c=IN IP4 74.125.127.126\r\n"
407 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
408 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
409 "generation 2\r\n"
410 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
411 "generation 2\r\n"
412 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
413 "generation 2\r\n"
414 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
415 "generation 2\r\n"
416 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
417 "raddr 192.168.1.5 rport 2346 "
418 "generation 2\r\n"
419 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
420 "raddr 192.168.1.5 rport 2348 "
421 "generation 2\r\n"
422 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
423 "a=mid:audio_content_name\r\n"
424 "a=sendrecv\r\n"
425 "a=rtcp-mux\r\n"
426 "a=rtcp-rsize\r\n"
427 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
428 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
429 "dummy_session_params\r\n"
430 "a=rtpmap:111 opus/48000/2\r\n"
431 "a=rtpmap:103 ISAC/16000\r\n"
432 "a=rtpmap:104 ISAC/32000\r\n"
433 "a=ssrc:1 cname:stream_1_cname\r\n"
434 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
435 "a=ssrc:1 mslabel:local_stream_1\r\n"
436 "a=ssrc:1 label:audio_track_id_1\r\n"
437 "a=ssrc:4 cname:stream_2_cname\r\n"
438 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
439 "a=ssrc:4 mslabel:local_stream_2\r\n"
440 "a=ssrc:4 label:audio_track_id_2\r\n"
441 "m=video 3457 RTP/SAVPF 120\r\n"
442 "c=IN IP4 74.125.224.39\r\n"
443 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
444 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
445 "generation 2\r\n"
446 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
447 "generation 2\r\n"
448 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
449 "generation 2\r\n"
450 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
451 "generation 2\r\n"
452 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
453 "generation 2\r\n"
454 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
455 "generation 2\r\n"
456 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
457 "a=mid:video_content_name\r\n"
458 "a=sendrecv\r\n"
459 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
460 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
461 "a=rtpmap:120 VP8/90000\r\n"
462 "a=ssrc-group:FEC 2 3\r\n"
463 "a=ssrc:2 cname:stream_1_cname\r\n"
464 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
465 "a=ssrc:2 mslabel:local_stream_1\r\n"
466 "a=ssrc:2 label:video_track_id_1\r\n"
467 "a=ssrc:3 cname:stream_1_cname\r\n"
468 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
469 "a=ssrc:3 mslabel:local_stream_1\r\n"
470 "a=ssrc:3 label:video_track_id_1\r\n"
471 "a=ssrc:5 cname:stream_2_cname\r\n"
472 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
473 "a=ssrc:5 mslabel:local_stream_2\r\n"
474 "a=ssrc:5 label:video_track_id_2\r\n"
475 "a=ssrc:6 cname:stream_2_cname\r\n"
476 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
477 "a=ssrc:6 mslabel:local_stream_2\r\n"
478 "a=ssrc:6 label:video_track_id_3\r\n";
479
Taylor Brandstetter5de6b752016-03-09 17:02:30 -0800480// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
481// tracks, but with the unified plan "a=msid" attribute.
482static const char kPlanBSdpFullStringWithMsid[] =
483 "v=0\r\n"
484 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
485 "s=-\r\n"
486 "t=0 0\r\n"
487 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
488 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
489 "c=IN IP4 74.125.127.126\r\n"
490 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
491 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
492 "generation 2\r\n"
493 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
494 "generation 2\r\n"
495 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
496 "generation 2\r\n"
497 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
498 "generation 2\r\n"
499 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
500 "raddr 192.168.1.5 rport 2346 "
501 "generation 2\r\n"
502 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
503 "raddr 192.168.1.5 rport 2348 "
504 "generation 2\r\n"
505 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
506 "a=mid:audio_content_name\r\n"
507 "a=msid:local_stream_1 audio_track_id_1\r\n"
508 "a=sendrecv\r\n"
509 "a=rtcp-mux\r\n"
510 "a=rtcp-rsize\r\n"
511 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
512 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
513 "dummy_session_params\r\n"
514 "a=rtpmap:111 opus/48000/2\r\n"
515 "a=rtpmap:103 ISAC/16000\r\n"
516 "a=rtpmap:104 ISAC/32000\r\n"
517 "a=ssrc:1 cname:stream_1_cname\r\n"
518 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
519 "a=ssrc:1 mslabel:local_stream_1\r\n"
520 "a=ssrc:1 label:audio_track_id_1\r\n"
521 "a=ssrc:4 cname:stream_2_cname\r\n"
522 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
523 "a=ssrc:4 mslabel:local_stream_2\r\n"
524 "a=ssrc:4 label:audio_track_id_2\r\n"
525 "m=video 3457 RTP/SAVPF 120\r\n"
526 "c=IN IP4 74.125.224.39\r\n"
527 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
528 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
529 "generation 2\r\n"
530 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
531 "generation 2\r\n"
532 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
533 "generation 2\r\n"
534 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
535 "generation 2\r\n"
536 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
537 "generation 2\r\n"
538 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
539 "generation 2\r\n"
540 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
541 "a=mid:video_content_name\r\n"
542 "a=msid:local_stream_1 video_track_id_1\r\n"
543 "a=sendrecv\r\n"
544 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
545 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
546 "a=rtpmap:120 VP8/90000\r\n"
547 "a=ssrc-group:FEC 2 3\r\n"
548 "a=ssrc:2 cname:stream_1_cname\r\n"
549 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
550 "a=ssrc:2 mslabel:local_stream_1\r\n"
551 "a=ssrc:2 label:video_track_id_1\r\n"
552 "a=ssrc:3 cname:stream_1_cname\r\n"
553 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
554 "a=ssrc:3 mslabel:local_stream_1\r\n"
555 "a=ssrc:3 label:video_track_id_1\r\n"
556 "a=ssrc:5 cname:stream_2_cname\r\n"
557 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
558 "a=ssrc:5 mslabel:local_stream_2\r\n"
559 "a=ssrc:5 label:video_track_id_2\r\n"
560 "a=ssrc:6 cname:stream_2_cname\r\n"
561 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
562 "a=ssrc:6 mslabel:local_stream_2\r\n"
563 "a=ssrc:6 label:video_track_id_3\r\n";
564
deadbeef9d3584c2016-02-16 17:54:10 -0800565// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
566// tracks.
567static const char kUnifiedPlanSdpFullString[] =
568 "v=0\r\n"
569 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
570 "s=-\r\n"
571 "t=0 0\r\n"
572 "a=msid-semantic: WMS local_stream_1\r\n"
573 // Audio track 1, stream 1 (with candidates).
574 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
575 "c=IN IP4 74.125.127.126\r\n"
576 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
577 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
578 "generation 2\r\n"
579 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
580 "generation 2\r\n"
581 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
582 "generation 2\r\n"
583 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
584 "generation 2\r\n"
585 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
586 "raddr 192.168.1.5 rport 2346 "
587 "generation 2\r\n"
588 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
589 "raddr 192.168.1.5 rport 2348 "
590 "generation 2\r\n"
591 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
592 "a=mid:audio_content_name\r\n"
593 "a=msid:local_stream_1 audio_track_id_1\r\n"
594 "a=sendrecv\r\n"
595 "a=rtcp-mux\r\n"
596 "a=rtcp-rsize\r\n"
597 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
598 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
599 "dummy_session_params\r\n"
600 "a=rtpmap:111 opus/48000/2\r\n"
601 "a=rtpmap:103 ISAC/16000\r\n"
602 "a=rtpmap:104 ISAC/32000\r\n"
603 "a=ssrc:1 cname:stream_1_cname\r\n"
604 // Video track 1, stream 1 (with candidates).
605 "m=video 3457 RTP/SAVPF 120\r\n"
606 "c=IN IP4 74.125.224.39\r\n"
607 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
608 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
609 "generation 2\r\n"
610 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
611 "generation 2\r\n"
612 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
613 "generation 2\r\n"
614 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
615 "generation 2\r\n"
616 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
617 "generation 2\r\n"
618 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
619 "generation 2\r\n"
620 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
621 "a=mid:video_content_name\r\n"
622 "a=msid:local_stream_1 video_track_id_1\r\n"
623 "a=sendrecv\r\n"
624 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
625 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
626 "a=rtpmap:120 VP8/90000\r\n"
627 "a=ssrc-group:FEC 2 3\r\n"
628 "a=ssrc:2 cname:stream_1_cname\r\n"
629 "a=ssrc:3 cname:stream_1_cname\r\n"
630 // Audio track 2, stream 2.
631 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
632 "c=IN IP4 0.0.0.0\r\n"
633 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
634 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
635 "a=mid:audio_content_name_2\r\n"
636 "a=msid:local_stream_2 audio_track_id_2\r\n"
637 "a=sendrecv\r\n"
638 "a=rtcp-mux\r\n"
639 "a=rtcp-rsize\r\n"
640 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
641 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
642 "dummy_session_params\r\n"
643 "a=rtpmap:111 opus/48000/2\r\n"
644 "a=rtpmap:103 ISAC/16000\r\n"
645 "a=rtpmap:104 ISAC/32000\r\n"
646 "a=ssrc:4 cname:stream_2_cname\r\n"
647 // Video track 2, stream 2.
648 "m=video 9 RTP/SAVPF 120\r\n"
649 "c=IN IP4 0.0.0.0\r\n"
650 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
651 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
652 "a=mid:video_content_name_2\r\n"
653 "a=msid:local_stream_2 video_track_id_2\r\n"
654 "a=sendrecv\r\n"
655 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
656 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
657 "a=rtpmap:120 VP8/90000\r\n"
658 "a=ssrc:5 cname:stream_2_cname\r\n"
659 // Video track 3, stream 2.
660 "m=video 9 RTP/SAVPF 120\r\n"
661 "c=IN IP4 0.0.0.0\r\n"
662 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
663 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
664 "a=mid:video_content_name_3\r\n"
665 "a=msid:local_stream_2 video_track_id_3\r\n"
666 "a=sendrecv\r\n"
667 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
668 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
669 "a=rtpmap:120 VP8/90000\r\n"
670 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000671
672// One candidate reference string as per W3c spec.
673// candidate:<blah> not a=candidate:<blah>CRLF
674static const char kRawCandidate[] =
675 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
676// One candidate reference string.
677static const char kSdpOneCandidate[] =
678 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
679 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000680
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000681static const char kSdpTcpActiveCandidate[] =
682 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
683 "tcptype active generation 2";
684static const char kSdpTcpPassiveCandidate[] =
685 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
686 "tcptype passive generation 2";
687static const char kSdpTcpSOCandidate[] =
688 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
689 "tcptype so generation 2";
690static const char kSdpTcpInvalidCandidate[] =
691 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
692 "tcptype invalid generation 2";
693
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000694// One candidate reference string with IPV6 address.
695static const char kRawIPV6Candidate[] =
696 "candidate:a0+B/1 1 udp 2130706432 "
697 "abcd::abcd::abcd::abcd::abcd::abcd::abcd::abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000698
699// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800700static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000701 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800702 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000703
704// Session id and version
705static const char kSessionId[] = "18446744069414584320";
706static const char kSessionVersion[] = "18446462598732840960";
707
deadbeef9d3584c2016-02-16 17:54:10 -0800708// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000709static const char kIceOption1[] = "iceoption1";
710static const char kIceOption2[] = "iceoption2";
711static const char kIceOption3[] = "iceoption3";
712
deadbeef9d3584c2016-02-16 17:54:10 -0800713// ICE ufrags/passwords.
714static const char kUfragVoice[] = "ufrag_voice";
715static const char kPwdVoice[] = "pwd_voice";
716static const char kUfragVideo[] = "ufrag_video";
717static const char kPwdVideo[] = "pwd_video";
718static const char kUfragData[] = "ufrag_data";
719static const char kPwdData[] = "pwd_data";
720
721// Extra ufrags/passwords for extra unified plan m= sections.
722static const char kUfragVoice2[] = "ufrag_voice_2";
723static const char kPwdVoice2[] = "pwd_voice_2";
724static const char kUfragVideo2[] = "ufrag_video_2";
725static const char kPwdVideo2[] = "pwd_video_2";
726static const char kUfragVideo3[] = "ufrag_video_3";
727static const char kPwdVideo3[] = "pwd_video_3";
728
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000729// Content name
730static const char kAudioContentName[] = "audio_content_name";
731static const char kVideoContentName[] = "video_content_name";
732static const char kDataContentName[] = "data_content_name";
733
deadbeef9d3584c2016-02-16 17:54:10 -0800734// Extra content names for extra unified plan m= sections.
735static const char kAudioContentName2[] = "audio_content_name_2";
736static const char kVideoContentName2[] = "video_content_name_2";
737static const char kVideoContentName3[] = "video_content_name_3";
738
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000739// MediaStream 1
740static const char kStreamLabel1[] = "local_stream_1";
741static const char kStream1Cname[] = "stream_1_cname";
742static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200743static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000744static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800745static const uint32_t kVideoTrack1Ssrc1 = 2;
746static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000747
748// MediaStream 2
749static const char kStreamLabel2[] = "local_stream_2";
750static const char kStream2Cname[] = "stream_2_cname";
751static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200752static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800753static const char kVideoTrackId2[] = "video_track_id_2";
754static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000755static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800756static const uint32_t kVideoTrack3Ssrc = 6;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000757
758// DataChannel
759static const char kDataChannelLabel[] = "data_channel";
760static const char kDataChannelMsid[] = "data_channeld0";
761static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200762static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000763
764// Candidate
765static const char kDummyMid[] = "dummy_mid";
766static const int kDummyIndex = 123;
767
768// Misc
769static const char kDummyString[] = "dummy";
770
771// Helper functions
772
773static bool SdpDeserialize(const std::string& message,
774 JsepSessionDescription* jdesc) {
775 return webrtc::SdpDeserialize(message, jdesc, NULL);
776}
777
778static bool SdpDeserializeCandidate(const std::string& message,
779 JsepIceCandidate* candidate) {
780 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
781}
782
783// Add some extra |newlines| to the |message| after |line|.
784static void InjectAfter(const std::string& line,
785 const std::string& newlines,
786 std::string* message) {
787 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000788 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000789 tmp.c_str(), tmp.length(), message);
790}
791
792static void Replace(const std::string& line,
793 const std::string& newlines,
794 std::string* message) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000795 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000796 newlines.c_str(), newlines.length(), message);
797}
798
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000799// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
800// message.
801static void ExpectParseFailure(const std::string& bad_sdp,
802 const std::string& bad_part) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000803 JsepSessionDescription desc(kDummyString);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000805 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000806 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000807 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
808}
809
810// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
811static void ExpectParseFailure(const char* good_part, const char* bad_part) {
812 std::string bad_sdp = kSdpFullString;
813 Replace(good_part, bad_part, &bad_sdp);
814 ExpectParseFailure(bad_sdp, bad_part);
815}
816
817// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
818static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
819 const std::string& newlines,
820 const std::string& bad_part) {
821 std::string bad_sdp = kSdpFullString;
822 InjectAfter(injectpoint, newlines, &bad_sdp);
823 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000824}
825
826static void ReplaceDirection(cricket::MediaContentDirection direction,
827 std::string* message) {
828 std::string new_direction;
829 switch (direction) {
830 case cricket::MD_INACTIVE:
831 new_direction = "a=inactive";
832 break;
833 case cricket::MD_SENDONLY:
834 new_direction = "a=sendonly";
835 break;
836 case cricket::MD_RECVONLY:
837 new_direction = "a=recvonly";
838 break;
839 case cricket::MD_SENDRECV:
840 default:
841 new_direction = "a=sendrecv";
842 break;
843 }
844 Replace("a=sendrecv", new_direction, message);
845}
846
847static void ReplaceRejected(bool audio_rejected, bool video_rejected,
848 std::string* message) {
849 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800850 Replace("m=audio 9", "m=audio 0", message);
851 Replace(kAttributeIceUfragVoice, "", message);
852 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000853 }
854 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800855 Replace("m=video 9", "m=video 0", message);
856 Replace(kAttributeIceUfragVideo, "", message);
857 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000858 }
859}
860
861// WebRtcSdpTest
862
863class WebRtcSdpTest : public testing::Test {
864 public:
865 WebRtcSdpTest()
866 : jdesc_(kDummyString) {
phoglund37ebcf02016-01-08 05:04:57 -0800867#ifdef WEBRTC_ANDROID
868 webrtc::InitializeAndroidObjects();
869#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000870 // AudioContentDescription
871 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -0800872 StreamParams audio_stream;
873 audio_stream.id = kAudioTrackId1;
874 audio_stream.cname = kStream1Cname;
875 audio_stream.sync_label = kStreamLabel1;
876 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
877 audio_desc_->AddStream(audio_stream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000878 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
879
880 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -0800881 video_desc_ = CreateVideoContentDescription();
882 StreamParams video_stream;
883 video_stream.id = kVideoTrackId1;
884 video_stream.cname = kStream1Cname;
885 video_stream.sync_label = kStreamLabel1;
886 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
887 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
888 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
889 video_stream.ssrc_groups.push_back(ssrc_group);
890 video_desc_->AddStream(video_stream);
891 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000892
893 // TransportInfo
deadbeef9d3584c2016-02-16 17:54:10 -0800894 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
895 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice))));
896 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
897 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000898
899 // v4 host
900 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000901 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000902 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000903 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
904 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000905 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000906 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000907 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
908 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000909 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000910 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000911 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
912 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000913 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000914 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000915 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
916 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000917
918 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000919 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000920 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
921 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000922 cricket::LOCAL_PORT_TYPE,
923 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000924 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000925 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
926 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000927 cricket::LOCAL_PORT_TYPE,
928 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000929 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000930 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
931 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000932 cricket::LOCAL_PORT_TYPE,
933 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000934 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000935 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
936 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000937 cricket::LOCAL_PORT_TYPE,
938 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000939
940 // stun
941 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000942 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
943 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000944 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
945 address_stun, kCandidatePriority, "", "",
946 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000947 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000948 candidate9.set_related_address(rel_address_stun);
949
950 address_stun.SetPort(port_stun++);
951 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000952 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
953 address_stun, kCandidatePriority, "", "",
954 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000955 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000956 candidate10.set_related_address(rel_address_stun);
957
958 // relay
959 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000960 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000961 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
962 address_relay, kCandidatePriority, "", "",
963 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000964 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000965 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000966 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
967 address_relay, kCandidatePriority, "", "",
968 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000969 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000970
971 // voice
972 candidates_.push_back(candidate1);
973 candidates_.push_back(candidate2);
974 candidates_.push_back(candidate5);
975 candidates_.push_back(candidate6);
976 candidates_.push_back(candidate9);
977 candidates_.push_back(candidate10);
978
979 // video
980 candidates_.push_back(candidate3);
981 candidates_.push_back(candidate4);
982 candidates_.push_back(candidate7);
983 candidates_.push_back(candidate8);
984 candidates_.push_back(candidate11);
985 candidates_.push_back(candidate12);
986
987 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"),
988 0, candidate1));
989
990 // Set up JsepSessionDescription.
991 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
992 std::string mline_id;
993 int mline_index = 0;
994 for (size_t i = 0; i< candidates_.size(); ++i) {
995 // In this test, the audio m line index will be 0, and the video m line
996 // will be 1.
997 bool is_video = (i > 5);
998 mline_id = is_video ? "video_content_name" : "audio_content_name";
999 mline_index = is_video ? 1 : 0;
1000 JsepIceCandidate jice(mline_id,
1001 mline_index,
1002 candidates_.at(i));
1003 jdesc_.AddCandidate(&jice);
1004 }
1005 }
1006
deadbeef25ed4352016-12-12 18:37:36 -08001007 // Turns the existing reference description into a description using
1008 // a=bundle-only. This means no transport attributes and a 0 port value on
1009 // the m= sections not associated with the BUNDLE-tag.
1010 void MakeBundleOnlyDescription() {
1011 // Remove video candidates. JsepSessionDescription doesn't make it
1012 // simple.
1013 const IceCandidateCollection* video_candidates_collection =
1014 jdesc_.candidates(1);
1015 ASSERT_NE(nullptr, video_candidates_collection);
1016 std::vector<cricket::Candidate> video_candidates;
1017 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1018 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1019 c.set_transport_name("video_content_name");
1020 video_candidates.push_back(c);
1021 }
1022 jdesc_.RemoveCandidates(video_candidates);
1023
1024 // And the rest of the transport attributes.
1025 desc_.transport_infos()[1].description.ice_ufrag.clear();
1026 desc_.transport_infos()[1].description.ice_pwd.clear();
1027 desc_.transport_infos()[1].description.connection_role =
1028 cricket::CONNECTIONROLE_NONE;
1029
1030 // Set bundle-only flag.
1031 desc_.contents()[1].bundle_only = true;
1032
1033 // Add BUNDLE group.
1034 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1035 group.AddContentName(kAudioContentName);
1036 group.AddContentName(kVideoContentName);
1037 desc_.AddGroup(group);
1038
1039 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1040 jdesc_.session_version()));
1041 }
1042
deadbeef9d3584c2016-02-16 17:54:10 -08001043 // Turns the existing reference description into a plan B description,
1044 // with 2 audio tracks and 3 video tracks.
1045 void MakePlanBDescription() {
1046 audio_desc_ = static_cast<AudioContentDescription*>(audio_desc_->Copy());
1047 video_desc_ = static_cast<VideoContentDescription*>(video_desc_->Copy());
1048
1049 StreamParams audio_track_2;
1050 audio_track_2.id = kAudioTrackId2;
1051 audio_track_2.cname = kStream2Cname;
1052 audio_track_2.sync_label = kStreamLabel2;
1053 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1054 audio_desc_->AddStream(audio_track_2);
1055
1056 StreamParams video_track_2;
1057 video_track_2.id = kVideoTrackId2;
1058 video_track_2.cname = kStream2Cname;
1059 video_track_2.sync_label = kStreamLabel2;
1060 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1061 video_desc_->AddStream(video_track_2);
1062
1063 StreamParams video_track_3;
1064 video_track_3.id = kVideoTrackId3;
1065 video_track_3.cname = kStream2Cname;
1066 video_track_3.sync_label = kStreamLabel2;
1067 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1068 video_desc_->AddStream(video_track_3);
1069
1070 desc_.RemoveContentByName(kAudioContentName);
1071 desc_.RemoveContentByName(kVideoContentName);
1072 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1073 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1074
1075 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1076 jdesc_.session_version()));
1077 }
1078
1079 // Turns the existing reference description into a unified plan description,
1080 // with 2 audio tracks and 3 video tracks.
1081 void MakeUnifiedPlanDescription() {
1082 // Audio track 2.
1083 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1084 StreamParams audio_track_2;
1085 audio_track_2.id = kAudioTrackId2;
1086 audio_track_2.cname = kStream2Cname;
1087 audio_track_2.sync_label = kStreamLabel2;
1088 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1089 audio_desc_2->AddStream(audio_track_2);
1090 desc_.AddContent(kAudioContentName2, NS_JINGLE_RTP, audio_desc_2);
1091 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1092 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
1093
1094 // Video track 2, in stream 2.
1095 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1096 StreamParams video_track_2;
1097 video_track_2.id = kVideoTrackId2;
1098 video_track_2.cname = kStream2Cname;
1099 video_track_2.sync_label = kStreamLabel2;
1100 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1101 video_desc_2->AddStream(video_track_2);
1102 desc_.AddContent(kVideoContentName2, NS_JINGLE_RTP, video_desc_2);
1103 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1104 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2))));
1105
1106 // Video track 3, in stream 2.
1107 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1108 StreamParams video_track_3;
1109 video_track_3.id = kVideoTrackId3;
1110 video_track_3.cname = kStream2Cname;
1111 video_track_3.sync_label = kStreamLabel2;
1112 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1113 video_desc_3->AddStream(video_track_3);
1114 desc_.AddContent(kVideoContentName3, NS_JINGLE_RTP, video_desc_3);
1115 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1116 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3))));
1117
1118 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1119 jdesc_.session_version()));
1120 }
1121
1122 // Creates an audio content description with no streams, and some default
1123 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001124 AudioContentDescription* CreateAudioContentDescription() {
1125 AudioContentDescription* audio = new AudioContentDescription();
1126 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -08001127 audio->set_rtcp_reduced_size(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001128 audio->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_32",
1129 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1130 "dummy_session_params"));
1131 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef67cf2c12016-04-13 10:07:16 -07001132 AudioCodec opus(111, "opus", 48000, 0, 2);
deadbeef9d3584c2016-02-16 17:54:10 -08001133 audio->AddCodec(opus);
ossue1405ad2017-01-23 08:55:48 -08001134 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1135 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001136 return audio;
1137 }
1138
deadbeef9d3584c2016-02-16 17:54:10 -08001139 // Creates a video content description with no streams, and some default
1140 // configuration.
1141 VideoContentDescription* CreateVideoContentDescription() {
1142 VideoContentDescription* video = new VideoContentDescription();
1143 video->AddCrypto(CryptoParams(
1144 1, "AES_CM_128_HMAC_SHA1_80",
1145 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1146 video->set_protocol(cricket::kMediaProtocolSavpf);
1147 video->AddCodec(
perkj26752742016-10-24 01:21:16 -07001148 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-16 17:54:10 -08001149 return video;
1150 }
1151
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001152 template <class MCD>
1153 void CompareMediaContentDescription(const MCD* cd1,
1154 const MCD* cd2) {
1155 // type
1156 EXPECT_EQ(cd1->type(), cd1->type());
1157
1158 // content direction
1159 EXPECT_EQ(cd1->direction(), cd2->direction());
1160
1161 // rtcp_mux
1162 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1163
deadbeef13871492015-12-09 12:37:51 -08001164 // rtcp_reduced_size
1165 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1166
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001167 // cryptos
1168 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1169 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1170 ADD_FAILURE();
1171 return;
1172 }
1173 for (size_t i = 0; i< cd1->cryptos().size(); ++i) {
1174 const CryptoParams c1 = cd1->cryptos().at(i);
1175 const CryptoParams c2 = cd2->cryptos().at(i);
1176 EXPECT_TRUE(c1.Matches(c2));
1177 EXPECT_EQ(c1.key_params, c2.key_params);
1178 EXPECT_EQ(c1.session_params, c2.session_params);
1179 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001180
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001181 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001182 // Use an equivalence class here, for old and new versions of the
1183 // protocol description.
1184 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:35 +00001185 || cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp
1186 || cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
1187 const bool cd2_is_also_dtls_sctp =
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001188 cd2->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:35 +00001189 || cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp
1190 || cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
1191 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001192 } else {
1193 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1194 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001195
1196 // codecs
1197 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1198
1199 // bandwidth
1200 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1201
1202 // streams
1203 EXPECT_EQ(cd1->streams(), cd2->streams());
1204
1205 // extmap
1206 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1207 cd2->rtp_header_extensions().size());
1208 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 11:24:55 -07001209 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1210 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001211 EXPECT_EQ(ext1.uri, ext2.uri);
1212 EXPECT_EQ(ext1.id, ext2.id);
1213 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001214 }
1215
zstein4b2e0822017-02-17 19:48:38 -08001216 void CompareDataContentDescription(const DataContentDescription* dcd1,
1217 const DataContentDescription* dcd2) {
1218 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
1219 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
1220 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001221
1222 void CompareSessionDescription(const SessionDescription& desc1,
1223 const SessionDescription& desc2) {
1224 // Compare content descriptions.
1225 if (desc1.contents().size() != desc2.contents().size()) {
1226 ADD_FAILURE();
1227 return;
1228 }
1229 for (size_t i = 0 ; i < desc1.contents().size(); ++i) {
1230 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1231 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-12 18:37:36 -08001232 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001233 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-12 18:37:36 -08001234 EXPECT_EQ(c1.type, c2.type);
1235 EXPECT_EQ(c1.rejected, c2.rejected);
1236 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001237
1238 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1239 if (IsAudioContent(&c1)) {
1240 const AudioContentDescription* acd1 =
1241 static_cast<const AudioContentDescription*>(c1.description);
1242 const AudioContentDescription* acd2 =
1243 static_cast<const AudioContentDescription*>(c2.description);
1244 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1245 }
1246
1247 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1248 if (IsVideoContent(&c1)) {
1249 const VideoContentDescription* vcd1 =
1250 static_cast<const VideoContentDescription*>(c1.description);
1251 const VideoContentDescription* vcd2 =
1252 static_cast<const VideoContentDescription*>(c2.description);
1253 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1254 }
1255
1256 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
1257 if (IsDataContent(&c1)) {
1258 const DataContentDescription* dcd1 =
1259 static_cast<const DataContentDescription*>(c1.description);
1260 const DataContentDescription* dcd2 =
1261 static_cast<const DataContentDescription*>(c2.description);
zstein4b2e0822017-02-17 19:48:38 -08001262 CompareDataContentDescription(dcd1, dcd2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001263 }
1264 }
1265
1266 // group
1267 const cricket::ContentGroups groups1 = desc1.groups();
1268 const cricket::ContentGroups groups2 = desc2.groups();
1269 EXPECT_EQ(groups1.size(), groups1.size());
1270 if (groups1.size() != groups2.size()) {
1271 ADD_FAILURE();
1272 return;
1273 }
1274 for (size_t i = 0; i < groups1.size(); ++i) {
1275 const cricket::ContentGroup group1 = groups1.at(i);
1276 const cricket::ContentGroup group2 = groups2.at(i);
1277 EXPECT_EQ(group1.semantics(), group2.semantics());
1278 const cricket::ContentNames names1 = group1.content_names();
1279 const cricket::ContentNames names2 = group2.content_names();
1280 EXPECT_EQ(names1.size(), names2.size());
1281 if (names1.size() != names2.size()) {
1282 ADD_FAILURE();
1283 return;
1284 }
1285 cricket::ContentNames::const_iterator iter1 = names1.begin();
1286 cricket::ContentNames::const_iterator iter2 = names2.begin();
1287 while (iter1 != names1.end()) {
1288 EXPECT_EQ(*iter1++, *iter2++);
1289 }
1290 }
1291
1292 // transport info
1293 const cricket::TransportInfos transports1 = desc1.transport_infos();
1294 const cricket::TransportInfos transports2 = desc2.transport_infos();
1295 EXPECT_EQ(transports1.size(), transports2.size());
1296 if (transports1.size() != transports2.size()) {
1297 ADD_FAILURE();
1298 return;
1299 }
1300 for (size_t i = 0; i < transports1.size(); ++i) {
1301 const cricket::TransportInfo transport1 = transports1.at(i);
1302 const cricket::TransportInfo transport2 = transports2.at(i);
1303 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001304 EXPECT_EQ(transport1.description.ice_ufrag,
1305 transport2.description.ice_ufrag);
1306 EXPECT_EQ(transport1.description.ice_pwd,
1307 transport2.description.ice_pwd);
1308 if (transport1.description.identity_fingerprint) {
1309 EXPECT_EQ(*transport1.description.identity_fingerprint,
1310 *transport2.description.identity_fingerprint);
1311 } else {
1312 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1313 transport2.description.identity_fingerprint.get());
1314 }
1315 EXPECT_EQ(transport1.description.transport_options,
1316 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001317 }
deadbeefc80741f2015-10-22 13:14:45 -07001318
1319 // global attributes
1320 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001321 }
1322
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001323 bool CompareSessionDescription(
1324 const JsepSessionDescription& desc1,
1325 const JsepSessionDescription& desc2) {
1326 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1327 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1328 CompareSessionDescription(*desc1.description(), *desc2.description());
1329 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1330 return false;
1331 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1332 const IceCandidateCollection* cc1 = desc1.candidates(i);
1333 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-12 18:37:36 -08001334 if (cc1->count() != cc2->count()) {
1335 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001336 return false;
deadbeef25ed4352016-12-12 18:37:36 -08001337 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001338 for (size_t j = 0; j < cc1->count(); ++j) {
1339 const IceCandidateInterface* c1 = cc1->at(j);
1340 const IceCandidateInterface* c2 = cc2->at(j);
1341 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1342 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1343 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1344 }
1345 }
1346 return true;
1347 }
1348
1349 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1350 // them with invalid keywords so that the parser will just ignore them.
1351 bool RemoveCandidateUfragPwd(std::string* sdp) {
1352 const char ice_ufrag[] = "a=ice-ufrag";
1353 const char ice_ufragx[] = "a=xice-ufrag";
1354 const char ice_pwd[] = "a=ice-pwd";
1355 const char ice_pwdx[] = "a=xice-pwd";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001356 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001357 ice_ufragx, strlen(ice_ufragx), sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001358 rtc::replace_substrs(ice_pwd, strlen(ice_pwd),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001359 ice_pwdx, strlen(ice_pwdx), sdp);
1360 return true;
1361 }
1362
1363 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
1364 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, int mline_index,
1365 const std::string& ufrag, const std::string& pwd) {
1366 std::string content_name;
1367 if (mline_index == 0) {
1368 content_name = kAudioContentName;
1369 } else if (mline_index == 1) {
1370 content_name = kVideoContentName;
1371 } else {
nissec80e7412017-01-11 05:56:46 -08001372 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001373 }
1374 TransportInfo transport_info(
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001375 content_name, TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001376 SessionDescription* desc =
1377 const_cast<SessionDescription*>(jdesc->description());
1378 desc->RemoveTransportInfoByName(content_name);
1379 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
1380 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1381 const IceCandidateCollection* cc = jdesc_.candidates(i);
1382 for (size_t j = 0; j < cc->count(); ++j) {
1383 if (cc->at(j)->sdp_mline_index() == mline_index) {
1384 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(
1385 ufrag);
1386 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(
1387 pwd);
1388 }
1389 }
1390 }
1391 return true;
1392 }
1393
1394 void AddIceOptions(const std::string& content_name,
1395 const std::vector<std::string>& transport_options) {
1396 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1397 cricket::TransportInfo transport_info =
1398 *(desc_.GetTransportInfoByName(content_name));
1399 desc_.RemoveTransportInfoByName(content_name);
1400 transport_info.description.transport_options = transport_options;
1401 desc_.AddTransportInfo(transport_info);
1402 }
1403
deadbeef3f7219b2015-12-28 15:17:14 -08001404 void SetIceUfragPwd(const std::string& content_name,
1405 const std::string& ice_ufrag,
1406 const std::string& ice_pwd) {
1407 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1408 cricket::TransportInfo transport_info =
1409 *(desc_.GetTransportInfoByName(content_name));
1410 desc_.RemoveTransportInfoByName(content_name);
1411 transport_info.description.ice_ufrag = ice_ufrag;
1412 transport_info.description.ice_pwd = ice_pwd;
1413 desc_.AddTransportInfo(transport_info);
1414 }
1415
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001416 void AddFingerprint() {
1417 desc_.RemoveTransportInfoByName(kAudioContentName);
1418 desc_.RemoveTransportInfoByName(kVideoContentName);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001419 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001420 kIdentityDigest,
1421 sizeof(kIdentityDigest));
deadbeef46eed762016-01-28 13:24:37 -08001422 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1423 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001424 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1425 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001426 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1427 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1428 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001429 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1430 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001431 cricket::CONNECTIONROLE_NONE, &fingerprint))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001432 }
1433
1434 void AddExtmap() {
1435 audio_desc_ = static_cast<AudioContentDescription*>(
1436 audio_desc_->Copy());
1437 video_desc_ = static_cast<VideoContentDescription*>(
1438 video_desc_->Copy());
isheriff6f8d6862016-05-26 11:24:55 -07001439 audio_desc_->AddRtpHeaderExtension(RtpExtension(kExtmapUri, kExtmapId));
1440 video_desc_->AddRtpHeaderExtension(RtpExtension(kExtmapUri, kExtmapId));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001441 desc_.RemoveContentByName(kAudioContentName);
1442 desc_.RemoveContentByName(kVideoContentName);
1443 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1444 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1445 }
1446
1447 void RemoveCryptos() {
1448 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1449 video_desc_->set_cryptos(std::vector<CryptoParams>());
1450 }
1451
1452 bool TestSerializeDirection(cricket::MediaContentDirection direction) {
1453 audio_desc_->set_direction(direction);
1454 video_desc_->set_direction(direction);
1455 std::string new_sdp = kSdpFullString;
1456 ReplaceDirection(direction, &new_sdp);
1457
1458 if (!jdesc_.Initialize(desc_.Copy(),
1459 jdesc_.session_id(),
1460 jdesc_.session_version())) {
1461 return false;
1462 }
deadbeef9d3584c2016-02-16 17:54:10 -08001463 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001464 EXPECT_EQ(new_sdp, message);
1465 return true;
1466 }
1467
1468 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
1469 audio_desc_ = static_cast<AudioContentDescription*>(
1470 audio_desc_->Copy());
1471 video_desc_ = static_cast<VideoContentDescription*>(
1472 video_desc_->Copy());
1473 desc_.RemoveContentByName(kAudioContentName);
1474 desc_.RemoveContentByName(kVideoContentName);
1475 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1476 audio_desc_);
1477 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1478 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001479 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1480 audio_rejected ? "" : kPwdVoice);
1481 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1482 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001483
1484 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001485 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1486
deadbeef3f7219b2015-12-28 15:17:14 -08001487 JsepSessionDescription jdesc_no_candidates(kDummyString);
1488 if (!jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
1489 kSessionVersion)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001490 return false;
1491 }
deadbeef9d3584c2016-02-16 17:54:10 -08001492 std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001493 EXPECT_EQ(new_sdp, message);
1494 return true;
1495 }
1496
zstein4b2e0822017-02-17 19:48:38 -08001497 void AddSctpDataChannel(bool use_sctpmap) {
kwibergd1fe2812016-04-27 06:47:29 -07001498 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001499 data_desc_ = data.get();
zstein4b2e0822017-02-17 19:48:38 -08001500 data_desc_->set_use_sctpmap(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001501 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
solenberg9fa49752016-10-08 13:02:44 -07001502 DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07001503 cricket::kGoogleSctpDataCodecName);
wu@webrtc.org78187522013-10-07 23:32:02 +00001504 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1505 data_desc_->AddCodec(codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001506 desc_.AddContent(kDataContentName, NS_JINGLE_DRAFT_SCTP, data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001507 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1508 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001509 }
1510
1511 void AddRtpDataChannel() {
kwibergd1fe2812016-04-27 06:47:29 -07001512 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001513 data_desc_ = data.get();
1514
deadbeef67cf2c12016-04-13 10:07:16 -07001515 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001516 StreamParams data_stream;
1517 data_stream.id = kDataChannelMsid;
1518 data_stream.cname = kDataChannelCname;
1519 data_stream.sync_label = kDataChannelLabel;
1520 data_stream.ssrcs.push_back(kDataChannelSsrc);
1521 data_desc_->AddStream(data_stream);
1522 data_desc_->AddCrypto(CryptoParams(
1523 1, "AES_CM_128_HMAC_SHA1_80",
1524 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
1525 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
1526 desc_.AddContent(kDataContentName, NS_JINGLE_RTP, data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001527 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1528 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001529 }
1530
1531 bool TestDeserializeDirection(cricket::MediaContentDirection direction) {
1532 std::string new_sdp = kSdpFullString;
1533 ReplaceDirection(direction, &new_sdp);
1534 JsepSessionDescription new_jdesc(kDummyString);
1535
1536 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1537
1538 audio_desc_->set_direction(direction);
1539 video_desc_->set_direction(direction);
1540 if (!jdesc_.Initialize(desc_.Copy(),
1541 jdesc_.session_id(),
1542 jdesc_.session_version())) {
1543 return false;
1544 }
1545 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1546 return true;
1547 }
1548
1549 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001550 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001551 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1552 JsepSessionDescription new_jdesc(JsepSessionDescription::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001553 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001554
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001555 audio_desc_ = static_cast<AudioContentDescription*>(
1556 audio_desc_->Copy());
1557 video_desc_ = static_cast<VideoContentDescription*>(
1558 video_desc_->Copy());
1559 desc_.RemoveContentByName(kAudioContentName);
1560 desc_.RemoveContentByName(kVideoContentName);
1561 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1562 audio_desc_);
1563 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1564 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001565 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1566 audio_rejected ? "" : kPwdVoice);
1567 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1568 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001569 JsepSessionDescription jdesc_no_candidates(kDummyString);
1570 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1571 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001572 return false;
1573 }
deadbeef3f7219b2015-12-28 15:17:14 -08001574 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001575 return true;
1576 }
1577
1578 void TestDeserializeExtmap(bool session_level, bool media_level) {
1579 AddExtmap();
1580 JsepSessionDescription new_jdesc("dummy");
1581 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1582 jdesc_.session_id(),
1583 jdesc_.session_version()));
1584 JsepSessionDescription jdesc_with_extmap("dummy");
1585 std::string sdp_with_extmap = kSdpString;
1586 if (session_level) {
1587 InjectAfter(kSessionTime, kExtmapWithDirectionAndAttribute,
1588 &sdp_with_extmap);
1589 }
1590 if (media_level) {
1591 InjectAfter(kAttributeIcePwdVoice, kExtmapWithDirectionAndAttribute,
1592 &sdp_with_extmap);
1593 InjectAfter(kAttributeIcePwdVideo, kExtmapWithDirectionAndAttribute,
1594 &sdp_with_extmap);
1595 }
1596 // The extmap can't be present at the same time in both session level and
1597 // media level.
1598 if (session_level && media_level) {
1599 SdpParseError error;
1600 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap,
1601 &jdesc_with_extmap, &error));
1602 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1603 } else {
1604 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1605 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1606 }
1607 }
1608
1609 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
1610 const std::string& name, int expected_value) {
1611 cricket::CodecParameterMap::const_iterator found = params.find(name);
1612 ASSERT_TRUE(found != params.end());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001613 EXPECT_EQ(found->second, rtc::ToString<int>(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001614 }
1615
1616 void TestDeserializeCodecParams(const CodecParams& params,
1617 JsepSessionDescription* jdesc_output) {
1618 std::string sdp =
1619 "v=0\r\n"
1620 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1621 "s=-\r\n"
1622 "t=0 0\r\n"
1623 // Include semantics for WebRTC Media Streams since it is supported by
1624 // this parser, and will be added to the SDP when serializing a session
1625 // description.
1626 "a=msid-semantic: WMS\r\n"
1627 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001628 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001629 // Pltype 111 listed before 103 and 104 in the map.
1630 "a=rtpmap:111 opus/48000/2\r\n"
1631 // Pltype 103 listed before 104.
1632 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001633 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001634 "a=fmtp:111 0-15,66,70\r\n"
1635 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001636 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001637 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001638 << "; sprop-stereo=" << params.sprop_stereo
1639 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001640 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001641 << "a=ptime:" << params.ptime << "\r\n"
1642 << "a=maxptime:" << params.max_ptime << "\r\n";
1643 sdp += os.str();
1644
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001645 os.clear();
1646 os.str("");
1647 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001648 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001649 << "a=rtpmap:99 VP8/90000\r\n"
1650 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001651 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001652 sdp += os.str();
1653
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001654 // Deserialize
1655 SdpParseError error;
1656 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1657
1658 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1659 ASSERT_TRUE(ac != NULL);
1660 const AudioContentDescription* acd =
1661 static_cast<const AudioContentDescription*>(ac->description);
1662 ASSERT_FALSE(acd->codecs().empty());
1663 cricket::AudioCodec opus = acd->codecs()[0];
1664 EXPECT_EQ("opus", opus.name);
1665 EXPECT_EQ(111, opus.id);
1666 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1667 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1668 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1669 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001670 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1671 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001672 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1673 cricket::AudioCodec codec = acd->codecs()[i];
1674 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1675 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001676 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001677
1678 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1679 ASSERT_TRUE(vc != NULL);
1680 const VideoContentDescription* vcd =
1681 static_cast<const VideoContentDescription*>(vc->description);
1682 ASSERT_FALSE(vcd->codecs().empty());
1683 cricket::VideoCodec vp8 = vcd->codecs()[0];
1684 EXPECT_EQ("VP8", vp8.name);
1685 EXPECT_EQ(99, vp8.id);
1686 cricket::VideoCodec rtx = vcd->codecs()[1];
1687 EXPECT_EQ("RTX", rtx.name);
1688 EXPECT_EQ(95, rtx.id);
1689 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001690 }
1691
1692 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1693 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001694 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001695 "v=0\r\n"
1696 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1697 "s=-\r\n"
1698 "t=0 0\r\n"
1699 // Include semantics for WebRTC Media Streams since it is supported by
1700 // this parser, and will be added to the SDP when serializing a session
1701 // description.
1702 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001703 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001704 "a=rtpmap:111 opus/48000/2\r\n";
1705 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001706 "m=video 3457 RTP/SAVPF 101\r\n"
1707 "a=rtpmap:101 VP8/90000\r\n"
1708 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001709 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001710 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001711 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001712 os << sdp_session_and_audio;
1713 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
1714 os << sdp_video;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001715 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001716 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001717 // Deserialize
1718 SdpParseError error;
1719 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1720 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1721 ASSERT_TRUE(ac != NULL);
1722 const AudioContentDescription* acd =
1723 static_cast<const AudioContentDescription*>(ac->description);
1724 ASSERT_FALSE(acd->codecs().empty());
1725 cricket::AudioCodec opus = acd->codecs()[0];
1726 EXPECT_EQ(111, opus.id);
1727 EXPECT_TRUE(opus.HasFeedbackParam(
1728 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1729 cricket::kParamValueEmpty)));
1730
1731 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1732 ASSERT_TRUE(vc != NULL);
1733 const VideoContentDescription* vcd =
1734 static_cast<const VideoContentDescription*>(vc->description);
1735 ASSERT_FALSE(vcd->codecs().empty());
1736 cricket::VideoCodec vp8 = vcd->codecs()[0];
1737 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1738 vp8.name.c_str());
1739 EXPECT_EQ(101, vp8.id);
1740 EXPECT_TRUE(vp8.HasFeedbackParam(
1741 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1742 cricket::kParamValueEmpty)));
1743 EXPECT_TRUE(vp8.HasFeedbackParam(
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001744 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1745 cricket::kRtcpFbNackParamPli)));
1746 EXPECT_TRUE(vp8.HasFeedbackParam(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001747 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
1748 cricket::kParamValueEmpty)));
1749 EXPECT_TRUE(vp8.HasFeedbackParam(
1750 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
1751 cricket::kRtcpFbCcmParamFir)));
1752 }
1753
1754 // Two SDP messages can mean the same thing but be different strings, e.g.
1755 // some of the lines can be serialized in different order.
1756 // However, a deserialized description can be compared field by field and has
1757 // no order. If deserializer has already been tested, serializing then
1758 // deserializing and comparing JsepSessionDescription will test
1759 // the serializer sufficiently.
deadbeef9d3584c2016-02-16 17:54:10 -08001760 void TestSerialize(const JsepSessionDescription& jdesc,
1761 bool unified_plan_sdp) {
1762 std::string message = webrtc::SdpSerialize(jdesc, unified_plan_sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001763 JsepSessionDescription jdesc_output_des(kDummyString);
1764 SdpParseError error;
1765 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1766 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1767 }
1768
1769 protected:
1770 SessionDescription desc_;
1771 AudioContentDescription* audio_desc_;
1772 VideoContentDescription* video_desc_;
1773 DataContentDescription* data_desc_;
1774 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07001775 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001776 JsepSessionDescription jdesc_;
1777};
1778
1779void TestMismatch(const std::string& string1, const std::string& string2) {
1780 int position = 0;
1781 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1782 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001783 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001784 break;
1785 }
1786 }
1787 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1788 << " character\n"
1789 << " 1: " << string1.substr(position, 20) << "\n"
1790 << " 2: " << string2.substr(position, 20) << "\n";
1791}
1792
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001793TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1794 // SessionDescription with desc and candidates.
deadbeef9d3584c2016-02-16 17:54:10 -08001795 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001796 TestMismatch(std::string(kSdpFullString), message);
1797}
1798
1799TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
1800 JsepSessionDescription jdesc_empty(kDummyString);
deadbeef9d3584c2016-02-16 17:54:10 -08001801 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty, false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001802}
1803
guoweis@webrtc.org57ac2c82015-02-06 00:45:13 +00001804// This tests serialization of SDP with only IPv6 candidates and verifies that
1805// IPv6 is used as default address in c line according to preference.
1806TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIPv6Only) {
1807 // Only test 1 m line.
1808 desc_.RemoveContentByName("video_content_name");
1809 // Stun has a high preference than local host.
1810 cricket::Candidate candidate1(
1811 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1812 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1813 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1814 cricket::Candidate candidate2(
1815 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1816 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
1817 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1818 JsepSessionDescription jdesc(kDummyString);
1819 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1820
1821 // Only add the candidates to audio m line.
1822 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1823 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1824 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1825 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
deadbeef9d3584c2016-02-16 17:54:10 -08001826 std::string message = webrtc::SdpSerialize(jdesc, false);
guoweis@webrtc.org57ac2c82015-02-06 00:45:13 +00001827
1828 // Audio line should have a c line like this one.
1829 EXPECT_NE(message.find("c=IN IP6 ::1"), std::string::npos);
1830 // Shouldn't have a IP4 c line.
1831 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
1832}
1833
1834// This tests serialization of SDP with both IPv4 and IPv6 candidates and
1835// verifies that IPv4 is used as default address in c line even if the
1836// preference of IPv4 is lower.
1837TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothIPFamilies) {
1838 // Only test 1 m line.
1839 desc_.RemoveContentByName("video_content_name");
1840 cricket::Candidate candidate_v4(
1841 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1842 rtc::SocketAddress("192.168.1.5", 1234), kCandidatePriority, "", "",
1843 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1844 cricket::Candidate candidate_v6(
1845 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1846 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1847 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1848 JsepSessionDescription jdesc(kDummyString);
1849 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1850
1851 // Only add the candidates to audio m line.
1852 JsepIceCandidate jice_v4("audio_content_name", 0, candidate_v4);
1853 JsepIceCandidate jice_v6("audio_content_name", 0, candidate_v6);
1854 ASSERT_TRUE(jdesc.AddCandidate(&jice_v4));
1855 ASSERT_TRUE(jdesc.AddCandidate(&jice_v6));
deadbeef9d3584c2016-02-16 17:54:10 -08001856 std::string message = webrtc::SdpSerialize(jdesc, false);
guoweis@webrtc.org57ac2c82015-02-06 00:45:13 +00001857
1858 // Audio line should have a c line like this one.
1859 EXPECT_NE(message.find("c=IN IP4 192.168.1.5"), std::string::npos);
1860 // Shouldn't have a IP6 c line.
1861 EXPECT_EQ(message.find("c=IN IP6"), std::string::npos);
1862}
1863
1864// This tests serialization of SDP with both UDP and TCP candidates and
1865// verifies that UDP is used as default address in c line even if the
1866// preference of UDP is lower.
1867TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothProtocols) {
1868 // Only test 1 m line.
1869 desc_.RemoveContentByName("video_content_name");
1870 // Stun has a high preference than local host.
1871 cricket::Candidate candidate1(
1872 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1873 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1874 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1875 cricket::Candidate candidate2(
1876 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1877 rtc::SocketAddress("fe80::1234:5678:abcd:ef12", 1235), kCandidatePriority,
1878 "", "", cricket::LOCAL_PORT_TYPE, kCandidateGeneration,
1879 kCandidateFoundation1);
1880 JsepSessionDescription jdesc(kDummyString);
1881 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1882
1883 // Only add the candidates to audio m line.
1884 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1885 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1886 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1887 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
deadbeef9d3584c2016-02-16 17:54:10 -08001888 std::string message = webrtc::SdpSerialize(jdesc, false);
guoweis@webrtc.org57ac2c82015-02-06 00:45:13 +00001889
1890 // Audio line should have a c line like this one.
1891 EXPECT_NE(message.find("c=IN IP6 fe80::1234:5678:abcd:ef12"),
1892 std::string::npos);
1893 // Shouldn't have a IP4 c line.
1894 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
1895}
1896
1897// This tests serialization of SDP with only TCP candidates and verifies that
1898// null IPv4 is used as default address in c line.
1899TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithTCPOnly) {
1900 // Only test 1 m line.
1901 desc_.RemoveContentByName("video_content_name");
1902 // Stun has a high preference than local host.
1903 cricket::Candidate candidate1(
1904 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1905 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1906 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1907 cricket::Candidate candidate2(
1908 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1909 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
1910 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1911 JsepSessionDescription jdesc(kDummyString);
1912 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1913
1914 // Only add the candidates to audio m line.
1915 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1916 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1917 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1918 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
deadbeef9d3584c2016-02-16 17:54:10 -08001919 std::string message = webrtc::SdpSerialize(jdesc, false);
guoweis@webrtc.org57ac2c82015-02-06 00:45:13 +00001920
1921 // Audio line should have a c line like this one when no any default exists.
1922 EXPECT_NE(message.find("c=IN IP4 0.0.0.0"), std::string::npos);
1923}
1924
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001925// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1926// the case in a DTLS offer.
1927TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1928 AddFingerprint();
1929 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1930 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1931 kSessionId, kSessionVersion));
deadbeef9d3584c2016-02-16 17:54:10 -08001932 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001933
1934 std::string sdp_with_fingerprint = kSdpString;
1935 InjectAfter(kAttributeIcePwdVoice,
1936 kFingerprint, &sdp_with_fingerprint);
1937 InjectAfter(kAttributeIcePwdVideo,
1938 kFingerprint, &sdp_with_fingerprint);
1939
1940 EXPECT_EQ(sdp_with_fingerprint, message);
1941}
1942
1943// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1944// be the case in a DTLS answer.
1945TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1946 AddFingerprint();
1947 RemoveCryptos();
1948 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1949 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1950 kSessionId, kSessionVersion));
deadbeef9d3584c2016-02-16 17:54:10 -08001951 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001952
1953 std::string sdp_with_fingerprint = kSdpString;
1954 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1955 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
1956 InjectAfter(kAttributeIcePwdVoice,
1957 kFingerprint, &sdp_with_fingerprint);
1958 InjectAfter(kAttributeIcePwdVideo,
1959 kFingerprint, &sdp_with_fingerprint);
1960
1961 EXPECT_EQ(sdp_with_fingerprint, message);
1962}
1963
1964TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1965 // JsepSessionDescription with desc but without candidates.
1966 JsepSessionDescription jdesc_no_candidates(kDummyString);
deadbeef3f7219b2015-12-28 15:17:14 -08001967 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
1968 kSessionVersion));
deadbeef9d3584c2016-02-16 17:54:10 -08001969 std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001970 EXPECT_EQ(std::string(kSdpString), message);
1971}
1972
1973TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1974 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1975 group.AddContentName(kAudioContentName);
1976 group.AddContentName(kVideoContentName);
1977 desc_.AddGroup(group);
1978 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1979 jdesc_.session_id(),
1980 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08001981 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001982 std::string sdp_with_bundle = kSdpFullString;
1983 InjectAfter(kSessionTime,
1984 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1985 &sdp_with_bundle);
1986 EXPECT_EQ(sdp_with_bundle, message);
1987}
1988
1989TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
1990 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1991 GetFirstVideoContent(&desc_)->description);
1992 vcd->set_bandwidth(100 * 1000);
1993 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1994 GetFirstAudioContent(&desc_)->description);
1995 acd->set_bandwidth(50 * 1000);
1996 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1997 jdesc_.session_id(),
1998 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08001999 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002000 std::string sdp_with_bandwidth = kSdpFullString;
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00002001 InjectAfter("c=IN IP4 74.125.224.39\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002002 "b=AS:100\r\n",
2003 &sdp_with_bandwidth);
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00002004 InjectAfter("c=IN IP4 74.125.127.126\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002005 "b=AS:50\r\n",
2006 &sdp_with_bandwidth);
2007 EXPECT_EQ(sdp_with_bandwidth, message);
2008}
2009
2010TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
2011 std::vector<std::string> transport_options;
2012 transport_options.push_back(kIceOption1);
2013 transport_options.push_back(kIceOption3);
2014 AddIceOptions(kAudioContentName, transport_options);
2015 transport_options.clear();
2016 transport_options.push_back(kIceOption2);
2017 transport_options.push_back(kIceOption3);
2018 AddIceOptions(kVideoContentName, transport_options);
2019 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2020 jdesc_.session_id(),
2021 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08002022 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002023 std::string sdp_with_ice_options = kSdpFullString;
2024 InjectAfter(kAttributeIcePwdVoice,
2025 "a=ice-options:iceoption1 iceoption3\r\n",
2026 &sdp_with_ice_options);
2027 InjectAfter(kAttributeIcePwdVideo,
2028 "a=ice-options:iceoption2 iceoption3\r\n",
2029 &sdp_with_ice_options);
2030 EXPECT_EQ(sdp_with_ice_options, message);
2031}
2032
2033TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
2034 EXPECT_TRUE(TestSerializeDirection(cricket::MD_RECVONLY));
2035}
2036
2037TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
2038 EXPECT_TRUE(TestSerializeDirection(cricket::MD_SENDONLY));
2039}
2040
2041TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
2042 EXPECT_TRUE(TestSerializeDirection(cricket::MD_INACTIVE));
2043}
2044
2045TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2046 EXPECT_TRUE(TestSerializeRejected(true, false));
2047}
2048
2049TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2050 EXPECT_TRUE(TestSerializeRejected(false, true));
2051}
2052
2053TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2054 EXPECT_TRUE(TestSerializeRejected(true, true));
2055}
2056
2057TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
2058 AddRtpDataChannel();
2059 JsepSessionDescription jsep_desc(kDummyString);
2060
2061 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
deadbeef9d3584c2016-02-16 17:54:10 -08002062 std::string message = webrtc::SdpSerialize(jsep_desc, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002063
2064 std::string expected_sdp = kSdpString;
2065 expected_sdp.append(kSdpRtpDataChannelString);
2066 EXPECT_EQ(expected_sdp, message);
2067}
2068
2069TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08002070 bool use_sctpmap = true;
2071 AddSctpDataChannel(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002072 JsepSessionDescription jsep_desc(kDummyString);
2073
2074 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
deadbeef9d3584c2016-02-16 17:54:10 -08002075 std::string message = webrtc::SdpSerialize(jsep_desc, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002076
2077 std::string expected_sdp = kSdpString;
2078 expected_sdp.append(kSdpSctpDataChannelString);
2079 EXPECT_EQ(message, expected_sdp);
2080}
2081
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002082TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08002083 bool use_sctpmap = true;
2084 AddSctpDataChannel(use_sctpmap);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002085 JsepSessionDescription jsep_desc(kDummyString);
2086
2087 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2088 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
2089 jsep_desc.description()->GetContentDescriptionByName(kDataContentName));
2090
2091 const int kNewPort = 1234;
solenberg9fa49752016-10-08 13:02:44 -07002092 cricket::DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07002093 cricket::kGoogleSctpDataCodecName);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002094 codec.SetParam(cricket::kCodecParamPort, kNewPort);
2095 dcdesc->AddOrReplaceCodec(codec);
2096
deadbeef9d3584c2016-02-16 17:54:10 -08002097 std::string message = webrtc::SdpSerialize(jsep_desc, false);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002098
2099 std::string expected_sdp = kSdpString;
2100 expected_sdp.append(kSdpSctpDataChannelString);
2101
2102 char default_portstr[16];
2103 char new_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002104 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002105 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002106 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
2107 rtc::replace_substrs(default_portstr, strlen(default_portstr),
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002108 new_portstr, strlen(new_portstr),
2109 &expected_sdp);
2110
2111 EXPECT_EQ(expected_sdp, message);
2112}
2113
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002114TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
2115 AddRtpDataChannel();
2116 data_desc_->set_bandwidth(100*1000);
2117 JsepSessionDescription jsep_desc(kDummyString);
2118
2119 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
deadbeef9d3584c2016-02-16 17:54:10 -08002120 std::string message = webrtc::SdpSerialize(jsep_desc, false);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002121
2122 std::string expected_sdp = kSdpString;
2123 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002124 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00002125 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 +00002126 "b=AS:100\r\n",
2127 &expected_sdp);
2128 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002129}
2130
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002131TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
2132 AddExtmap();
2133 JsepSessionDescription desc_with_extmap("dummy");
2134 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(),
2135 kSessionId, kSessionVersion));
deadbeef9d3584c2016-02-16 17:54:10 -08002136 std::string message = webrtc::SdpSerialize(desc_with_extmap, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002137
2138 std::string sdp_with_extmap = kSdpString;
2139 InjectAfter("a=mid:audio_content_name\r\n",
2140 kExtmap, &sdp_with_extmap);
2141 InjectAfter("a=mid:video_content_name\r\n",
2142 kExtmap, &sdp_with_extmap);
2143
2144 EXPECT_EQ(sdp_with_extmap, message);
2145}
2146
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002147TEST_F(WebRtcSdpTest, SerializeCandidates) {
2148 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002149 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002150
2151 Candidate candidate_with_ufrag(candidates_.front());
2152 candidate_with_ufrag.set_username("ABC");
2153 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2154 candidate_with_ufrag));
2155 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2156 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002157
2158 Candidate candidate_with_network_info(candidates_.front());
2159 candidate_with_network_info.set_network_id(1);
2160 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2161 candidate_with_network_info));
2162 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2163 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2164 candidate_with_network_info.set_network_cost(999);
2165 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2166 candidate_with_network_info));
2167 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2168 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2169 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002170}
2171
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002172// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2173// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002174TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002175 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002176 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2177 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2178 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002179 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002180 std::unique_ptr<IceCandidateInterface> jcandidate(
2181 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002182
2183 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2184 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2185}
2186
htaa6b99442016-04-12 10:29:17 -07002187TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002188 cricket::VideoCodec h264_codec("H264");
2189 h264_codec.SetParam("profile-level-id", "42e01f");
2190 h264_codec.SetParam("level-asymmetry-allowed", "1");
2191 h264_codec.SetParam("packetization-mode", "1");
2192 video_desc_->AddCodec(h264_codec);
2193
htaa6b99442016-04-12 10:29:17 -07002194 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
2195
2196 std::string message = webrtc::SdpSerialize(jdesc_, false);
2197 size_t after_pt = message.find(" H264/90000");
2198 ASSERT_NE(after_pt, std::string::npos);
2199 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2200 ASSERT_NE(before_pt, std::string::npos);
2201 before_pt += strlen("a=rtpmap:");
2202 std::string pt = message.substr(before_pt, after_pt - before_pt);
2203 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2204 std::string to_find = "a=fmtp:" + pt + " ";
2205 size_t fmtp_pos = message.find(to_find);
2206 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
2207 size_t fmtp_endpos = message.find("\n", fmtp_pos);
2208 ASSERT_NE(std::string::npos, fmtp_endpos);
2209 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2210 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2211 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2212 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002213 // Check that there are no spaces after semicolons.
2214 // https://bugs.webrtc.org/5793
2215 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002216}
2217
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002218TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
2219 JsepSessionDescription jdesc(kDummyString);
2220 // Deserialize
2221 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2222 // Verify
2223 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2224}
2225
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002226TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
2227 JsepSessionDescription jdesc(kDummyString);
2228 const char kSdpWithoutMline[] =
2229 "v=0\r\n"
2230 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2231 "s=-\r\n"
2232 "t=0 0\r\n"
2233 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
2234 // Deserialize
2235 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2236 EXPECT_EQ(0u, jdesc.description()->contents().size());
2237}
2238
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002239TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
2240 JsepSessionDescription jdesc(kDummyString);
2241 std::string sdp_without_carriage_return = kSdpFullString;
2242 Replace("\r\n", "\n", &sdp_without_carriage_return);
2243 // Deserialize
2244 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2245 // Verify
2246 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2247}
2248
2249TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2250 // SessionDescription with desc but without candidates.
2251 JsepSessionDescription jdesc_no_candidates(kDummyString);
2252 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
2253 kSessionId, kSessionVersion));
2254 JsepSessionDescription new_jdesc(kDummyString);
2255 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2256 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2257}
2258
2259TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2260 static const char kSdpNoRtpmapString[] =
2261 "v=0\r\n"
2262 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2263 "s=-\r\n"
2264 "t=0 0\r\n"
2265 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2266 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002267 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002268 // The rtpmap line for static payload codec is optional.
2269 "a=rtpmap:18 G729/16000\r\n"
2270 "a=rtpmap:103 ISAC/16000\r\n";
2271
2272 JsepSessionDescription jdesc(kDummyString);
2273 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2274 cricket::AudioContentDescription* audio =
2275 static_cast<AudioContentDescription*>(
2276 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2277 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002278 // The codecs in the AudioContentDescription should be in the same order as
2279 // the payload types (<fmt>s) on the m= line.
2280 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2281 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002282 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002283 EXPECT_EQ(ref_codecs, audio->codecs());
2284}
2285
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002286TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2287 static const char kSdpNoRtpmapString[] =
2288 "v=0\r\n"
2289 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2290 "s=-\r\n"
2291 "t=0 0\r\n"
2292 "m=audio 49232 RTP/AVP 18 103\r\n"
2293 "a=fmtp:18 annexb=yes\r\n"
2294 "a=rtpmap:103 ISAC/16000\r\n";
2295
2296 JsepSessionDescription jdesc(kDummyString);
2297 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2298 cricket::AudioContentDescription* audio =
2299 static_cast<AudioContentDescription*>(
2300 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2301
2302 cricket::AudioCodec g729 = audio->codecs()[0];
2303 EXPECT_EQ("G729", g729.name);
2304 EXPECT_EQ(8000, g729.clockrate);
2305 EXPECT_EQ(18, g729.id);
2306 cricket::CodecParameterMap::iterator found =
2307 g729.params.find("annexb");
2308 ASSERT_TRUE(found != g729.params.end());
2309 EXPECT_EQ(found->second, "yes");
2310
2311 cricket::AudioCodec isac = audio->codecs()[1];
2312 EXPECT_EQ("ISAC", isac.name);
2313 EXPECT_EQ(103, isac.id);
2314 EXPECT_EQ(16000, isac.clockrate);
2315}
2316
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002317// Ensure that we can deserialize SDP with a=fingerprint properly.
2318TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2319 // Add a DTLS a=fingerprint attribute to our session description.
2320 AddFingerprint();
2321 JsepSessionDescription new_jdesc(kDummyString);
2322 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
2323 jdesc_.session_id(),
2324 jdesc_.session_version()));
2325
2326 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
2327 std::string sdp_with_fingerprint = kSdpString;
2328 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2329 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2330 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2331 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2332}
2333
2334TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
2335 JsepSessionDescription jdesc_with_bundle(kDummyString);
2336 std::string sdp_with_bundle = kSdpFullString;
2337 InjectAfter(kSessionTime,
2338 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2339 &sdp_with_bundle);
2340 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2341 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2342 group.AddContentName(kAudioContentName);
2343 group.AddContentName(kVideoContentName);
2344 desc_.AddGroup(group);
2345 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2346 jdesc_.session_id(),
2347 jdesc_.session_version()));
2348 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2349}
2350
2351TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
2352 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2353 std::string sdp_with_bandwidth = kSdpFullString;
2354 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
2355 "b=AS:100\r\n",
2356 &sdp_with_bandwidth);
2357 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
2358 "b=AS:50\r\n",
2359 &sdp_with_bandwidth);
2360 EXPECT_TRUE(
2361 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2362 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
2363 GetFirstVideoContent(&desc_)->description);
2364 vcd->set_bandwidth(100 * 1000);
2365 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
2366 GetFirstAudioContent(&desc_)->description);
2367 acd->set_bandwidth(50 * 1000);
2368 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2369 jdesc_.session_id(),
2370 jdesc_.session_version()));
2371 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2372}
2373
2374TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
2375 JsepSessionDescription jdesc_with_ice_options(kDummyString);
2376 std::string sdp_with_ice_options = kSdpFullString;
2377 InjectAfter(kSessionTime,
2378 "a=ice-options:iceoption3\r\n",
2379 &sdp_with_ice_options);
2380 InjectAfter(kAttributeIcePwdVoice,
2381 "a=ice-options:iceoption1\r\n",
2382 &sdp_with_ice_options);
2383 InjectAfter(kAttributeIcePwdVideo,
2384 "a=ice-options:iceoption2\r\n",
2385 &sdp_with_ice_options);
2386 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2387 std::vector<std::string> transport_options;
2388 transport_options.push_back(kIceOption3);
2389 transport_options.push_back(kIceOption1);
2390 AddIceOptions(kAudioContentName, transport_options);
2391 transport_options.clear();
2392 transport_options.push_back(kIceOption3);
2393 transport_options.push_back(kIceOption2);
2394 AddIceOptions(kVideoContentName, transport_options);
2395 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2396 jdesc_.session_id(),
2397 jdesc_.session_version()));
2398 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2399}
2400
2401TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2402 // Remove the original ice-ufrag and ice-pwd
2403 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyString);
2404 std::string sdp_with_ufrag_pwd = kSdpFullString;
2405 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2406 // Add session level ufrag and pwd
2407 InjectAfter(kSessionTime,
2408 "a=ice-pwd:session+level+icepwd\r\n"
2409 "a=ice-ufrag:session+level+iceufrag\r\n",
2410 &sdp_with_ufrag_pwd);
2411 // Add media level ufrag and pwd for audio
2412 InjectAfter("a=mid:audio_content_name\r\n",
2413 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2414 &sdp_with_ufrag_pwd);
2415 // Update the candidate ufrag and pwd to the expected ones.
2416 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0,
2417 "media+level+iceufrag", "media+level+icepwd"));
2418 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1,
2419 "session+level+iceufrag", "session+level+icepwd"));
2420 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2421 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2422}
2423
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002424TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
2425 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_RECVONLY));
2426}
2427
2428TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
2429 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_SENDONLY));
2430}
2431
2432TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
2433 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_INACTIVE));
2434}
2435
2436TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2437 EXPECT_TRUE(TestDeserializeRejected(true, false));
2438}
2439
2440TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2441 EXPECT_TRUE(TestDeserializeRejected(false, true));
2442}
2443
2444TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2445 EXPECT_TRUE(TestDeserializeRejected(true, true));
2446}
2447
2448// Tests that we can still handle the sdp uses mslabel and label instead of
2449// msid for backward compatibility.
2450TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07002451 jdesc_.description()->set_msid_supported(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002452 JsepSessionDescription jdesc(kDummyString);
2453 std::string sdp_without_msid = kSdpFullString;
2454 Replace("msid", "xmsid", &sdp_without_msid);
2455 // Deserialize
2456 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2457 // Verify
2458 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2459}
2460
2461TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2462 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2463
2464 std::string sdp = kSdpOneCandidate;
2465 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2466 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2467 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2468 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002469 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002470
2471 // Candidate line without generation extension.
2472 sdp = kSdpOneCandidate;
2473 Replace(" generation 2", "", &sdp);
2474 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2475 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2476 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2477 Candidate expected = jcandidate_->candidate();
2478 expected.set_generation(0);
2479 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2480
honghaiza0c44ea2016-03-23 16:07:48 -07002481 // Candidate with network id and/or cost.
2482 sdp = kSdpOneCandidate;
2483 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2484 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2485 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2486 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2487 expected = jcandidate_->candidate();
2488 expected.set_network_id(2);
2489 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2490 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2491 // Add network cost
2492 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2493 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2494 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2495 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2496
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002497 sdp = kSdpTcpActiveCandidate;
2498 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2499 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002500 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002501 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2502 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2503 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002504 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2505 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002506 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(
2507 jcandidate_template->candidate()));
2508 sdp = kSdpTcpPassiveCandidate;
2509 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2510 sdp = kSdpTcpSOCandidate;
2511 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002512}
2513
2514// This test verifies the deserialization of candidate-attribute
2515// as per RFC 5245. Candiate-attribute will be of the format
2516// candidate:<blah>. This format will be used when candidates
2517// are trickled.
2518TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2519 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2520
2521 std::string candidate_attribute = kRawCandidate;
2522 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2523 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2524 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2525 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2526 EXPECT_EQ(2u, jcandidate.candidate().generation());
2527
2528 // Candidate line without generation extension.
2529 candidate_attribute = kRawCandidate;
2530 Replace(" generation 2", "", &candidate_attribute);
2531 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2532 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2533 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2534 Candidate expected = jcandidate_->candidate();
2535 expected.set_generation(0);
2536 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2537
2538 // Candidate line without candidate:
2539 candidate_attribute = kRawCandidate;
2540 Replace("candidate:", "", &candidate_attribute);
2541 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2542
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002543 // Candidate line with IPV6 address.
2544 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
2545}
2546
2547// This test verifies that the deserialization of an invalid candidate string
2548// fails.
2549TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
2550 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2551
2552 std::string candidate_attribute = kRawCandidate;
2553 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002554 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002555
2556 candidate_attribute = kSdpOneCandidate;
2557 candidate_attribute.replace(0, 1, "x");
2558 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2559
2560 candidate_attribute = kRawCandidate;
2561 candidate_attribute.append("\r\n");
2562 candidate_attribute.append(kRawCandidate);
2563 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2564
2565 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002566}
2567
2568TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2569 AddRtpDataChannel();
2570 JsepSessionDescription jdesc(kDummyString);
2571 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2572
2573 std::string sdp_with_data = kSdpString;
2574 sdp_with_data.append(kSdpRtpDataChannelString);
2575 JsepSessionDescription jdesc_output(kDummyString);
2576
2577 // Deserialize
2578 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2579 // Verify
2580 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2581}
2582
2583TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002584 bool use_sctpmap = true;
2585 AddSctpDataChannel(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002586 JsepSessionDescription jdesc(kDummyString);
2587 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2588
2589 std::string sdp_with_data = kSdpString;
2590 sdp_with_data.append(kSdpSctpDataChannelString);
2591 JsepSessionDescription jdesc_output(kDummyString);
2592
lally@webrtc.org36300852015-02-24 20:19:35 +00002593 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2594 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2595 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2596
2597 // Verify with UDP/DTLS/SCTP.
2598 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2599 strlen(kDtlsSctp), kUdpDtlsSctp);
2600 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2601 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2602
2603 // Verify with TCP/DTLS/SCTP.
2604 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2605 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002606 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2607 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2608}
2609
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002610TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002611 bool use_sctpmap = false;
2612 AddSctpDataChannel(use_sctpmap);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002613 JsepSessionDescription jdesc(kDummyString);
2614 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2615
2616 std::string sdp_with_data = kSdpString;
2617 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2618 JsepSessionDescription jdesc_output(kDummyString);
2619
lally@webrtc.org36300852015-02-24 20:19:35 +00002620 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002621 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2622 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002623
lally@webrtc.org36300852015-02-24 20:19:35 +00002624 // Verify with UDP/DTLS/SCTP.
2625 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2626 strlen(kDtlsSctp), kUdpDtlsSctp);
2627 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2628 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002629
lally@webrtc.org36300852015-02-24 20:19:35 +00002630 // Verify with TCP/DTLS/SCTP.
2631 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2632 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002633 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2634 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2635}
2636
lally69f57602015-10-08 10:15:04 -07002637TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002638 bool use_sctpmap = false;
2639 AddSctpDataChannel(use_sctpmap);
lally69f57602015-10-08 10:15:04 -07002640 JsepSessionDescription jdesc(kDummyString);
2641 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2642
2643 std::string sdp_with_data = kSdpString;
2644 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
2645 JsepSessionDescription jdesc_output(kDummyString);
2646
2647 // Verify with DTLS/SCTP.
2648 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2649 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2650
2651 // Verify with UDP/DTLS/SCTP.
2652 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2653 strlen(kDtlsSctp), kUdpDtlsSctp);
2654 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2655 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2656
2657 // Verify with TCP/DTLS/SCTP.
2658 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2659 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
2660 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2661 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2662}
2663
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002664// Test to check the behaviour if sctp-port is specified
2665// on the m= line and in a=sctp-port.
2666TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002667 bool use_sctpmap = true;
2668 AddSctpDataChannel(use_sctpmap);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002669 JsepSessionDescription jdesc(kDummyString);
2670 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2671
2672 std::string sdp_with_data = kSdpString;
2673 // Append m= attributes
2674 sdp_with_data.append(kSdpSctpDataChannelString);
2675 // Append a=sctp-port attribute
2676 sdp_with_data.append("a=sctp-port 5000\r\n");
2677 JsepSessionDescription jdesc_output(kDummyString);
2678
2679 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2680}
2681
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002682// For crbug/344475.
2683TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2684 std::string sdp_with_data = kSdpString;
2685 sdp_with_data.append(kSdpSctpDataChannelString);
2686 // Remove the "\n" at the end.
2687 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
2688 JsepSessionDescription jdesc_output(kDummyString);
2689
2690 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2691 // No crash is a pass.
2692}
2693
zstein4b2e0822017-02-17 19:48:38 -08002694void MutateJsepSctpPort(JsepSessionDescription& jdesc,
2695 const SessionDescription& desc) {
wu@webrtc.org78187522013-10-07 23:32:02 +00002696 // take our pre-built session description and change the SCTP port.
zstein4b2e0822017-02-17 19:48:38 -08002697 cricket::SessionDescription* mutant = desc.Copy();
wu@webrtc.org78187522013-10-07 23:32:02 +00002698 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
2699 mutant->GetContentDescriptionByName(kDataContentName));
2700 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002701 EXPECT_EQ(1U, codecs.size());
solenberg9fa49752016-10-08 13:02:44 -07002702 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002703 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002704 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002705
2706 // note: mutant's owned by jdesc now.
2707 ASSERT_TRUE(jdesc.Initialize(mutant, kSessionId, kSessionVersion));
2708 mutant = NULL;
zstein4b2e0822017-02-17 19:48:38 -08002709}
2710
2711TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
2712 bool use_sctpmap = true;
2713 AddSctpDataChannel(use_sctpmap);
2714
2715 // First setup the expected JsepSessionDescription.
2716 JsepSessionDescription jdesc(kDummyString);
2717 MutateJsepSctpPort(jdesc, desc_);
wu@webrtc.org78187522013-10-07 23:32:02 +00002718
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002719 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002720 std::string sdp_with_data = kSdpString;
2721 sdp_with_data.append(kSdpSctpDataChannelString);
zstein4b2e0822017-02-17 19:48:38 -08002722 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2723 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2724 &sdp_with_data);
wu@webrtc.org78187522013-10-07 23:32:02 +00002725 JsepSessionDescription jdesc_output(kDummyString);
2726
2727 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2728 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08002729}
2730
2731TEST_F(WebRtcSdpTest,
2732 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
2733 bool use_sctpmap = false;
2734 AddSctpDataChannel(use_sctpmap);
2735
2736 JsepSessionDescription jdesc(kDummyString);
2737 MutateJsepSctpPort(jdesc, desc_);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002738
2739 // We need to test the deserialized JsepSessionDescription from
2740 // kSdpSctpDataChannelStringWithSctpPort for
2741 // draft-ietf-mmusic-sctp-sdp-07
2742 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08002743 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002744 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
zstein4b2e0822017-02-17 19:48:38 -08002745 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2746 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2747 &sdp_with_data);
2748 JsepSessionDescription jdesc_output(kDummyString);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002749
2750 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2751 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002752}
2753
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002754TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002755 // We want to test that deserializing data content limits bandwidth
2756 // settings (it should never be greater than the default).
2757 // This should prevent someone from using unlimited data bandwidth through
2758 // JS and "breaking the Internet".
2759 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002760 std::string sdp_with_bandwidth = kSdpString;
2761 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
2762 InjectAfter("a=mid:data_content_name\r\n",
2763 "b=AS:100\r\n",
2764 &sdp_with_bandwidth);
2765 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2766
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002767 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2768}
2769
2770TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08002771 bool use_sctpmap = true;
2772 AddSctpDataChannel(use_sctpmap);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002773 JsepSessionDescription jdesc(kDummyString);
2774 DataContentDescription* dcd = static_cast<DataContentDescription*>(
2775 GetFirstDataContent(&desc_)->description);
2776 dcd->set_bandwidth(100 * 1000);
2777 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2778
2779 std::string sdp_with_bandwidth = kSdpString;
2780 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
2781 InjectAfter("a=mid:data_content_name\r\n",
2782 "b=AS:100\r\n",
2783 &sdp_with_bandwidth);
2784 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2785
2786 // SCTP has congestion control, so we shouldn't limit the bandwidth
2787 // as we do for RTP.
2788 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002789 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2790}
2791
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002792TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSessionLevelExtmap) {
2793 TestDeserializeExtmap(true, false);
2794}
2795
2796TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
2797 TestDeserializeExtmap(false, true);
2798}
2799
2800TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInvalidExtmap) {
2801 TestDeserializeExtmap(true, true);
2802}
2803
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002804TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
2805 JsepSessionDescription jdesc(kDummyString);
2806 std::string sdp = kSdpFullString;
2807 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2808 // Deserialize
2809 SdpParseError error;
2810 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-16 17:54:10 -08002811 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002812 EXPECT_EQ(lastline, error.line);
2813 EXPECT_EQ("Invalid SDP line.", error.description);
2814}
2815
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002816TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2817 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2818 std::string new_sdp = kSdpOneCandidate;
2819 Replace("udp", "unsupported_transport", &new_sdp);
2820 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2821 new_sdp = kSdpOneCandidate;
2822 Replace("udp", "uDP", &new_sdp);
2823 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2824 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2825 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2826 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2827}
2828
honghaiza54a0802015-12-16 18:37:23 -08002829TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002830 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08002831 EXPECT_TRUE(
2832 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002833 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2834 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2835 Candidate ref_candidate = jcandidate_->candidate();
2836 ref_candidate.set_username("user_rtp");
2837 ref_candidate.set_password("password_rtp");
2838 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2839}
2840
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002841TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
2842 JsepSessionDescription jdesc(kDummyString);
2843
2844 // Deserialize
2845 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2846
2847 // Verify
2848 cricket::AudioContentDescription* audio =
2849 static_cast<AudioContentDescription*>(
2850 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2851 EXPECT_TRUE(audio->conference_mode());
2852
2853 cricket::VideoContentDescription* video =
2854 static_cast<VideoContentDescription*>(
2855 jdesc.description()->GetContentDescriptionByName(cricket::CN_VIDEO));
2856 EXPECT_TRUE(video->conference_mode());
2857}
2858
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002859TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2860 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002861 const char kSdpEmptyType[] = " =candidate";
2862 const char kSdpEqualAsPlus[] = "a+candidate";
2863 const char kSdpSpaceAfterEqual[] = "a= candidate";
2864 const char kSdpUpperType[] = "A=candidate";
2865 const char kSdpEmptyLine[] = "";
2866 const char kSdpMissingValue[] = "a=";
2867
2868 const char kSdpBrokenFingerprint[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002869 "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 +00002870 const char kSdpExtraField[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002871 "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 +00002872 const char kSdpMissingSpace[] = "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002873 "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 +00002874 // MD5 is not allowed in fingerprints.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002875 const char kSdpMd5[] = "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002876 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002877
2878 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002879 ExpectParseFailure("v=", kSdpDestroyer);
2880 ExpectParseFailure("o=", kSdpDestroyer);
2881 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002882 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002883 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002884
2885 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002886 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2887 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002888
2889 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002890 ExpectParseFailure("a=candidate", kSdpEmptyType);
2891 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2892 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
2893 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002894
2895 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2896 // because it's orthogonal to what we are replacing and hence
2897 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002898 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
2899 ExpectParseFailure("a=sendrecv", kSdpExtraField);
2900 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
2901 ExpectParseFailure("a=sendrecv", kSdpMd5);
2902
2903 // Empty Line
2904 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
2905 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002906}
2907
2908TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2909 // ssrc
2910 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08002911 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002912 // crypto
2913 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
2914 // rtpmap
2915 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
2916 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
2917 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
2918 // candidate
2919 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
2920 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
2921 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
2922 ExpectParseFailure("rport 2346", "rport badvalue");
2923 ExpectParseFailure("rport 2346 generation 2",
2924 "rport 2346 generation badvalue");
2925 // m line
2926 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
2927 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
2928
2929 // bandwidth
2930 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2931 "b=AS:badvalue\r\n",
2932 "b=AS:badvalue");
2933 // rtcp-fb
2934 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2935 "a=rtcp-fb:badvalue nack\r\n",
2936 "a=rtcp-fb:badvalue nack");
2937 // extmap
2938 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2939 "a=extmap:badvalue http://example.com\r\n",
2940 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002941}
2942
2943TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
2944 JsepSessionDescription jdesc_output(kDummyString);
2945
2946 const char kSdpWithReorderedPlTypesString[] =
2947 "v=0\r\n"
2948 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2949 "s=-\r\n"
2950 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00002951 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002952 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
2953 // in the map.
2954 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002955 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002956
2957 // Deserialize
2958 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
2959
2960 const ContentInfo* ac = GetFirstAudioContent(jdesc_output.description());
2961 ASSERT_TRUE(ac != NULL);
2962 const AudioContentDescription* acd =
2963 static_cast<const AudioContentDescription*>(ac->description);
2964 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002965 EXPECT_EQ("ISAC", acd->codecs()[0].name);
2966 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002967 EXPECT_EQ(104, acd->codecs()[0].id);
2968}
2969
2970TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
2971 JsepSessionDescription jdesc_output(kDummyString);
2972 CodecParams params;
2973 params.max_ptime = 40;
2974 params.ptime = 30;
2975 params.min_ptime = 10;
2976 params.sprop_stereo = 1;
2977 params.stereo = 1;
2978 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002979 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002980 TestDeserializeCodecParams(params, &jdesc_output);
deadbeef9d3584c2016-02-16 17:54:10 -08002981 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002982}
2983
2984TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
2985 const bool kUseWildcard = false;
2986 JsepSessionDescription jdesc_output(kDummyString);
2987 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
deadbeef9d3584c2016-02-16 17:54:10 -08002988 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002989}
2990
2991TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
2992 const bool kUseWildcard = true;
2993 JsepSessionDescription jdesc_output(kDummyString);
2994 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
deadbeef9d3584c2016-02-16 17:54:10 -08002995 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002996}
2997
2998TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
2999 JsepSessionDescription jdesc_output(kDummyString);
3000
3001 const char kSdpWithFmtpString[] =
3002 "v=0\r\n"
3003 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3004 "s=-\r\n"
3005 "t=0 0\r\n"
3006 "m=video 3457 RTP/SAVPF 120\r\n"
3007 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07003008 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3009
3010 // Deserialize
3011 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07003012 EXPECT_TRUE(
3013 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07003014
3015 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
3016 ASSERT_TRUE(vc != NULL);
3017 const VideoContentDescription* vcd =
3018 static_cast<const VideoContentDescription*>(vc->description);
3019 ASSERT_FALSE(vcd->codecs().empty());
3020 cricket::VideoCodec vp8 = vcd->codecs()[0];
3021 EXPECT_EQ("VP8", vp8.name);
3022 EXPECT_EQ(120, vp8.id);
3023 cricket::CodecParameterMap::iterator found =
3024 vp8.params.find("x-google-min-bitrate");
3025 ASSERT_TRUE(found != vp8.params.end());
3026 EXPECT_EQ(found->second, "10");
3027 found = vp8.params.find("x-google-max-quantization");
3028 ASSERT_TRUE(found != vp8.params.end());
3029 EXPECT_EQ(found->second, "40");
3030}
3031
johan2d8d23e2016-06-03 01:22:42 -07003032TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
3033 JsepSessionDescription jdesc_output(kDummyString);
3034
3035 const char kSdpWithFmtpString[] =
3036 "v=0\r\n"
3037 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3038 "s=-\r\n"
3039 "t=0 0\r\n"
3040 "m=video 49170 RTP/AVP 98\r\n"
3041 "a=rtpmap:98 H264/90000\r\n"
3042 "a=fmtp:98 profile-level-id=42A01E; "
3043 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3044
3045 // Deserialize.
3046 SdpParseError error;
3047 EXPECT_TRUE(
3048 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3049
3050 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
3051 ASSERT_TRUE(vc != NULL);
3052 const VideoContentDescription* vcd =
3053 static_cast<const VideoContentDescription*>(vc->description);
3054 ASSERT_TRUE(vcd != NULL);
3055 ASSERT_FALSE(vcd->codecs().empty());
3056 cricket::VideoCodec h264 = vcd->codecs()[0];
3057 EXPECT_EQ("H264", h264.name);
3058 EXPECT_EQ(98, h264.id);
3059 cricket::CodecParameterMap::const_iterator found =
3060 h264.params.find("profile-level-id");
3061 ASSERT_TRUE(found != h264.params.end());
3062 EXPECT_EQ(found->second, "42A01E");
3063 found = h264.params.find("sprop-parameter-sets");
3064 ASSERT_TRUE(found != h264.params.end());
3065 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3066}
3067
Donald Curtis0e07f922015-05-15 09:21:23 -07003068TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
3069 JsepSessionDescription jdesc_output(kDummyString);
3070
3071 const char kSdpWithFmtpString[] =
3072 "v=0\r\n"
3073 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3074 "s=-\r\n"
3075 "t=0 0\r\n"
3076 "m=video 3457 RTP/SAVPF 120\r\n"
3077 "a=rtpmap:120 VP8/90000\r\n"
3078 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003079
3080 // Deserialize
3081 SdpParseError error;
3082 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output,
3083 &error));
3084
3085 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
3086 ASSERT_TRUE(vc != NULL);
3087 const VideoContentDescription* vcd =
3088 static_cast<const VideoContentDescription*>(vc->description);
3089 ASSERT_FALSE(vcd->codecs().empty());
3090 cricket::VideoCodec vp8 = vcd->codecs()[0];
3091 EXPECT_EQ("VP8", vp8.name);
3092 EXPECT_EQ(120, vp8.id);
3093 cricket::CodecParameterMap::iterator found =
3094 vp8.params.find("x-google-min-bitrate");
3095 ASSERT_TRUE(found != vp8.params.end());
3096 EXPECT_EQ(found->second, "10");
3097 found = vp8.params.find("x-google-max-quantization");
3098 ASSERT_TRUE(found != vp8.params.end());
3099 EXPECT_EQ(found->second, "40");
3100}
3101
ossuaa4b0772017-01-30 07:41:18 -08003102TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
3103 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
3104 GetFirstAudioContent(&desc_)->description);
3105
3106 cricket::AudioCodecs codecs = acd->codecs();
3107 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3108 acd->set_codecs(codecs);
3109
3110 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3111 jdesc_.session_id(),
3112 jdesc_.session_version()));
3113 std::string message = webrtc::SdpSerialize(jdesc_, false);
3114 std::string sdp_with_fmtp = kSdpFullString;
3115 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3116 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3117 &sdp_with_fmtp);
3118 EXPECT_EQ(sdp_with_fmtp, message);
3119}
3120
3121TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
3122 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
3123 GetFirstAudioContent(&desc_)->description);
3124
3125 cricket::AudioCodecs codecs = acd->codecs();
3126 codecs[0].params["stereo"] = "1";
3127 acd->set_codecs(codecs);
3128
3129 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3130 jdesc_.session_id(),
3131 jdesc_.session_version()));
3132 std::string message = webrtc::SdpSerialize(jdesc_, false);
3133 std::string sdp_with_fmtp = kSdpFullString;
3134 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3135 "a=fmtp:111 stereo=1\r\n",
3136 &sdp_with_fmtp);
3137 EXPECT_EQ(sdp_with_fmtp, message);
3138}
3139
3140TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
3141 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
3142 GetFirstAudioContent(&desc_)->description);
3143
3144 cricket::AudioCodecs codecs = acd->codecs();
3145 codecs[0].params["ptime"] = "20";
3146 codecs[0].params["maxptime"] = "120";
3147 acd->set_codecs(codecs);
3148
3149 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3150 jdesc_.session_id(),
3151 jdesc_.session_version()));
3152 std::string message = webrtc::SdpSerialize(jdesc_, false);
3153 std::string sdp_with_fmtp = kSdpFullString;
3154 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3155 "a=maxptime:120\r\n" // No comma here. String merging!
3156 "a=ptime:20\r\n",
3157 &sdp_with_fmtp);
3158 EXPECT_EQ(sdp_with_fmtp, message);
3159}
3160
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003161TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
3162 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
3163 GetFirstVideoContent(&desc_)->description);
3164
3165 cricket::VideoCodecs codecs = vcd->codecs();
3166 codecs[0].params["x-google-min-bitrate"] = "10";
3167 vcd->set_codecs(codecs);
3168
3169 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3170 jdesc_.session_id(),
3171 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08003172 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003173 std::string sdp_with_fmtp = kSdpFullString;
3174 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
3175 "a=fmtp:120 x-google-min-bitrate=10\r\n",
3176 &sdp_with_fmtp);
3177 EXPECT_EQ(sdp_with_fmtp, message);
3178}
3179
3180TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) {
3181 JsepSessionDescription jdesc_with_icelite(kDummyString);
3182 std::string sdp_with_icelite = kSdpFullString;
3183 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3184 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3185 const cricket::TransportInfo* tinfo1 =
3186 desc->GetTransportInfoByName("audio_content_name");
3187 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3188 const cricket::TransportInfo* tinfo2 =
3189 desc->GetTransportInfoByName("video_content_name");
3190 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
3191 InjectAfter(kSessionTime,
3192 "a=ice-lite\r\n",
3193 &sdp_with_icelite);
3194 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3195 desc = jdesc_with_icelite.description();
3196 const cricket::TransportInfo* atinfo =
3197 desc->GetTransportInfoByName("audio_content_name");
3198 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3199 const cricket::TransportInfo* vtinfo =
3200 desc->GetTransportInfoByName("video_content_name");
3201 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
3202}
3203
3204// Verifies that the candidates in the input SDP are parsed and serialized
3205// correctly in the output SDP.
3206TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3207 std::string sdp_with_data = kSdpString;
3208 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
3209 JsepSessionDescription jdesc_output(kDummyString);
3210
3211 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
deadbeef9d3584c2016-02-16 17:54:10 -08003212 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output, false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003213}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003214
3215TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3216 AddFingerprint();
3217 TransportInfo audio_transport_info =
3218 *(desc_.GetTransportInfoByName(kAudioContentName));
3219 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3220 audio_transport_info.description.connection_role);
3221 audio_transport_info.description.connection_role =
3222 cricket::CONNECTIONROLE_ACTIVE;
3223
3224 TransportInfo video_transport_info =
3225 *(desc_.GetTransportInfoByName(kVideoContentName));
3226 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3227 video_transport_info.description.connection_role);
3228 video_transport_info.description.connection_role =
3229 cricket::CONNECTIONROLE_ACTIVE;
3230
3231 desc_.RemoveTransportInfoByName(kAudioContentName);
3232 desc_.RemoveTransportInfoByName(kVideoContentName);
3233
3234 desc_.AddTransportInfo(audio_transport_info);
3235 desc_.AddTransportInfo(video_transport_info);
3236
3237 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3238 jdesc_.session_id(),
3239 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08003240 std::string message = webrtc::SdpSerialize(jdesc_, false);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003241 std::string sdp_with_dtlssetup = kSdpFullString;
3242
3243 // Fingerprint attribute is necessary to add DTLS setup attribute.
3244 InjectAfter(kAttributeIcePwdVoice,
3245 kFingerprint, &sdp_with_dtlssetup);
3246 InjectAfter(kAttributeIcePwdVideo,
3247 kFingerprint, &sdp_with_dtlssetup);
3248 // Now adding |setup| attribute.
3249 InjectAfter(kFingerprint,
3250 "a=setup:active\r\n", &sdp_with_dtlssetup);
3251 EXPECT_EQ(sdp_with_dtlssetup, message);
3252}
3253
3254TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
3255 JsepSessionDescription jdesc_with_dtlssetup(kDummyString);
3256 std::string sdp_with_dtlssetup = kSdpFullString;
3257 InjectAfter(kSessionTime,
3258 "a=setup:actpass\r\n",
3259 &sdp_with_dtlssetup);
3260 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3261 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3262 const cricket::TransportInfo* atinfo =
3263 desc->GetTransportInfoByName("audio_content_name");
3264 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3265 atinfo->description.connection_role);
3266 const cricket::TransportInfo* vtinfo =
3267 desc->GetTransportInfoByName("video_content_name");
3268 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3269 vtinfo->description.connection_role);
3270}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003271
3272// Verifies that the order of the serialized m-lines follows the order of the
3273// ContentInfo in SessionDescription, and vise versa for deserialization.
3274TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
3275 JsepSessionDescription jdesc(kDummyString);
3276 const std::string media_content_sdps[3] = {
3277 kSdpAudioString,
3278 kSdpVideoString,
3279 kSdpSctpDataChannelString
3280 };
3281 const cricket::MediaType media_types[3] = {
3282 cricket::MEDIA_TYPE_AUDIO,
3283 cricket::MEDIA_TYPE_VIDEO,
3284 cricket::MEDIA_TYPE_DATA
3285 };
3286
3287 // Verifies all 6 permutations.
3288 for (size_t i = 0; i < 6; ++i) {
3289 size_t media_content_in_sdp[3];
3290 // The index of the first media content.
3291 media_content_in_sdp[0] = i / 2;
3292 // The index of the second media content.
3293 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3294 // The index of the third media content.
3295 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3296
3297 std::string sdp_string = kSdpSessionString;
3298 for (size_t i = 0; i < 3; ++i)
3299 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3300
3301 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3302 cricket::SessionDescription* desc = jdesc.description();
3303 EXPECT_EQ(3u, desc->contents().size());
3304
3305 for (size_t i = 0; i < 3; ++i) {
3306 const cricket::MediaContentDescription* mdesc =
3307 static_cast<const cricket::MediaContentDescription*>(
3308 desc->contents()[i].description);
3309 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3310 }
3311
deadbeef9d3584c2016-02-16 17:54:10 -08003312 std::string serialized_sdp = webrtc::SdpSerialize(jdesc, false);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003313 EXPECT_EQ(sdp_string, serialized_sdp);
3314 }
3315}
deadbeef9d3584c2016-02-16 17:54:10 -08003316
deadbeef25ed4352016-12-12 18:37:36 -08003317TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3318 MakeBundleOnlyDescription();
3319 JsepSessionDescription deserialized_description(kDummyString);
deadbeef12771a12017-01-03 13:53:47 -08003320 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003321 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3322 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3323}
3324
deadbeef12771a12017-01-03 13:53:47 -08003325// The semantics of "a=bundle-only" are only defined when it's used in
3326// combination with a 0 port on the m= line. We should ignore it if used with a
3327// nonzero port.
3328TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3329 // Make the base bundle-only description but unset the bundle-only flag.
3330 MakeBundleOnlyDescription();
3331 jdesc_.description()->contents()[1].bundle_only = false;
3332
3333 std::string modified_sdp = kBundleOnlySdpFullString;
3334 Replace("m=video 0", "m=video 9", &modified_sdp);
3335 JsepSessionDescription deserialized_description(kDummyString);
3336 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3337 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003338}
3339
3340TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3341 MakeBundleOnlyDescription();
3342 TestSerialize(jdesc_, false);
3343}
3344
deadbeef9d3584c2016-02-16 17:54:10 -08003345TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3346 MakePlanBDescription();
3347
3348 JsepSessionDescription deserialized_description(kDummyString);
3349 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3350
3351 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3352}
3353
3354TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3355 MakePlanBDescription();
3356 TestSerialize(jdesc_, false);
3357}
3358
Taylor Brandstetter5de6b752016-03-09 17:02:30 -08003359// Some WebRTC endpoints include the msid in both the Plan B and Unified Plan
3360// ways, to make SDP that's compatible with both Plan B and Unified Plan (to
3361// some extent). If we parse this, the Plan B msid attribute (which is more
3362// specific, since it's at the SSRC level) should take priority.
3363TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescriptionWithMsid) {
3364 MakePlanBDescription();
3365
3366 JsepSessionDescription deserialized_description(kDummyString);
3367 EXPECT_TRUE(
3368 SdpDeserialize(kPlanBSdpFullStringWithMsid, &deserialized_description));
3369
3370 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3371}
3372
deadbeef9d3584c2016-02-16 17:54:10 -08003373TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3374 MakeUnifiedPlanDescription();
3375
3376 JsepSessionDescription deserialized_description(kDummyString);
3377 EXPECT_TRUE(
3378 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3379
3380 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3381}
3382
3383TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3384 MakeUnifiedPlanDescription();
3385 TestSerialize(jdesc_, true);
3386}
deadbeef7e146cb2016-09-28 10:04:34 -07003387
3388// Regression test for heap overflow bug:
3389// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3390TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 10:04:34 -07003391 // The issue occurs when the sctp-port attribute is found in a video
3392 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 12:43:58 -08003393 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 10:04:34 -07003394 "v=0\r\n"
3395 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3396 "s=-\r\n"
3397 "t=0 0\r\n"
3398 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3399 "a=sctp-port 5000\r\n"
3400 "a=fmtp:108 foo=10\r\n";
3401
3402 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3403 "sctp-port");
3404}
deadbeefb2362572016-12-13 16:37:06 -08003405
3406// Regression test for integer overflow bug:
3407// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3408TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003409 // Bandwidth attribute is the max signed 32-bit int, which will get
3410 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003411 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003412 "v=0\r\n"
3413 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3414 "s=-\r\n"
3415 "t=0 0\r\n"
3416 "m=video 3457 RTP/SAVPF 120\r\n"
3417 "b=AS:2147483647\r\n"
3418 "foo=fail\r\n";
3419
3420 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3421}
deadbeef7bcdb692017-01-20 12:43:58 -08003422
3423// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3424// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3425// Regression test for:
3426// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3427TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3428 // Important piece is "ufrag foo pwd bar".
3429 static const char kSdpWithIceCredentialsInCandidateString[] =
3430 "v=0\r\n"
3431 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3432 "s=-\r\n"
3433 "t=0 0\r\n"
3434 "m=audio 9 RTP/SAVPF 111\r\n"
3435 "c=IN IP4 0.0.0.0\r\n"
3436 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3437 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3438 "a=rtpmap:111 opus/48000/2\r\n"
3439 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3440 "generation 2 ufrag foo pwd bar\r\n";
3441
3442 JsepSessionDescription jdesc_output(kDummyString);
3443 EXPECT_TRUE(
3444 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
3445 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3446 ASSERT_NE(nullptr, candidates);
3447 ASSERT_EQ(1, candidates->count());
3448 cricket::Candidate c = candidates->at(0)->candidate();
3449 EXPECT_EQ("ufrag_voice", c.username());
3450 EXPECT_EQ("pwd_voice", c.password());
3451}
deadbeef90f1e1e2017-02-10 12:35:05 -08003452
3453// Test that SDP with an invalid port number in "a=candidate" lines is
3454// rejected, without crashing.
3455// Regression test for:
3456// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
3457TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
3458 static const char kSdpWithInvalidCandidatePort[] =
3459 "v=0\r\n"
3460 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3461 "s=-\r\n"
3462 "t=0 0\r\n"
3463 "m=audio 9 RTP/SAVPF 111\r\n"
3464 "c=IN IP4 0.0.0.0\r\n"
3465 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3466 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3467 "a=rtpmap:111 opus/48000/2\r\n"
3468 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
3469 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
3470
3471 JsepSessionDescription jdesc_output(kDummyString);
3472 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
3473}
deadbeefa4549d62017-02-10 17:26:22 -08003474
3475// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
3476// Regression test for:
3477// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
3478TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
3479 static const char kSdpWithMissingTrackId[] =
3480 "v=0\r\n"
3481 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3482 "s=-\r\n"
3483 "t=0 0\r\n"
3484 "m=audio 9 RTP/SAVPF 111\r\n"
3485 "c=IN IP4 0.0.0.0\r\n"
3486 "a=rtpmap:111 opus/48000/2\r\n"
3487 "a=msid:stream_id \r\n";
3488
3489 JsepSessionDescription jdesc_output(kDummyString);
3490 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
3491}
3492
3493TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
3494 static const char kSdpWithMissingStreamId[] =
3495 "v=0\r\n"
3496 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3497 "s=-\r\n"
3498 "t=0 0\r\n"
3499 "m=audio 9 RTP/SAVPF 111\r\n"
3500 "c=IN IP4 0.0.0.0\r\n"
3501 "a=rtpmap:111 opus/48000/2\r\n"
3502 "a=msid: track_id\r\n";
3503
3504 JsepSessionDescription jdesc_output(kDummyString);
3505 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
3506}