blob: 0ff5249738854ad42e92f46149b861c49f3d81df [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "api/jsepsessiondescription.h"
17#include "media/base/mediaconstants.h"
18#include "media/engine/webrtcvideoengine.h"
Patrik Höglundaba85d12017-11-28 15:46:08 +010019#include "p2p/base/port.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "p2p/base/p2pconstants.h"
21#include "pc/mediasession.h"
22#include "rtc_base/checks.h"
23#include "rtc_base/gunit.h"
24#include "rtc_base/logging.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020025#include "rtc_base/stringencode.h"
26#include "rtc_base/stringutils.h"
Patrik Höglund563934e2017-09-15 09:04:28 +020027
ossu7bb87ee2017-01-23 04:56:25 -080028#ifdef WEBRTC_ANDROID
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020029#include "pc/test/androidtestinitializer.h"
ossu7bb87ee2017-01-23 04:56:25 -080030#endif
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020031#include "pc/webrtcsdp.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000032
33using cricket::AudioCodec;
34using cricket::AudioContentDescription;
35using cricket::Candidate;
36using cricket::ContentInfo;
37using cricket::CryptoParams;
38using cricket::ContentGroup;
39using cricket::DataCodec;
40using cricket::DataContentDescription;
41using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
42using cricket::ICE_CANDIDATE_COMPONENT_RTP;
43using cricket::kFecSsrcGroupSemantics;
44using cricket::LOCAL_PORT_TYPE;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000045using cricket::RELAY_PORT_TYPE;
46using cricket::SessionDescription;
Steve Anton5adfafd2017-12-20 16:34:00 -080047using cricket::MediaProtocolType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000048using cricket::StreamParams;
49using cricket::STUN_PORT_TYPE;
50using cricket::TransportDescription;
51using cricket::TransportInfo;
52using cricket::VideoCodec;
53using cricket::VideoContentDescription;
54using webrtc::IceCandidateCollection;
55using webrtc::IceCandidateInterface;
56using webrtc::JsepIceCandidate;
57using webrtc::JsepSessionDescription;
isheriff6f8d6862016-05-26 11:24:55 -070058using webrtc::RtpExtension;
Steve Anton4e70a722017-11-28 14:57:10 -080059using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060using webrtc::SdpParseError;
Steve Antona3a92c22017-12-07 10:27:41 -080061using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062using 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";
jbauch5869f502017-06-29 12:31:36 -070097static const char kExtmapWithDirectionAndAttributeEncrypted[] =
98 "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt "
99 "http://example.com/082005/ext.htm#ttime a1 a2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100
Peter Boström0c4e06b2015-10-07 12:23:21 +0200101static const uint8_t kIdentityDigest[] = {
102 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
103 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000104
lally@webrtc.org34807282015-02-24 20:19:39 +0000105static const char kDtlsSctp[] = "DTLS/SCTP";
106static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
107static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +0000108
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000109struct CodecParams {
110 int max_ptime;
111 int ptime;
112 int min_ptime;
113 int sprop_stereo;
114 int stereo;
115 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000116 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000117};
118
deadbeef9d3584c2016-02-16 17:54:10 -0800119// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
120// instead of "a=crypto", and have an explicit test for adding "a=crypto".
121// Currently it's the other way around.
122
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000123// Reference sdp string
124static const char kSdpFullString[] =
125 "v=0\r\n"
126 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
127 "s=-\r\n"
128 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800129 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000130 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
131 "c=IN IP4 74.125.127.126\r\n"
132 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
133 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
134 "generation 2\r\n"
135 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
136 "generation 2\r\n"
137 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
138 "generation 2\r\n"
139 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
140 "generation 2\r\n"
141 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
142 "raddr 192.168.1.5 rport 2346 "
143 "generation 2\r\n"
144 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
145 "raddr 192.168.1.5 rport 2348 "
146 "generation 2\r\n"
147 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
148 "a=mid:audio_content_name\r\n"
149 "a=sendrecv\r\n"
150 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800151 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000152 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
153 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
154 "dummy_session_params\r\n"
155 "a=rtpmap:111 opus/48000/2\r\n"
156 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000157 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000158 "a=ssrc:1 cname:stream_1_cname\r\n"
159 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
160 "a=ssrc:1 mslabel:local_stream_1\r\n"
161 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000162 "m=video 3457 RTP/SAVPF 120\r\n"
163 "c=IN IP4 74.125.224.39\r\n"
164 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
165 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
166 "generation 2\r\n"
167 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
168 "generation 2\r\n"
169 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
170 "generation 2\r\n"
171 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
172 "generation 2\r\n"
173 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
174 "generation 2\r\n"
175 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
176 "generation 2\r\n"
177 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
178 "a=mid:video_content_name\r\n"
179 "a=sendrecv\r\n"
180 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
181 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
182 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800183 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000184 "a=ssrc:2 cname:stream_1_cname\r\n"
185 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
186 "a=ssrc:2 mslabel:local_stream_1\r\n"
187 "a=ssrc:2 label:video_track_id_1\r\n"
188 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800189 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000190 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800191 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000192
193// SDP reference string without the candidates.
194static const char kSdpString[] =
195 "v=0\r\n"
196 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
197 "s=-\r\n"
198 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800199 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000200 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000201 "c=IN IP4 0.0.0.0\r\n"
202 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000203 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
204 "a=mid:audio_content_name\r\n"
205 "a=sendrecv\r\n"
206 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800207 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000208 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
209 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
210 "dummy_session_params\r\n"
211 "a=rtpmap:111 opus/48000/2\r\n"
212 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000213 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000214 "a=ssrc:1 cname:stream_1_cname\r\n"
215 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
216 "a=ssrc:1 mslabel:local_stream_1\r\n"
217 "a=ssrc:1 label:audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000218 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000219 "c=IN IP4 0.0.0.0\r\n"
220 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000221 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
222 "a=mid:video_content_name\r\n"
223 "a=sendrecv\r\n"
224 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
225 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
226 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800227 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000228 "a=ssrc:2 cname:stream_1_cname\r\n"
229 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
230 "a=ssrc:2 mslabel:local_stream_1\r\n"
231 "a=ssrc:2 label:video_track_id_1\r\n"
232 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800233 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000234 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800235 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000236
237static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000238 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000239 "c=IN IP4 0.0.0.0\r\n"
240 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000241 "a=ice-ufrag:ufrag_data\r\n"
242 "a=ice-pwd:pwd_data\r\n"
243 "a=mid:data_content_name\r\n"
244 "a=sendrecv\r\n"
245 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
246 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
247 "a=rtpmap:101 google-data/90000\r\n"
248 "a=ssrc:10 cname:data_channel_cname\r\n"
249 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
250 "a=ssrc:10 mslabel:data_channel\r\n"
251 "a=ssrc:10 label:data_channeld0\r\n";
252
253static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000254 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000255 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000256 "a=ice-ufrag:ufrag_data\r\n"
257 "a=ice-pwd:pwd_data\r\n"
258 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000259 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000260
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000261// draft-ietf-mmusic-sctp-sdp-12
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000262static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000263 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
264 "a=max-message-size=100000\r\n"
265 "a=sctp-port 5000\r\n"
266 "c=IN IP4 0.0.0.0\r\n"
267 "a=ice-ufrag:ufrag_data\r\n"
268 "a=ice-pwd:pwd_data\r\n"
269 "a=mid:data_content_name\r\n";
270
lally69f57602015-10-08 10:15:04 -0700271static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
272 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
273 "a=max-message-size=100000\r\n"
274 "a=sctp-port:5000\r\n"
275 "c=IN IP4 0.0.0.0\r\n"
276 "a=ice-ufrag:ufrag_data\r\n"
277 "a=ice-pwd:pwd_data\r\n"
278 "a=mid:data_content_name\r\n";
279
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000280static const char kSdpSctpDataChannelWithCandidatesString[] =
281 "m=application 2345 DTLS/SCTP 5000\r\n"
282 "c=IN IP4 74.125.127.126\r\n"
283 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
284 "generation 2\r\n"
285 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
286 "generation 2\r\n"
287 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
288 "raddr 192.168.1.5 rport 2346 "
289 "generation 2\r\n"
290 "a=ice-ufrag:ufrag_data\r\n"
291 "a=ice-pwd:pwd_data\r\n"
292 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000293 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000294
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000295static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000296 "v=0\r\n"
297 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
298 "s=-\r\n"
299 "t=0 0\r\n"
300 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000301 "m=audio 9 RTP/SAVPF 111 103 104\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"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000304 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000305 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000306 "a=x-google-flag:conference\r\n";
307
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000308static const char kSdpSessionString[] =
309 "v=0\r\n"
310 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
311 "s=-\r\n"
312 "t=0 0\r\n"
313 "a=msid-semantic: WMS local_stream\r\n";
314
315static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000316 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000317 "c=IN IP4 0.0.0.0\r\n"
318 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000319 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
320 "a=mid:audio_content_name\r\n"
321 "a=sendrecv\r\n"
322 "a=rtpmap:111 opus/48000/2\r\n"
323 "a=ssrc:1 cname:stream_1_cname\r\n"
324 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
325 "a=ssrc:1 mslabel:local_stream\r\n"
326 "a=ssrc:1 label:audio_track_id_1\r\n";
327
328static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000329 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000330 "c=IN IP4 0.0.0.0\r\n"
331 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000332 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
333 "a=mid:video_content_name\r\n"
334 "a=sendrecv\r\n"
335 "a=rtpmap:120 VP8/90000\r\n"
336 "a=ssrc:2 cname:stream_1_cname\r\n"
337 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
338 "a=ssrc:2 mslabel:local_stream\r\n"
339 "a=ssrc:2 label:video_track_id_1\r\n";
340
deadbeef25ed4352016-12-12 18:37:36 -0800341// Reference sdp string using bundle-only.
342static const char kBundleOnlySdpFullString[] =
343 "v=0\r\n"
344 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
345 "s=-\r\n"
346 "t=0 0\r\n"
347 "a=group:BUNDLE audio_content_name video_content_name\r\n"
348 "a=msid-semantic: WMS local_stream_1\r\n"
349 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
350 "c=IN IP4 74.125.127.126\r\n"
351 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
352 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
353 "generation 2\r\n"
354 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
355 "generation 2\r\n"
356 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
357 "generation 2\r\n"
358 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
359 "generation 2\r\n"
360 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
361 "raddr 192.168.1.5 rport 2346 "
362 "generation 2\r\n"
363 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
364 "raddr 192.168.1.5 rport 2348 "
365 "generation 2\r\n"
366 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
367 "a=mid:audio_content_name\r\n"
368 "a=sendrecv\r\n"
369 "a=rtcp-mux\r\n"
370 "a=rtcp-rsize\r\n"
371 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
372 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
373 "dummy_session_params\r\n"
374 "a=rtpmap:111 opus/48000/2\r\n"
375 "a=rtpmap:103 ISAC/16000\r\n"
376 "a=rtpmap:104 ISAC/32000\r\n"
377 "a=ssrc:1 cname:stream_1_cname\r\n"
378 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
379 "a=ssrc:1 mslabel:local_stream_1\r\n"
380 "a=ssrc:1 label:audio_track_id_1\r\n"
381 "m=video 0 RTP/SAVPF 120\r\n"
382 "c=IN IP4 0.0.0.0\r\n"
383 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
384 "a=bundle-only\r\n"
385 "a=mid:video_content_name\r\n"
386 "a=sendrecv\r\n"
387 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
388 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
389 "a=rtpmap:120 VP8/90000\r\n"
390 "a=ssrc-group:FEC 2 3\r\n"
391 "a=ssrc:2 cname:stream_1_cname\r\n"
392 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
393 "a=ssrc:2 mslabel:local_stream_1\r\n"
394 "a=ssrc:2 label:video_track_id_1\r\n"
395 "a=ssrc:3 cname:stream_1_cname\r\n"
396 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
397 "a=ssrc:3 mslabel:local_stream_1\r\n"
398 "a=ssrc:3 label:video_track_id_1\r\n";
399
deadbeef9d3584c2016-02-16 17:54:10 -0800400// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
401// tracks.
402static const char kPlanBSdpFullString[] =
403 "v=0\r\n"
404 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
405 "s=-\r\n"
406 "t=0 0\r\n"
407 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
408 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
409 "c=IN IP4 74.125.127.126\r\n"
410 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
411 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
412 "generation 2\r\n"
413 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
414 "generation 2\r\n"
415 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
416 "generation 2\r\n"
417 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
418 "generation 2\r\n"
419 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
420 "raddr 192.168.1.5 rport 2346 "
421 "generation 2\r\n"
422 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
423 "raddr 192.168.1.5 rport 2348 "
424 "generation 2\r\n"
425 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
426 "a=mid:audio_content_name\r\n"
427 "a=sendrecv\r\n"
428 "a=rtcp-mux\r\n"
429 "a=rtcp-rsize\r\n"
430 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
431 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
432 "dummy_session_params\r\n"
433 "a=rtpmap:111 opus/48000/2\r\n"
434 "a=rtpmap:103 ISAC/16000\r\n"
435 "a=rtpmap:104 ISAC/32000\r\n"
436 "a=ssrc:1 cname:stream_1_cname\r\n"
437 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
438 "a=ssrc:1 mslabel:local_stream_1\r\n"
439 "a=ssrc:1 label:audio_track_id_1\r\n"
440 "a=ssrc:4 cname:stream_2_cname\r\n"
441 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
442 "a=ssrc:4 mslabel:local_stream_2\r\n"
443 "a=ssrc:4 label:audio_track_id_2\r\n"
444 "m=video 3457 RTP/SAVPF 120\r\n"
445 "c=IN IP4 74.125.224.39\r\n"
446 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
447 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
448 "generation 2\r\n"
449 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
450 "generation 2\r\n"
451 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
452 "generation 2\r\n"
453 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
454 "generation 2\r\n"
455 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
456 "generation 2\r\n"
457 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
458 "generation 2\r\n"
459 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
460 "a=mid:video_content_name\r\n"
461 "a=sendrecv\r\n"
462 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
463 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
464 "a=rtpmap:120 VP8/90000\r\n"
465 "a=ssrc-group:FEC 2 3\r\n"
466 "a=ssrc:2 cname:stream_1_cname\r\n"
467 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
468 "a=ssrc:2 mslabel:local_stream_1\r\n"
469 "a=ssrc:2 label:video_track_id_1\r\n"
470 "a=ssrc:3 cname:stream_1_cname\r\n"
471 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
472 "a=ssrc:3 mslabel:local_stream_1\r\n"
473 "a=ssrc:3 label:video_track_id_1\r\n"
474 "a=ssrc:5 cname:stream_2_cname\r\n"
475 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
476 "a=ssrc:5 mslabel:local_stream_2\r\n"
477 "a=ssrc:5 label:video_track_id_2\r\n"
478 "a=ssrc:6 cname:stream_2_cname\r\n"
479 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
480 "a=ssrc:6 mslabel:local_stream_2\r\n"
481 "a=ssrc:6 label:video_track_id_3\r\n";
482
483// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
484// tracks.
485static const char kUnifiedPlanSdpFullString[] =
486 "v=0\r\n"
487 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
488 "s=-\r\n"
489 "t=0 0\r\n"
490 "a=msid-semantic: WMS local_stream_1\r\n"
491 // Audio track 1, stream 1 (with candidates).
492 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
493 "c=IN IP4 74.125.127.126\r\n"
494 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
495 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
496 "generation 2\r\n"
497 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
498 "generation 2\r\n"
499 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
500 "generation 2\r\n"
501 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
502 "generation 2\r\n"
503 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
504 "raddr 192.168.1.5 rport 2346 "
505 "generation 2\r\n"
506 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
507 "raddr 192.168.1.5 rport 2348 "
508 "generation 2\r\n"
509 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
510 "a=mid:audio_content_name\r\n"
511 "a=msid:local_stream_1 audio_track_id_1\r\n"
512 "a=sendrecv\r\n"
513 "a=rtcp-mux\r\n"
514 "a=rtcp-rsize\r\n"
515 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
516 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
517 "dummy_session_params\r\n"
518 "a=rtpmap:111 opus/48000/2\r\n"
519 "a=rtpmap:103 ISAC/16000\r\n"
520 "a=rtpmap:104 ISAC/32000\r\n"
521 "a=ssrc:1 cname:stream_1_cname\r\n"
522 // Video track 1, stream 1 (with candidates).
523 "m=video 3457 RTP/SAVPF 120\r\n"
524 "c=IN IP4 74.125.224.39\r\n"
525 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
526 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
527 "generation 2\r\n"
528 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
529 "generation 2\r\n"
530 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
531 "generation 2\r\n"
532 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
533 "generation 2\r\n"
534 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
535 "generation 2\r\n"
536 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
537 "generation 2\r\n"
538 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
539 "a=mid:video_content_name\r\n"
540 "a=msid:local_stream_1 video_track_id_1\r\n"
541 "a=sendrecv\r\n"
542 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
543 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
544 "a=rtpmap:120 VP8/90000\r\n"
545 "a=ssrc-group:FEC 2 3\r\n"
546 "a=ssrc:2 cname:stream_1_cname\r\n"
547 "a=ssrc:3 cname:stream_1_cname\r\n"
548 // Audio track 2, stream 2.
549 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
550 "c=IN IP4 0.0.0.0\r\n"
551 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
552 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
553 "a=mid:audio_content_name_2\r\n"
554 "a=msid:local_stream_2 audio_track_id_2\r\n"
555 "a=sendrecv\r\n"
556 "a=rtcp-mux\r\n"
557 "a=rtcp-rsize\r\n"
558 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
559 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
560 "dummy_session_params\r\n"
561 "a=rtpmap:111 opus/48000/2\r\n"
562 "a=rtpmap:103 ISAC/16000\r\n"
563 "a=rtpmap:104 ISAC/32000\r\n"
564 "a=ssrc:4 cname:stream_2_cname\r\n"
565 // Video track 2, stream 2.
566 "m=video 9 RTP/SAVPF 120\r\n"
567 "c=IN IP4 0.0.0.0\r\n"
568 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
569 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
570 "a=mid:video_content_name_2\r\n"
571 "a=msid:local_stream_2 video_track_id_2\r\n"
572 "a=sendrecv\r\n"
573 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
574 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
575 "a=rtpmap:120 VP8/90000\r\n"
576 "a=ssrc:5 cname:stream_2_cname\r\n"
577 // Video track 3, stream 2.
578 "m=video 9 RTP/SAVPF 120\r\n"
579 "c=IN IP4 0.0.0.0\r\n"
580 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
581 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
582 "a=mid:video_content_name_3\r\n"
583 "a=msid:local_stream_2 video_track_id_3\r\n"
584 "a=sendrecv\r\n"
585 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
586 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
587 "a=rtpmap:120 VP8/90000\r\n"
588 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000589
Seth Hampson5b4f0752018-04-02 16:31:36 -0700590// Unified Plan SDP reference string:
591// - audio track 1 has 1 a=msid lines
592// - audio track 2 has 2 a=msid lines
593// - audio track 3 has 1 a=msid line with the special "-" marker signifying that
594// there are 0 media stream ids.
595// This Unified Plan SDP represents a SDP that signals the msid using both
596// a=msid and a=ssrc msid semantics.
597static const char kUnifiedPlanSdpFullStringWithSpecialMsid[] =
598 "v=0\r\n"
599 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
600 "s=-\r\n"
601 "t=0 0\r\n"
602 "a=msid-semantic: WMS local_stream_1\r\n"
603 // Audio track 1, with 1 stream id.
604 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
605 "c=IN IP4 74.125.127.126\r\n"
606 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
607 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
608 "generation 2\r\n"
609 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
610 "generation 2\r\n"
611 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
612 "generation 2\r\n"
613 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
614 "generation 2\r\n"
615 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
616 "raddr 192.168.1.5 rport 2346 "
617 "generation 2\r\n"
618 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
619 "raddr 192.168.1.5 rport 2348 "
620 "generation 2\r\n"
621 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
622 "a=mid:audio_content_name\r\n"
623 "a=msid:local_stream_1 audio_track_id_1\r\n"
624 "a=sendrecv\r\n"
625 "a=rtcp-mux\r\n"
626 "a=rtcp-rsize\r\n"
627 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
628 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
629 "dummy_session_params\r\n"
630 "a=rtpmap:111 opus/48000/2\r\n"
631 "a=rtpmap:103 ISAC/16000\r\n"
632 "a=rtpmap:104 ISAC/32000\r\n"
633 "a=ssrc:1 cname:stream_1_cname\r\n"
634 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
635 "a=ssrc:1 mslabel:local_stream_1\r\n"
636 "a=ssrc:1 label:audio_track_id_1\r\n"
637 // Audio track 2, with two stream ids.
638 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
639 "c=IN IP4 0.0.0.0\r\n"
640 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
641 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
642 "a=mid:audio_content_name_2\r\n"
643 "a=msid:local_stream_1 audio_track_id_2\r\n"
644 "a=msid:local_stream_2 audio_track_id_2\r\n"
645 "a=sendrecv\r\n"
646 "a=rtcp-mux\r\n"
647 "a=rtcp-rsize\r\n"
648 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
649 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
650 "dummy_session_params\r\n"
651 "a=rtpmap:111 opus/48000/2\r\n"
652 "a=rtpmap:103 ISAC/16000\r\n"
653 "a=rtpmap:104 ISAC/32000\r\n"
654 "a=ssrc:4 cname:stream_1_cname\r\n"
655 // The support for Plan B msid signaling only includes the
656 // first media stream id "local_stream_1."
657 "a=ssrc:4 msid:local_stream_1 audio_track_id_2\r\n"
658 "a=ssrc:4 mslabel:local_stream_1\r\n"
659 "a=ssrc:4 label:audio_track_id_2\r\n"
660 // Audio track 3, with no stream ids.
661 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
662 "c=IN IP4 0.0.0.0\r\n"
663 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
664 "a=ice-ufrag:ufrag_voice_3\r\na=ice-pwd:pwd_voice_3\r\n"
665 "a=mid:audio_content_name_3\r\n"
666 "a=msid:- audio_track_id_3\r\n"
667 "a=sendrecv\r\n"
668 "a=rtcp-mux\r\n"
669 "a=rtcp-rsize\r\n"
670 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
671 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
672 "dummy_session_params\r\n"
673 "a=rtpmap:111 opus/48000/2\r\n"
674 "a=rtpmap:103 ISAC/16000\r\n"
675 "a=rtpmap:104 ISAC/32000\r\n"
676 "a=ssrc:7 cname:stream_2_cname\r\n";
677
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000678// One candidate reference string as per W3c spec.
679// candidate:<blah> not a=candidate:<blah>CRLF
680static const char kRawCandidate[] =
681 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
682// One candidate reference string.
683static const char kSdpOneCandidate[] =
684 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
685 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000686
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000687static const char kSdpTcpActiveCandidate[] =
688 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
689 "tcptype active generation 2";
690static const char kSdpTcpPassiveCandidate[] =
691 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
692 "tcptype passive generation 2";
693static const char kSdpTcpSOCandidate[] =
694 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
695 "tcptype so generation 2";
696static const char kSdpTcpInvalidCandidate[] =
697 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
698 "tcptype invalid generation 2";
699
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000700// One candidate reference string with IPV6 address.
701static const char kRawIPV6Candidate[] =
702 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 12:04:36 -0700703 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000704
705// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800706static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000707 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800708 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000709
710// Session id and version
711static const char kSessionId[] = "18446744069414584320";
712static const char kSessionVersion[] = "18446462598732840960";
713
deadbeef9d3584c2016-02-16 17:54:10 -0800714// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000715static const char kIceOption1[] = "iceoption1";
716static const char kIceOption2[] = "iceoption2";
717static const char kIceOption3[] = "iceoption3";
718
deadbeef9d3584c2016-02-16 17:54:10 -0800719// ICE ufrags/passwords.
720static const char kUfragVoice[] = "ufrag_voice";
721static const char kPwdVoice[] = "pwd_voice";
722static const char kUfragVideo[] = "ufrag_video";
723static const char kPwdVideo[] = "pwd_video";
724static const char kUfragData[] = "ufrag_data";
725static const char kPwdData[] = "pwd_data";
726
727// Extra ufrags/passwords for extra unified plan m= sections.
728static const char kUfragVoice2[] = "ufrag_voice_2";
729static const char kPwdVoice2[] = "pwd_voice_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700730static const char kUfragVoice3[] = "ufrag_voice_3";
731static const char kPwdVoice3[] = "pwd_voice_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800732static const char kUfragVideo2[] = "ufrag_video_2";
733static const char kPwdVideo2[] = "pwd_video_2";
734static const char kUfragVideo3[] = "ufrag_video_3";
735static const char kPwdVideo3[] = "pwd_video_3";
736
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000737// Content name
738static const char kAudioContentName[] = "audio_content_name";
739static const char kVideoContentName[] = "video_content_name";
740static const char kDataContentName[] = "data_content_name";
741
deadbeef9d3584c2016-02-16 17:54:10 -0800742// Extra content names for extra unified plan m= sections.
743static const char kAudioContentName2[] = "audio_content_name_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700744static const char kAudioContentName3[] = "audio_content_name_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800745static const char kVideoContentName2[] = "video_content_name_2";
746static const char kVideoContentName3[] = "video_content_name_3";
747
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000748// MediaStream 1
Seth Hampson845e8782018-03-02 11:34:10 -0800749static const char kStreamId1[] = "local_stream_1";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000750static const char kStream1Cname[] = "stream_1_cname";
751static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200752static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000753static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800754static const uint32_t kVideoTrack1Ssrc1 = 2;
755static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000756
757// MediaStream 2
Seth Hampson845e8782018-03-02 11:34:10 -0800758static const char kStreamId2[] = "local_stream_2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000759static const char kStream2Cname[] = "stream_2_cname";
760static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200761static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800762static const char kVideoTrackId2[] = "video_track_id_2";
763static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000764static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800765static const uint32_t kVideoTrack3Ssrc = 6;
Seth Hampson5b4f0752018-04-02 16:31:36 -0700766static const char kAudioTrackId3[] = "audio_track_id_3";
767static const uint32_t kAudioTrack3Ssrc = 7;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000768
769// DataChannel
770static const char kDataChannelLabel[] = "data_channel";
771static const char kDataChannelMsid[] = "data_channeld0";
772static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200773static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000774
775// Candidate
776static const char kDummyMid[] = "dummy_mid";
777static const int kDummyIndex = 123;
778
779// Misc
Steve Antona3a92c22017-12-07 10:27:41 -0800780static SdpType kDummyType = SdpType::kOffer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000781
782// Helper functions
783
784static bool SdpDeserialize(const std::string& message,
785 JsepSessionDescription* jdesc) {
786 return webrtc::SdpDeserialize(message, jdesc, NULL);
787}
788
789static bool SdpDeserializeCandidate(const std::string& message,
790 JsepIceCandidate* candidate) {
791 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
792}
793
794// Add some extra |newlines| to the |message| after |line|.
795static void InjectAfter(const std::string& line,
796 const std::string& newlines,
797 std::string* message) {
798 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000799 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000800 tmp.c_str(), tmp.length(), message);
801}
802
803static void Replace(const std::string& line,
804 const std::string& newlines,
805 std::string* message) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000806 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000807 newlines.c_str(), newlines.length(), message);
808}
809
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000810// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
811// message.
812static void ExpectParseFailure(const std::string& bad_sdp,
813 const std::string& bad_part) {
Steve Antona3a92c22017-12-07 10:27:41 -0800814 JsepSessionDescription desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000815 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000816 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000817 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000818 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
819}
820
821// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
822static void ExpectParseFailure(const char* good_part, const char* bad_part) {
823 std::string bad_sdp = kSdpFullString;
824 Replace(good_part, bad_part, &bad_sdp);
825 ExpectParseFailure(bad_sdp, bad_part);
826}
827
828// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
829static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
830 const std::string& newlines,
831 const std::string& bad_part) {
832 std::string bad_sdp = kSdpFullString;
833 InjectAfter(injectpoint, newlines, &bad_sdp);
834 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000835}
836
Steve Anton4e70a722017-11-28 14:57:10 -0800837static void ReplaceDirection(RtpTransceiverDirection direction,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000838 std::string* message) {
839 std::string new_direction;
840 switch (direction) {
Steve Anton4e70a722017-11-28 14:57:10 -0800841 case RtpTransceiverDirection::kInactive:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842 new_direction = "a=inactive";
843 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800844 case RtpTransceiverDirection::kSendOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000845 new_direction = "a=sendonly";
846 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800847 case RtpTransceiverDirection::kRecvOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000848 new_direction = "a=recvonly";
849 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800850 case RtpTransceiverDirection::kSendRecv:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000851 default:
852 new_direction = "a=sendrecv";
853 break;
854 }
855 Replace("a=sendrecv", new_direction, message);
856}
857
858static void ReplaceRejected(bool audio_rejected, bool video_rejected,
859 std::string* message) {
860 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800861 Replace("m=audio 9", "m=audio 0", message);
862 Replace(kAttributeIceUfragVoice, "", message);
863 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000864 }
865 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800866 Replace("m=video 9", "m=video 0", message);
867 Replace(kAttributeIceUfragVideo, "", message);
868 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000869 }
870}
871
872// WebRtcSdpTest
873
874class WebRtcSdpTest : public testing::Test {
875 public:
Steve Antona3a92c22017-12-07 10:27:41 -0800876 WebRtcSdpTest() : jdesc_(kDummyType) {
phoglund37ebcf02016-01-08 05:04:57 -0800877#ifdef WEBRTC_ANDROID
878 webrtc::InitializeAndroidObjects();
879#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000880 // AudioContentDescription
881 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -0800882 StreamParams audio_stream;
883 audio_stream.id = kAudioTrackId1;
884 audio_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -0800885 audio_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -0800886 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
887 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 11:04:53 -0700888 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
889 audio_desc_->set_connection_address(audio_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -0800890 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000891
892 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -0800893 video_desc_ = CreateVideoContentDescription();
894 StreamParams video_stream;
895 video_stream.id = kVideoTrackId1;
896 video_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -0800897 video_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -0800898 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
899 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
900 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
901 video_stream.ssrc_groups.push_back(ssrc_group);
902 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 11:04:53 -0700903 rtc::SocketAddress video_addr("74.125.224.39", 3457);
904 video_desc_->set_connection_address(video_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -0800905 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000906
907 // TransportInfo
deadbeef9d3584c2016-02-16 17:54:10 -0800908 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
909 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice))));
910 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
911 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000912
913 // v4 host
914 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000915 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000916 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000917 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
918 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000920 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000921 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
922 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000923 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000924 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000925 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
926 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000927 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000928 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000929 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
930 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000931
932 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000933 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000934 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
935 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000936 cricket::LOCAL_PORT_TYPE,
937 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000938 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000939 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
940 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000941 cricket::LOCAL_PORT_TYPE,
942 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000943 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000944 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
945 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000946 cricket::LOCAL_PORT_TYPE,
947 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000948 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000949 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
950 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000951 cricket::LOCAL_PORT_TYPE,
952 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000953
954 // stun
955 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000956 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
957 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000958 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
959 address_stun, kCandidatePriority, "", "",
960 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000961 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000962 candidate9.set_related_address(rel_address_stun);
963
964 address_stun.SetPort(port_stun++);
965 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000966 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
967 address_stun, kCandidatePriority, "", "",
968 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000969 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000970 candidate10.set_related_address(rel_address_stun);
971
972 // relay
973 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000974 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000975 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
976 address_relay, kCandidatePriority, "", "",
977 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000978 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000979 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000980 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
981 address_relay, kCandidatePriority, "", "",
982 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000983 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000984
985 // voice
986 candidates_.push_back(candidate1);
987 candidates_.push_back(candidate2);
988 candidates_.push_back(candidate5);
989 candidates_.push_back(candidate6);
990 candidates_.push_back(candidate9);
991 candidates_.push_back(candidate10);
992
993 // video
994 candidates_.push_back(candidate3);
995 candidates_.push_back(candidate4);
996 candidates_.push_back(candidate7);
997 candidates_.push_back(candidate8);
998 candidates_.push_back(candidate11);
999 candidates_.push_back(candidate12);
1000
1001 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"),
1002 0, candidate1));
1003
1004 // Set up JsepSessionDescription.
1005 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
1006 std::string mline_id;
1007 int mline_index = 0;
1008 for (size_t i = 0; i< candidates_.size(); ++i) {
1009 // In this test, the audio m line index will be 0, and the video m line
1010 // will be 1.
1011 bool is_video = (i > 5);
1012 mline_id = is_video ? "video_content_name" : "audio_content_name";
1013 mline_index = is_video ? 1 : 0;
1014 JsepIceCandidate jice(mline_id,
1015 mline_index,
1016 candidates_.at(i));
1017 jdesc_.AddCandidate(&jice);
1018 }
1019 }
1020
Seth Hampson5b4f0752018-04-02 16:31:36 -07001021 void RemoveVideoCandidates() {
deadbeef25ed4352016-12-12 18:37:36 -08001022 const IceCandidateCollection* video_candidates_collection =
1023 jdesc_.candidates(1);
1024 ASSERT_NE(nullptr, video_candidates_collection);
1025 std::vector<cricket::Candidate> video_candidates;
1026 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1027 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1028 c.set_transport_name("video_content_name");
1029 video_candidates.push_back(c);
1030 }
1031 jdesc_.RemoveCandidates(video_candidates);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001032 }
1033
1034 // Turns the existing reference description into a description using
1035 // a=bundle-only. This means no transport attributes and a 0 port value on
1036 // the m= sections not associated with the BUNDLE-tag.
1037 void MakeBundleOnlyDescription() {
1038 RemoveVideoCandidates();
deadbeef25ed4352016-12-12 18:37:36 -08001039
1040 // And the rest of the transport attributes.
1041 desc_.transport_infos()[1].description.ice_ufrag.clear();
1042 desc_.transport_infos()[1].description.ice_pwd.clear();
1043 desc_.transport_infos()[1].description.connection_role =
1044 cricket::CONNECTIONROLE_NONE;
1045
1046 // Set bundle-only flag.
1047 desc_.contents()[1].bundle_only = true;
1048
1049 // Add BUNDLE group.
1050 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1051 group.AddContentName(kAudioContentName);
1052 group.AddContentName(kVideoContentName);
1053 desc_.AddGroup(group);
1054
1055 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1056 jdesc_.session_version()));
1057 }
1058
deadbeef9d3584c2016-02-16 17:54:10 -08001059 // Turns the existing reference description into a plan B description,
1060 // with 2 audio tracks and 3 video tracks.
1061 void MakePlanBDescription() {
Steve Antonb1c1de12017-12-21 15:14:30 -08001062 audio_desc_ = audio_desc_->Copy();
1063 video_desc_ = video_desc_->Copy();
deadbeef9d3584c2016-02-16 17:54:10 -08001064
1065 StreamParams audio_track_2;
1066 audio_track_2.id = kAudioTrackId2;
1067 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001068 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001069 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1070 audio_desc_->AddStream(audio_track_2);
1071
1072 StreamParams video_track_2;
1073 video_track_2.id = kVideoTrackId2;
1074 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001075 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001076 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1077 video_desc_->AddStream(video_track_2);
1078
1079 StreamParams video_track_3;
1080 video_track_3.id = kVideoTrackId3;
1081 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001082 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001083 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1084 video_desc_->AddStream(video_track_3);
1085
1086 desc_.RemoveContentByName(kAudioContentName);
1087 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001088 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1089 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001090
1091 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1092 jdesc_.session_version()));
1093 }
1094
1095 // Turns the existing reference description into a unified plan description,
1096 // with 2 audio tracks and 3 video tracks.
1097 void MakeUnifiedPlanDescription() {
1098 // Audio track 2.
1099 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1100 StreamParams audio_track_2;
1101 audio_track_2.id = kAudioTrackId2;
1102 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001103 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001104 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1105 audio_desc_2->AddStream(audio_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001106 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
deadbeef9d3584c2016-02-16 17:54:10 -08001107 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1108 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
deadbeef9d3584c2016-02-16 17:54:10 -08001109 // Video track 2, in stream 2.
1110 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1111 StreamParams video_track_2;
1112 video_track_2.id = kVideoTrackId2;
1113 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001114 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001115 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1116 video_desc_2->AddStream(video_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001117 desc_.AddContent(kVideoContentName2, MediaProtocolType::kRtp, video_desc_2);
deadbeef9d3584c2016-02-16 17:54:10 -08001118 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1119 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2))));
1120
1121 // Video track 3, in stream 2.
1122 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1123 StreamParams video_track_3;
1124 video_track_3.id = kVideoTrackId3;
1125 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001126 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001127 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1128 video_desc_3->AddStream(video_track_3);
Steve Anton5adfafd2017-12-20 16:34:00 -08001129 desc_.AddContent(kVideoContentName3, MediaProtocolType::kRtp, video_desc_3);
deadbeef9d3584c2016-02-16 17:54:10 -08001130 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1131 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3))));
Steve Antone831b8c2018-02-01 12:22:16 -08001132 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
deadbeef9d3584c2016-02-16 17:54:10 -08001133
1134 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1135 jdesc_.session_version()));
1136 }
1137
1138 // Creates an audio content description with no streams, and some default
1139 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001140 AudioContentDescription* CreateAudioContentDescription() {
1141 AudioContentDescription* audio = new AudioContentDescription();
1142 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -08001143 audio->set_rtcp_reduced_size(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001144 audio->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_32",
1145 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1146 "dummy_session_params"));
1147 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef67cf2c12016-04-13 10:07:16 -07001148 AudioCodec opus(111, "opus", 48000, 0, 2);
deadbeef9d3584c2016-02-16 17:54:10 -08001149 audio->AddCodec(opus);
ossue1405ad2017-01-23 08:55:48 -08001150 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1151 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001152 return audio;
1153 }
1154
Seth Hampson5b4f0752018-04-02 16:31:36 -07001155 // Turns the existing reference description into a unified plan description,
1156 // with 3 audio MediaContentDescriptions with special StreamParams that
1157 // contain 0 or multiple stream ids: - audio track 1 has 1 media stream id -
1158 // audio track 2 has 2 media stream ids - audio track 3 has 0 media stream ids
1159 void MakeUnifiedPlanDescriptionMultipleStreamIds() {
1160 desc_.RemoveContentByName(kVideoContentName);
1161 desc_.RemoveTransportInfoByName(kVideoContentName);
1162 RemoveVideoCandidates();
1163
1164 // Audio track 2 has 2 media stream ids.
1165 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1166 StreamParams audio_track_2;
1167 audio_track_2.id = kAudioTrackId2;
1168 audio_track_2.cname = kStream1Cname;
1169 audio_track_2.set_stream_ids({kStreamId1, kStreamId2});
1170 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1171 audio_desc_2->AddStream(audio_track_2);
1172 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
1173 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1174 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
1175
1176 // Audio track 3 has no stream ids.
1177 AudioContentDescription* audio_desc_3 = CreateAudioContentDescription();
1178 StreamParams audio_track_3;
1179 audio_track_3.id = kAudioTrackId3;
1180 audio_track_3.cname = kStream2Cname;
1181 audio_track_3.set_stream_ids({});
1182 audio_track_3.ssrcs.push_back(kAudioTrack3Ssrc);
1183 audio_desc_3->AddStream(audio_track_3);
1184 desc_.AddContent(kAudioContentName3, MediaProtocolType::kRtp, audio_desc_3);
1185 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1186 kAudioContentName3, TransportDescription(kUfragVoice3, kPwdVoice3))));
1187 // Make sure to create both a=msid lines.
1188 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection |
1189 cricket::kMsidSignalingSsrcAttribute);
1190 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1191 jdesc_.session_version()));
1192 }
1193
Seth Hampson5897a6e2018-04-03 11:16:33 -07001194 // Turns the existing reference description into a unified plan description
1195 // with one audio MediaContentDescription that contains one StreamParams with
1196 // 0 ssrcs.
1197 void MakeUnifiedPlanDescriptionNoSsrcSignaling() {
1198 desc_.RemoveContentByName(kVideoContentName);
1199 desc_.RemoveContentByName(kAudioContentName);
1200 desc_.RemoveTransportInfoByName(kVideoContentName);
1201 RemoveVideoCandidates();
1202
1203 AudioContentDescription* audio_desc = CreateAudioContentDescription();
1204 StreamParams audio_track;
1205 audio_track.id = kAudioTrackId1;
1206 audio_track.set_stream_ids({kStreamId1});
1207 audio_desc->AddStream(audio_track);
1208 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc);
1209
1210 // Enable signaling a=msid lines.
1211 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
1212 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1213 jdesc_.session_version()));
1214 }
1215
deadbeef9d3584c2016-02-16 17:54:10 -08001216 // Creates a video content description with no streams, and some default
1217 // configuration.
1218 VideoContentDescription* CreateVideoContentDescription() {
1219 VideoContentDescription* video = new VideoContentDescription();
1220 video->AddCrypto(CryptoParams(
1221 1, "AES_CM_128_HMAC_SHA1_80",
1222 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1223 video->set_protocol(cricket::kMediaProtocolSavpf);
1224 video->AddCodec(
perkj26752742016-10-24 01:21:16 -07001225 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-16 17:54:10 -08001226 return video;
1227 }
1228
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001229 template <class MCD>
1230 void CompareMediaContentDescription(const MCD* cd1,
1231 const MCD* cd2) {
1232 // type
1233 EXPECT_EQ(cd1->type(), cd1->type());
1234
1235 // content direction
1236 EXPECT_EQ(cd1->direction(), cd2->direction());
1237
1238 // rtcp_mux
1239 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1240
deadbeef13871492015-12-09 12:37:51 -08001241 // rtcp_reduced_size
1242 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1243
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001244 // cryptos
1245 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1246 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1247 ADD_FAILURE();
1248 return;
1249 }
1250 for (size_t i = 0; i< cd1->cryptos().size(); ++i) {
1251 const CryptoParams c1 = cd1->cryptos().at(i);
1252 const CryptoParams c2 = cd2->cryptos().at(i);
1253 EXPECT_TRUE(c1.Matches(c2));
1254 EXPECT_EQ(c1.key_params, c2.key_params);
1255 EXPECT_EQ(c1.session_params, c2.session_params);
1256 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001257
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001258 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001259 // Use an equivalence class here, for old and new versions of the
1260 // protocol description.
1261 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:35 +00001262 || cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp
1263 || cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
1264 const bool cd2_is_also_dtls_sctp =
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001265 cd2->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:35 +00001266 || cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp
1267 || cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
1268 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001269 } else {
1270 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1271 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001272
1273 // codecs
1274 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1275
1276 // bandwidth
1277 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1278
1279 // streams
1280 EXPECT_EQ(cd1->streams(), cd2->streams());
1281
1282 // extmap
1283 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1284 cd2->rtp_header_extensions().size());
1285 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 11:24:55 -07001286 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1287 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001288 EXPECT_EQ(ext1.uri, ext2.uri);
1289 EXPECT_EQ(ext1.id, ext2.id);
jbauch5869f502017-06-29 12:31:36 -07001290 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001291 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001292 }
1293
zstein4b2e0822017-02-17 19:48:38 -08001294 void CompareDataContentDescription(const DataContentDescription* dcd1,
1295 const DataContentDescription* dcd2) {
1296 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
1297 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
1298 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001299
1300 void CompareSessionDescription(const SessionDescription& desc1,
1301 const SessionDescription& desc2) {
1302 // Compare content descriptions.
1303 if (desc1.contents().size() != desc2.contents().size()) {
1304 ADD_FAILURE();
1305 return;
1306 }
1307 for (size_t i = 0 ; i < desc1.contents().size(); ++i) {
1308 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1309 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-12 18:37:36 -08001310 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001311 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-12 18:37:36 -08001312 EXPECT_EQ(c1.type, c2.type);
1313 EXPECT_EQ(c1.rejected, c2.rejected);
1314 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001315
1316 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1317 if (IsAudioContent(&c1)) {
1318 const AudioContentDescription* acd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001319 c1.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001320 const AudioContentDescription* acd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001321 c2.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001322 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1323 }
1324
1325 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1326 if (IsVideoContent(&c1)) {
1327 const VideoContentDescription* vcd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001328 c1.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001329 const VideoContentDescription* vcd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001330 c2.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001331 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1332 }
1333
1334 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
1335 if (IsDataContent(&c1)) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001336 const DataContentDescription* dcd1 = c1.media_description()->as_data();
1337 const DataContentDescription* dcd2 = c2.media_description()->as_data();
zstein4b2e0822017-02-17 19:48:38 -08001338 CompareDataContentDescription(dcd1, dcd2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001339 }
1340 }
1341
1342 // group
1343 const cricket::ContentGroups groups1 = desc1.groups();
1344 const cricket::ContentGroups groups2 = desc2.groups();
1345 EXPECT_EQ(groups1.size(), groups1.size());
1346 if (groups1.size() != groups2.size()) {
1347 ADD_FAILURE();
1348 return;
1349 }
1350 for (size_t i = 0; i < groups1.size(); ++i) {
1351 const cricket::ContentGroup group1 = groups1.at(i);
1352 const cricket::ContentGroup group2 = groups2.at(i);
1353 EXPECT_EQ(group1.semantics(), group2.semantics());
1354 const cricket::ContentNames names1 = group1.content_names();
1355 const cricket::ContentNames names2 = group2.content_names();
1356 EXPECT_EQ(names1.size(), names2.size());
1357 if (names1.size() != names2.size()) {
1358 ADD_FAILURE();
1359 return;
1360 }
1361 cricket::ContentNames::const_iterator iter1 = names1.begin();
1362 cricket::ContentNames::const_iterator iter2 = names2.begin();
1363 while (iter1 != names1.end()) {
1364 EXPECT_EQ(*iter1++, *iter2++);
1365 }
1366 }
1367
1368 // transport info
1369 const cricket::TransportInfos transports1 = desc1.transport_infos();
1370 const cricket::TransportInfos transports2 = desc2.transport_infos();
1371 EXPECT_EQ(transports1.size(), transports2.size());
1372 if (transports1.size() != transports2.size()) {
1373 ADD_FAILURE();
1374 return;
1375 }
1376 for (size_t i = 0; i < transports1.size(); ++i) {
1377 const cricket::TransportInfo transport1 = transports1.at(i);
1378 const cricket::TransportInfo transport2 = transports2.at(i);
1379 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001380 EXPECT_EQ(transport1.description.ice_ufrag,
1381 transport2.description.ice_ufrag);
1382 EXPECT_EQ(transport1.description.ice_pwd,
1383 transport2.description.ice_pwd);
1384 if (transport1.description.identity_fingerprint) {
1385 EXPECT_EQ(*transport1.description.identity_fingerprint,
1386 *transport2.description.identity_fingerprint);
1387 } else {
1388 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1389 transport2.description.identity_fingerprint.get());
1390 }
1391 EXPECT_EQ(transport1.description.transport_options,
1392 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001393 }
deadbeefc80741f2015-10-22 13:14:45 -07001394
1395 // global attributes
1396 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001397 }
1398
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001399 bool CompareSessionDescription(
1400 const JsepSessionDescription& desc1,
1401 const JsepSessionDescription& desc2) {
1402 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1403 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1404 CompareSessionDescription(*desc1.description(), *desc2.description());
1405 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1406 return false;
1407 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1408 const IceCandidateCollection* cc1 = desc1.candidates(i);
1409 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-12 18:37:36 -08001410 if (cc1->count() != cc2->count()) {
1411 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001412 return false;
deadbeef25ed4352016-12-12 18:37:36 -08001413 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001414 for (size_t j = 0; j < cc1->count(); ++j) {
1415 const IceCandidateInterface* c1 = cc1->at(j);
1416 const IceCandidateInterface* c2 = cc2->at(j);
1417 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1418 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1419 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1420 }
1421 }
1422 return true;
1423 }
1424
1425 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1426 // them with invalid keywords so that the parser will just ignore them.
1427 bool RemoveCandidateUfragPwd(std::string* sdp) {
1428 const char ice_ufrag[] = "a=ice-ufrag";
1429 const char ice_ufragx[] = "a=xice-ufrag";
1430 const char ice_pwd[] = "a=ice-pwd";
1431 const char ice_pwdx[] = "a=xice-pwd";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001432 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001433 ice_ufragx, strlen(ice_ufragx), sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001434 rtc::replace_substrs(ice_pwd, strlen(ice_pwd),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001435 ice_pwdx, strlen(ice_pwdx), sdp);
1436 return true;
1437 }
1438
1439 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
1440 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, int mline_index,
1441 const std::string& ufrag, const std::string& pwd) {
1442 std::string content_name;
1443 if (mline_index == 0) {
1444 content_name = kAudioContentName;
1445 } else if (mline_index == 1) {
1446 content_name = kVideoContentName;
1447 } else {
nissec80e7412017-01-11 05:56:46 -08001448 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001449 }
1450 TransportInfo transport_info(
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001451 content_name, TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001452 SessionDescription* desc =
1453 const_cast<SessionDescription*>(jdesc->description());
1454 desc->RemoveTransportInfoByName(content_name);
1455 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
1456 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1457 const IceCandidateCollection* cc = jdesc_.candidates(i);
1458 for (size_t j = 0; j < cc->count(); ++j) {
1459 if (cc->at(j)->sdp_mline_index() == mline_index) {
1460 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(
1461 ufrag);
1462 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(
1463 pwd);
1464 }
1465 }
1466 }
1467 return true;
1468 }
1469
1470 void AddIceOptions(const std::string& content_name,
1471 const std::vector<std::string>& transport_options) {
1472 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1473 cricket::TransportInfo transport_info =
1474 *(desc_.GetTransportInfoByName(content_name));
1475 desc_.RemoveTransportInfoByName(content_name);
1476 transport_info.description.transport_options = transport_options;
1477 desc_.AddTransportInfo(transport_info);
1478 }
1479
deadbeef3f7219b2015-12-28 15:17:14 -08001480 void SetIceUfragPwd(const std::string& content_name,
1481 const std::string& ice_ufrag,
1482 const std::string& ice_pwd) {
1483 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1484 cricket::TransportInfo transport_info =
1485 *(desc_.GetTransportInfoByName(content_name));
1486 desc_.RemoveTransportInfoByName(content_name);
1487 transport_info.description.ice_ufrag = ice_ufrag;
1488 transport_info.description.ice_pwd = ice_pwd;
1489 desc_.AddTransportInfo(transport_info);
1490 }
1491
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001492 void AddFingerprint() {
1493 desc_.RemoveTransportInfoByName(kAudioContentName);
1494 desc_.RemoveTransportInfoByName(kVideoContentName);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001495 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001496 kIdentityDigest,
1497 sizeof(kIdentityDigest));
deadbeef46eed762016-01-28 13:24:37 -08001498 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1499 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001500 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1501 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001502 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1503 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1504 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001505 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1506 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001507 cricket::CONNECTIONROLE_NONE, &fingerprint))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001508 }
1509
jbauch5869f502017-06-29 12:31:36 -07001510 void AddExtmap(bool encrypted) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001511 audio_desc_ = audio_desc_->Copy();
1512 video_desc_ = video_desc_->Copy();
jbauch5869f502017-06-29 12:31:36 -07001513 audio_desc_->AddRtpHeaderExtension(
1514 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1515 video_desc_->AddRtpHeaderExtension(
1516 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001517 desc_.RemoveContentByName(kAudioContentName);
1518 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001519 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1520 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001521 }
1522
1523 void RemoveCryptos() {
1524 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1525 video_desc_->set_cryptos(std::vector<CryptoParams>());
1526 }
1527
Seth Hampson5897a6e2018-04-03 11:16:33 -07001528 // Removes everything in StreamParams from the session description that is
1529 // used for a=ssrc lines.
1530 void RemoveSsrcSignalingFromStreamParams() {
1531 for (cricket::ContentInfo content_info : jdesc_.description()->contents()) {
1532 // With Unified Plan there should be one StreamParams per m= section.
1533 StreamParams& stream =
1534 content_info.media_description()->mutable_streams()[0];
1535 stream.ssrcs.clear();
1536 stream.ssrc_groups.clear();
1537 stream.cname.clear();
1538 }
1539 }
1540
1541 // Removes all a=ssrc lines from the SDP string.
1542 void RemoveSsrcLinesFromSdpString(std::string* sdp_string) {
1543 const char kAttributeSsrc[] = "a=ssrc";
1544 while (sdp_string->find(kAttributeSsrc) != std::string::npos) {
1545 size_t pos_ssrc_attribute = sdp_string->find(kAttributeSsrc);
1546 size_t beg_line_pos = sdp_string->rfind('\n', pos_ssrc_attribute);
1547 size_t end_line_pos = sdp_string->find('\n', pos_ssrc_attribute);
1548 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1549 }
1550 }
1551
Steve Anton4e70a722017-11-28 14:57:10 -08001552 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001553 audio_desc_->set_direction(direction);
1554 video_desc_->set_direction(direction);
1555 std::string new_sdp = kSdpFullString;
1556 ReplaceDirection(direction, &new_sdp);
1557
1558 if (!jdesc_.Initialize(desc_.Copy(),
1559 jdesc_.session_id(),
1560 jdesc_.session_version())) {
1561 return false;
1562 }
Steve Antone831b8c2018-02-01 12:22:16 -08001563 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001564 EXPECT_EQ(new_sdp, message);
1565 return true;
1566 }
1567
1568 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001569 audio_desc_ = audio_desc_->Copy();
1570 video_desc_ = video_desc_->Copy();
zhihuang38989e52017-03-21 11:04:53 -07001571
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001572 desc_.RemoveContentByName(kAudioContentName);
1573 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001574 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001575 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001576 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001577 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001578 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1579 audio_rejected ? "" : kPwdVoice);
1580 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1581 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001582
1583 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001584 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1585
Steve Antona3a92c22017-12-07 10:27:41 -08001586 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001587 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001588 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001589 EXPECT_EQ(new_sdp, message);
1590 return true;
1591 }
1592
zstein4b2e0822017-02-17 19:48:38 -08001593 void AddSctpDataChannel(bool use_sctpmap) {
kwibergd1fe2812016-04-27 06:47:29 -07001594 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001595 data_desc_ = data.get();
zstein4b2e0822017-02-17 19:48:38 -08001596 data_desc_->set_use_sctpmap(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001597 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
solenberg9fa49752016-10-08 13:02:44 -07001598 DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07001599 cricket::kGoogleSctpDataCodecName);
wu@webrtc.org78187522013-10-07 23:32:02 +00001600 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1601 data_desc_->AddCodec(codec);
Steve Anton5adfafd2017-12-20 16:34:00 -08001602 desc_.AddContent(kDataContentName, MediaProtocolType::kSctp,
1603 data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001604 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1605 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001606 }
1607
1608 void AddRtpDataChannel() {
kwibergd1fe2812016-04-27 06:47:29 -07001609 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001610 data_desc_ = data.get();
1611
deadbeef67cf2c12016-04-13 10:07:16 -07001612 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001613 StreamParams data_stream;
1614 data_stream.id = kDataChannelMsid;
1615 data_stream.cname = kDataChannelCname;
Seth Hampson845e8782018-03-02 11:34:10 -08001616 data_stream.set_stream_ids({kDataChannelLabel});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001617 data_stream.ssrcs.push_back(kDataChannelSsrc);
1618 data_desc_->AddStream(data_stream);
1619 data_desc_->AddCrypto(CryptoParams(
1620 1, "AES_CM_128_HMAC_SHA1_80",
1621 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
1622 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
Steve Anton5adfafd2017-12-20 16:34:00 -08001623 desc_.AddContent(kDataContentName, MediaProtocolType::kRtp, data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001624 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1625 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001626 }
1627
Steve Anton4e70a722017-11-28 14:57:10 -08001628 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001629 std::string new_sdp = kSdpFullString;
1630 ReplaceDirection(direction, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001631 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001632
1633 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1634
1635 audio_desc_->set_direction(direction);
1636 video_desc_->set_direction(direction);
1637 if (!jdesc_.Initialize(desc_.Copy(),
1638 jdesc_.session_id(),
1639 jdesc_.session_version())) {
1640 return false;
1641 }
1642 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1643 return true;
1644 }
1645
1646 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001647 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001648 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001649 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001650 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001651
Steve Antonb1c1de12017-12-21 15:14:30 -08001652 audio_desc_ = audio_desc_->Copy();
1653 video_desc_ = video_desc_->Copy();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001654 desc_.RemoveContentByName(kAudioContentName);
1655 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001656 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001657 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001658 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001659 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001660 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1661 audio_rejected ? "" : kPwdVoice);
1662 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1663 video_rejected ? "" : kPwdVideo);
Steve Antona3a92c22017-12-07 10:27:41 -08001664 JsepSessionDescription jdesc_no_candidates(kDummyType);
deadbeef3f7219b2015-12-28 15:17:14 -08001665 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1666 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001667 return false;
1668 }
deadbeef3f7219b2015-12-28 15:17:14 -08001669 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001670 return true;
1671 }
1672
jbauch5869f502017-06-29 12:31:36 -07001673 void TestDeserializeExtmap(bool session_level, bool media_level,
1674 bool encrypted) {
1675 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08001676 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001677 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1678 jdesc_.session_id(),
1679 jdesc_.session_version()));
Steve Antona3a92c22017-12-07 10:27:41 -08001680 JsepSessionDescription jdesc_with_extmap(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001681 std::string sdp_with_extmap = kSdpString;
1682 if (session_level) {
jbauch5869f502017-06-29 12:31:36 -07001683 InjectAfter(kSessionTime,
1684 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1685 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001686 &sdp_with_extmap);
1687 }
1688 if (media_level) {
jbauch5869f502017-06-29 12:31:36 -07001689 InjectAfter(kAttributeIcePwdVoice,
1690 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1691 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001692 &sdp_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07001693 InjectAfter(kAttributeIcePwdVideo,
1694 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1695 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001696 &sdp_with_extmap);
1697 }
1698 // The extmap can't be present at the same time in both session level and
1699 // media level.
1700 if (session_level && media_level) {
1701 SdpParseError error;
1702 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap,
1703 &jdesc_with_extmap, &error));
1704 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1705 } else {
1706 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1707 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1708 }
1709 }
1710
1711 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
1712 const std::string& name, int expected_value) {
1713 cricket::CodecParameterMap::const_iterator found = params.find(name);
1714 ASSERT_TRUE(found != params.end());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001715 EXPECT_EQ(found->second, rtc::ToString<int>(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001716 }
1717
1718 void TestDeserializeCodecParams(const CodecParams& params,
1719 JsepSessionDescription* jdesc_output) {
1720 std::string sdp =
1721 "v=0\r\n"
1722 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1723 "s=-\r\n"
1724 "t=0 0\r\n"
1725 // Include semantics for WebRTC Media Streams since it is supported by
1726 // this parser, and will be added to the SDP when serializing a session
1727 // description.
1728 "a=msid-semantic: WMS\r\n"
1729 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001730 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001731 // Pltype 111 listed before 103 and 104 in the map.
1732 "a=rtpmap:111 opus/48000/2\r\n"
1733 // Pltype 103 listed before 104.
1734 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001735 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001736 "a=fmtp:111 0-15,66,70\r\n"
1737 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001738 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001739 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001740 << "; sprop-stereo=" << params.sprop_stereo
1741 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001742 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001743 << "a=ptime:" << params.ptime << "\r\n"
1744 << "a=maxptime:" << params.max_ptime << "\r\n";
1745 sdp += os.str();
1746
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001747 os.clear();
1748 os.str("");
1749 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001750 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001751 << "a=rtpmap:99 VP8/90000\r\n"
1752 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001753 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001754 sdp += os.str();
1755
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001756 // Deserialize
1757 SdpParseError error;
1758 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1759
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001760 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001761 GetFirstAudioContentDescription(jdesc_output->description());
1762 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001763 ASSERT_FALSE(acd->codecs().empty());
1764 cricket::AudioCodec opus = acd->codecs()[0];
1765 EXPECT_EQ("opus", opus.name);
1766 EXPECT_EQ(111, opus.id);
1767 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1768 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1769 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1770 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001771 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1772 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001773 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1774 cricket::AudioCodec codec = acd->codecs()[i];
1775 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1776 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001777 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001778
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001779 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001780 GetFirstVideoContentDescription(jdesc_output->description());
1781 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001782 ASSERT_FALSE(vcd->codecs().empty());
1783 cricket::VideoCodec vp8 = vcd->codecs()[0];
1784 EXPECT_EQ("VP8", vp8.name);
1785 EXPECT_EQ(99, vp8.id);
1786 cricket::VideoCodec rtx = vcd->codecs()[1];
1787 EXPECT_EQ("RTX", rtx.name);
1788 EXPECT_EQ(95, rtx.id);
1789 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001790 }
1791
1792 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1793 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001794 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001795 "v=0\r\n"
1796 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1797 "s=-\r\n"
1798 "t=0 0\r\n"
1799 // Include semantics for WebRTC Media Streams since it is supported by
1800 // this parser, and will be added to the SDP when serializing a session
1801 // description.
1802 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001803 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001804 "a=rtpmap:111 opus/48000/2\r\n";
1805 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001806 "m=video 3457 RTP/SAVPF 101\r\n"
1807 "a=rtpmap:101 VP8/90000\r\n"
1808 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001809 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001810 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001811 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001812 os << sdp_session_and_audio;
1813 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
1814 os << sdp_video;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001815 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001816 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001817 // Deserialize
1818 SdpParseError error;
1819 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001820 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001821 GetFirstAudioContentDescription(jdesc_output->description());
1822 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001823 ASSERT_FALSE(acd->codecs().empty());
1824 cricket::AudioCodec opus = acd->codecs()[0];
1825 EXPECT_EQ(111, opus.id);
1826 EXPECT_TRUE(opus.HasFeedbackParam(
1827 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1828 cricket::kParamValueEmpty)));
1829
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001830 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001831 GetFirstVideoContentDescription(jdesc_output->description());
1832 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001833 ASSERT_FALSE(vcd->codecs().empty());
1834 cricket::VideoCodec vp8 = vcd->codecs()[0];
1835 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1836 vp8.name.c_str());
1837 EXPECT_EQ(101, vp8.id);
1838 EXPECT_TRUE(vp8.HasFeedbackParam(
1839 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1840 cricket::kParamValueEmpty)));
1841 EXPECT_TRUE(vp8.HasFeedbackParam(
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001842 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1843 cricket::kRtcpFbNackParamPli)));
1844 EXPECT_TRUE(vp8.HasFeedbackParam(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001845 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
1846 cricket::kParamValueEmpty)));
1847 EXPECT_TRUE(vp8.HasFeedbackParam(
1848 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
1849 cricket::kRtcpFbCcmParamFir)));
1850 }
1851
1852 // Two SDP messages can mean the same thing but be different strings, e.g.
1853 // some of the lines can be serialized in different order.
1854 // However, a deserialized description can be compared field by field and has
1855 // no order. If deserializer has already been tested, serializing then
1856 // deserializing and comparing JsepSessionDescription will test
1857 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 12:22:16 -08001858 void TestSerialize(const JsepSessionDescription& jdesc) {
1859 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 10:27:41 -08001860 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001861 SdpParseError error;
1862 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1863 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1864 }
1865
zhihuang38989e52017-03-21 11:04:53 -07001866 // Calling 'Initialize' with a copy of the inner SessionDescription will
1867 // create a copy of the JsepSessionDescription without candidates. The
1868 // 'connection address' field, previously set from the candidates, must also
1869 // be reset.
1870 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
1871 rtc::SocketAddress audio_addr("0.0.0.0", 9);
1872 rtc::SocketAddress video_addr("0.0.0.0", 9);
1873 audio_desc_->set_connection_address(audio_addr);
1874 video_desc_->set_connection_address(video_addr);
1875 ASSERT_TRUE(jdesc->Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1876 }
1877
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001878 protected:
1879 SessionDescription desc_;
1880 AudioContentDescription* audio_desc_;
1881 VideoContentDescription* video_desc_;
1882 DataContentDescription* data_desc_;
1883 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07001884 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001885 JsepSessionDescription jdesc_;
1886};
1887
1888void TestMismatch(const std::string& string1, const std::string& string2) {
1889 int position = 0;
1890 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1891 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001892 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001893 break;
1894 }
1895 }
1896 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1897 << " character\n"
1898 << " 1: " << string1.substr(position, 20) << "\n"
1899 << " 2: " << string2.substr(position, 20) << "\n";
1900}
1901
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001902TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1903 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 12:22:16 -08001904 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001905 TestMismatch(std::string(kSdpFullString), message);
1906}
1907
1908TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 10:27:41 -08001909 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 12:22:16 -08001910 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001911}
1912
1913// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1914// the case in a DTLS offer.
1915TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1916 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08001917 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001918 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08001919 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001920
1921 std::string sdp_with_fingerprint = kSdpString;
1922 InjectAfter(kAttributeIcePwdVoice,
1923 kFingerprint, &sdp_with_fingerprint);
1924 InjectAfter(kAttributeIcePwdVideo,
1925 kFingerprint, &sdp_with_fingerprint);
1926
1927 EXPECT_EQ(sdp_with_fingerprint, message);
1928}
1929
1930// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1931// be the case in a DTLS answer.
1932TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1933 AddFingerprint();
1934 RemoveCryptos();
Steve Antona3a92c22017-12-07 10:27:41 -08001935 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001936 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08001937 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001938
1939 std::string sdp_with_fingerprint = kSdpString;
1940 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1941 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
1942 InjectAfter(kAttributeIcePwdVoice,
1943 kFingerprint, &sdp_with_fingerprint);
1944 InjectAfter(kAttributeIcePwdVideo,
1945 kFingerprint, &sdp_with_fingerprint);
1946
1947 EXPECT_EQ(sdp_with_fingerprint, message);
1948}
1949
1950TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1951 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08001952 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001953 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001954 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001955 EXPECT_EQ(std::string(kSdpString), message);
1956}
1957
1958TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1959 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1960 group.AddContentName(kAudioContentName);
1961 group.AddContentName(kVideoContentName);
1962 desc_.AddGroup(group);
1963 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1964 jdesc_.session_id(),
1965 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08001966 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001967 std::string sdp_with_bundle = kSdpFullString;
1968 InjectAfter(kSessionTime,
1969 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1970 &sdp_with_bundle);
1971 EXPECT_EQ(sdp_with_bundle, message);
1972}
1973
1974TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001975 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001976 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08001977 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001978 acd->set_bandwidth(50 * 1000);
1979 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1980 jdesc_.session_id(),
1981 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08001982 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001983 std::string sdp_with_bandwidth = kSdpFullString;
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001984 InjectAfter("c=IN IP4 74.125.224.39\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001985 "b=AS:100\r\n",
1986 &sdp_with_bandwidth);
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001987 InjectAfter("c=IN IP4 74.125.127.126\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001988 "b=AS:50\r\n",
1989 &sdp_with_bandwidth);
1990 EXPECT_EQ(sdp_with_bandwidth, message);
1991}
1992
1993TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1994 std::vector<std::string> transport_options;
1995 transport_options.push_back(kIceOption1);
1996 transport_options.push_back(kIceOption3);
1997 AddIceOptions(kAudioContentName, transport_options);
1998 transport_options.clear();
1999 transport_options.push_back(kIceOption2);
2000 transport_options.push_back(kIceOption3);
2001 AddIceOptions(kVideoContentName, transport_options);
2002 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2003 jdesc_.session_id(),
2004 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002005 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002006 std::string sdp_with_ice_options = kSdpFullString;
2007 InjectAfter(kAttributeIcePwdVoice,
2008 "a=ice-options:iceoption1 iceoption3\r\n",
2009 &sdp_with_ice_options);
2010 InjectAfter(kAttributeIcePwdVideo,
2011 "a=ice-options:iceoption2 iceoption3\r\n",
2012 &sdp_with_ice_options);
2013 EXPECT_EQ(sdp_with_ice_options, message);
2014}
2015
2016TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002017 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002018}
2019
2020TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002021 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002022}
2023
2024TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002025 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002026}
2027
2028TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2029 EXPECT_TRUE(TestSerializeRejected(true, false));
2030}
2031
2032TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2033 EXPECT_TRUE(TestSerializeRejected(false, true));
2034}
2035
2036TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2037 EXPECT_TRUE(TestSerializeRejected(true, true));
2038}
2039
2040TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
2041 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002042 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002043
zhihuang38989e52017-03-21 11:04:53 -07002044 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002045 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002046
2047 std::string expected_sdp = kSdpString;
2048 expected_sdp.append(kSdpRtpDataChannelString);
2049 EXPECT_EQ(expected_sdp, message);
2050}
2051
2052TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08002053 bool use_sctpmap = true;
2054 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002055 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002056
zhihuang38989e52017-03-21 11:04:53 -07002057 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002058 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002059
2060 std::string expected_sdp = kSdpString;
2061 expected_sdp.append(kSdpSctpDataChannelString);
2062 EXPECT_EQ(message, expected_sdp);
2063}
2064
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002065TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08002066 bool use_sctpmap = true;
2067 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002068 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002069 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antonb1c1de12017-12-21 15:14:30 -08002070 DataContentDescription* dcdesc =
2071 jsep_desc.description()
2072 ->GetContentDescriptionByName(kDataContentName)
2073 ->as_data();
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002074
2075 const int kNewPort = 1234;
solenberg9fa49752016-10-08 13:02:44 -07002076 cricket::DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07002077 cricket::kGoogleSctpDataCodecName);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002078 codec.SetParam(cricket::kCodecParamPort, kNewPort);
2079 dcdesc->AddOrReplaceCodec(codec);
2080
Steve Antone831b8c2018-02-01 12:22:16 -08002081 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002082
2083 std::string expected_sdp = kSdpString;
2084 expected_sdp.append(kSdpSctpDataChannelString);
2085
2086 char default_portstr[16];
2087 char new_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002088 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002089 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002090 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
2091 rtc::replace_substrs(default_portstr, strlen(default_portstr),
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002092 new_portstr, strlen(new_portstr),
2093 &expected_sdp);
2094
2095 EXPECT_EQ(expected_sdp, message);
2096}
2097
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002098TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002099 JsepSessionDescription jsep_desc(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002100 AddRtpDataChannel();
2101 data_desc_->set_bandwidth(100*1000);
zhihuang38989e52017-03-21 11:04:53 -07002102 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002103 std::string message = webrtc::SdpSerialize(jsep_desc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002104
2105 std::string expected_sdp = kSdpString;
2106 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002107 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00002108 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 +00002109 "b=AS:100\r\n",
2110 &expected_sdp);
2111 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002112}
2113
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002114TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002115 bool encrypted = false;
2116 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002117 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002118 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 12:22:16 -08002119 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002120
2121 std::string sdp_with_extmap = kSdpString;
2122 InjectAfter("a=mid:audio_content_name\r\n",
2123 kExtmap, &sdp_with_extmap);
2124 InjectAfter("a=mid:video_content_name\r\n",
2125 kExtmap, &sdp_with_extmap);
2126
2127 EXPECT_EQ(sdp_with_extmap, message);
2128}
2129
jbauch5869f502017-06-29 12:31:36 -07002130TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2131 bool encrypted = true;
2132 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002133 JsepSessionDescription desc_with_extmap(kDummyType);
jbauch5869f502017-06-29 12:31:36 -07002134 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(),
2135 kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 12:22:16 -08002136 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07002137}
2138
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002139TEST_F(WebRtcSdpTest, SerializeCandidates) {
2140 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002141 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002142
2143 Candidate candidate_with_ufrag(candidates_.front());
2144 candidate_with_ufrag.set_username("ABC");
2145 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2146 candidate_with_ufrag));
2147 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2148 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002149
2150 Candidate candidate_with_network_info(candidates_.front());
2151 candidate_with_network_info.set_network_id(1);
2152 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2153 candidate_with_network_info));
2154 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2155 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2156 candidate_with_network_info.set_network_cost(999);
2157 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2158 candidate_with_network_info));
2159 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2160 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2161 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002162}
2163
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002164// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2165// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002166TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002167 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002168 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2169 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2170 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002171 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002172 std::unique_ptr<IceCandidateInterface> jcandidate(
2173 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002174
2175 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2176 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2177}
2178
htaa6b99442016-04-12 10:29:17 -07002179TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002180 cricket::VideoCodec h264_codec("H264");
2181 h264_codec.SetParam("profile-level-id", "42e01f");
2182 h264_codec.SetParam("level-asymmetry-allowed", "1");
2183 h264_codec.SetParam("packetization-mode", "1");
2184 video_desc_->AddCodec(h264_codec);
2185
htaa6b99442016-04-12 10:29:17 -07002186 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
2187
Steve Antone831b8c2018-02-01 12:22:16 -08002188 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 10:29:17 -07002189 size_t after_pt = message.find(" H264/90000");
2190 ASSERT_NE(after_pt, std::string::npos);
2191 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2192 ASSERT_NE(before_pt, std::string::npos);
2193 before_pt += strlen("a=rtpmap:");
2194 std::string pt = message.substr(before_pt, after_pt - before_pt);
2195 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2196 std::string to_find = "a=fmtp:" + pt + " ";
2197 size_t fmtp_pos = message.find(to_find);
2198 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
2199 size_t fmtp_endpos = message.find("\n", fmtp_pos);
2200 ASSERT_NE(std::string::npos, fmtp_endpos);
2201 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2202 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2203 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2204 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002205 // Check that there are no spaces after semicolons.
2206 // https://bugs.webrtc.org/5793
2207 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002208}
2209
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002210TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 10:27:41 -08002211 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002212 // Deserialize
2213 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2214 // Verify
2215 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2216}
2217
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002218TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 10:27:41 -08002219 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002220 const char kSdpWithoutMline[] =
2221 "v=0\r\n"
2222 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2223 "s=-\r\n"
2224 "t=0 0\r\n"
2225 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
2226 // Deserialize
2227 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2228 EXPECT_EQ(0u, jdesc.description()->contents().size());
2229}
2230
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002231TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 10:27:41 -08002232 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002233 std::string sdp_without_carriage_return = kSdpFullString;
2234 Replace("\r\n", "\n", &sdp_without_carriage_return);
2235 // Deserialize
2236 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2237 // Verify
2238 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2239}
2240
2241TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2242 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002243 JsepSessionDescription jdesc_no_candidates(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002244 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
2245 kSessionId, kSessionVersion));
Steve Antona3a92c22017-12-07 10:27:41 -08002246 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002247 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2248 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2249}
2250
2251TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2252 static const char kSdpNoRtpmapString[] =
2253 "v=0\r\n"
2254 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2255 "s=-\r\n"
2256 "t=0 0\r\n"
2257 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2258 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002259 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002260 // The rtpmap line for static payload codec is optional.
2261 "a=rtpmap:18 G729/16000\r\n"
2262 "a=rtpmap:103 ISAC/16000\r\n";
2263
Steve Antona3a92c22017-12-07 10:27:41 -08002264 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002265 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2266 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002267 jdesc.description()
2268 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2269 ->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002270 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002271 // The codecs in the AudioContentDescription should be in the same order as
2272 // the payload types (<fmt>s) on the m= line.
2273 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2274 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002275 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002276 EXPECT_EQ(ref_codecs, audio->codecs());
2277}
2278
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002279TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2280 static const char kSdpNoRtpmapString[] =
2281 "v=0\r\n"
2282 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2283 "s=-\r\n"
2284 "t=0 0\r\n"
2285 "m=audio 49232 RTP/AVP 18 103\r\n"
2286 "a=fmtp:18 annexb=yes\r\n"
2287 "a=rtpmap:103 ISAC/16000\r\n";
2288
Steve Antona3a92c22017-12-07 10:27:41 -08002289 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002290 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2291 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002292 jdesc.description()
2293 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2294 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002295
2296 cricket::AudioCodec g729 = audio->codecs()[0];
2297 EXPECT_EQ("G729", g729.name);
2298 EXPECT_EQ(8000, g729.clockrate);
2299 EXPECT_EQ(18, g729.id);
2300 cricket::CodecParameterMap::iterator found =
2301 g729.params.find("annexb");
2302 ASSERT_TRUE(found != g729.params.end());
2303 EXPECT_EQ(found->second, "yes");
2304
2305 cricket::AudioCodec isac = audio->codecs()[1];
2306 EXPECT_EQ("ISAC", isac.name);
2307 EXPECT_EQ(103, isac.id);
2308 EXPECT_EQ(16000, isac.clockrate);
2309}
2310
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002311// Ensure that we can deserialize SDP with a=fingerprint properly.
2312TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2313 // Add a DTLS a=fingerprint attribute to our session description.
2314 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002315 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002316 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
2317 jdesc_.session_id(),
2318 jdesc_.session_version()));
2319
Steve Antona3a92c22017-12-07 10:27:41 -08002320 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002321 std::string sdp_with_fingerprint = kSdpString;
2322 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2323 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2324 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2325 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2326}
2327
2328TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 10:27:41 -08002329 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002330 std::string sdp_with_bundle = kSdpFullString;
2331 InjectAfter(kSessionTime,
2332 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2333 &sdp_with_bundle);
2334 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2335 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2336 group.AddContentName(kAudioContentName);
2337 group.AddContentName(kVideoContentName);
2338 desc_.AddGroup(group);
2339 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2340 jdesc_.session_id(),
2341 jdesc_.session_version()));
2342 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2343}
2344
2345TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002346 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002347 std::string sdp_with_bandwidth = kSdpFullString;
2348 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
2349 "b=AS:100\r\n",
2350 &sdp_with_bandwidth);
2351 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
2352 "b=AS:50\r\n",
2353 &sdp_with_bandwidth);
2354 EXPECT_TRUE(
2355 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 15:14:30 -08002356 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002357 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002358 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002359 acd->set_bandwidth(50 * 1000);
2360 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2361 jdesc_.session_id(),
2362 jdesc_.session_version()));
2363 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2364}
2365
2366TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 10:27:41 -08002367 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002368 std::string sdp_with_ice_options = kSdpFullString;
2369 InjectAfter(kSessionTime,
2370 "a=ice-options:iceoption3\r\n",
2371 &sdp_with_ice_options);
2372 InjectAfter(kAttributeIcePwdVoice,
2373 "a=ice-options:iceoption1\r\n",
2374 &sdp_with_ice_options);
2375 InjectAfter(kAttributeIcePwdVideo,
2376 "a=ice-options:iceoption2\r\n",
2377 &sdp_with_ice_options);
2378 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2379 std::vector<std::string> transport_options;
2380 transport_options.push_back(kIceOption3);
2381 transport_options.push_back(kIceOption1);
2382 AddIceOptions(kAudioContentName, transport_options);
2383 transport_options.clear();
2384 transport_options.push_back(kIceOption3);
2385 transport_options.push_back(kIceOption2);
2386 AddIceOptions(kVideoContentName, transport_options);
2387 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2388 jdesc_.session_id(),
2389 jdesc_.session_version()));
2390 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2391}
2392
2393TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2394 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 10:27:41 -08002395 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002396 std::string sdp_with_ufrag_pwd = kSdpFullString;
2397 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2398 // Add session level ufrag and pwd
2399 InjectAfter(kSessionTime,
2400 "a=ice-pwd:session+level+icepwd\r\n"
2401 "a=ice-ufrag:session+level+iceufrag\r\n",
2402 &sdp_with_ufrag_pwd);
2403 // Add media level ufrag and pwd for audio
2404 InjectAfter("a=mid:audio_content_name\r\n",
2405 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2406 &sdp_with_ufrag_pwd);
2407 // Update the candidate ufrag and pwd to the expected ones.
2408 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0,
2409 "media+level+iceufrag", "media+level+icepwd"));
2410 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1,
2411 "session+level+iceufrag", "session+level+icepwd"));
2412 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2413 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2414}
2415
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002416TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002417 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002418}
2419
2420TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002421 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002422}
2423
2424TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002425 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002426}
2427
2428TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2429 EXPECT_TRUE(TestDeserializeRejected(true, false));
2430}
2431
2432TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2433 EXPECT_TRUE(TestDeserializeRejected(false, true));
2434}
2435
2436TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2437 EXPECT_TRUE(TestDeserializeRejected(true, true));
2438}
2439
2440// Tests that we can still handle the sdp uses mslabel and label instead of
2441// msid for backward compatibility.
2442TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07002443 jdesc_.description()->set_msid_supported(false);
Steve Antona3a92c22017-12-07 10:27:41 -08002444 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002445 std::string sdp_without_msid = kSdpFullString;
2446 Replace("msid", "xmsid", &sdp_without_msid);
2447 // Deserialize
2448 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2449 // Verify
2450 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2451}
2452
2453TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2454 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2455
2456 std::string sdp = kSdpOneCandidate;
2457 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2458 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2459 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2460 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002461 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002462
2463 // Candidate line without generation extension.
2464 sdp = kSdpOneCandidate;
2465 Replace(" generation 2", "", &sdp);
2466 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2467 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2468 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2469 Candidate expected = jcandidate_->candidate();
2470 expected.set_generation(0);
2471 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2472
honghaiza0c44ea2016-03-23 16:07:48 -07002473 // Candidate with network id and/or cost.
2474 sdp = kSdpOneCandidate;
2475 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2476 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2477 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2478 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2479 expected = jcandidate_->candidate();
2480 expected.set_network_id(2);
2481 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2482 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2483 // Add network cost
2484 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2485 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2486 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2487 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2488
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002489 sdp = kSdpTcpActiveCandidate;
2490 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2491 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002492 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002493 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2494 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2495 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002496 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2497 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002498 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(
2499 jcandidate_template->candidate()));
2500 sdp = kSdpTcpPassiveCandidate;
2501 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2502 sdp = kSdpTcpSOCandidate;
2503 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002504}
2505
2506// This test verifies the deserialization of candidate-attribute
2507// as per RFC 5245. Candiate-attribute will be of the format
2508// candidate:<blah>. This format will be used when candidates
2509// are trickled.
2510TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2511 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2512
2513 std::string candidate_attribute = kRawCandidate;
2514 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2515 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2516 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2517 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2518 EXPECT_EQ(2u, jcandidate.candidate().generation());
2519
2520 // Candidate line without generation extension.
2521 candidate_attribute = kRawCandidate;
2522 Replace(" generation 2", "", &candidate_attribute);
2523 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2524 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2525 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2526 Candidate expected = jcandidate_->candidate();
2527 expected.set_generation(0);
2528 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2529
2530 // Candidate line without candidate:
2531 candidate_attribute = kRawCandidate;
2532 Replace("candidate:", "", &candidate_attribute);
2533 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2534
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002535 // Candidate line with IPV6 address.
2536 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
2537}
2538
2539// This test verifies that the deserialization of an invalid candidate string
2540// fails.
2541TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
2542 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2543
2544 std::string candidate_attribute = kRawCandidate;
2545 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002546 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002547
2548 candidate_attribute = kSdpOneCandidate;
2549 candidate_attribute.replace(0, 1, "x");
2550 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2551
2552 candidate_attribute = kRawCandidate;
2553 candidate_attribute.append("\r\n");
2554 candidate_attribute.append(kRawCandidate);
2555 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2556
2557 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002558}
2559
2560TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2561 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002562 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002563 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2564
2565 std::string sdp_with_data = kSdpString;
2566 sdp_with_data.append(kSdpRtpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002567 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002568
2569 // Deserialize
2570 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2571 // Verify
2572 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2573}
2574
2575TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002576 bool use_sctpmap = true;
2577 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002578 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002579 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2580
2581 std::string sdp_with_data = kSdpString;
2582 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002583 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002584
lally@webrtc.org36300852015-02-24 20:19:35 +00002585 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2586 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2587 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2588
2589 // Verify with UDP/DTLS/SCTP.
2590 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2591 strlen(kDtlsSctp), kUdpDtlsSctp);
2592 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2593 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2594
2595 // Verify with TCP/DTLS/SCTP.
2596 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2597 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002598 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2599 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2600}
2601
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002602TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002603 bool use_sctpmap = false;
2604 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002605 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002606 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2607
2608 std::string sdp_with_data = kSdpString;
2609 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002610 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002611
lally@webrtc.org36300852015-02-24 20:19:35 +00002612 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002613 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2614 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002615
lally@webrtc.org36300852015-02-24 20:19:35 +00002616 // Verify with UDP/DTLS/SCTP.
2617 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2618 strlen(kDtlsSctp), kUdpDtlsSctp);
2619 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2620 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002621
lally@webrtc.org36300852015-02-24 20:19:35 +00002622 // Verify with TCP/DTLS/SCTP.
2623 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2624 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002625 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2626 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2627}
2628
lally69f57602015-10-08 10:15:04 -07002629TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002630 bool use_sctpmap = false;
2631 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002632 JsepSessionDescription jdesc(kDummyType);
lally69f57602015-10-08 10:15:04 -07002633 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2634
2635 std::string sdp_with_data = kSdpString;
2636 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002637 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 10:15:04 -07002638
2639 // Verify with DTLS/SCTP.
2640 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2641 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2642
2643 // Verify with UDP/DTLS/SCTP.
2644 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2645 strlen(kDtlsSctp), kUdpDtlsSctp);
2646 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2647 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2648
2649 // Verify with TCP/DTLS/SCTP.
2650 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2651 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
2652 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2653 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2654}
2655
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002656// Test to check the behaviour if sctp-port is specified
2657// on the m= line and in a=sctp-port.
2658TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002659 bool use_sctpmap = true;
2660 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002661 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002662 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2663
2664 std::string sdp_with_data = kSdpString;
2665 // Append m= attributes
2666 sdp_with_data.append(kSdpSctpDataChannelString);
2667 // Append a=sctp-port attribute
2668 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 10:27:41 -08002669 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002670
2671 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2672}
2673
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002674// For crbug/344475.
2675TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2676 std::string sdp_with_data = kSdpString;
2677 sdp_with_data.append(kSdpSctpDataChannelString);
2678 // Remove the "\n" at the end.
2679 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 10:27:41 -08002680 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002681
2682 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2683 // No crash is a pass.
2684}
2685
Steve Anton36b29d12017-10-30 09:57:42 -07002686void MutateJsepSctpPort(JsepSessionDescription* jdesc,
zstein4b2e0822017-02-17 19:48:38 -08002687 const SessionDescription& desc) {
wu@webrtc.org78187522013-10-07 23:32:02 +00002688 // take our pre-built session description and change the SCTP port.
zstein4b2e0822017-02-17 19:48:38 -08002689 cricket::SessionDescription* mutant = desc.Copy();
Steve Antonb1c1de12017-12-21 15:14:30 -08002690 DataContentDescription* dcdesc =
2691 mutant->GetContentDescriptionByName(kDataContentName)->as_data();
wu@webrtc.org78187522013-10-07 23:32:02 +00002692 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002693 EXPECT_EQ(1U, codecs.size());
solenberg9fa49752016-10-08 13:02:44 -07002694 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002695 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002696 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002697
2698 // note: mutant's owned by jdesc now.
Steve Anton36b29d12017-10-30 09:57:42 -07002699 ASSERT_TRUE(jdesc->Initialize(mutant, kSessionId, kSessionVersion));
wu@webrtc.org78187522013-10-07 23:32:02 +00002700 mutant = NULL;
zstein4b2e0822017-02-17 19:48:38 -08002701}
2702
2703TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
2704 bool use_sctpmap = true;
2705 AddSctpDataChannel(use_sctpmap);
2706
2707 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 10:27:41 -08002708 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002709 MutateJsepSctpPort(&jdesc, desc_);
wu@webrtc.org78187522013-10-07 23:32:02 +00002710
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002711 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002712 std::string sdp_with_data = kSdpString;
2713 sdp_with_data.append(kSdpSctpDataChannelString);
zstein4b2e0822017-02-17 19:48:38 -08002714 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2715 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2716 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002717 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:02 +00002718
2719 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2720 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08002721}
2722
2723TEST_F(WebRtcSdpTest,
2724 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
2725 bool use_sctpmap = false;
2726 AddSctpDataChannel(use_sctpmap);
2727
Steve Antona3a92c22017-12-07 10:27:41 -08002728 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002729 MutateJsepSctpPort(&jdesc, desc_);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002730
2731 // We need to test the deserialized JsepSessionDescription from
2732 // kSdpSctpDataChannelStringWithSctpPort for
2733 // draft-ietf-mmusic-sctp-sdp-07
2734 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08002735 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002736 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
zstein4b2e0822017-02-17 19:48:38 -08002737 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2738 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2739 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002740 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002741
2742 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2743 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002744}
2745
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002746TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002747 // We want to test that deserializing data content limits bandwidth
2748 // settings (it should never be greater than the default).
2749 // This should prevent someone from using unlimited data bandwidth through
2750 // JS and "breaking the Internet".
2751 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002752 std::string sdp_with_bandwidth = kSdpString;
2753 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
2754 InjectAfter("a=mid:data_content_name\r\n",
2755 "b=AS:100\r\n",
2756 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002757 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002758
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002759 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2760}
2761
2762TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08002763 bool use_sctpmap = true;
2764 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002765 JsepSessionDescription jdesc(kDummyType);
Steve Antonb1c1de12017-12-21 15:14:30 -08002766 DataContentDescription* dcd = GetFirstDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002767 dcd->set_bandwidth(100 * 1000);
2768 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2769
2770 std::string sdp_with_bandwidth = kSdpString;
2771 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
2772 InjectAfter("a=mid:data_content_name\r\n",
2773 "b=AS:100\r\n",
2774 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002775 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002776
2777 // SCTP has congestion control, so we shouldn't limit the bandwidth
2778 // as we do for RTP.
2779 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002780 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2781}
2782
jbauch5869f502017-06-29 12:31:36 -07002783class WebRtcSdpExtmapTest
2784 : public WebRtcSdpTest, public testing::WithParamInterface<bool> {
2785};
2786
2787TEST_P(WebRtcSdpExtmapTest,
2788 DeserializeSessionDescriptionWithSessionLevelExtmap) {
2789 bool encrypted = GetParam();
2790 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002791}
2792
jbauch5869f502017-06-29 12:31:36 -07002793TEST_P(WebRtcSdpExtmapTest,
2794 DeserializeSessionDescriptionWithMediaLevelExtmap) {
2795 bool encrypted = GetParam();
2796 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002797}
2798
jbauch5869f502017-06-29 12:31:36 -07002799TEST_P(WebRtcSdpExtmapTest,
2800 DeserializeSessionDescriptionWithInvalidExtmap) {
2801 bool encrypted = GetParam();
2802 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002803}
2804
jbauch5869f502017-06-29 12:31:36 -07002805INSTANTIATE_TEST_CASE_P(Encrypted,
2806 WebRtcSdpExtmapTest,
2807 ::testing::Values(false, true));
2808
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002809TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 10:27:41 -08002810 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002811 std::string sdp = kSdpFullString;
2812 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2813 // Deserialize
2814 SdpParseError error;
2815 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-16 17:54:10 -08002816 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002817 EXPECT_EQ(lastline, error.line);
2818 EXPECT_EQ("Invalid SDP line.", error.description);
2819}
2820
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002821TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2822 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2823 std::string new_sdp = kSdpOneCandidate;
2824 Replace("udp", "unsupported_transport", &new_sdp);
2825 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2826 new_sdp = kSdpOneCandidate;
2827 Replace("udp", "uDP", &new_sdp);
2828 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2829 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2830 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2831 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2832}
2833
honghaiza54a0802015-12-16 18:37:23 -08002834TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002835 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08002836 EXPECT_TRUE(
2837 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002838 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2839 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2840 Candidate ref_candidate = jcandidate_->candidate();
2841 ref_candidate.set_username("user_rtp");
2842 ref_candidate.set_password("password_rtp");
2843 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2844}
2845
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002846TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08002847 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002848
2849 // Deserialize
2850 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2851
2852 // Verify
2853 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002854 jdesc.description()
2855 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2856 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002857 EXPECT_TRUE(audio->conference_mode());
2858
2859 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 15:14:30 -08002860 jdesc.description()
2861 ->GetContentDescriptionByName(cricket::CN_VIDEO)
2862 ->as_video();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002863 EXPECT_TRUE(video->conference_mode());
2864}
2865
deadbeefd45aea82017-09-16 01:24:29 -07002866TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08002867 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 01:24:29 -07002868
2869 // We tested deserialization already above, so just test that if we serialize
2870 // and deserialize the flag doesn't disappear.
2871 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 12:22:16 -08002872 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 01:24:29 -07002873 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
2874
2875 // Verify.
2876 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002877 jdesc.description()
2878 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2879 ->as_audio();
deadbeefd45aea82017-09-16 01:24:29 -07002880 EXPECT_TRUE(audio->conference_mode());
2881
2882 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 15:14:30 -08002883 jdesc.description()
2884 ->GetContentDescriptionByName(cricket::CN_VIDEO)
2885 ->as_video();
deadbeefd45aea82017-09-16 01:24:29 -07002886 EXPECT_TRUE(video->conference_mode());
2887}
2888
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002889TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2890 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002891 const char kSdpEmptyType[] = " =candidate";
2892 const char kSdpEqualAsPlus[] = "a+candidate";
2893 const char kSdpSpaceAfterEqual[] = "a= candidate";
2894 const char kSdpUpperType[] = "A=candidate";
2895 const char kSdpEmptyLine[] = "";
2896 const char kSdpMissingValue[] = "a=";
2897
2898 const char kSdpBrokenFingerprint[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002899 "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 +00002900 const char kSdpExtraField[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002901 "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 +00002902 const char kSdpMissingSpace[] = "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002903 "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 +00002904 // MD5 is not allowed in fingerprints.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002905 const char kSdpMd5[] = "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002906 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002907
2908 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002909 ExpectParseFailure("v=", kSdpDestroyer);
2910 ExpectParseFailure("o=", kSdpDestroyer);
2911 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002912 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002913 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002914
2915 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002916 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2917 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002918
2919 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002920 ExpectParseFailure("a=candidate", kSdpEmptyType);
2921 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2922 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
2923 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002924
2925 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2926 // because it's orthogonal to what we are replacing and hence
2927 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002928 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
2929 ExpectParseFailure("a=sendrecv", kSdpExtraField);
2930 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
2931 ExpectParseFailure("a=sendrecv", kSdpMd5);
2932
2933 // Empty Line
2934 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
2935 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002936}
2937
2938TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2939 // ssrc
2940 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08002941 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002942 // crypto
2943 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
2944 // rtpmap
2945 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
2946 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
2947 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
2948 // candidate
2949 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
2950 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
2951 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
2952 ExpectParseFailure("rport 2346", "rport badvalue");
2953 ExpectParseFailure("rport 2346 generation 2",
2954 "rport 2346 generation badvalue");
2955 // m line
2956 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
2957 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
2958
2959 // bandwidth
2960 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2961 "b=AS:badvalue\r\n",
2962 "b=AS:badvalue");
2963 // rtcp-fb
2964 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2965 "a=rtcp-fb:badvalue nack\r\n",
2966 "a=rtcp-fb:badvalue nack");
2967 // extmap
2968 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2969 "a=extmap:badvalue http://example.com\r\n",
2970 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002971}
2972
2973TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 10:27:41 -08002974 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002975
2976 const char kSdpWithReorderedPlTypesString[] =
2977 "v=0\r\n"
2978 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2979 "s=-\r\n"
2980 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00002981 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002982 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
2983 // in the map.
2984 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002985 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002986
2987 // Deserialize
2988 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
2989
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002990 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08002991 GetFirstAudioContentDescription(jdesc_output.description());
2992 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002993 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002994 EXPECT_EQ("ISAC", acd->codecs()[0].name);
2995 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002996 EXPECT_EQ(104, acd->codecs()[0].id);
2997}
2998
2999TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 10:27:41 -08003000 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003001 CodecParams params;
3002 params.max_ptime = 40;
3003 params.ptime = 30;
3004 params.min_ptime = 10;
3005 params.sprop_stereo = 1;
3006 params.stereo = 1;
3007 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003008 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003009 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 12:22:16 -08003010 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003011}
3012
3013TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
3014 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 10:27:41 -08003015 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003016 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003017 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003018}
3019
3020TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
3021 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 10:27:41 -08003022 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003023 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003024 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003025}
3026
3027TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 10:27:41 -08003028 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003029
3030 const char kSdpWithFmtpString[] =
3031 "v=0\r\n"
3032 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3033 "s=-\r\n"
3034 "t=0 0\r\n"
3035 "m=video 3457 RTP/SAVPF 120\r\n"
3036 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07003037 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3038
3039 // Deserialize
3040 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07003041 EXPECT_TRUE(
3042 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07003043
Donald Curtis0e07f922015-05-15 09:21:23 -07003044 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003045 GetFirstVideoContentDescription(jdesc_output.description());
3046 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 09:21:23 -07003047 ASSERT_FALSE(vcd->codecs().empty());
3048 cricket::VideoCodec vp8 = vcd->codecs()[0];
3049 EXPECT_EQ("VP8", vp8.name);
3050 EXPECT_EQ(120, vp8.id);
3051 cricket::CodecParameterMap::iterator found =
3052 vp8.params.find("x-google-min-bitrate");
3053 ASSERT_TRUE(found != vp8.params.end());
3054 EXPECT_EQ(found->second, "10");
3055 found = vp8.params.find("x-google-max-quantization");
3056 ASSERT_TRUE(found != vp8.params.end());
3057 EXPECT_EQ(found->second, "40");
3058}
3059
johan2d8d23e2016-06-03 01:22:42 -07003060TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 10:27:41 -08003061 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 01:22:42 -07003062
3063 const char kSdpWithFmtpString[] =
3064 "v=0\r\n"
3065 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3066 "s=-\r\n"
3067 "t=0 0\r\n"
3068 "m=video 49170 RTP/AVP 98\r\n"
3069 "a=rtpmap:98 H264/90000\r\n"
3070 "a=fmtp:98 profile-level-id=42A01E; "
3071 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3072
3073 // Deserialize.
3074 SdpParseError error;
3075 EXPECT_TRUE(
3076 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3077
johan2d8d23e2016-06-03 01:22:42 -07003078 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003079 GetFirstVideoContentDescription(jdesc_output.description());
3080 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 01:22:42 -07003081 ASSERT_FALSE(vcd->codecs().empty());
3082 cricket::VideoCodec h264 = vcd->codecs()[0];
3083 EXPECT_EQ("H264", h264.name);
3084 EXPECT_EQ(98, h264.id);
3085 cricket::CodecParameterMap::const_iterator found =
3086 h264.params.find("profile-level-id");
3087 ASSERT_TRUE(found != h264.params.end());
3088 EXPECT_EQ(found->second, "42A01E");
3089 found = h264.params.find("sprop-parameter-sets");
3090 ASSERT_TRUE(found != h264.params.end());
3091 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3092}
3093
Donald Curtis0e07f922015-05-15 09:21:23 -07003094TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 10:27:41 -08003095 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 09:21:23 -07003096
3097 const char kSdpWithFmtpString[] =
3098 "v=0\r\n"
3099 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3100 "s=-\r\n"
3101 "t=0 0\r\n"
3102 "m=video 3457 RTP/SAVPF 120\r\n"
3103 "a=rtpmap:120 VP8/90000\r\n"
3104 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003105
3106 // Deserialize
3107 SdpParseError error;
3108 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output,
3109 &error));
3110
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003111 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003112 GetFirstVideoContentDescription(jdesc_output.description());
3113 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003114 ASSERT_FALSE(vcd->codecs().empty());
3115 cricket::VideoCodec vp8 = vcd->codecs()[0];
3116 EXPECT_EQ("VP8", vp8.name);
3117 EXPECT_EQ(120, vp8.id);
3118 cricket::CodecParameterMap::iterator found =
3119 vp8.params.find("x-google-min-bitrate");
3120 ASSERT_TRUE(found != vp8.params.end());
3121 EXPECT_EQ(found->second, "10");
3122 found = vp8.params.find("x-google-max-quantization");
3123 ASSERT_TRUE(found != vp8.params.end());
3124 EXPECT_EQ(found->second, "40");
3125}
3126
ossuaa4b0772017-01-30 07:41:18 -08003127TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003128 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003129
3130 cricket::AudioCodecs codecs = acd->codecs();
3131 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3132 acd->set_codecs(codecs);
3133
3134 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3135 jdesc_.session_id(),
3136 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003137 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003138 std::string sdp_with_fmtp = kSdpFullString;
3139 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3140 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3141 &sdp_with_fmtp);
3142 EXPECT_EQ(sdp_with_fmtp, message);
3143}
3144
3145TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003146 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003147
3148 cricket::AudioCodecs codecs = acd->codecs();
3149 codecs[0].params["stereo"] = "1";
3150 acd->set_codecs(codecs);
3151
3152 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3153 jdesc_.session_id(),
3154 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003155 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003156 std::string sdp_with_fmtp = kSdpFullString;
3157 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3158 "a=fmtp:111 stereo=1\r\n",
3159 &sdp_with_fmtp);
3160 EXPECT_EQ(sdp_with_fmtp, message);
3161}
3162
3163TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003164 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003165
3166 cricket::AudioCodecs codecs = acd->codecs();
3167 codecs[0].params["ptime"] = "20";
3168 codecs[0].params["maxptime"] = "120";
3169 acd->set_codecs(codecs);
3170
3171 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3172 jdesc_.session_id(),
3173 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003174 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003175 std::string sdp_with_fmtp = kSdpFullString;
3176 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3177 "a=maxptime:120\r\n" // No comma here. String merging!
3178 "a=ptime:20\r\n",
3179 &sdp_with_fmtp);
3180 EXPECT_EQ(sdp_with_fmtp, message);
3181}
3182
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003183TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003184 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003185
3186 cricket::VideoCodecs codecs = vcd->codecs();
3187 codecs[0].params["x-google-min-bitrate"] = "10";
3188 vcd->set_codecs(codecs);
3189
3190 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3191 jdesc_.session_id(),
3192 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003193 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003194 std::string sdp_with_fmtp = kSdpFullString;
3195 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
3196 "a=fmtp:120 x-google-min-bitrate=10\r\n",
3197 &sdp_with_fmtp);
3198 EXPECT_EQ(sdp_with_fmtp, message);
3199}
3200
3201TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) {
Steve Antona3a92c22017-12-07 10:27:41 -08003202 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003203 std::string sdp_with_icelite = kSdpFullString;
3204 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3205 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3206 const cricket::TransportInfo* tinfo1 =
3207 desc->GetTransportInfoByName("audio_content_name");
3208 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3209 const cricket::TransportInfo* tinfo2 =
3210 desc->GetTransportInfoByName("video_content_name");
3211 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
3212 InjectAfter(kSessionTime,
3213 "a=ice-lite\r\n",
3214 &sdp_with_icelite);
3215 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3216 desc = jdesc_with_icelite.description();
3217 const cricket::TransportInfo* atinfo =
3218 desc->GetTransportInfoByName("audio_content_name");
3219 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3220 const cricket::TransportInfo* vtinfo =
3221 desc->GetTransportInfoByName("video_content_name");
3222 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
3223}
3224
3225// Verifies that the candidates in the input SDP are parsed and serialized
3226// correctly in the output SDP.
3227TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3228 std::string sdp_with_data = kSdpString;
3229 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 10:27:41 -08003230 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003231
3232 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 12:22:16 -08003233 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003234}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003235
3236TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3237 AddFingerprint();
3238 TransportInfo audio_transport_info =
3239 *(desc_.GetTransportInfoByName(kAudioContentName));
3240 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3241 audio_transport_info.description.connection_role);
3242 audio_transport_info.description.connection_role =
3243 cricket::CONNECTIONROLE_ACTIVE;
3244
3245 TransportInfo video_transport_info =
3246 *(desc_.GetTransportInfoByName(kVideoContentName));
3247 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3248 video_transport_info.description.connection_role);
3249 video_transport_info.description.connection_role =
3250 cricket::CONNECTIONROLE_ACTIVE;
3251
3252 desc_.RemoveTransportInfoByName(kAudioContentName);
3253 desc_.RemoveTransportInfoByName(kVideoContentName);
3254
3255 desc_.AddTransportInfo(audio_transport_info);
3256 desc_.AddTransportInfo(video_transport_info);
3257
3258 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3259 jdesc_.session_id(),
3260 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003261 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003262 std::string sdp_with_dtlssetup = kSdpFullString;
3263
3264 // Fingerprint attribute is necessary to add DTLS setup attribute.
3265 InjectAfter(kAttributeIcePwdVoice,
3266 kFingerprint, &sdp_with_dtlssetup);
3267 InjectAfter(kAttributeIcePwdVideo,
3268 kFingerprint, &sdp_with_dtlssetup);
3269 // Now adding |setup| attribute.
3270 InjectAfter(kFingerprint,
3271 "a=setup:active\r\n", &sdp_with_dtlssetup);
3272 EXPECT_EQ(sdp_with_dtlssetup, message);
3273}
3274
3275TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
Steve Antona3a92c22017-12-07 10:27:41 -08003276 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003277 std::string sdp_with_dtlssetup = kSdpFullString;
3278 InjectAfter(kSessionTime,
3279 "a=setup:actpass\r\n",
3280 &sdp_with_dtlssetup);
3281 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3282 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3283 const cricket::TransportInfo* atinfo =
3284 desc->GetTransportInfoByName("audio_content_name");
3285 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3286 atinfo->description.connection_role);
3287 const cricket::TransportInfo* vtinfo =
3288 desc->GetTransportInfoByName("video_content_name");
3289 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3290 vtinfo->description.connection_role);
3291}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003292
3293// Verifies that the order of the serialized m-lines follows the order of the
3294// ContentInfo in SessionDescription, and vise versa for deserialization.
3295TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 10:27:41 -08003296 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003297 const std::string media_content_sdps[3] = {
3298 kSdpAudioString,
3299 kSdpVideoString,
3300 kSdpSctpDataChannelString
3301 };
3302 const cricket::MediaType media_types[3] = {
3303 cricket::MEDIA_TYPE_AUDIO,
3304 cricket::MEDIA_TYPE_VIDEO,
3305 cricket::MEDIA_TYPE_DATA
3306 };
3307
3308 // Verifies all 6 permutations.
3309 for (size_t i = 0; i < 6; ++i) {
3310 size_t media_content_in_sdp[3];
3311 // The index of the first media content.
3312 media_content_in_sdp[0] = i / 2;
3313 // The index of the second media content.
3314 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3315 // The index of the third media content.
3316 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3317
3318 std::string sdp_string = kSdpSessionString;
3319 for (size_t i = 0; i < 3; ++i)
3320 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3321
3322 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3323 cricket::SessionDescription* desc = jdesc.description();
3324 EXPECT_EQ(3u, desc->contents().size());
3325
3326 for (size_t i = 0; i < 3; ++i) {
3327 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 15:14:30 -08003328 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003329 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3330 }
3331
Steve Antone831b8c2018-02-01 12:22:16 -08003332 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003333 EXPECT_EQ(sdp_string, serialized_sdp);
3334 }
3335}
deadbeef9d3584c2016-02-16 17:54:10 -08003336
deadbeef25ed4352016-12-12 18:37:36 -08003337TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3338 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 10:27:41 -08003339 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003340 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003341 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3342 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3343}
3344
deadbeef12771a12017-01-03 13:53:47 -08003345// The semantics of "a=bundle-only" are only defined when it's used in
3346// combination with a 0 port on the m= line. We should ignore it if used with a
3347// nonzero port.
3348TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3349 // Make the base bundle-only description but unset the bundle-only flag.
3350 MakeBundleOnlyDescription();
3351 jdesc_.description()->contents()[1].bundle_only = false;
3352
3353 std::string modified_sdp = kBundleOnlySdpFullString;
3354 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08003355 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003356 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3357 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003358}
3359
3360TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3361 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003362 TestSerialize(jdesc_);
deadbeef25ed4352016-12-12 18:37:36 -08003363}
3364
deadbeef9d3584c2016-02-16 17:54:10 -08003365TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3366 MakePlanBDescription();
3367
Steve Antona3a92c22017-12-07 10:27:41 -08003368 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003369 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3370
3371 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3372}
3373
3374TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3375 MakePlanBDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003376 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-16 17:54:10 -08003377}
3378
3379TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3380 MakeUnifiedPlanDescription();
3381
Steve Antona3a92c22017-12-07 10:27:41 -08003382 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003383 EXPECT_TRUE(
3384 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3385
3386 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3387}
3388
3389TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3390 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003391 TestSerialize(jdesc_);
3392}
3393
Seth Hampson5b4f0752018-04-02 16:31:36 -07003394// This tests deserializing a Unified Plan SDP that is compatible with both
3395// Unified Plan and Plan B style SDP. It tests the case for audio/video tracks
3396// with no stream ids and multiple stream ids. For parsing this, the Unified
3397// Plan a=msid lines should take priority, because the Plan B style a=ssrc msid
3398// lines do not support multiple stream ids and no stream ids.
3399TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionSpecialMsid) {
3400 MakeUnifiedPlanDescriptionMultipleStreamIds();
3401
3402 JsepSessionDescription deserialized_description(kDummyType);
3403 EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid,
3404 &deserialized_description));
3405
3406 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3407}
3408
3409TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionSpecialMsid) {
3410 MakeUnifiedPlanDescriptionMultipleStreamIds();
3411 TestSerialize(jdesc_);
3412}
3413
Seth Hampson5897a6e2018-04-03 11:16:33 -07003414// This tests that a Unified Plan SDP with no a=ssrc lines is
3415// serialized/deserialized appropriately. In this case the
3416// MediaContentDescription will contain a StreamParams object that doesn't have
3417// any SSRCs. Vice versa, this will be created upon deserializing an SDP with no
3418// SSRC lines.
3419TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3420 MakeUnifiedPlanDescription();
3421 RemoveSsrcSignalingFromStreamParams();
3422 std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString;
3423 RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string);
3424
3425 JsepSessionDescription deserialized_description(kDummyType);
3426 EXPECT_TRUE(
3427 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3428 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3429}
3430
3431TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3432 MakeUnifiedPlanDescription();
3433 RemoveSsrcSignalingFromStreamParams();
3434
3435 TestSerialize(jdesc_);
3436}
3437
Steve Antone831b8c2018-02-01 12:22:16 -08003438TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
3439 JsepSessionDescription jsep_desc(kDummyType);
3440 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
3441 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3442}
3443
3444TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
3445 JsepSessionDescription jsep_desc(kDummyType);
3446 std::string sdp = kSdpSessionString;
3447 sdp += kSdpSctpDataChannelString;
3448 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3449 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3450}
3451
3452TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
3453 JsepSessionDescription jsep_desc(kDummyType);
3454 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
3455 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
3456 jsep_desc.description()->msid_signaling());
3457}
3458
3459TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
3460 JsepSessionDescription jsep_desc(kDummyType);
3461 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
3462 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
3463 jsep_desc.description()->msid_signaling());
3464}
3465
3466const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
3467const char kSsrcAttributeMsidLine[] =
3468 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
3469
3470TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
3471 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
3472 std::string sdp = webrtc::SdpSerialize(jdesc_);
3473
3474 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3475 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3476}
3477
3478TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
3479 jdesc_.description()->set_msid_signaling(
3480 cricket::kMsidSignalingSsrcAttribute);
3481 std::string sdp = webrtc::SdpSerialize(jdesc_);
3482
3483 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
3484 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3485}
3486
3487TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
3488 jdesc_.description()->set_msid_signaling(
3489 cricket::kMsidSignalingMediaSection |
3490 cricket::kMsidSignalingSsrcAttribute);
3491 std::string sdp = webrtc::SdpSerialize(jdesc_);
3492
3493 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3494 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-16 17:54:10 -08003495}
deadbeef7e146cb2016-09-28 10:04:34 -07003496
3497// Regression test for heap overflow bug:
3498// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3499TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 10:04:34 -07003500 // The issue occurs when the sctp-port attribute is found in a video
3501 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 12:43:58 -08003502 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 10:04:34 -07003503 "v=0\r\n"
3504 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3505 "s=-\r\n"
3506 "t=0 0\r\n"
3507 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3508 "a=sctp-port 5000\r\n"
3509 "a=fmtp:108 foo=10\r\n";
3510
3511 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3512 "sctp-port");
3513}
deadbeefb2362572016-12-13 16:37:06 -08003514
3515// Regression test for integer overflow bug:
3516// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3517TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003518 // Bandwidth attribute is the max signed 32-bit int, which will get
3519 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003520 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003521 "v=0\r\n"
3522 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3523 "s=-\r\n"
3524 "t=0 0\r\n"
3525 "m=video 3457 RTP/SAVPF 120\r\n"
3526 "b=AS:2147483647\r\n"
3527 "foo=fail\r\n";
3528
3529 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3530}
deadbeef7bcdb692017-01-20 12:43:58 -08003531
deadbeefbc88c6b2017-08-02 11:26:34 -07003532// Similar to the above, except that negative values are illegal, not just
3533// error-prone as large values are.
3534// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3535TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3536 static const char kSdpWithNegativeBandwidth[] =
3537 "v=0\r\n"
3538 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3539 "s=-\r\n"
3540 "t=0 0\r\n"
3541 "m=video 3457 RTP/SAVPF 120\r\n"
3542 "b=AS:-1000\r\n";
3543
3544 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3545}
3546
deadbeef3e8016e2017-08-03 17:49:30 -07003547// An exception to the above rule: a value of -1 for b=AS should just be
3548// ignored, resulting in "kAutoBandwidth" in the deserialized object.
3549// Applications historically may be using "b=AS:-1" to mean "no bandwidth
3550// limit", but this is now what ommitting the attribute entirely will do, so
3551// ignoring it will have the intended effect.
3552TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
3553 static const char kSdpWithBandwidthOfNegativeOne[] =
3554 "v=0\r\n"
3555 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3556 "s=-\r\n"
3557 "t=0 0\r\n"
3558 "m=video 3457 RTP/SAVPF 120\r\n"
3559 "b=AS:-1\r\n";
3560
Steve Antona3a92c22017-12-07 10:27:41 -08003561 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-03 17:49:30 -07003562 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-03 17:49:30 -07003563 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003564 GetFirstVideoContentDescription(jdesc_output.description());
3565 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-03 17:49:30 -07003566 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
3567}
3568
deadbeef7bcdb692017-01-20 12:43:58 -08003569// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3570// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3571// Regression test for:
3572// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3573TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3574 // Important piece is "ufrag foo pwd bar".
3575 static const char kSdpWithIceCredentialsInCandidateString[] =
3576 "v=0\r\n"
3577 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3578 "s=-\r\n"
3579 "t=0 0\r\n"
3580 "m=audio 9 RTP/SAVPF 111\r\n"
3581 "c=IN IP4 0.0.0.0\r\n"
3582 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3583 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3584 "a=rtpmap:111 opus/48000/2\r\n"
3585 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3586 "generation 2 ufrag foo pwd bar\r\n";
3587
Steve Antona3a92c22017-12-07 10:27:41 -08003588 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 12:43:58 -08003589 EXPECT_TRUE(
3590 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
3591 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3592 ASSERT_NE(nullptr, candidates);
3593 ASSERT_EQ(1, candidates->count());
3594 cricket::Candidate c = candidates->at(0)->candidate();
3595 EXPECT_EQ("ufrag_voice", c.username());
3596 EXPECT_EQ("pwd_voice", c.password());
3597}
deadbeef90f1e1e2017-02-10 12:35:05 -08003598
3599// Test that SDP with an invalid port number in "a=candidate" lines is
3600// rejected, without crashing.
3601// Regression test for:
3602// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
3603TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
3604 static const char kSdpWithInvalidCandidatePort[] =
3605 "v=0\r\n"
3606 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3607 "s=-\r\n"
3608 "t=0 0\r\n"
3609 "m=audio 9 RTP/SAVPF 111\r\n"
3610 "c=IN IP4 0.0.0.0\r\n"
3611 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3612 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3613 "a=rtpmap:111 opus/48000/2\r\n"
3614 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
3615 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
3616
Steve Antona3a92c22017-12-07 10:27:41 -08003617 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 12:35:05 -08003618 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
3619}
deadbeefa4549d62017-02-10 17:26:22 -08003620
3621// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
3622// Regression test for:
3623// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
3624TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
3625 static const char kSdpWithMissingTrackId[] =
3626 "v=0\r\n"
3627 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3628 "s=-\r\n"
3629 "t=0 0\r\n"
3630 "m=audio 9 RTP/SAVPF 111\r\n"
3631 "c=IN IP4 0.0.0.0\r\n"
3632 "a=rtpmap:111 opus/48000/2\r\n"
3633 "a=msid:stream_id \r\n";
3634
Steve Antona3a92c22017-12-07 10:27:41 -08003635 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003636 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
3637}
3638
3639TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
3640 static const char kSdpWithMissingStreamId[] =
3641 "v=0\r\n"
3642 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3643 "s=-\r\n"
3644 "t=0 0\r\n"
3645 "m=audio 9 RTP/SAVPF 111\r\n"
3646 "c=IN IP4 0.0.0.0\r\n"
3647 "a=rtpmap:111 opus/48000/2\r\n"
3648 "a=msid: track_id\r\n";
3649
Steve Antona3a92c22017-12-07 10:27:41 -08003650 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003651 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
3652}
zhihuang38989e52017-03-21 11:04:53 -07003653
3654// Tests that if both session-level address and media-level address exist, use
3655// the media-level address.
3656TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 10:27:41 -08003657 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003658
3659 // Sesssion-level address.
3660 std::string sdp = kSdpFullString;
3661 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3662 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3663
3664 const auto& content1 = jsep_desc.description()->contents()[0];
3665 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 15:14:30 -08003666 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003667 const auto& content2 = jsep_desc.description()->contents()[1];
3668 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 15:14:30 -08003669 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003670}
3671
3672// Tests that the session-level connection address will be used if the media
3673// level-addresses are not specified.
3674TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 10:27:41 -08003675 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003676
3677 // Sesssion-level address.
3678 std::string sdp = kSdpString;
3679 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3680 // Remove the media level addresses.
3681 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3682 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3683 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3684
3685 const auto& content1 = jsep_desc.description()->contents()[0];
3686 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003687 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003688 const auto& content2 = jsep_desc.description()->contents()[1];
3689 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003690 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003691}
3692
3693TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 10:27:41 -08003694 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003695
3696 std::string sdp = kSdpString;
3697 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3698 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
3699 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
3700 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
3701 &sdp);
3702 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
3703 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
3704 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
3705 &sdp);
3706 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3707 const auto& content1 = jsep_desc.description()->contents()[0];
3708 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003709 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003710 const auto& content2 = jsep_desc.description()->contents()[1];
3711 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003712 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003713}
3714
3715// Test that the invalid or unsupprted connection data cannot be parsed.
3716TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 10:27:41 -08003717 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003718 std::string sdp = kSdpString;
3719 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3720
3721 // Unsupported multicast IPv4 address.
3722 sdp = kSdpFullString;
3723 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
3724 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3725
3726 // Unsupported multicast IPv6 address.
3727 sdp = kSdpFullString;
3728 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
3729 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3730
3731 // Mismatched address type.
3732 sdp = kSdpFullString;
3733 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
3734 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3735
3736 sdp = kSdpFullString;
3737 Replace("c=IN IP4 74.125.224.39\r\n",
3738 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
3739 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3740}
3741
3742TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 10:27:41 -08003743 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003744 MakeDescriptionWithoutCandidates(&expected_jsep);
3745 // Serialization.
Steve Antone831b8c2018-02-01 12:22:16 -08003746 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 11:04:53 -07003747 // Deserialization.
Steve Antona3a92c22017-12-07 10:27:41 -08003748 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003749 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 15:14:30 -08003750 auto audio_desc = jdesc.description()
3751 ->GetContentByName(kAudioContentName)
3752 ->media_description();
3753 auto video_desc = jdesc.description()
3754 ->GetContentByName(kVideoContentName)
3755 ->media_description();
zhihuang38989e52017-03-21 11:04:53 -07003756 EXPECT_EQ(audio_desc_->connection_address().ToString(),
3757 audio_desc->connection_address().ToString());
3758 EXPECT_EQ(video_desc_->connection_address().ToString(),
3759 video_desc->connection_address().ToString());
3760}
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07003761
3762// RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be
3763// used (i.e., a single space as the session name)." So we should accept that.
3764TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) {
3765 JsepSessionDescription jsep_desc(kDummyType);
3766 std::string sdp = kSdpString;
3767 Replace("s=-\r\n", "s= \r\n", &sdp);
3768 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3769}