blob: 6a4d5a66e464db262dff3f11c11178d6f4bc150a [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);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07001384 EXPECT_EQ(transport1.description.ice_mode,
1385 transport2.description.ice_mode);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001386 if (transport1.description.identity_fingerprint) {
1387 EXPECT_EQ(*transport1.description.identity_fingerprint,
1388 *transport2.description.identity_fingerprint);
1389 } else {
1390 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1391 transport2.description.identity_fingerprint.get());
1392 }
1393 EXPECT_EQ(transport1.description.transport_options,
1394 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001395 }
deadbeefc80741f2015-10-22 13:14:45 -07001396
1397 // global attributes
1398 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001399 }
1400
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001401 bool CompareSessionDescription(
1402 const JsepSessionDescription& desc1,
1403 const JsepSessionDescription& desc2) {
1404 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1405 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1406 CompareSessionDescription(*desc1.description(), *desc2.description());
1407 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1408 return false;
1409 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1410 const IceCandidateCollection* cc1 = desc1.candidates(i);
1411 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-12 18:37:36 -08001412 if (cc1->count() != cc2->count()) {
1413 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001414 return false;
deadbeef25ed4352016-12-12 18:37:36 -08001415 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001416 for (size_t j = 0; j < cc1->count(); ++j) {
1417 const IceCandidateInterface* c1 = cc1->at(j);
1418 const IceCandidateInterface* c2 = cc2->at(j);
1419 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1420 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1421 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1422 }
1423 }
1424 return true;
1425 }
1426
1427 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1428 // them with invalid keywords so that the parser will just ignore them.
1429 bool RemoveCandidateUfragPwd(std::string* sdp) {
1430 const char ice_ufrag[] = "a=ice-ufrag";
1431 const char ice_ufragx[] = "a=xice-ufrag";
1432 const char ice_pwd[] = "a=ice-pwd";
1433 const char ice_pwdx[] = "a=xice-pwd";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001434 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001435 ice_ufragx, strlen(ice_ufragx), sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001436 rtc::replace_substrs(ice_pwd, strlen(ice_pwd),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001437 ice_pwdx, strlen(ice_pwdx), sdp);
1438 return true;
1439 }
1440
1441 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
1442 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, int mline_index,
1443 const std::string& ufrag, const std::string& pwd) {
1444 std::string content_name;
1445 if (mline_index == 0) {
1446 content_name = kAudioContentName;
1447 } else if (mline_index == 1) {
1448 content_name = kVideoContentName;
1449 } else {
nissec80e7412017-01-11 05:56:46 -08001450 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001451 }
1452 TransportInfo transport_info(
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001453 content_name, TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001454 SessionDescription* desc =
1455 const_cast<SessionDescription*>(jdesc->description());
1456 desc->RemoveTransportInfoByName(content_name);
1457 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
1458 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1459 const IceCandidateCollection* cc = jdesc_.candidates(i);
1460 for (size_t j = 0; j < cc->count(); ++j) {
1461 if (cc->at(j)->sdp_mline_index() == mline_index) {
1462 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(
1463 ufrag);
1464 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(
1465 pwd);
1466 }
1467 }
1468 }
1469 return true;
1470 }
1471
1472 void AddIceOptions(const std::string& content_name,
1473 const std::vector<std::string>& transport_options) {
1474 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1475 cricket::TransportInfo transport_info =
1476 *(desc_.GetTransportInfoByName(content_name));
1477 desc_.RemoveTransportInfoByName(content_name);
1478 transport_info.description.transport_options = transport_options;
1479 desc_.AddTransportInfo(transport_info);
1480 }
1481
deadbeef3f7219b2015-12-28 15:17:14 -08001482 void SetIceUfragPwd(const std::string& content_name,
1483 const std::string& ice_ufrag,
1484 const std::string& ice_pwd) {
1485 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1486 cricket::TransportInfo transport_info =
1487 *(desc_.GetTransportInfoByName(content_name));
1488 desc_.RemoveTransportInfoByName(content_name);
1489 transport_info.description.ice_ufrag = ice_ufrag;
1490 transport_info.description.ice_pwd = ice_pwd;
1491 desc_.AddTransportInfo(transport_info);
1492 }
1493
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001494 void AddFingerprint() {
1495 desc_.RemoveTransportInfoByName(kAudioContentName);
1496 desc_.RemoveTransportInfoByName(kVideoContentName);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001497 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001498 kIdentityDigest,
1499 sizeof(kIdentityDigest));
deadbeef46eed762016-01-28 13:24:37 -08001500 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1501 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001502 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1503 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001504 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1505 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1506 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001507 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1508 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001509 cricket::CONNECTIONROLE_NONE, &fingerprint))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001510 }
1511
jbauch5869f502017-06-29 12:31:36 -07001512 void AddExtmap(bool encrypted) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001513 audio_desc_ = audio_desc_->Copy();
1514 video_desc_ = video_desc_->Copy();
jbauch5869f502017-06-29 12:31:36 -07001515 audio_desc_->AddRtpHeaderExtension(
1516 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1517 video_desc_->AddRtpHeaderExtension(
1518 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001519 desc_.RemoveContentByName(kAudioContentName);
1520 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001521 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1522 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001523 }
1524
1525 void RemoveCryptos() {
1526 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1527 video_desc_->set_cryptos(std::vector<CryptoParams>());
1528 }
1529
Seth Hampson5897a6e2018-04-03 11:16:33 -07001530 // Removes everything in StreamParams from the session description that is
1531 // used for a=ssrc lines.
1532 void RemoveSsrcSignalingFromStreamParams() {
1533 for (cricket::ContentInfo content_info : jdesc_.description()->contents()) {
1534 // With Unified Plan there should be one StreamParams per m= section.
1535 StreamParams& stream =
1536 content_info.media_description()->mutable_streams()[0];
1537 stream.ssrcs.clear();
1538 stream.ssrc_groups.clear();
1539 stream.cname.clear();
1540 }
1541 }
1542
1543 // Removes all a=ssrc lines from the SDP string.
1544 void RemoveSsrcLinesFromSdpString(std::string* sdp_string) {
1545 const char kAttributeSsrc[] = "a=ssrc";
1546 while (sdp_string->find(kAttributeSsrc) != std::string::npos) {
1547 size_t pos_ssrc_attribute = sdp_string->find(kAttributeSsrc);
1548 size_t beg_line_pos = sdp_string->rfind('\n', pos_ssrc_attribute);
1549 size_t end_line_pos = sdp_string->find('\n', pos_ssrc_attribute);
1550 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1551 }
1552 }
1553
Steve Anton4e70a722017-11-28 14:57:10 -08001554 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001555 audio_desc_->set_direction(direction);
1556 video_desc_->set_direction(direction);
1557 std::string new_sdp = kSdpFullString;
1558 ReplaceDirection(direction, &new_sdp);
1559
1560 if (!jdesc_.Initialize(desc_.Copy(),
1561 jdesc_.session_id(),
1562 jdesc_.session_version())) {
1563 return false;
1564 }
Steve Antone831b8c2018-02-01 12:22:16 -08001565 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001566 EXPECT_EQ(new_sdp, message);
1567 return true;
1568 }
1569
1570 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001571 audio_desc_ = audio_desc_->Copy();
1572 video_desc_ = video_desc_->Copy();
zhihuang38989e52017-03-21 11:04:53 -07001573
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001574 desc_.RemoveContentByName(kAudioContentName);
1575 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001576 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001577 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001578 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001579 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001580 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1581 audio_rejected ? "" : kPwdVoice);
1582 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1583 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001584
1585 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001586 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1587
Steve Antona3a92c22017-12-07 10:27:41 -08001588 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001589 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001590 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001591 EXPECT_EQ(new_sdp, message);
1592 return true;
1593 }
1594
zstein4b2e0822017-02-17 19:48:38 -08001595 void AddSctpDataChannel(bool use_sctpmap) {
kwibergd1fe2812016-04-27 06:47:29 -07001596 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001597 data_desc_ = data.get();
zstein4b2e0822017-02-17 19:48:38 -08001598 data_desc_->set_use_sctpmap(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001599 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
solenberg9fa49752016-10-08 13:02:44 -07001600 DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07001601 cricket::kGoogleSctpDataCodecName);
wu@webrtc.org78187522013-10-07 23:32:02 +00001602 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1603 data_desc_->AddCodec(codec);
Steve Anton5adfafd2017-12-20 16:34:00 -08001604 desc_.AddContent(kDataContentName, MediaProtocolType::kSctp,
1605 data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001606 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1607 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001608 }
1609
1610 void AddRtpDataChannel() {
kwibergd1fe2812016-04-27 06:47:29 -07001611 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001612 data_desc_ = data.get();
1613
deadbeef67cf2c12016-04-13 10:07:16 -07001614 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001615 StreamParams data_stream;
1616 data_stream.id = kDataChannelMsid;
1617 data_stream.cname = kDataChannelCname;
Seth Hampson845e8782018-03-02 11:34:10 -08001618 data_stream.set_stream_ids({kDataChannelLabel});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001619 data_stream.ssrcs.push_back(kDataChannelSsrc);
1620 data_desc_->AddStream(data_stream);
1621 data_desc_->AddCrypto(CryptoParams(
1622 1, "AES_CM_128_HMAC_SHA1_80",
1623 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
1624 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
Steve Anton5adfafd2017-12-20 16:34:00 -08001625 desc_.AddContent(kDataContentName, MediaProtocolType::kRtp, data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001626 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1627 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001628 }
1629
Steve Anton4e70a722017-11-28 14:57:10 -08001630 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001631 std::string new_sdp = kSdpFullString;
1632 ReplaceDirection(direction, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001633 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001634
1635 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1636
1637 audio_desc_->set_direction(direction);
1638 video_desc_->set_direction(direction);
1639 if (!jdesc_.Initialize(desc_.Copy(),
1640 jdesc_.session_id(),
1641 jdesc_.session_version())) {
1642 return false;
1643 }
1644 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1645 return true;
1646 }
1647
1648 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001649 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001650 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001651 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001652 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001653
Steve Antonb1c1de12017-12-21 15:14:30 -08001654 audio_desc_ = audio_desc_->Copy();
1655 video_desc_ = video_desc_->Copy();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001656 desc_.RemoveContentByName(kAudioContentName);
1657 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001658 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001659 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001660 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001661 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001662 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1663 audio_rejected ? "" : kPwdVoice);
1664 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1665 video_rejected ? "" : kPwdVideo);
Steve Antona3a92c22017-12-07 10:27:41 -08001666 JsepSessionDescription jdesc_no_candidates(kDummyType);
deadbeef3f7219b2015-12-28 15:17:14 -08001667 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1668 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001669 return false;
1670 }
deadbeef3f7219b2015-12-28 15:17:14 -08001671 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001672 return true;
1673 }
1674
jbauch5869f502017-06-29 12:31:36 -07001675 void TestDeserializeExtmap(bool session_level, bool media_level,
1676 bool encrypted) {
1677 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08001678 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001679 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1680 jdesc_.session_id(),
1681 jdesc_.session_version()));
Steve Antona3a92c22017-12-07 10:27:41 -08001682 JsepSessionDescription jdesc_with_extmap(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001683 std::string sdp_with_extmap = kSdpString;
1684 if (session_level) {
jbauch5869f502017-06-29 12:31:36 -07001685 InjectAfter(kSessionTime,
1686 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1687 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001688 &sdp_with_extmap);
1689 }
1690 if (media_level) {
jbauch5869f502017-06-29 12:31:36 -07001691 InjectAfter(kAttributeIcePwdVoice,
1692 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1693 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001694 &sdp_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07001695 InjectAfter(kAttributeIcePwdVideo,
1696 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1697 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001698 &sdp_with_extmap);
1699 }
1700 // The extmap can't be present at the same time in both session level and
1701 // media level.
1702 if (session_level && media_level) {
1703 SdpParseError error;
1704 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap,
1705 &jdesc_with_extmap, &error));
1706 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1707 } else {
1708 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1709 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1710 }
1711 }
1712
1713 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
1714 const std::string& name, int expected_value) {
1715 cricket::CodecParameterMap::const_iterator found = params.find(name);
1716 ASSERT_TRUE(found != params.end());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001717 EXPECT_EQ(found->second, rtc::ToString<int>(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001718 }
1719
1720 void TestDeserializeCodecParams(const CodecParams& params,
1721 JsepSessionDescription* jdesc_output) {
1722 std::string sdp =
1723 "v=0\r\n"
1724 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1725 "s=-\r\n"
1726 "t=0 0\r\n"
1727 // Include semantics for WebRTC Media Streams since it is supported by
1728 // this parser, and will be added to the SDP when serializing a session
1729 // description.
1730 "a=msid-semantic: WMS\r\n"
1731 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001732 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001733 // Pltype 111 listed before 103 and 104 in the map.
1734 "a=rtpmap:111 opus/48000/2\r\n"
1735 // Pltype 103 listed before 104.
1736 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001737 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001738 "a=fmtp:111 0-15,66,70\r\n"
1739 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001740 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001741 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001742 << "; sprop-stereo=" << params.sprop_stereo
1743 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001744 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001745 << "a=ptime:" << params.ptime << "\r\n"
1746 << "a=maxptime:" << params.max_ptime << "\r\n";
1747 sdp += os.str();
1748
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001749 os.clear();
1750 os.str("");
1751 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001752 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001753 << "a=rtpmap:99 VP8/90000\r\n"
1754 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001755 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001756 sdp += os.str();
1757
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001758 // Deserialize
1759 SdpParseError error;
1760 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1761
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001762 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001763 GetFirstAudioContentDescription(jdesc_output->description());
1764 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765 ASSERT_FALSE(acd->codecs().empty());
1766 cricket::AudioCodec opus = acd->codecs()[0];
1767 EXPECT_EQ("opus", opus.name);
1768 EXPECT_EQ(111, opus.id);
1769 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1770 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1771 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1772 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001773 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1774 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001775 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1776 cricket::AudioCodec codec = acd->codecs()[i];
1777 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1778 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001779 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001780
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001781 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001782 GetFirstVideoContentDescription(jdesc_output->description());
1783 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001784 ASSERT_FALSE(vcd->codecs().empty());
1785 cricket::VideoCodec vp8 = vcd->codecs()[0];
1786 EXPECT_EQ("VP8", vp8.name);
1787 EXPECT_EQ(99, vp8.id);
1788 cricket::VideoCodec rtx = vcd->codecs()[1];
1789 EXPECT_EQ("RTX", rtx.name);
1790 EXPECT_EQ(95, rtx.id);
1791 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001792 }
1793
1794 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1795 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001796 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001797 "v=0\r\n"
1798 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1799 "s=-\r\n"
1800 "t=0 0\r\n"
1801 // Include semantics for WebRTC Media Streams since it is supported by
1802 // this parser, and will be added to the SDP when serializing a session
1803 // description.
1804 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001805 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001806 "a=rtpmap:111 opus/48000/2\r\n";
1807 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001808 "m=video 3457 RTP/SAVPF 101\r\n"
1809 "a=rtpmap:101 VP8/90000\r\n"
1810 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001811 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001812 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001813 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001814 os << sdp_session_and_audio;
1815 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
1816 os << sdp_video;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001817 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001818 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001819 // Deserialize
1820 SdpParseError error;
1821 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001822 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001823 GetFirstAudioContentDescription(jdesc_output->description());
1824 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001825 ASSERT_FALSE(acd->codecs().empty());
1826 cricket::AudioCodec opus = acd->codecs()[0];
1827 EXPECT_EQ(111, opus.id);
1828 EXPECT_TRUE(opus.HasFeedbackParam(
1829 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1830 cricket::kParamValueEmpty)));
1831
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001832 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001833 GetFirstVideoContentDescription(jdesc_output->description());
1834 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001835 ASSERT_FALSE(vcd->codecs().empty());
1836 cricket::VideoCodec vp8 = vcd->codecs()[0];
1837 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1838 vp8.name.c_str());
1839 EXPECT_EQ(101, vp8.id);
1840 EXPECT_TRUE(vp8.HasFeedbackParam(
1841 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1842 cricket::kParamValueEmpty)));
1843 EXPECT_TRUE(vp8.HasFeedbackParam(
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001844 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1845 cricket::kRtcpFbNackParamPli)));
1846 EXPECT_TRUE(vp8.HasFeedbackParam(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001847 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
1848 cricket::kParamValueEmpty)));
1849 EXPECT_TRUE(vp8.HasFeedbackParam(
1850 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
1851 cricket::kRtcpFbCcmParamFir)));
1852 }
1853
1854 // Two SDP messages can mean the same thing but be different strings, e.g.
1855 // some of the lines can be serialized in different order.
1856 // However, a deserialized description can be compared field by field and has
1857 // no order. If deserializer has already been tested, serializing then
1858 // deserializing and comparing JsepSessionDescription will test
1859 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 12:22:16 -08001860 void TestSerialize(const JsepSessionDescription& jdesc) {
1861 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 10:27:41 -08001862 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001863 SdpParseError error;
1864 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1865 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1866 }
1867
zhihuang38989e52017-03-21 11:04:53 -07001868 // Calling 'Initialize' with a copy of the inner SessionDescription will
1869 // create a copy of the JsepSessionDescription without candidates. The
1870 // 'connection address' field, previously set from the candidates, must also
1871 // be reset.
1872 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
1873 rtc::SocketAddress audio_addr("0.0.0.0", 9);
1874 rtc::SocketAddress video_addr("0.0.0.0", 9);
1875 audio_desc_->set_connection_address(audio_addr);
1876 video_desc_->set_connection_address(video_addr);
1877 ASSERT_TRUE(jdesc->Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1878 }
1879
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001880 protected:
1881 SessionDescription desc_;
1882 AudioContentDescription* audio_desc_;
1883 VideoContentDescription* video_desc_;
1884 DataContentDescription* data_desc_;
1885 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07001886 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001887 JsepSessionDescription jdesc_;
1888};
1889
1890void TestMismatch(const std::string& string1, const std::string& string2) {
1891 int position = 0;
1892 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1893 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001894 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001895 break;
1896 }
1897 }
1898 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1899 << " character\n"
1900 << " 1: " << string1.substr(position, 20) << "\n"
1901 << " 2: " << string2.substr(position, 20) << "\n";
1902}
1903
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001904TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1905 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 12:22:16 -08001906 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001907 TestMismatch(std::string(kSdpFullString), message);
1908}
1909
1910TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 10:27:41 -08001911 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 12:22:16 -08001912 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001913}
1914
1915// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1916// the case in a DTLS offer.
1917TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1918 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08001919 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001920 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08001921 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001922
1923 std::string sdp_with_fingerprint = kSdpString;
1924 InjectAfter(kAttributeIcePwdVoice,
1925 kFingerprint, &sdp_with_fingerprint);
1926 InjectAfter(kAttributeIcePwdVideo,
1927 kFingerprint, &sdp_with_fingerprint);
1928
1929 EXPECT_EQ(sdp_with_fingerprint, message);
1930}
1931
1932// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1933// be the case in a DTLS answer.
1934TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1935 AddFingerprint();
1936 RemoveCryptos();
Steve Antona3a92c22017-12-07 10:27:41 -08001937 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001938 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08001939 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001940
1941 std::string sdp_with_fingerprint = kSdpString;
1942 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1943 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
1944 InjectAfter(kAttributeIcePwdVoice,
1945 kFingerprint, &sdp_with_fingerprint);
1946 InjectAfter(kAttributeIcePwdVideo,
1947 kFingerprint, &sdp_with_fingerprint);
1948
1949 EXPECT_EQ(sdp_with_fingerprint, message);
1950}
1951
1952TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1953 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08001954 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001955 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001956 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001957 EXPECT_EQ(std::string(kSdpString), message);
1958}
1959
1960TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1961 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1962 group.AddContentName(kAudioContentName);
1963 group.AddContentName(kVideoContentName);
1964 desc_.AddGroup(group);
1965 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1966 jdesc_.session_id(),
1967 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08001968 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001969 std::string sdp_with_bundle = kSdpFullString;
1970 InjectAfter(kSessionTime,
1971 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1972 &sdp_with_bundle);
1973 EXPECT_EQ(sdp_with_bundle, message);
1974}
1975
1976TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001977 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001978 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08001979 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001980 acd->set_bandwidth(50 * 1000);
1981 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1982 jdesc_.session_id(),
1983 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08001984 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001985 std::string sdp_with_bandwidth = kSdpFullString;
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001986 InjectAfter("c=IN IP4 74.125.224.39\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001987 "b=AS:100\r\n",
1988 &sdp_with_bandwidth);
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001989 InjectAfter("c=IN IP4 74.125.127.126\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001990 "b=AS:50\r\n",
1991 &sdp_with_bandwidth);
1992 EXPECT_EQ(sdp_with_bandwidth, message);
1993}
1994
1995TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1996 std::vector<std::string> transport_options;
1997 transport_options.push_back(kIceOption1);
1998 transport_options.push_back(kIceOption3);
1999 AddIceOptions(kAudioContentName, transport_options);
2000 transport_options.clear();
2001 transport_options.push_back(kIceOption2);
2002 transport_options.push_back(kIceOption3);
2003 AddIceOptions(kVideoContentName, transport_options);
2004 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2005 jdesc_.session_id(),
2006 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002007 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002008 std::string sdp_with_ice_options = kSdpFullString;
2009 InjectAfter(kAttributeIcePwdVoice,
2010 "a=ice-options:iceoption1 iceoption3\r\n",
2011 &sdp_with_ice_options);
2012 InjectAfter(kAttributeIcePwdVideo,
2013 "a=ice-options:iceoption2 iceoption3\r\n",
2014 &sdp_with_ice_options);
2015 EXPECT_EQ(sdp_with_ice_options, message);
2016}
2017
2018TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002019 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002020}
2021
2022TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002023 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002024}
2025
2026TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002027 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002028}
2029
2030TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2031 EXPECT_TRUE(TestSerializeRejected(true, false));
2032}
2033
2034TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2035 EXPECT_TRUE(TestSerializeRejected(false, true));
2036}
2037
2038TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2039 EXPECT_TRUE(TestSerializeRejected(true, true));
2040}
2041
2042TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
2043 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002044 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002045
zhihuang38989e52017-03-21 11:04:53 -07002046 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002047 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002048
2049 std::string expected_sdp = kSdpString;
2050 expected_sdp.append(kSdpRtpDataChannelString);
2051 EXPECT_EQ(expected_sdp, message);
2052}
2053
2054TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08002055 bool use_sctpmap = true;
2056 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002057 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002058
zhihuang38989e52017-03-21 11:04:53 -07002059 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002060 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002061
2062 std::string expected_sdp = kSdpString;
2063 expected_sdp.append(kSdpSctpDataChannelString);
2064 EXPECT_EQ(message, expected_sdp);
2065}
2066
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002067TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08002068 bool use_sctpmap = true;
2069 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002070 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002071 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antonb1c1de12017-12-21 15:14:30 -08002072 DataContentDescription* dcdesc =
2073 jsep_desc.description()
2074 ->GetContentDescriptionByName(kDataContentName)
2075 ->as_data();
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002076
2077 const int kNewPort = 1234;
solenberg9fa49752016-10-08 13:02:44 -07002078 cricket::DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07002079 cricket::kGoogleSctpDataCodecName);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002080 codec.SetParam(cricket::kCodecParamPort, kNewPort);
2081 dcdesc->AddOrReplaceCodec(codec);
2082
Steve Antone831b8c2018-02-01 12:22:16 -08002083 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002084
2085 std::string expected_sdp = kSdpString;
2086 expected_sdp.append(kSdpSctpDataChannelString);
2087
2088 char default_portstr[16];
2089 char new_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002090 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002091 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002092 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
2093 rtc::replace_substrs(default_portstr, strlen(default_portstr),
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002094 new_portstr, strlen(new_portstr),
2095 &expected_sdp);
2096
2097 EXPECT_EQ(expected_sdp, message);
2098}
2099
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002100TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002101 JsepSessionDescription jsep_desc(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002102 AddRtpDataChannel();
2103 data_desc_->set_bandwidth(100*1000);
zhihuang38989e52017-03-21 11:04:53 -07002104 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002105 std::string message = webrtc::SdpSerialize(jsep_desc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002106
2107 std::string expected_sdp = kSdpString;
2108 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002109 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00002110 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 +00002111 "b=AS:100\r\n",
2112 &expected_sdp);
2113 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002114}
2115
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002116TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002117 bool encrypted = false;
2118 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002119 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002120 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 12:22:16 -08002121 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002122
2123 std::string sdp_with_extmap = kSdpString;
2124 InjectAfter("a=mid:audio_content_name\r\n",
2125 kExtmap, &sdp_with_extmap);
2126 InjectAfter("a=mid:video_content_name\r\n",
2127 kExtmap, &sdp_with_extmap);
2128
2129 EXPECT_EQ(sdp_with_extmap, message);
2130}
2131
jbauch5869f502017-06-29 12:31:36 -07002132TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2133 bool encrypted = true;
2134 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002135 JsepSessionDescription desc_with_extmap(kDummyType);
jbauch5869f502017-06-29 12:31:36 -07002136 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(),
2137 kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 12:22:16 -08002138 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07002139}
2140
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002141TEST_F(WebRtcSdpTest, SerializeCandidates) {
2142 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002143 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002144
2145 Candidate candidate_with_ufrag(candidates_.front());
2146 candidate_with_ufrag.set_username("ABC");
2147 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2148 candidate_with_ufrag));
2149 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2150 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002151
2152 Candidate candidate_with_network_info(candidates_.front());
2153 candidate_with_network_info.set_network_id(1);
2154 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2155 candidate_with_network_info));
2156 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2157 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2158 candidate_with_network_info.set_network_cost(999);
2159 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2160 candidate_with_network_info));
2161 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2162 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2163 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002164}
2165
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002166// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2167// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002168TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002169 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002170 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2171 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2172 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002173 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002174 std::unique_ptr<IceCandidateInterface> jcandidate(
2175 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002176
2177 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2178 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2179}
2180
htaa6b99442016-04-12 10:29:17 -07002181TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002182 cricket::VideoCodec h264_codec("H264");
2183 h264_codec.SetParam("profile-level-id", "42e01f");
2184 h264_codec.SetParam("level-asymmetry-allowed", "1");
2185 h264_codec.SetParam("packetization-mode", "1");
2186 video_desc_->AddCodec(h264_codec);
2187
htaa6b99442016-04-12 10:29:17 -07002188 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
2189
Steve Antone831b8c2018-02-01 12:22:16 -08002190 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 10:29:17 -07002191 size_t after_pt = message.find(" H264/90000");
2192 ASSERT_NE(after_pt, std::string::npos);
2193 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2194 ASSERT_NE(before_pt, std::string::npos);
2195 before_pt += strlen("a=rtpmap:");
2196 std::string pt = message.substr(before_pt, after_pt - before_pt);
2197 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2198 std::string to_find = "a=fmtp:" + pt + " ";
2199 size_t fmtp_pos = message.find(to_find);
2200 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
2201 size_t fmtp_endpos = message.find("\n", fmtp_pos);
2202 ASSERT_NE(std::string::npos, fmtp_endpos);
2203 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2204 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2205 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2206 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002207 // Check that there are no spaces after semicolons.
2208 // https://bugs.webrtc.org/5793
2209 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002210}
2211
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002212TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 10:27:41 -08002213 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002214 // Deserialize
2215 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2216 // Verify
2217 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2218}
2219
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002220TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 10:27:41 -08002221 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002222 const char kSdpWithoutMline[] =
2223 "v=0\r\n"
2224 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2225 "s=-\r\n"
2226 "t=0 0\r\n"
2227 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
2228 // Deserialize
2229 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2230 EXPECT_EQ(0u, jdesc.description()->contents().size());
2231}
2232
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002233TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 10:27:41 -08002234 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002235 std::string sdp_without_carriage_return = kSdpFullString;
2236 Replace("\r\n", "\n", &sdp_without_carriage_return);
2237 // Deserialize
2238 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2239 // Verify
2240 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2241}
2242
2243TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2244 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002245 JsepSessionDescription jdesc_no_candidates(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002246 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
2247 kSessionId, kSessionVersion));
Steve Antona3a92c22017-12-07 10:27:41 -08002248 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002249 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2250 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2251}
2252
2253TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2254 static const char kSdpNoRtpmapString[] =
2255 "v=0\r\n"
2256 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2257 "s=-\r\n"
2258 "t=0 0\r\n"
2259 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2260 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002261 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002262 // The rtpmap line for static payload codec is optional.
2263 "a=rtpmap:18 G729/16000\r\n"
2264 "a=rtpmap:103 ISAC/16000\r\n";
2265
Steve Antona3a92c22017-12-07 10:27:41 -08002266 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002267 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2268 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002269 jdesc.description()
2270 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2271 ->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002272 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002273 // The codecs in the AudioContentDescription should be in the same order as
2274 // the payload types (<fmt>s) on the m= line.
2275 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2276 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002277 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002278 EXPECT_EQ(ref_codecs, audio->codecs());
2279}
2280
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002281TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2282 static const char kSdpNoRtpmapString[] =
2283 "v=0\r\n"
2284 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2285 "s=-\r\n"
2286 "t=0 0\r\n"
2287 "m=audio 49232 RTP/AVP 18 103\r\n"
2288 "a=fmtp:18 annexb=yes\r\n"
2289 "a=rtpmap:103 ISAC/16000\r\n";
2290
Steve Antona3a92c22017-12-07 10:27:41 -08002291 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002292 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2293 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002294 jdesc.description()
2295 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2296 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002297
2298 cricket::AudioCodec g729 = audio->codecs()[0];
2299 EXPECT_EQ("G729", g729.name);
2300 EXPECT_EQ(8000, g729.clockrate);
2301 EXPECT_EQ(18, g729.id);
2302 cricket::CodecParameterMap::iterator found =
2303 g729.params.find("annexb");
2304 ASSERT_TRUE(found != g729.params.end());
2305 EXPECT_EQ(found->second, "yes");
2306
2307 cricket::AudioCodec isac = audio->codecs()[1];
2308 EXPECT_EQ("ISAC", isac.name);
2309 EXPECT_EQ(103, isac.id);
2310 EXPECT_EQ(16000, isac.clockrate);
2311}
2312
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002313// Ensure that we can deserialize SDP with a=fingerprint properly.
2314TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2315 // Add a DTLS a=fingerprint attribute to our session description.
2316 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002317 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002318 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
2319 jdesc_.session_id(),
2320 jdesc_.session_version()));
2321
Steve Antona3a92c22017-12-07 10:27:41 -08002322 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002323 std::string sdp_with_fingerprint = kSdpString;
2324 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2325 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2326 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2327 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2328}
2329
2330TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 10:27:41 -08002331 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002332 std::string sdp_with_bundle = kSdpFullString;
2333 InjectAfter(kSessionTime,
2334 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2335 &sdp_with_bundle);
2336 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2337 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2338 group.AddContentName(kAudioContentName);
2339 group.AddContentName(kVideoContentName);
2340 desc_.AddGroup(group);
2341 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2342 jdesc_.session_id(),
2343 jdesc_.session_version()));
2344 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2345}
2346
2347TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002348 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002349 std::string sdp_with_bandwidth = kSdpFullString;
2350 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
2351 "b=AS:100\r\n",
2352 &sdp_with_bandwidth);
2353 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
2354 "b=AS:50\r\n",
2355 &sdp_with_bandwidth);
2356 EXPECT_TRUE(
2357 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 15:14:30 -08002358 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002359 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002360 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002361 acd->set_bandwidth(50 * 1000);
2362 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2363 jdesc_.session_id(),
2364 jdesc_.session_version()));
2365 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2366}
2367
2368TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 10:27:41 -08002369 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002370 std::string sdp_with_ice_options = kSdpFullString;
2371 InjectAfter(kSessionTime,
2372 "a=ice-options:iceoption3\r\n",
2373 &sdp_with_ice_options);
2374 InjectAfter(kAttributeIcePwdVoice,
2375 "a=ice-options:iceoption1\r\n",
2376 &sdp_with_ice_options);
2377 InjectAfter(kAttributeIcePwdVideo,
2378 "a=ice-options:iceoption2\r\n",
2379 &sdp_with_ice_options);
2380 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2381 std::vector<std::string> transport_options;
2382 transport_options.push_back(kIceOption3);
2383 transport_options.push_back(kIceOption1);
2384 AddIceOptions(kAudioContentName, transport_options);
2385 transport_options.clear();
2386 transport_options.push_back(kIceOption3);
2387 transport_options.push_back(kIceOption2);
2388 AddIceOptions(kVideoContentName, transport_options);
2389 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2390 jdesc_.session_id(),
2391 jdesc_.session_version()));
2392 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2393}
2394
2395TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2396 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 10:27:41 -08002397 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002398 std::string sdp_with_ufrag_pwd = kSdpFullString;
2399 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2400 // Add session level ufrag and pwd
2401 InjectAfter(kSessionTime,
2402 "a=ice-pwd:session+level+icepwd\r\n"
2403 "a=ice-ufrag:session+level+iceufrag\r\n",
2404 &sdp_with_ufrag_pwd);
2405 // Add media level ufrag and pwd for audio
2406 InjectAfter("a=mid:audio_content_name\r\n",
2407 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2408 &sdp_with_ufrag_pwd);
2409 // Update the candidate ufrag and pwd to the expected ones.
2410 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0,
2411 "media+level+iceufrag", "media+level+icepwd"));
2412 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1,
2413 "session+level+iceufrag", "session+level+icepwd"));
2414 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2415 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2416}
2417
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002418TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002419 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002420}
2421
2422TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002423 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002424}
2425
2426TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002427 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002428}
2429
2430TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2431 EXPECT_TRUE(TestDeserializeRejected(true, false));
2432}
2433
2434TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2435 EXPECT_TRUE(TestDeserializeRejected(false, true));
2436}
2437
2438TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2439 EXPECT_TRUE(TestDeserializeRejected(true, true));
2440}
2441
2442// Tests that we can still handle the sdp uses mslabel and label instead of
2443// msid for backward compatibility.
2444TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07002445 jdesc_.description()->set_msid_supported(false);
Steve Antona3a92c22017-12-07 10:27:41 -08002446 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002447 std::string sdp_without_msid = kSdpFullString;
2448 Replace("msid", "xmsid", &sdp_without_msid);
2449 // Deserialize
2450 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2451 // Verify
2452 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2453}
2454
2455TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2456 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2457
2458 std::string sdp = kSdpOneCandidate;
2459 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2460 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2461 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2462 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002463 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002464
2465 // Candidate line without generation extension.
2466 sdp = kSdpOneCandidate;
2467 Replace(" generation 2", "", &sdp);
2468 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2469 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2470 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2471 Candidate expected = jcandidate_->candidate();
2472 expected.set_generation(0);
2473 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2474
honghaiza0c44ea2016-03-23 16:07:48 -07002475 // Candidate with network id and/or cost.
2476 sdp = kSdpOneCandidate;
2477 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2478 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2479 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2480 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2481 expected = jcandidate_->candidate();
2482 expected.set_network_id(2);
2483 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2484 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2485 // Add network cost
2486 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2487 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2488 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2489 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2490
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002491 sdp = kSdpTcpActiveCandidate;
2492 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2493 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002494 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002495 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2496 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2497 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002498 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2499 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002500 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(
2501 jcandidate_template->candidate()));
2502 sdp = kSdpTcpPassiveCandidate;
2503 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2504 sdp = kSdpTcpSOCandidate;
2505 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002506}
2507
2508// This test verifies the deserialization of candidate-attribute
2509// as per RFC 5245. Candiate-attribute will be of the format
2510// candidate:<blah>. This format will be used when candidates
2511// are trickled.
2512TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2513 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2514
2515 std::string candidate_attribute = kRawCandidate;
2516 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2517 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2518 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2519 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2520 EXPECT_EQ(2u, jcandidate.candidate().generation());
2521
2522 // Candidate line without generation extension.
2523 candidate_attribute = kRawCandidate;
2524 Replace(" generation 2", "", &candidate_attribute);
2525 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2526 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2527 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2528 Candidate expected = jcandidate_->candidate();
2529 expected.set_generation(0);
2530 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2531
2532 // Candidate line without candidate:
2533 candidate_attribute = kRawCandidate;
2534 Replace("candidate:", "", &candidate_attribute);
2535 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2536
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002537 // Candidate line with IPV6 address.
2538 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
2539}
2540
2541// This test verifies that the deserialization of an invalid candidate string
2542// fails.
2543TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
2544 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2545
2546 std::string candidate_attribute = kRawCandidate;
2547 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002548 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002549
2550 candidate_attribute = kSdpOneCandidate;
2551 candidate_attribute.replace(0, 1, "x");
2552 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2553
2554 candidate_attribute = kRawCandidate;
2555 candidate_attribute.append("\r\n");
2556 candidate_attribute.append(kRawCandidate);
2557 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2558
2559 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002560}
2561
2562TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2563 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002564 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002565 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2566
2567 std::string sdp_with_data = kSdpString;
2568 sdp_with_data.append(kSdpRtpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002569 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002570
2571 // Deserialize
2572 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2573 // Verify
2574 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2575}
2576
2577TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002578 bool use_sctpmap = true;
2579 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002580 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002581 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2582
2583 std::string sdp_with_data = kSdpString;
2584 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002585 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002586
lally@webrtc.org36300852015-02-24 20:19:35 +00002587 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2588 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2589 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2590
2591 // Verify with UDP/DTLS/SCTP.
2592 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2593 strlen(kDtlsSctp), kUdpDtlsSctp);
2594 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2595 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2596
2597 // Verify with TCP/DTLS/SCTP.
2598 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2599 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002600 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2601 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2602}
2603
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002604TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002605 bool use_sctpmap = false;
2606 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002607 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002608 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2609
2610 std::string sdp_with_data = kSdpString;
2611 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002612 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002613
lally@webrtc.org36300852015-02-24 20:19:35 +00002614 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002615 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2616 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002617
lally@webrtc.org36300852015-02-24 20:19:35 +00002618 // Verify with UDP/DTLS/SCTP.
2619 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2620 strlen(kDtlsSctp), kUdpDtlsSctp);
2621 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2622 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002623
lally@webrtc.org36300852015-02-24 20:19:35 +00002624 // Verify with TCP/DTLS/SCTP.
2625 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2626 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002627 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2628 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2629}
2630
lally69f57602015-10-08 10:15:04 -07002631TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002632 bool use_sctpmap = false;
2633 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002634 JsepSessionDescription jdesc(kDummyType);
lally69f57602015-10-08 10:15:04 -07002635 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2636
2637 std::string sdp_with_data = kSdpString;
2638 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002639 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 10:15:04 -07002640
2641 // Verify with DTLS/SCTP.
2642 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2643 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2644
2645 // Verify with UDP/DTLS/SCTP.
2646 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2647 strlen(kDtlsSctp), kUdpDtlsSctp);
2648 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2649 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2650
2651 // Verify with TCP/DTLS/SCTP.
2652 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2653 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
2654 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2655 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2656}
2657
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002658// Test to check the behaviour if sctp-port is specified
2659// on the m= line and in a=sctp-port.
2660TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002661 bool use_sctpmap = true;
2662 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002663 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002664 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2665
2666 std::string sdp_with_data = kSdpString;
2667 // Append m= attributes
2668 sdp_with_data.append(kSdpSctpDataChannelString);
2669 // Append a=sctp-port attribute
2670 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 10:27:41 -08002671 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002672
2673 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2674}
2675
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002676// For crbug/344475.
2677TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2678 std::string sdp_with_data = kSdpString;
2679 sdp_with_data.append(kSdpSctpDataChannelString);
2680 // Remove the "\n" at the end.
2681 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 10:27:41 -08002682 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002683
2684 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2685 // No crash is a pass.
2686}
2687
Steve Anton36b29d12017-10-30 09:57:42 -07002688void MutateJsepSctpPort(JsepSessionDescription* jdesc,
zstein4b2e0822017-02-17 19:48:38 -08002689 const SessionDescription& desc) {
wu@webrtc.org78187522013-10-07 23:32:02 +00002690 // take our pre-built session description and change the SCTP port.
zstein4b2e0822017-02-17 19:48:38 -08002691 cricket::SessionDescription* mutant = desc.Copy();
Steve Antonb1c1de12017-12-21 15:14:30 -08002692 DataContentDescription* dcdesc =
2693 mutant->GetContentDescriptionByName(kDataContentName)->as_data();
wu@webrtc.org78187522013-10-07 23:32:02 +00002694 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002695 EXPECT_EQ(1U, codecs.size());
solenberg9fa49752016-10-08 13:02:44 -07002696 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002697 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002698 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002699
2700 // note: mutant's owned by jdesc now.
Steve Anton36b29d12017-10-30 09:57:42 -07002701 ASSERT_TRUE(jdesc->Initialize(mutant, kSessionId, kSessionVersion));
wu@webrtc.org78187522013-10-07 23:32:02 +00002702 mutant = NULL;
zstein4b2e0822017-02-17 19:48:38 -08002703}
2704
2705TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
2706 bool use_sctpmap = true;
2707 AddSctpDataChannel(use_sctpmap);
2708
2709 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 10:27:41 -08002710 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002711 MutateJsepSctpPort(&jdesc, desc_);
wu@webrtc.org78187522013-10-07 23:32:02 +00002712
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002713 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002714 std::string sdp_with_data = kSdpString;
2715 sdp_with_data.append(kSdpSctpDataChannelString);
zstein4b2e0822017-02-17 19:48:38 -08002716 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2717 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2718 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002719 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:02 +00002720
2721 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2722 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08002723}
2724
2725TEST_F(WebRtcSdpTest,
2726 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
2727 bool use_sctpmap = false;
2728 AddSctpDataChannel(use_sctpmap);
2729
Steve Antona3a92c22017-12-07 10:27:41 -08002730 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002731 MutateJsepSctpPort(&jdesc, desc_);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002732
2733 // We need to test the deserialized JsepSessionDescription from
2734 // kSdpSctpDataChannelStringWithSctpPort for
2735 // draft-ietf-mmusic-sctp-sdp-07
2736 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08002737 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002738 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
zstein4b2e0822017-02-17 19:48:38 -08002739 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2740 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2741 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002742 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002743
2744 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2745 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002746}
2747
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002748TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002749 // We want to test that deserializing data content limits bandwidth
2750 // settings (it should never be greater than the default).
2751 // This should prevent someone from using unlimited data bandwidth through
2752 // JS and "breaking the Internet".
2753 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002754 std::string sdp_with_bandwidth = kSdpString;
2755 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
2756 InjectAfter("a=mid:data_content_name\r\n",
2757 "b=AS:100\r\n",
2758 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002759 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002760
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002761 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2762}
2763
2764TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08002765 bool use_sctpmap = true;
2766 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002767 JsepSessionDescription jdesc(kDummyType);
Steve Antonb1c1de12017-12-21 15:14:30 -08002768 DataContentDescription* dcd = GetFirstDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002769 dcd->set_bandwidth(100 * 1000);
2770 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2771
2772 std::string sdp_with_bandwidth = kSdpString;
2773 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
2774 InjectAfter("a=mid:data_content_name\r\n",
2775 "b=AS:100\r\n",
2776 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002777 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002778
2779 // SCTP has congestion control, so we shouldn't limit the bandwidth
2780 // as we do for RTP.
2781 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002782 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2783}
2784
jbauch5869f502017-06-29 12:31:36 -07002785class WebRtcSdpExtmapTest
2786 : public WebRtcSdpTest, public testing::WithParamInterface<bool> {
2787};
2788
2789TEST_P(WebRtcSdpExtmapTest,
2790 DeserializeSessionDescriptionWithSessionLevelExtmap) {
2791 bool encrypted = GetParam();
2792 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002793}
2794
jbauch5869f502017-06-29 12:31:36 -07002795TEST_P(WebRtcSdpExtmapTest,
2796 DeserializeSessionDescriptionWithMediaLevelExtmap) {
2797 bool encrypted = GetParam();
2798 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002799}
2800
jbauch5869f502017-06-29 12:31:36 -07002801TEST_P(WebRtcSdpExtmapTest,
2802 DeserializeSessionDescriptionWithInvalidExtmap) {
2803 bool encrypted = GetParam();
2804 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002805}
2806
jbauch5869f502017-06-29 12:31:36 -07002807INSTANTIATE_TEST_CASE_P(Encrypted,
2808 WebRtcSdpExtmapTest,
2809 ::testing::Values(false, true));
2810
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002811TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 10:27:41 -08002812 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002813 std::string sdp = kSdpFullString;
2814 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2815 // Deserialize
2816 SdpParseError error;
2817 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-16 17:54:10 -08002818 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002819 EXPECT_EQ(lastline, error.line);
2820 EXPECT_EQ("Invalid SDP line.", error.description);
2821}
2822
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002823TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2824 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2825 std::string new_sdp = kSdpOneCandidate;
2826 Replace("udp", "unsupported_transport", &new_sdp);
2827 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2828 new_sdp = kSdpOneCandidate;
2829 Replace("udp", "uDP", &new_sdp);
2830 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2831 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2832 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2833 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2834}
2835
honghaiza54a0802015-12-16 18:37:23 -08002836TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002837 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08002838 EXPECT_TRUE(
2839 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002840 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2841 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2842 Candidate ref_candidate = jcandidate_->candidate();
2843 ref_candidate.set_username("user_rtp");
2844 ref_candidate.set_password("password_rtp");
2845 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2846}
2847
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002848TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08002849 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002850
2851 // Deserialize
2852 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2853
2854 // Verify
2855 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002856 jdesc.description()
2857 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2858 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002859 EXPECT_TRUE(audio->conference_mode());
2860
2861 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 15:14:30 -08002862 jdesc.description()
2863 ->GetContentDescriptionByName(cricket::CN_VIDEO)
2864 ->as_video();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002865 EXPECT_TRUE(video->conference_mode());
2866}
2867
deadbeefd45aea82017-09-16 01:24:29 -07002868TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08002869 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 01:24:29 -07002870
2871 // We tested deserialization already above, so just test that if we serialize
2872 // and deserialize the flag doesn't disappear.
2873 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 12:22:16 -08002874 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 01:24:29 -07002875 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
2876
2877 // Verify.
2878 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002879 jdesc.description()
2880 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2881 ->as_audio();
deadbeefd45aea82017-09-16 01:24:29 -07002882 EXPECT_TRUE(audio->conference_mode());
2883
2884 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 15:14:30 -08002885 jdesc.description()
2886 ->GetContentDescriptionByName(cricket::CN_VIDEO)
2887 ->as_video();
deadbeefd45aea82017-09-16 01:24:29 -07002888 EXPECT_TRUE(video->conference_mode());
2889}
2890
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002891TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2892 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002893 const char kSdpEmptyType[] = " =candidate";
2894 const char kSdpEqualAsPlus[] = "a+candidate";
2895 const char kSdpSpaceAfterEqual[] = "a= candidate";
2896 const char kSdpUpperType[] = "A=candidate";
2897 const char kSdpEmptyLine[] = "";
2898 const char kSdpMissingValue[] = "a=";
2899
2900 const char kSdpBrokenFingerprint[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002901 "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 +00002902 const char kSdpExtraField[] = "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 XXX";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002904 const char kSdpMissingSpace[] = "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002905 "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 +00002906 // MD5 is not allowed in fingerprints.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002907 const char kSdpMd5[] = "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002908 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002909
2910 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002911 ExpectParseFailure("v=", kSdpDestroyer);
2912 ExpectParseFailure("o=", kSdpDestroyer);
2913 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002914 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002915 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002916
2917 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002918 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2919 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002920
2921 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002922 ExpectParseFailure("a=candidate", kSdpEmptyType);
2923 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2924 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
2925 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002926
2927 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2928 // because it's orthogonal to what we are replacing and hence
2929 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002930 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
2931 ExpectParseFailure("a=sendrecv", kSdpExtraField);
2932 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
2933 ExpectParseFailure("a=sendrecv", kSdpMd5);
2934
2935 // Empty Line
2936 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
2937 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002938}
2939
2940TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2941 // ssrc
2942 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08002943 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002944 // crypto
2945 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
2946 // rtpmap
2947 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
2948 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
2949 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
2950 // candidate
2951 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
2952 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
2953 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
2954 ExpectParseFailure("rport 2346", "rport badvalue");
2955 ExpectParseFailure("rport 2346 generation 2",
2956 "rport 2346 generation badvalue");
2957 // m line
2958 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
2959 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
2960
2961 // bandwidth
2962 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2963 "b=AS:badvalue\r\n",
2964 "b=AS:badvalue");
2965 // rtcp-fb
2966 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2967 "a=rtcp-fb:badvalue nack\r\n",
2968 "a=rtcp-fb:badvalue nack");
2969 // extmap
2970 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2971 "a=extmap:badvalue http://example.com\r\n",
2972 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002973}
2974
2975TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 10:27:41 -08002976 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002977
2978 const char kSdpWithReorderedPlTypesString[] =
2979 "v=0\r\n"
2980 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2981 "s=-\r\n"
2982 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00002983 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002984 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
2985 // in the map.
2986 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002987 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002988
2989 // Deserialize
2990 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
2991
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002992 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08002993 GetFirstAudioContentDescription(jdesc_output.description());
2994 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002995 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002996 EXPECT_EQ("ISAC", acd->codecs()[0].name);
2997 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002998 EXPECT_EQ(104, acd->codecs()[0].id);
2999}
3000
3001TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 10:27:41 -08003002 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003003 CodecParams params;
3004 params.max_ptime = 40;
3005 params.ptime = 30;
3006 params.min_ptime = 10;
3007 params.sprop_stereo = 1;
3008 params.stereo = 1;
3009 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003010 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003011 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 12:22:16 -08003012 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003013}
3014
3015TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
3016 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 10:27:41 -08003017 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003018 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003019 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003020}
3021
3022TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
3023 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 10:27:41 -08003024 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003025 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003026 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003027}
3028
3029TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 10:27:41 -08003030 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003031
3032 const char kSdpWithFmtpString[] =
3033 "v=0\r\n"
3034 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3035 "s=-\r\n"
3036 "t=0 0\r\n"
3037 "m=video 3457 RTP/SAVPF 120\r\n"
3038 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07003039 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3040
3041 // Deserialize
3042 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07003043 EXPECT_TRUE(
3044 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07003045
Donald Curtis0e07f922015-05-15 09:21:23 -07003046 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003047 GetFirstVideoContentDescription(jdesc_output.description());
3048 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 09:21:23 -07003049 ASSERT_FALSE(vcd->codecs().empty());
3050 cricket::VideoCodec vp8 = vcd->codecs()[0];
3051 EXPECT_EQ("VP8", vp8.name);
3052 EXPECT_EQ(120, vp8.id);
3053 cricket::CodecParameterMap::iterator found =
3054 vp8.params.find("x-google-min-bitrate");
3055 ASSERT_TRUE(found != vp8.params.end());
3056 EXPECT_EQ(found->second, "10");
3057 found = vp8.params.find("x-google-max-quantization");
3058 ASSERT_TRUE(found != vp8.params.end());
3059 EXPECT_EQ(found->second, "40");
3060}
3061
johan2d8d23e2016-06-03 01:22:42 -07003062TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 10:27:41 -08003063 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 01:22:42 -07003064
3065 const char kSdpWithFmtpString[] =
3066 "v=0\r\n"
3067 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3068 "s=-\r\n"
3069 "t=0 0\r\n"
3070 "m=video 49170 RTP/AVP 98\r\n"
3071 "a=rtpmap:98 H264/90000\r\n"
3072 "a=fmtp:98 profile-level-id=42A01E; "
3073 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3074
3075 // Deserialize.
3076 SdpParseError error;
3077 EXPECT_TRUE(
3078 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3079
johan2d8d23e2016-06-03 01:22:42 -07003080 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003081 GetFirstVideoContentDescription(jdesc_output.description());
3082 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 01:22:42 -07003083 ASSERT_FALSE(vcd->codecs().empty());
3084 cricket::VideoCodec h264 = vcd->codecs()[0];
3085 EXPECT_EQ("H264", h264.name);
3086 EXPECT_EQ(98, h264.id);
3087 cricket::CodecParameterMap::const_iterator found =
3088 h264.params.find("profile-level-id");
3089 ASSERT_TRUE(found != h264.params.end());
3090 EXPECT_EQ(found->second, "42A01E");
3091 found = h264.params.find("sprop-parameter-sets");
3092 ASSERT_TRUE(found != h264.params.end());
3093 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3094}
3095
Donald Curtis0e07f922015-05-15 09:21:23 -07003096TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 10:27:41 -08003097 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 09:21:23 -07003098
3099 const char kSdpWithFmtpString[] =
3100 "v=0\r\n"
3101 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3102 "s=-\r\n"
3103 "t=0 0\r\n"
3104 "m=video 3457 RTP/SAVPF 120\r\n"
3105 "a=rtpmap:120 VP8/90000\r\n"
3106 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003107
3108 // Deserialize
3109 SdpParseError error;
3110 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output,
3111 &error));
3112
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003113 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003114 GetFirstVideoContentDescription(jdesc_output.description());
3115 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003116 ASSERT_FALSE(vcd->codecs().empty());
3117 cricket::VideoCodec vp8 = vcd->codecs()[0];
3118 EXPECT_EQ("VP8", vp8.name);
3119 EXPECT_EQ(120, vp8.id);
3120 cricket::CodecParameterMap::iterator found =
3121 vp8.params.find("x-google-min-bitrate");
3122 ASSERT_TRUE(found != vp8.params.end());
3123 EXPECT_EQ(found->second, "10");
3124 found = vp8.params.find("x-google-max-quantization");
3125 ASSERT_TRUE(found != vp8.params.end());
3126 EXPECT_EQ(found->second, "40");
3127}
3128
ossuaa4b0772017-01-30 07:41:18 -08003129TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003130 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003131
3132 cricket::AudioCodecs codecs = acd->codecs();
3133 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3134 acd->set_codecs(codecs);
3135
3136 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3137 jdesc_.session_id(),
3138 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003139 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003140 std::string sdp_with_fmtp = kSdpFullString;
3141 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3142 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3143 &sdp_with_fmtp);
3144 EXPECT_EQ(sdp_with_fmtp, message);
3145}
3146
3147TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003148 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003149
3150 cricket::AudioCodecs codecs = acd->codecs();
3151 codecs[0].params["stereo"] = "1";
3152 acd->set_codecs(codecs);
3153
3154 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3155 jdesc_.session_id(),
3156 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003157 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003158 std::string sdp_with_fmtp = kSdpFullString;
3159 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3160 "a=fmtp:111 stereo=1\r\n",
3161 &sdp_with_fmtp);
3162 EXPECT_EQ(sdp_with_fmtp, message);
3163}
3164
3165TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003166 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003167
3168 cricket::AudioCodecs codecs = acd->codecs();
3169 codecs[0].params["ptime"] = "20";
3170 codecs[0].params["maxptime"] = "120";
3171 acd->set_codecs(codecs);
3172
3173 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3174 jdesc_.session_id(),
3175 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003176 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003177 std::string sdp_with_fmtp = kSdpFullString;
3178 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3179 "a=maxptime:120\r\n" // No comma here. String merging!
3180 "a=ptime:20\r\n",
3181 &sdp_with_fmtp);
3182 EXPECT_EQ(sdp_with_fmtp, message);
3183}
3184
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003185TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003186 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003187
3188 cricket::VideoCodecs codecs = vcd->codecs();
3189 codecs[0].params["x-google-min-bitrate"] = "10";
3190 vcd->set_codecs(codecs);
3191
3192 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3193 jdesc_.session_id(),
3194 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003195 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003196 std::string sdp_with_fmtp = kSdpFullString;
3197 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
3198 "a=fmtp:120 x-google-min-bitrate=10\r\n",
3199 &sdp_with_fmtp);
3200 EXPECT_EQ(sdp_with_fmtp, message);
3201}
3202
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003203TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) {
3204 // Deserialize the baseline description, making sure it's ICE full.
Steve Antona3a92c22017-12-07 10:27:41 -08003205 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003206 std::string sdp_with_icelite = kSdpFullString;
3207 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3208 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3209 const cricket::TransportInfo* tinfo1 =
3210 desc->GetTransportInfoByName("audio_content_name");
3211 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3212 const cricket::TransportInfo* tinfo2 =
3213 desc->GetTransportInfoByName("video_content_name");
3214 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003215
3216 // Add "a=ice-lite" and deserialize, making sure it's ICE lite.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003217 InjectAfter(kSessionTime,
3218 "a=ice-lite\r\n",
3219 &sdp_with_icelite);
3220 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3221 desc = jdesc_with_icelite.description();
3222 const cricket::TransportInfo* atinfo =
3223 desc->GetTransportInfoByName("audio_content_name");
3224 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3225 const cricket::TransportInfo* vtinfo =
3226 desc->GetTransportInfoByName("video_content_name");
3227 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003228
3229 // Now that we know deserialization works, we can use TestSerialize to test
3230 // serialization.
3231 TestSerialize(jdesc_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003232}
3233
3234// Verifies that the candidates in the input SDP are parsed and serialized
3235// correctly in the output SDP.
3236TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3237 std::string sdp_with_data = kSdpString;
3238 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 10:27:41 -08003239 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003240
3241 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 12:22:16 -08003242 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003243}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003244
3245TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3246 AddFingerprint();
3247 TransportInfo audio_transport_info =
3248 *(desc_.GetTransportInfoByName(kAudioContentName));
3249 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3250 audio_transport_info.description.connection_role);
3251 audio_transport_info.description.connection_role =
3252 cricket::CONNECTIONROLE_ACTIVE;
3253
3254 TransportInfo video_transport_info =
3255 *(desc_.GetTransportInfoByName(kVideoContentName));
3256 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3257 video_transport_info.description.connection_role);
3258 video_transport_info.description.connection_role =
3259 cricket::CONNECTIONROLE_ACTIVE;
3260
3261 desc_.RemoveTransportInfoByName(kAudioContentName);
3262 desc_.RemoveTransportInfoByName(kVideoContentName);
3263
3264 desc_.AddTransportInfo(audio_transport_info);
3265 desc_.AddTransportInfo(video_transport_info);
3266
3267 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3268 jdesc_.session_id(),
3269 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003270 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003271 std::string sdp_with_dtlssetup = kSdpFullString;
3272
3273 // Fingerprint attribute is necessary to add DTLS setup attribute.
3274 InjectAfter(kAttributeIcePwdVoice,
3275 kFingerprint, &sdp_with_dtlssetup);
3276 InjectAfter(kAttributeIcePwdVideo,
3277 kFingerprint, &sdp_with_dtlssetup);
3278 // Now adding |setup| attribute.
3279 InjectAfter(kFingerprint,
3280 "a=setup:active\r\n", &sdp_with_dtlssetup);
3281 EXPECT_EQ(sdp_with_dtlssetup, message);
3282}
3283
3284TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
Steve Antona3a92c22017-12-07 10:27:41 -08003285 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003286 std::string sdp_with_dtlssetup = kSdpFullString;
3287 InjectAfter(kSessionTime,
3288 "a=setup:actpass\r\n",
3289 &sdp_with_dtlssetup);
3290 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3291 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3292 const cricket::TransportInfo* atinfo =
3293 desc->GetTransportInfoByName("audio_content_name");
3294 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3295 atinfo->description.connection_role);
3296 const cricket::TransportInfo* vtinfo =
3297 desc->GetTransportInfoByName("video_content_name");
3298 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3299 vtinfo->description.connection_role);
3300}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003301
3302// Verifies that the order of the serialized m-lines follows the order of the
3303// ContentInfo in SessionDescription, and vise versa for deserialization.
3304TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 10:27:41 -08003305 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003306 const std::string media_content_sdps[3] = {
3307 kSdpAudioString,
3308 kSdpVideoString,
3309 kSdpSctpDataChannelString
3310 };
3311 const cricket::MediaType media_types[3] = {
3312 cricket::MEDIA_TYPE_AUDIO,
3313 cricket::MEDIA_TYPE_VIDEO,
3314 cricket::MEDIA_TYPE_DATA
3315 };
3316
3317 // Verifies all 6 permutations.
3318 for (size_t i = 0; i < 6; ++i) {
3319 size_t media_content_in_sdp[3];
3320 // The index of the first media content.
3321 media_content_in_sdp[0] = i / 2;
3322 // The index of the second media content.
3323 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3324 // The index of the third media content.
3325 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3326
3327 std::string sdp_string = kSdpSessionString;
3328 for (size_t i = 0; i < 3; ++i)
3329 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3330
3331 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3332 cricket::SessionDescription* desc = jdesc.description();
3333 EXPECT_EQ(3u, desc->contents().size());
3334
3335 for (size_t i = 0; i < 3; ++i) {
3336 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 15:14:30 -08003337 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003338 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3339 }
3340
Steve Antone831b8c2018-02-01 12:22:16 -08003341 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003342 EXPECT_EQ(sdp_string, serialized_sdp);
3343 }
3344}
deadbeef9d3584c2016-02-16 17:54:10 -08003345
deadbeef25ed4352016-12-12 18:37:36 -08003346TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3347 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 10:27:41 -08003348 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003349 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003350 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3351 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3352}
3353
deadbeef12771a12017-01-03 13:53:47 -08003354// The semantics of "a=bundle-only" are only defined when it's used in
3355// combination with a 0 port on the m= line. We should ignore it if used with a
3356// nonzero port.
3357TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3358 // Make the base bundle-only description but unset the bundle-only flag.
3359 MakeBundleOnlyDescription();
3360 jdesc_.description()->contents()[1].bundle_only = false;
3361
3362 std::string modified_sdp = kBundleOnlySdpFullString;
3363 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08003364 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003365 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3366 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003367}
3368
3369TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3370 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003371 TestSerialize(jdesc_);
deadbeef25ed4352016-12-12 18:37:36 -08003372}
3373
deadbeef9d3584c2016-02-16 17:54:10 -08003374TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3375 MakePlanBDescription();
3376
Steve Antona3a92c22017-12-07 10:27:41 -08003377 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003378 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3379
3380 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3381}
3382
3383TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3384 MakePlanBDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003385 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-16 17:54:10 -08003386}
3387
3388TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3389 MakeUnifiedPlanDescription();
3390
Steve Antona3a92c22017-12-07 10:27:41 -08003391 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003392 EXPECT_TRUE(
3393 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3394
3395 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3396}
3397
3398TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3399 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003400 TestSerialize(jdesc_);
3401}
3402
Seth Hampson5b4f0752018-04-02 16:31:36 -07003403// This tests deserializing a Unified Plan SDP that is compatible with both
3404// Unified Plan and Plan B style SDP. It tests the case for audio/video tracks
3405// with no stream ids and multiple stream ids. For parsing this, the Unified
3406// Plan a=msid lines should take priority, because the Plan B style a=ssrc msid
3407// lines do not support multiple stream ids and no stream ids.
3408TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionSpecialMsid) {
3409 MakeUnifiedPlanDescriptionMultipleStreamIds();
3410
3411 JsepSessionDescription deserialized_description(kDummyType);
3412 EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid,
3413 &deserialized_description));
3414
3415 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3416}
3417
3418TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionSpecialMsid) {
3419 MakeUnifiedPlanDescriptionMultipleStreamIds();
3420 TestSerialize(jdesc_);
3421}
3422
Seth Hampson5897a6e2018-04-03 11:16:33 -07003423// This tests that a Unified Plan SDP with no a=ssrc lines is
3424// serialized/deserialized appropriately. In this case the
3425// MediaContentDescription will contain a StreamParams object that doesn't have
3426// any SSRCs. Vice versa, this will be created upon deserializing an SDP with no
3427// SSRC lines.
3428TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3429 MakeUnifiedPlanDescription();
3430 RemoveSsrcSignalingFromStreamParams();
3431 std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString;
3432 RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string);
3433
3434 JsepSessionDescription deserialized_description(kDummyType);
3435 EXPECT_TRUE(
3436 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3437 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3438}
3439
3440TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3441 MakeUnifiedPlanDescription();
3442 RemoveSsrcSignalingFromStreamParams();
3443
3444 TestSerialize(jdesc_);
3445}
3446
Steve Antone831b8c2018-02-01 12:22:16 -08003447TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
3448 JsepSessionDescription jsep_desc(kDummyType);
3449 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
3450 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3451}
3452
3453TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
3454 JsepSessionDescription jsep_desc(kDummyType);
3455 std::string sdp = kSdpSessionString;
3456 sdp += kSdpSctpDataChannelString;
3457 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3458 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3459}
3460
3461TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
3462 JsepSessionDescription jsep_desc(kDummyType);
3463 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
3464 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
3465 jsep_desc.description()->msid_signaling());
3466}
3467
3468TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
3469 JsepSessionDescription jsep_desc(kDummyType);
3470 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
3471 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
3472 jsep_desc.description()->msid_signaling());
3473}
3474
3475const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
3476const char kSsrcAttributeMsidLine[] =
3477 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
3478
3479TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
3480 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
3481 std::string sdp = webrtc::SdpSerialize(jdesc_);
3482
3483 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3484 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3485}
3486
3487TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
3488 jdesc_.description()->set_msid_signaling(
3489 cricket::kMsidSignalingSsrcAttribute);
3490 std::string sdp = webrtc::SdpSerialize(jdesc_);
3491
3492 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
3493 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3494}
3495
3496TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
3497 jdesc_.description()->set_msid_signaling(
3498 cricket::kMsidSignalingMediaSection |
3499 cricket::kMsidSignalingSsrcAttribute);
3500 std::string sdp = webrtc::SdpSerialize(jdesc_);
3501
3502 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3503 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-16 17:54:10 -08003504}
deadbeef7e146cb2016-09-28 10:04:34 -07003505
3506// Regression test for heap overflow bug:
3507// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3508TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 10:04:34 -07003509 // The issue occurs when the sctp-port attribute is found in a video
3510 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 12:43:58 -08003511 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 10:04:34 -07003512 "v=0\r\n"
3513 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3514 "s=-\r\n"
3515 "t=0 0\r\n"
3516 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3517 "a=sctp-port 5000\r\n"
3518 "a=fmtp:108 foo=10\r\n";
3519
3520 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3521 "sctp-port");
3522}
deadbeefb2362572016-12-13 16:37:06 -08003523
3524// Regression test for integer overflow bug:
3525// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3526TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003527 // Bandwidth attribute is the max signed 32-bit int, which will get
3528 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003529 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003530 "v=0\r\n"
3531 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3532 "s=-\r\n"
3533 "t=0 0\r\n"
3534 "m=video 3457 RTP/SAVPF 120\r\n"
3535 "b=AS:2147483647\r\n"
3536 "foo=fail\r\n";
3537
3538 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3539}
deadbeef7bcdb692017-01-20 12:43:58 -08003540
deadbeefbc88c6b2017-08-02 11:26:34 -07003541// Similar to the above, except that negative values are illegal, not just
3542// error-prone as large values are.
3543// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3544TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3545 static const char kSdpWithNegativeBandwidth[] =
3546 "v=0\r\n"
3547 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3548 "s=-\r\n"
3549 "t=0 0\r\n"
3550 "m=video 3457 RTP/SAVPF 120\r\n"
3551 "b=AS:-1000\r\n";
3552
3553 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3554}
3555
deadbeef3e8016e2017-08-03 17:49:30 -07003556// An exception to the above rule: a value of -1 for b=AS should just be
3557// ignored, resulting in "kAutoBandwidth" in the deserialized object.
3558// Applications historically may be using "b=AS:-1" to mean "no bandwidth
3559// limit", but this is now what ommitting the attribute entirely will do, so
3560// ignoring it will have the intended effect.
3561TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
3562 static const char kSdpWithBandwidthOfNegativeOne[] =
3563 "v=0\r\n"
3564 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3565 "s=-\r\n"
3566 "t=0 0\r\n"
3567 "m=video 3457 RTP/SAVPF 120\r\n"
3568 "b=AS:-1\r\n";
3569
Steve Antona3a92c22017-12-07 10:27:41 -08003570 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-03 17:49:30 -07003571 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-03 17:49:30 -07003572 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003573 GetFirstVideoContentDescription(jdesc_output.description());
3574 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-03 17:49:30 -07003575 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
3576}
3577
deadbeef7bcdb692017-01-20 12:43:58 -08003578// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3579// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3580// Regression test for:
3581// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3582TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3583 // Important piece is "ufrag foo pwd bar".
3584 static const char kSdpWithIceCredentialsInCandidateString[] =
3585 "v=0\r\n"
3586 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3587 "s=-\r\n"
3588 "t=0 0\r\n"
3589 "m=audio 9 RTP/SAVPF 111\r\n"
3590 "c=IN IP4 0.0.0.0\r\n"
3591 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3592 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3593 "a=rtpmap:111 opus/48000/2\r\n"
3594 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3595 "generation 2 ufrag foo pwd bar\r\n";
3596
Steve Antona3a92c22017-12-07 10:27:41 -08003597 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 12:43:58 -08003598 EXPECT_TRUE(
3599 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
3600 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3601 ASSERT_NE(nullptr, candidates);
3602 ASSERT_EQ(1, candidates->count());
3603 cricket::Candidate c = candidates->at(0)->candidate();
3604 EXPECT_EQ("ufrag_voice", c.username());
3605 EXPECT_EQ("pwd_voice", c.password());
3606}
deadbeef90f1e1e2017-02-10 12:35:05 -08003607
3608// Test that SDP with an invalid port number in "a=candidate" lines is
3609// rejected, without crashing.
3610// Regression test for:
3611// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
3612TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
3613 static const char kSdpWithInvalidCandidatePort[] =
3614 "v=0\r\n"
3615 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3616 "s=-\r\n"
3617 "t=0 0\r\n"
3618 "m=audio 9 RTP/SAVPF 111\r\n"
3619 "c=IN IP4 0.0.0.0\r\n"
3620 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3621 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3622 "a=rtpmap:111 opus/48000/2\r\n"
3623 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
3624 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
3625
Steve Antona3a92c22017-12-07 10:27:41 -08003626 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 12:35:05 -08003627 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
3628}
deadbeefa4549d62017-02-10 17:26:22 -08003629
3630// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
3631// Regression test for:
3632// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
3633TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
3634 static const char kSdpWithMissingTrackId[] =
3635 "v=0\r\n"
3636 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3637 "s=-\r\n"
3638 "t=0 0\r\n"
3639 "m=audio 9 RTP/SAVPF 111\r\n"
3640 "c=IN IP4 0.0.0.0\r\n"
3641 "a=rtpmap:111 opus/48000/2\r\n"
3642 "a=msid:stream_id \r\n";
3643
Steve Antona3a92c22017-12-07 10:27:41 -08003644 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003645 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
3646}
3647
3648TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
3649 static const char kSdpWithMissingStreamId[] =
3650 "v=0\r\n"
3651 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3652 "s=-\r\n"
3653 "t=0 0\r\n"
3654 "m=audio 9 RTP/SAVPF 111\r\n"
3655 "c=IN IP4 0.0.0.0\r\n"
3656 "a=rtpmap:111 opus/48000/2\r\n"
3657 "a=msid: track_id\r\n";
3658
Steve Antona3a92c22017-12-07 10:27:41 -08003659 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003660 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
3661}
zhihuang38989e52017-03-21 11:04:53 -07003662
3663// Tests that if both session-level address and media-level address exist, use
3664// the media-level address.
3665TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 10:27:41 -08003666 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003667
3668 // Sesssion-level address.
3669 std::string sdp = kSdpFullString;
3670 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3671 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3672
3673 const auto& content1 = jsep_desc.description()->contents()[0];
3674 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 15:14:30 -08003675 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003676 const auto& content2 = jsep_desc.description()->contents()[1];
3677 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 15:14:30 -08003678 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003679}
3680
3681// Tests that the session-level connection address will be used if the media
3682// level-addresses are not specified.
3683TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 10:27:41 -08003684 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003685
3686 // Sesssion-level address.
3687 std::string sdp = kSdpString;
3688 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3689 // Remove the media level addresses.
3690 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3691 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3692 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3693
3694 const auto& content1 = jsep_desc.description()->contents()[0];
3695 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003696 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003697 const auto& content2 = jsep_desc.description()->contents()[1];
3698 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003699 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003700}
3701
3702TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 10:27:41 -08003703 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003704
3705 std::string sdp = kSdpString;
3706 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3707 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
3708 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
3709 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
3710 &sdp);
3711 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
3712 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
3713 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
3714 &sdp);
3715 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3716 const auto& content1 = jsep_desc.description()->contents()[0];
3717 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003718 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003719 const auto& content2 = jsep_desc.description()->contents()[1];
3720 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003721 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003722}
3723
3724// Test that the invalid or unsupprted connection data cannot be parsed.
3725TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 10:27:41 -08003726 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003727 std::string sdp = kSdpString;
3728 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3729
3730 // Unsupported multicast IPv4 address.
3731 sdp = kSdpFullString;
3732 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
3733 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3734
3735 // Unsupported multicast IPv6 address.
3736 sdp = kSdpFullString;
3737 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
3738 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3739
3740 // Mismatched address type.
3741 sdp = kSdpFullString;
3742 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
3743 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3744
3745 sdp = kSdpFullString;
3746 Replace("c=IN IP4 74.125.224.39\r\n",
3747 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
3748 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3749}
3750
3751TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 10:27:41 -08003752 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003753 MakeDescriptionWithoutCandidates(&expected_jsep);
3754 // Serialization.
Steve Antone831b8c2018-02-01 12:22:16 -08003755 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 11:04:53 -07003756 // Deserialization.
Steve Antona3a92c22017-12-07 10:27:41 -08003757 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003758 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 15:14:30 -08003759 auto audio_desc = jdesc.description()
3760 ->GetContentByName(kAudioContentName)
3761 ->media_description();
3762 auto video_desc = jdesc.description()
3763 ->GetContentByName(kVideoContentName)
3764 ->media_description();
zhihuang38989e52017-03-21 11:04:53 -07003765 EXPECT_EQ(audio_desc_->connection_address().ToString(),
3766 audio_desc->connection_address().ToString());
3767 EXPECT_EQ(video_desc_->connection_address().ToString(),
3768 video_desc->connection_address().ToString());
3769}
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07003770
3771// RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be
3772// used (i.e., a single space as the session name)." So we should accept that.
3773TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) {
3774 JsepSessionDescription jsep_desc(kDummyType);
3775 std::string sdp = kSdpString;
3776 Replace("s=-\r\n", "s= \r\n", &sdp);
3777 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3778}