blob: 8a3c28fe5b95afde0801620cd4daffdf91fb0c19 [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
Yves Gerey3e707812018-11-28 16:47:49 +010011#include <stdio.h>
12#include <string.h>
13#include <cstdint>
14#include <map>
kwibergd1fe2812016-04-27 06:47:29 -070015#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000016#include <string>
Yves Gerey3e707812018-11-28 16:47:49 +010017#include <utility>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000018#include <vector>
19
Yves Gerey3e707812018-11-28 16:47:49 +010020#include "api/array_view.h"
21#include "api/cryptoparams.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "api/jsepsessiondescription.h"
Yves Gerey3e707812018-11-28 16:47:49 +010023#include "api/mediatypes.h"
24#include "api/rtpparameters.h"
25#include "api/rtptransceiverinterface.h"
26#include "media/base/codec.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020027#include "media/base/mediaconstants.h"
Yves Gerey3e707812018-11-28 16:47:49 +010028#include "media/base/streamparams.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020029#include "p2p/base/p2pconstants.h"
Yves Gerey665174f2018-06-19 15:03:05 +020030#include "p2p/base/port.h"
Yves Gerey3e707812018-11-28 16:47:49 +010031#include "p2p/base/transportdescription.h"
32#include "p2p/base/transportinfo.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020033#include "pc/mediasession.h"
Yves Gerey3e707812018-11-28 16:47:49 +010034#include "pc/sessiondescription.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020035#include "rtc_base/checks.h"
Yves Gerey2e00abc2018-10-05 15:39:24 +020036#include "rtc_base/messagedigest.h"
Yves Gerey3e707812018-11-28 16:47:49 +010037#include "rtc_base/socketaddress.h"
38#include "rtc_base/sslfingerprint.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020039#include "rtc_base/stringencode.h"
40#include "rtc_base/stringutils.h"
Yves Gerey3e707812018-11-28 16:47:49 +010041#include "test/gtest.h"
Patrik Höglund563934e2017-09-15 09:04:28 +020042
ossu7bb87ee2017-01-23 04:56:25 -080043#ifdef WEBRTC_ANDROID
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020044#include "pc/test/androidtestinitializer.h"
ossu7bb87ee2017-01-23 04:56:25 -080045#endif
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020046#include "pc/webrtcsdp.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047
48using cricket::AudioCodec;
49using cricket::AudioContentDescription;
50using cricket::Candidate;
51using cricket::ContentInfo;
52using cricket::CryptoParams;
53using cricket::ContentGroup;
54using cricket::DataCodec;
55using cricket::DataContentDescription;
56using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
57using cricket::ICE_CANDIDATE_COMPONENT_RTP;
58using cricket::kFecSsrcGroupSemantics;
59using cricket::LOCAL_PORT_TYPE;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060using cricket::RELAY_PORT_TYPE;
61using cricket::SessionDescription;
Steve Anton5adfafd2017-12-20 16:34:00 -080062using cricket::MediaProtocolType;
Amit Hilbucha2012042018-12-03 11:35:05 -080063using cricket::SimulcastDescription;
64using cricket::SimulcastLayer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000065using cricket::StreamParams;
66using cricket::STUN_PORT_TYPE;
67using cricket::TransportDescription;
68using cricket::TransportInfo;
69using cricket::VideoCodec;
70using cricket::VideoContentDescription;
71using webrtc::IceCandidateCollection;
72using webrtc::IceCandidateInterface;
73using webrtc::JsepIceCandidate;
74using webrtc::JsepSessionDescription;
isheriff6f8d6862016-05-26 11:24:55 -070075using webrtc::RtpExtension;
Steve Anton4e70a722017-11-28 14:57:10 -080076using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077using webrtc::SdpParseError;
Steve Antona3a92c22017-12-07 10:27:41 -080078using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079using webrtc::SessionDescriptionInterface;
80
81typedef std::vector<AudioCodec> AudioCodecs;
82typedef std::vector<Candidate> Candidates;
83
Peter Boström0c4e06b2015-10-07 12:23:21 +020084static const uint32_t kDefaultSctpPort = 5000;
zstein4b2e0822017-02-17 19:48:38 -080085static const char kDefaultSctpPortStr[] = "5000";
86static const uint16_t kUnusualSctpPort = 9556;
87static const char kUnusualSctpPortStr[] = "9556";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020089static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 15:17:14 -080090static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 15:17:14 -080092static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000093static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020094static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095static const char kCandidateFoundation1[] = "a0+B/1";
96static const char kCandidateFoundation2[] = "a0+B/2";
97static const char kCandidateFoundation3[] = "a0+B/3";
98static const char kCandidateFoundation4[] = "a0+B/4";
99static const char kAttributeCryptoVoice[] =
100 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
101 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
102 "dummy_session_params\r\n";
103static const char kAttributeCryptoVideo[] =
104 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
105 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
Yves Gerey665174f2018-06-19 15:03:05 +0200106static const char kFingerprint[] =
107 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000108 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n";
Johannes Kron0854eb62018-10-10 22:33:20 +0200109static const char kExtmapAllowMixed[] = "a=extmap-allow-mixed\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000110static const int kExtmapId = 1;
111static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
112static const char kExtmap[] =
113 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
114static const char kExtmapWithDirectionAndAttribute[] =
115 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
jbauch5869f502017-06-29 12:31:36 -0700116static const char kExtmapWithDirectionAndAttributeEncrypted[] =
117 "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt "
118 "http://example.com/082005/ext.htm#ttime a1 a2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000119
Peter Boström0c4e06b2015-10-07 12:23:21 +0200120static const uint8_t kIdentityDigest[] = {
121 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
122 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000123
lally@webrtc.org34807282015-02-24 20:19:39 +0000124static const char kDtlsSctp[] = "DTLS/SCTP";
125static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
126static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +0000127
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000128struct CodecParams {
129 int max_ptime;
130 int ptime;
131 int min_ptime;
132 int sprop_stereo;
133 int stereo;
134 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000135 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000136};
137
deadbeef9d3584c2016-02-16 17:54:10 -0800138// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
139// instead of "a=crypto", and have an explicit test for adding "a=crypto".
140// Currently it's the other way around.
141
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000142// Reference sdp string
143static const char kSdpFullString[] =
144 "v=0\r\n"
145 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
146 "s=-\r\n"
147 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800148 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000149 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
150 "c=IN IP4 74.125.127.126\r\n"
151 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
152 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
153 "generation 2\r\n"
154 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
155 "generation 2\r\n"
156 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
157 "generation 2\r\n"
158 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
159 "generation 2\r\n"
160 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
161 "raddr 192.168.1.5 rport 2346 "
162 "generation 2\r\n"
163 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
164 "raddr 192.168.1.5 rport 2348 "
165 "generation 2\r\n"
166 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
167 "a=mid:audio_content_name\r\n"
168 "a=sendrecv\r\n"
169 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800170 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000171 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
172 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
173 "dummy_session_params\r\n"
174 "a=rtpmap:111 opus/48000/2\r\n"
175 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000176 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000177 "a=ssrc:1 cname:stream_1_cname\r\n"
178 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
179 "a=ssrc:1 mslabel:local_stream_1\r\n"
180 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000181 "m=video 3457 RTP/SAVPF 120\r\n"
182 "c=IN IP4 74.125.224.39\r\n"
183 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
184 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
185 "generation 2\r\n"
186 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
187 "generation 2\r\n"
188 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
189 "generation 2\r\n"
190 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
191 "generation 2\r\n"
192 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
193 "generation 2\r\n"
194 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
195 "generation 2\r\n"
196 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
197 "a=mid:video_content_name\r\n"
198 "a=sendrecv\r\n"
199 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
200 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
201 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800202 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000203 "a=ssrc:2 cname:stream_1_cname\r\n"
204 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
205 "a=ssrc:2 mslabel:local_stream_1\r\n"
206 "a=ssrc:2 label:video_track_id_1\r\n"
207 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800208 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000209 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800210 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211
212// SDP reference string without the candidates.
213static const char kSdpString[] =
214 "v=0\r\n"
215 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
216 "s=-\r\n"
217 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800218 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000219 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000220 "c=IN IP4 0.0.0.0\r\n"
221 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000222 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
223 "a=mid:audio_content_name\r\n"
224 "a=sendrecv\r\n"
225 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800226 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000227 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
228 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
229 "dummy_session_params\r\n"
230 "a=rtpmap:111 opus/48000/2\r\n"
231 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000232 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000233 "a=ssrc:1 cname:stream_1_cname\r\n"
234 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
235 "a=ssrc:1 mslabel:local_stream_1\r\n"
236 "a=ssrc:1 label:audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000237 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000238 "c=IN IP4 0.0.0.0\r\n"
239 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000240 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
241 "a=mid:video_content_name\r\n"
242 "a=sendrecv\r\n"
243 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
244 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
245 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800246 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000247 "a=ssrc:2 cname:stream_1_cname\r\n"
248 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
249 "a=ssrc:2 mslabel:local_stream_1\r\n"
250 "a=ssrc:2 label:video_track_id_1\r\n"
251 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800252 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000253 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800254 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000255
256static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000257 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000258 "c=IN IP4 0.0.0.0\r\n"
259 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000260 "a=ice-ufrag:ufrag_data\r\n"
261 "a=ice-pwd:pwd_data\r\n"
262 "a=mid:data_content_name\r\n"
263 "a=sendrecv\r\n"
264 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
265 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
266 "a=rtpmap:101 google-data/90000\r\n"
267 "a=ssrc:10 cname:data_channel_cname\r\n"
268 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
269 "a=ssrc:10 mslabel:data_channel\r\n"
270 "a=ssrc:10 label:data_channeld0\r\n";
271
272static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000273 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000274 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000275 "a=ice-ufrag:ufrag_data\r\n"
276 "a=ice-pwd:pwd_data\r\n"
277 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000278 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000279
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000280// draft-ietf-mmusic-sctp-sdp-12
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000281static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000282 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
283 "a=max-message-size=100000\r\n"
284 "a=sctp-port 5000\r\n"
285 "c=IN IP4 0.0.0.0\r\n"
286 "a=ice-ufrag:ufrag_data\r\n"
287 "a=ice-pwd:pwd_data\r\n"
288 "a=mid:data_content_name\r\n";
289
lally69f57602015-10-08 10:15:04 -0700290static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
291 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
292 "a=max-message-size=100000\r\n"
293 "a=sctp-port:5000\r\n"
294 "c=IN IP4 0.0.0.0\r\n"
295 "a=ice-ufrag:ufrag_data\r\n"
296 "a=ice-pwd:pwd_data\r\n"
297 "a=mid:data_content_name\r\n";
298
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000299static const char kSdpSctpDataChannelWithCandidatesString[] =
300 "m=application 2345 DTLS/SCTP 5000\r\n"
301 "c=IN IP4 74.125.127.126\r\n"
302 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
303 "generation 2\r\n"
304 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
305 "generation 2\r\n"
306 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
307 "raddr 192.168.1.5 rport 2346 "
308 "generation 2\r\n"
309 "a=ice-ufrag:ufrag_data\r\n"
310 "a=ice-pwd:pwd_data\r\n"
311 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000312 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000313
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000314static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000315 "v=0\r\n"
316 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
317 "s=-\r\n"
318 "t=0 0\r\n"
319 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000320 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000321 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000322 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000323 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000324 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000325 "a=x-google-flag:conference\r\n";
326
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000327static const char kSdpSessionString[] =
328 "v=0\r\n"
329 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
330 "s=-\r\n"
331 "t=0 0\r\n"
332 "a=msid-semantic: WMS local_stream\r\n";
333
334static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000335 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000336 "c=IN IP4 0.0.0.0\r\n"
337 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000338 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
339 "a=mid:audio_content_name\r\n"
340 "a=sendrecv\r\n"
341 "a=rtpmap:111 opus/48000/2\r\n"
342 "a=ssrc:1 cname:stream_1_cname\r\n"
343 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
344 "a=ssrc:1 mslabel:local_stream\r\n"
345 "a=ssrc:1 label:audio_track_id_1\r\n";
346
347static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000348 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000349 "c=IN IP4 0.0.0.0\r\n"
350 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000351 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
352 "a=mid:video_content_name\r\n"
353 "a=sendrecv\r\n"
354 "a=rtpmap:120 VP8/90000\r\n"
355 "a=ssrc:2 cname:stream_1_cname\r\n"
356 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
357 "a=ssrc:2 mslabel:local_stream\r\n"
358 "a=ssrc:2 label:video_track_id_1\r\n";
359
deadbeef25ed4352016-12-12 18:37:36 -0800360// Reference sdp string using bundle-only.
361static const char kBundleOnlySdpFullString[] =
362 "v=0\r\n"
363 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
364 "s=-\r\n"
365 "t=0 0\r\n"
366 "a=group:BUNDLE audio_content_name video_content_name\r\n"
367 "a=msid-semantic: WMS local_stream_1\r\n"
368 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
369 "c=IN IP4 74.125.127.126\r\n"
370 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
371 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
372 "generation 2\r\n"
373 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
374 "generation 2\r\n"
375 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
376 "generation 2\r\n"
377 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
378 "generation 2\r\n"
379 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
380 "raddr 192.168.1.5 rport 2346 "
381 "generation 2\r\n"
382 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
383 "raddr 192.168.1.5 rport 2348 "
384 "generation 2\r\n"
385 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
386 "a=mid:audio_content_name\r\n"
387 "a=sendrecv\r\n"
388 "a=rtcp-mux\r\n"
389 "a=rtcp-rsize\r\n"
390 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
391 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
392 "dummy_session_params\r\n"
393 "a=rtpmap:111 opus/48000/2\r\n"
394 "a=rtpmap:103 ISAC/16000\r\n"
395 "a=rtpmap:104 ISAC/32000\r\n"
396 "a=ssrc:1 cname:stream_1_cname\r\n"
397 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
398 "a=ssrc:1 mslabel:local_stream_1\r\n"
399 "a=ssrc:1 label:audio_track_id_1\r\n"
400 "m=video 0 RTP/SAVPF 120\r\n"
401 "c=IN IP4 0.0.0.0\r\n"
402 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
403 "a=bundle-only\r\n"
404 "a=mid:video_content_name\r\n"
405 "a=sendrecv\r\n"
406 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
407 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
408 "a=rtpmap:120 VP8/90000\r\n"
409 "a=ssrc-group:FEC 2 3\r\n"
410 "a=ssrc:2 cname:stream_1_cname\r\n"
411 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
412 "a=ssrc:2 mslabel:local_stream_1\r\n"
413 "a=ssrc:2 label:video_track_id_1\r\n"
414 "a=ssrc:3 cname:stream_1_cname\r\n"
415 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
416 "a=ssrc:3 mslabel:local_stream_1\r\n"
417 "a=ssrc:3 label:video_track_id_1\r\n";
418
deadbeef9d3584c2016-02-16 17:54:10 -0800419// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
420// tracks.
421static const char kPlanBSdpFullString[] =
422 "v=0\r\n"
423 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
424 "s=-\r\n"
425 "t=0 0\r\n"
426 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
427 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
428 "c=IN IP4 74.125.127.126\r\n"
429 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
430 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
431 "generation 2\r\n"
432 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
433 "generation 2\r\n"
434 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
435 "generation 2\r\n"
436 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
437 "generation 2\r\n"
438 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
439 "raddr 192.168.1.5 rport 2346 "
440 "generation 2\r\n"
441 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
442 "raddr 192.168.1.5 rport 2348 "
443 "generation 2\r\n"
444 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
445 "a=mid:audio_content_name\r\n"
446 "a=sendrecv\r\n"
447 "a=rtcp-mux\r\n"
448 "a=rtcp-rsize\r\n"
449 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
450 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
451 "dummy_session_params\r\n"
452 "a=rtpmap:111 opus/48000/2\r\n"
453 "a=rtpmap:103 ISAC/16000\r\n"
454 "a=rtpmap:104 ISAC/32000\r\n"
455 "a=ssrc:1 cname:stream_1_cname\r\n"
456 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
457 "a=ssrc:1 mslabel:local_stream_1\r\n"
458 "a=ssrc:1 label:audio_track_id_1\r\n"
459 "a=ssrc:4 cname:stream_2_cname\r\n"
460 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
461 "a=ssrc:4 mslabel:local_stream_2\r\n"
462 "a=ssrc:4 label:audio_track_id_2\r\n"
463 "m=video 3457 RTP/SAVPF 120\r\n"
464 "c=IN IP4 74.125.224.39\r\n"
465 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
466 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
467 "generation 2\r\n"
468 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
469 "generation 2\r\n"
470 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
471 "generation 2\r\n"
472 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
473 "generation 2\r\n"
474 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
475 "generation 2\r\n"
476 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
477 "generation 2\r\n"
478 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
479 "a=mid:video_content_name\r\n"
480 "a=sendrecv\r\n"
481 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
482 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
483 "a=rtpmap:120 VP8/90000\r\n"
484 "a=ssrc-group:FEC 2 3\r\n"
485 "a=ssrc:2 cname:stream_1_cname\r\n"
486 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
487 "a=ssrc:2 mslabel:local_stream_1\r\n"
488 "a=ssrc:2 label:video_track_id_1\r\n"
489 "a=ssrc:3 cname:stream_1_cname\r\n"
490 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
491 "a=ssrc:3 mslabel:local_stream_1\r\n"
492 "a=ssrc:3 label:video_track_id_1\r\n"
493 "a=ssrc:5 cname:stream_2_cname\r\n"
494 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
495 "a=ssrc:5 mslabel:local_stream_2\r\n"
496 "a=ssrc:5 label:video_track_id_2\r\n"
497 "a=ssrc:6 cname:stream_2_cname\r\n"
498 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
499 "a=ssrc:6 mslabel:local_stream_2\r\n"
500 "a=ssrc:6 label:video_track_id_3\r\n";
501
502// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
503// tracks.
504static const char kUnifiedPlanSdpFullString[] =
505 "v=0\r\n"
506 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
507 "s=-\r\n"
508 "t=0 0\r\n"
509 "a=msid-semantic: WMS local_stream_1\r\n"
510 // Audio track 1, stream 1 (with candidates).
511 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
512 "c=IN IP4 74.125.127.126\r\n"
513 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
514 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
515 "generation 2\r\n"
516 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
517 "generation 2\r\n"
518 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
519 "generation 2\r\n"
520 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
521 "generation 2\r\n"
522 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
523 "raddr 192.168.1.5 rport 2346 "
524 "generation 2\r\n"
525 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
526 "raddr 192.168.1.5 rport 2348 "
527 "generation 2\r\n"
528 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
529 "a=mid:audio_content_name\r\n"
530 "a=msid:local_stream_1 audio_track_id_1\r\n"
531 "a=sendrecv\r\n"
532 "a=rtcp-mux\r\n"
533 "a=rtcp-rsize\r\n"
534 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
535 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
536 "dummy_session_params\r\n"
537 "a=rtpmap:111 opus/48000/2\r\n"
538 "a=rtpmap:103 ISAC/16000\r\n"
539 "a=rtpmap:104 ISAC/32000\r\n"
540 "a=ssrc:1 cname:stream_1_cname\r\n"
541 // Video track 1, stream 1 (with candidates).
542 "m=video 3457 RTP/SAVPF 120\r\n"
543 "c=IN IP4 74.125.224.39\r\n"
544 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
545 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
546 "generation 2\r\n"
547 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
548 "generation 2\r\n"
549 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
550 "generation 2\r\n"
551 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
552 "generation 2\r\n"
553 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
554 "generation 2\r\n"
555 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
556 "generation 2\r\n"
557 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
558 "a=mid:video_content_name\r\n"
559 "a=msid:local_stream_1 video_track_id_1\r\n"
560 "a=sendrecv\r\n"
561 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
562 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
563 "a=rtpmap:120 VP8/90000\r\n"
564 "a=ssrc-group:FEC 2 3\r\n"
565 "a=ssrc:2 cname:stream_1_cname\r\n"
566 "a=ssrc:3 cname:stream_1_cname\r\n"
567 // Audio track 2, stream 2.
568 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
569 "c=IN IP4 0.0.0.0\r\n"
570 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
571 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
572 "a=mid:audio_content_name_2\r\n"
573 "a=msid:local_stream_2 audio_track_id_2\r\n"
574 "a=sendrecv\r\n"
575 "a=rtcp-mux\r\n"
576 "a=rtcp-rsize\r\n"
577 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
578 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
579 "dummy_session_params\r\n"
580 "a=rtpmap:111 opus/48000/2\r\n"
581 "a=rtpmap:103 ISAC/16000\r\n"
582 "a=rtpmap:104 ISAC/32000\r\n"
583 "a=ssrc:4 cname:stream_2_cname\r\n"
584 // Video track 2, stream 2.
585 "m=video 9 RTP/SAVPF 120\r\n"
586 "c=IN IP4 0.0.0.0\r\n"
587 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
588 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
589 "a=mid:video_content_name_2\r\n"
590 "a=msid:local_stream_2 video_track_id_2\r\n"
591 "a=sendrecv\r\n"
592 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
593 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
594 "a=rtpmap:120 VP8/90000\r\n"
595 "a=ssrc:5 cname:stream_2_cname\r\n"
596 // Video track 3, stream 2.
597 "m=video 9 RTP/SAVPF 120\r\n"
598 "c=IN IP4 0.0.0.0\r\n"
599 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
600 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
601 "a=mid:video_content_name_3\r\n"
602 "a=msid:local_stream_2 video_track_id_3\r\n"
603 "a=sendrecv\r\n"
604 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
605 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
606 "a=rtpmap:120 VP8/90000\r\n"
607 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000608
Seth Hampson5b4f0752018-04-02 16:31:36 -0700609// Unified Plan SDP reference string:
610// - audio track 1 has 1 a=msid lines
611// - audio track 2 has 2 a=msid lines
612// - audio track 3 has 1 a=msid line with the special "-" marker signifying that
613// there are 0 media stream ids.
614// This Unified Plan SDP represents a SDP that signals the msid using both
615// a=msid and a=ssrc msid semantics.
616static const char kUnifiedPlanSdpFullStringWithSpecialMsid[] =
617 "v=0\r\n"
618 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
619 "s=-\r\n"
620 "t=0 0\r\n"
621 "a=msid-semantic: WMS local_stream_1\r\n"
622 // Audio track 1, with 1 stream id.
623 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
624 "c=IN IP4 74.125.127.126\r\n"
625 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
626 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
627 "generation 2\r\n"
628 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
629 "generation 2\r\n"
630 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
631 "generation 2\r\n"
632 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
633 "generation 2\r\n"
634 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
635 "raddr 192.168.1.5 rport 2346 "
636 "generation 2\r\n"
637 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
638 "raddr 192.168.1.5 rport 2348 "
639 "generation 2\r\n"
640 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
641 "a=mid:audio_content_name\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700642 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700643 "a=msid:local_stream_1 audio_track_id_1\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700644 "a=rtcp-mux\r\n"
645 "a=rtcp-rsize\r\n"
646 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
647 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
648 "dummy_session_params\r\n"
649 "a=rtpmap:111 opus/48000/2\r\n"
650 "a=rtpmap:103 ISAC/16000\r\n"
651 "a=rtpmap:104 ISAC/32000\r\n"
652 "a=ssrc:1 cname:stream_1_cname\r\n"
653 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
654 "a=ssrc:1 mslabel:local_stream_1\r\n"
655 "a=ssrc:1 label:audio_track_id_1\r\n"
656 // Audio track 2, with two stream ids.
657 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
658 "c=IN IP4 0.0.0.0\r\n"
659 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
660 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
661 "a=mid:audio_content_name_2\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700662 "a=sendrecv\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700663 "a=msid:local_stream_1 audio_track_id_2\r\n"
664 "a=msid:local_stream_2 audio_track_id_2\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700665 "a=rtcp-mux\r\n"
666 "a=rtcp-rsize\r\n"
667 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
668 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
669 "dummy_session_params\r\n"
670 "a=rtpmap:111 opus/48000/2\r\n"
671 "a=rtpmap:103 ISAC/16000\r\n"
672 "a=rtpmap:104 ISAC/32000\r\n"
673 "a=ssrc:4 cname:stream_1_cname\r\n"
674 // The support for Plan B msid signaling only includes the
675 // first media stream id "local_stream_1."
676 "a=ssrc:4 msid:local_stream_1 audio_track_id_2\r\n"
677 "a=ssrc:4 mslabel:local_stream_1\r\n"
678 "a=ssrc:4 label:audio_track_id_2\r\n"
679 // Audio track 3, with no stream ids.
680 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
681 "c=IN IP4 0.0.0.0\r\n"
682 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
683 "a=ice-ufrag:ufrag_voice_3\r\na=ice-pwd:pwd_voice_3\r\n"
684 "a=mid:audio_content_name_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700685 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700686 "a=msid:- audio_track_id_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700687 "a=rtcp-mux\r\n"
688 "a=rtcp-rsize\r\n"
689 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
690 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
691 "dummy_session_params\r\n"
692 "a=rtpmap:111 opus/48000/2\r\n"
693 "a=rtpmap:103 ISAC/16000\r\n"
694 "a=rtpmap:104 ISAC/32000\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700695 "a=ssrc:7 cname:stream_2_cname\r\n"
696 "a=ssrc:7 msid:- audio_track_id_3\r\n"
697 "a=ssrc:7 mslabel:-\r\n"
698 "a=ssrc:7 label:audio_track_id_3\r\n";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700699
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000700// One candidate reference string as per W3c spec.
701// candidate:<blah> not a=candidate:<blah>CRLF
702static const char kRawCandidate[] =
703 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
704// One candidate reference string.
705static const char kSdpOneCandidate[] =
706 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
707 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000708
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000709static const char kSdpTcpActiveCandidate[] =
710 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
711 "tcptype active generation 2";
712static const char kSdpTcpPassiveCandidate[] =
713 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
714 "tcptype passive generation 2";
715static const char kSdpTcpSOCandidate[] =
716 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
717 "tcptype so generation 2";
718static const char kSdpTcpInvalidCandidate[] =
719 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
720 "tcptype invalid generation 2";
721
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000722// One candidate reference string with IPV6 address.
723static const char kRawIPV6Candidate[] =
724 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 12:04:36 -0700725 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000726
727// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800728static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000729 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800730 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000731
Zach Steinb336c272018-08-09 01:16:13 -0700732static const char kRawHostnameCandidate[] =
733 "candidate:a0+B/1 1 udp 2130706432 a.test 1234 typ host generation 2";
734
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000735// Session id and version
736static const char kSessionId[] = "18446744069414584320";
737static const char kSessionVersion[] = "18446462598732840960";
738
deadbeef9d3584c2016-02-16 17:54:10 -0800739// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000740static const char kIceOption1[] = "iceoption1";
741static const char kIceOption2[] = "iceoption2";
742static const char kIceOption3[] = "iceoption3";
743
deadbeef9d3584c2016-02-16 17:54:10 -0800744// ICE ufrags/passwords.
745static const char kUfragVoice[] = "ufrag_voice";
746static const char kPwdVoice[] = "pwd_voice";
747static const char kUfragVideo[] = "ufrag_video";
748static const char kPwdVideo[] = "pwd_video";
749static const char kUfragData[] = "ufrag_data";
750static const char kPwdData[] = "pwd_data";
751
752// Extra ufrags/passwords for extra unified plan m= sections.
753static const char kUfragVoice2[] = "ufrag_voice_2";
754static const char kPwdVoice2[] = "pwd_voice_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700755static const char kUfragVoice3[] = "ufrag_voice_3";
756static const char kPwdVoice3[] = "pwd_voice_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800757static const char kUfragVideo2[] = "ufrag_video_2";
758static const char kPwdVideo2[] = "pwd_video_2";
759static const char kUfragVideo3[] = "ufrag_video_3";
760static const char kPwdVideo3[] = "pwd_video_3";
761
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000762// Content name
763static const char kAudioContentName[] = "audio_content_name";
764static const char kVideoContentName[] = "video_content_name";
765static const char kDataContentName[] = "data_content_name";
766
deadbeef9d3584c2016-02-16 17:54:10 -0800767// Extra content names for extra unified plan m= sections.
768static const char kAudioContentName2[] = "audio_content_name_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700769static const char kAudioContentName3[] = "audio_content_name_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800770static const char kVideoContentName2[] = "video_content_name_2";
771static const char kVideoContentName3[] = "video_content_name_3";
772
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000773// MediaStream 1
Seth Hampson845e8782018-03-02 11:34:10 -0800774static const char kStreamId1[] = "local_stream_1";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000775static const char kStream1Cname[] = "stream_1_cname";
776static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200777static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000778static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800779static const uint32_t kVideoTrack1Ssrc1 = 2;
780static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000781
782// MediaStream 2
Seth Hampson845e8782018-03-02 11:34:10 -0800783static const char kStreamId2[] = "local_stream_2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000784static const char kStream2Cname[] = "stream_2_cname";
785static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200786static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800787static const char kVideoTrackId2[] = "video_track_id_2";
788static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000789static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800790static const uint32_t kVideoTrack3Ssrc = 6;
Seth Hampson5b4f0752018-04-02 16:31:36 -0700791static const char kAudioTrackId3[] = "audio_track_id_3";
792static const uint32_t kAudioTrack3Ssrc = 7;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000793
794// DataChannel
795static const char kDataChannelLabel[] = "data_channel";
796static const char kDataChannelMsid[] = "data_channeld0";
797static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200798static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799
800// Candidate
801static const char kDummyMid[] = "dummy_mid";
802static const int kDummyIndex = 123;
803
804// Misc
Steve Antona3a92c22017-12-07 10:27:41 -0800805static SdpType kDummyType = SdpType::kOffer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000806
807// Helper functions
808
809static bool SdpDeserialize(const std::string& message,
810 JsepSessionDescription* jdesc) {
811 return webrtc::SdpDeserialize(message, jdesc, NULL);
812}
813
814static bool SdpDeserializeCandidate(const std::string& message,
815 JsepIceCandidate* candidate) {
816 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
817}
818
819// Add some extra |newlines| to the |message| after |line|.
820static void InjectAfter(const std::string& line,
821 const std::string& newlines,
822 std::string* message) {
823 const std::string tmp = line + newlines;
Yves Gerey665174f2018-06-19 15:03:05 +0200824 rtc::replace_substrs(line.c_str(), line.length(), tmp.c_str(), tmp.length(),
825 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000826}
827
828static void Replace(const std::string& line,
829 const std::string& newlines,
830 std::string* message) {
Yves Gerey665174f2018-06-19 15:03:05 +0200831 rtc::replace_substrs(line.c_str(), line.length(), newlines.c_str(),
832 newlines.length(), message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000833}
834
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000835// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
836// message.
837static void ExpectParseFailure(const std::string& bad_sdp,
838 const std::string& bad_part) {
Steve Antona3a92c22017-12-07 10:27:41 -0800839 JsepSessionDescription desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000841 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000843 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
844}
845
846// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
847static void ExpectParseFailure(const char* good_part, const char* bad_part) {
848 std::string bad_sdp = kSdpFullString;
849 Replace(good_part, bad_part, &bad_sdp);
850 ExpectParseFailure(bad_sdp, bad_part);
851}
852
853// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
854static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
855 const std::string& newlines,
856 const std::string& bad_part) {
857 std::string bad_sdp = kSdpFullString;
858 InjectAfter(injectpoint, newlines, &bad_sdp);
859 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000860}
861
Steve Anton4e70a722017-11-28 14:57:10 -0800862static void ReplaceDirection(RtpTransceiverDirection direction,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000863 std::string* message) {
864 std::string new_direction;
865 switch (direction) {
Steve Anton4e70a722017-11-28 14:57:10 -0800866 case RtpTransceiverDirection::kInactive:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000867 new_direction = "a=inactive";
868 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800869 case RtpTransceiverDirection::kSendOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000870 new_direction = "a=sendonly";
871 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800872 case RtpTransceiverDirection::kRecvOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000873 new_direction = "a=recvonly";
874 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800875 case RtpTransceiverDirection::kSendRecv:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876 default:
877 new_direction = "a=sendrecv";
878 break;
879 }
880 Replace("a=sendrecv", new_direction, message);
881}
882
Yves Gerey665174f2018-06-19 15:03:05 +0200883static void ReplaceRejected(bool audio_rejected,
884 bool video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000885 std::string* message) {
886 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800887 Replace("m=audio 9", "m=audio 0", message);
888 Replace(kAttributeIceUfragVoice, "", message);
889 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890 }
891 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800892 Replace("m=video 9", "m=video 0", message);
893 Replace(kAttributeIceUfragVideo, "", message);
894 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000895 }
896}
897
898// WebRtcSdpTest
899
900class WebRtcSdpTest : public testing::Test {
901 public:
Steve Antona3a92c22017-12-07 10:27:41 -0800902 WebRtcSdpTest() : jdesc_(kDummyType) {
phoglund37ebcf02016-01-08 05:04:57 -0800903#ifdef WEBRTC_ANDROID
904 webrtc::InitializeAndroidObjects();
905#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000906 // AudioContentDescription
907 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -0800908 StreamParams audio_stream;
909 audio_stream.id = kAudioTrackId1;
910 audio_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -0800911 audio_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -0800912 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
913 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 11:04:53 -0700914 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
915 audio_desc_->set_connection_address(audio_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -0800916 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000917
918 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -0800919 video_desc_ = CreateVideoContentDescription();
920 StreamParams video_stream;
921 video_stream.id = kVideoTrackId1;
922 video_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -0800923 video_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -0800924 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
925 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
926 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
927 video_stream.ssrc_groups.push_back(ssrc_group);
928 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 11:04:53 -0700929 rtc::SocketAddress video_addr("74.125.224.39", 3457);
930 video_desc_->set_connection_address(video_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -0800931 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000932
933 // TransportInfo
deadbeef9d3584c2016-02-16 17:54:10 -0800934 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
935 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice))));
936 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
937 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000938
939 // v4 host
940 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000941 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000942 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000943 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
944 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000946 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000947 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
948 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000949 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000950 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000951 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
952 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000953 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000954 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000955 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
956 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000957
958 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000959 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000960 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
961 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000962 cricket::LOCAL_PORT_TYPE,
963 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000964 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000965 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
966 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000967 cricket::LOCAL_PORT_TYPE,
968 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000970 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
971 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000972 cricket::LOCAL_PORT_TYPE,
973 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000974 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000975 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
976 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000977 cricket::LOCAL_PORT_TYPE,
978 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000979
980 // stun
981 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000982 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
983 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000984 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
985 address_stun, kCandidatePriority, "", "",
986 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000987 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000988 candidate9.set_related_address(rel_address_stun);
989
990 address_stun.SetPort(port_stun++);
991 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000992 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
993 address_stun, kCandidatePriority, "", "",
994 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000995 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000996 candidate10.set_related_address(rel_address_stun);
997
998 // relay
999 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001000 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001001 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1002 address_relay, kCandidatePriority, "", "",
1003 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001004 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001005 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001006 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1007 address_relay, kCandidatePriority, "", "",
1008 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001009 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001010
1011 // voice
1012 candidates_.push_back(candidate1);
1013 candidates_.push_back(candidate2);
1014 candidates_.push_back(candidate5);
1015 candidates_.push_back(candidate6);
1016 candidates_.push_back(candidate9);
1017 candidates_.push_back(candidate10);
1018
1019 // video
1020 candidates_.push_back(candidate3);
1021 candidates_.push_back(candidate4);
1022 candidates_.push_back(candidate7);
1023 candidates_.push_back(candidate8);
1024 candidates_.push_back(candidate11);
1025 candidates_.push_back(candidate12);
1026
Yves Gerey665174f2018-06-19 15:03:05 +02001027 jcandidate_.reset(
1028 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001029
1030 // Set up JsepSessionDescription.
1031 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
1032 std::string mline_id;
1033 int mline_index = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001034 for (size_t i = 0; i < candidates_.size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001035 // In this test, the audio m line index will be 0, and the video m line
1036 // will be 1.
1037 bool is_video = (i > 5);
1038 mline_id = is_video ? "video_content_name" : "audio_content_name";
1039 mline_index = is_video ? 1 : 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001040 JsepIceCandidate jice(mline_id, mline_index, candidates_.at(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001041 jdesc_.AddCandidate(&jice);
1042 }
1043 }
1044
Seth Hampson5b4f0752018-04-02 16:31:36 -07001045 void RemoveVideoCandidates() {
deadbeef25ed4352016-12-12 18:37:36 -08001046 const IceCandidateCollection* video_candidates_collection =
1047 jdesc_.candidates(1);
1048 ASSERT_NE(nullptr, video_candidates_collection);
1049 std::vector<cricket::Candidate> video_candidates;
1050 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1051 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1052 c.set_transport_name("video_content_name");
1053 video_candidates.push_back(c);
1054 }
1055 jdesc_.RemoveCandidates(video_candidates);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001056 }
1057
1058 // Turns the existing reference description into a description using
1059 // a=bundle-only. This means no transport attributes and a 0 port value on
1060 // the m= sections not associated with the BUNDLE-tag.
1061 void MakeBundleOnlyDescription() {
1062 RemoveVideoCandidates();
deadbeef25ed4352016-12-12 18:37:36 -08001063
1064 // And the rest of the transport attributes.
1065 desc_.transport_infos()[1].description.ice_ufrag.clear();
1066 desc_.transport_infos()[1].description.ice_pwd.clear();
1067 desc_.transport_infos()[1].description.connection_role =
1068 cricket::CONNECTIONROLE_NONE;
1069
1070 // Set bundle-only flag.
1071 desc_.contents()[1].bundle_only = true;
1072
1073 // Add BUNDLE group.
1074 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1075 group.AddContentName(kAudioContentName);
1076 group.AddContentName(kVideoContentName);
1077 desc_.AddGroup(group);
1078
1079 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1080 jdesc_.session_version()));
1081 }
1082
deadbeef9d3584c2016-02-16 17:54:10 -08001083 // Turns the existing reference description into a plan B description,
1084 // with 2 audio tracks and 3 video tracks.
1085 void MakePlanBDescription() {
Steve Antonb1c1de12017-12-21 15:14:30 -08001086 audio_desc_ = audio_desc_->Copy();
1087 video_desc_ = video_desc_->Copy();
deadbeef9d3584c2016-02-16 17:54:10 -08001088
1089 StreamParams audio_track_2;
1090 audio_track_2.id = kAudioTrackId2;
1091 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001092 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001093 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1094 audio_desc_->AddStream(audio_track_2);
1095
1096 StreamParams video_track_2;
1097 video_track_2.id = kVideoTrackId2;
1098 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001099 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001100 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1101 video_desc_->AddStream(video_track_2);
1102
1103 StreamParams video_track_3;
1104 video_track_3.id = kVideoTrackId3;
1105 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001106 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001107 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1108 video_desc_->AddStream(video_track_3);
1109
1110 desc_.RemoveContentByName(kAudioContentName);
1111 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001112 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1113 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001114
1115 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1116 jdesc_.session_version()));
1117 }
1118
1119 // Turns the existing reference description into a unified plan description,
1120 // with 2 audio tracks and 3 video tracks.
1121 void MakeUnifiedPlanDescription() {
1122 // Audio track 2.
1123 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1124 StreamParams audio_track_2;
1125 audio_track_2.id = kAudioTrackId2;
1126 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001127 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001128 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1129 audio_desc_2->AddStream(audio_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001130 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
deadbeef9d3584c2016-02-16 17:54:10 -08001131 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1132 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
deadbeef9d3584c2016-02-16 17:54:10 -08001133 // Video track 2, in stream 2.
1134 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1135 StreamParams video_track_2;
1136 video_track_2.id = kVideoTrackId2;
1137 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001138 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001139 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1140 video_desc_2->AddStream(video_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001141 desc_.AddContent(kVideoContentName2, MediaProtocolType::kRtp, video_desc_2);
deadbeef9d3584c2016-02-16 17:54:10 -08001142 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1143 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2))));
1144
1145 // Video track 3, in stream 2.
1146 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1147 StreamParams video_track_3;
1148 video_track_3.id = kVideoTrackId3;
1149 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001150 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001151 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1152 video_desc_3->AddStream(video_track_3);
Steve Anton5adfafd2017-12-20 16:34:00 -08001153 desc_.AddContent(kVideoContentName3, MediaProtocolType::kRtp, video_desc_3);
deadbeef9d3584c2016-02-16 17:54:10 -08001154 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1155 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3))));
Steve Antone831b8c2018-02-01 12:22:16 -08001156 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
deadbeef9d3584c2016-02-16 17:54:10 -08001157
1158 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1159 jdesc_.session_version()));
1160 }
1161
1162 // Creates an audio content description with no streams, and some default
1163 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001164 AudioContentDescription* CreateAudioContentDescription() {
1165 AudioContentDescription* audio = new AudioContentDescription();
1166 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -08001167 audio->set_rtcp_reduced_size(true);
Yves Gerey665174f2018-06-19 15:03:05 +02001168 audio->AddCrypto(CryptoParams(
1169 1, "AES_CM_128_HMAC_SHA1_32",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001170 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1171 "dummy_session_params"));
1172 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef67cf2c12016-04-13 10:07:16 -07001173 AudioCodec opus(111, "opus", 48000, 0, 2);
deadbeef9d3584c2016-02-16 17:54:10 -08001174 audio->AddCodec(opus);
ossue1405ad2017-01-23 08:55:48 -08001175 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1176 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001177 return audio;
1178 }
1179
Seth Hampson5b4f0752018-04-02 16:31:36 -07001180 // Turns the existing reference description into a unified plan description,
1181 // with 3 audio MediaContentDescriptions with special StreamParams that
1182 // contain 0 or multiple stream ids: - audio track 1 has 1 media stream id -
1183 // audio track 2 has 2 media stream ids - audio track 3 has 0 media stream ids
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001184 void MakeUnifiedPlanDescriptionMultipleStreamIds(const int msid_signaling) {
Seth Hampson5b4f0752018-04-02 16:31:36 -07001185 desc_.RemoveContentByName(kVideoContentName);
1186 desc_.RemoveTransportInfoByName(kVideoContentName);
1187 RemoveVideoCandidates();
1188
1189 // Audio track 2 has 2 media stream ids.
1190 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1191 StreamParams audio_track_2;
1192 audio_track_2.id = kAudioTrackId2;
1193 audio_track_2.cname = kStream1Cname;
1194 audio_track_2.set_stream_ids({kStreamId1, kStreamId2});
1195 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1196 audio_desc_2->AddStream(audio_track_2);
1197 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
1198 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1199 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
1200
1201 // Audio track 3 has no stream ids.
1202 AudioContentDescription* audio_desc_3 = CreateAudioContentDescription();
1203 StreamParams audio_track_3;
1204 audio_track_3.id = kAudioTrackId3;
1205 audio_track_3.cname = kStream2Cname;
1206 audio_track_3.set_stream_ids({});
1207 audio_track_3.ssrcs.push_back(kAudioTrack3Ssrc);
1208 audio_desc_3->AddStream(audio_track_3);
1209 desc_.AddContent(kAudioContentName3, MediaProtocolType::kRtp, audio_desc_3);
1210 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1211 kAudioContentName3, TransportDescription(kUfragVoice3, kPwdVoice3))));
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001212 desc_.set_msid_signaling(msid_signaling);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001213 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1214 jdesc_.session_version()));
1215 }
1216
Seth Hampson5897a6e2018-04-03 11:16:33 -07001217 // Turns the existing reference description into a unified plan description
1218 // with one audio MediaContentDescription that contains one StreamParams with
1219 // 0 ssrcs.
1220 void MakeUnifiedPlanDescriptionNoSsrcSignaling() {
1221 desc_.RemoveContentByName(kVideoContentName);
1222 desc_.RemoveContentByName(kAudioContentName);
1223 desc_.RemoveTransportInfoByName(kVideoContentName);
1224 RemoveVideoCandidates();
1225
1226 AudioContentDescription* audio_desc = CreateAudioContentDescription();
1227 StreamParams audio_track;
1228 audio_track.id = kAudioTrackId1;
1229 audio_track.set_stream_ids({kStreamId1});
1230 audio_desc->AddStream(audio_track);
1231 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc);
1232
1233 // Enable signaling a=msid lines.
1234 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
1235 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1236 jdesc_.session_version()));
1237 }
1238
deadbeef9d3584c2016-02-16 17:54:10 -08001239 // Creates a video content description with no streams, and some default
1240 // configuration.
1241 VideoContentDescription* CreateVideoContentDescription() {
1242 VideoContentDescription* video = new VideoContentDescription();
1243 video->AddCrypto(CryptoParams(
1244 1, "AES_CM_128_HMAC_SHA1_80",
1245 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1246 video->set_protocol(cricket::kMediaProtocolSavpf);
1247 video->AddCodec(
perkj26752742016-10-24 01:21:16 -07001248 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-16 17:54:10 -08001249 return video;
1250 }
1251
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001252 template <class MCD>
Yves Gerey665174f2018-06-19 15:03:05 +02001253 void CompareMediaContentDescription(const MCD* cd1, const MCD* cd2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001254 // type
1255 EXPECT_EQ(cd1->type(), cd1->type());
1256
1257 // content direction
1258 EXPECT_EQ(cd1->direction(), cd2->direction());
1259
1260 // rtcp_mux
1261 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1262
deadbeef13871492015-12-09 12:37:51 -08001263 // rtcp_reduced_size
1264 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1265
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001266 // cryptos
1267 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1268 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1269 ADD_FAILURE();
1270 return;
1271 }
Yves Gerey665174f2018-06-19 15:03:05 +02001272 for (size_t i = 0; i < cd1->cryptos().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001273 const CryptoParams c1 = cd1->cryptos().at(i);
1274 const CryptoParams c2 = cd2->cryptos().at(i);
1275 EXPECT_TRUE(c1.Matches(c2));
1276 EXPECT_EQ(c1.key_params, c2.key_params);
1277 EXPECT_EQ(c1.session_params, c2.session_params);
1278 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001279
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001280 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001281 // Use an equivalence class here, for old and new versions of the
1282 // protocol description.
Yves Gerey665174f2018-06-19 15:03:05 +02001283 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp ||
1284 cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1285 cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
lally@webrtc.org36300852015-02-24 20:19:35 +00001286 const bool cd2_is_also_dtls_sctp =
Yves Gerey665174f2018-06-19 15:03:05 +02001287 cd2->protocol() == cricket::kMediaProtocolDtlsSctp ||
1288 cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1289 cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
lally@webrtc.org36300852015-02-24 20:19:35 +00001290 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001291 } else {
1292 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1293 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001294
1295 // codecs
1296 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1297
1298 // bandwidth
1299 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1300
1301 // streams
1302 EXPECT_EQ(cd1->streams(), cd2->streams());
1303
Johannes Kron0854eb62018-10-10 22:33:20 +02001304 // extmap-allow-mixed
Johannes Kron9581bc42018-10-23 10:17:39 +02001305 EXPECT_EQ(cd1->extmap_allow_mixed_enum(), cd2->extmap_allow_mixed_enum());
Johannes Kron0854eb62018-10-10 22:33:20 +02001306
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001307 // extmap
1308 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1309 cd2->rtp_header_extensions().size());
Yves Gerey665174f2018-06-19 15:03:05 +02001310 for (size_t i = 0; i < cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 11:24:55 -07001311 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1312 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001313 EXPECT_EQ(ext1.uri, ext2.uri);
1314 EXPECT_EQ(ext1.id, ext2.id);
jbauch5869f502017-06-29 12:31:36 -07001315 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001316 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001317 }
1318
Amit Hilbucha2012042018-12-03 11:35:05 -08001319 void CompareSimulcastDescription(const SimulcastDescription& simulcast1,
1320 const SimulcastDescription& simulcast2) {
1321 EXPECT_EQ(simulcast1.send_layers().size(), simulcast2.send_layers().size());
1322 EXPECT_EQ(simulcast1.receive_layers().size(),
1323 simulcast2.receive_layers().size());
1324 }
1325
zstein4b2e0822017-02-17 19:48:38 -08001326 void CompareDataContentDescription(const DataContentDescription* dcd1,
1327 const DataContentDescription* dcd2) {
1328 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
1329 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
1330 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001331
1332 void CompareSessionDescription(const SessionDescription& desc1,
1333 const SessionDescription& desc2) {
1334 // Compare content descriptions.
1335 if (desc1.contents().size() != desc2.contents().size()) {
1336 ADD_FAILURE();
1337 return;
1338 }
Yves Gerey665174f2018-06-19 15:03:05 +02001339 for (size_t i = 0; i < desc1.contents().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001340 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1341 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-12 18:37:36 -08001342 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001343 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-12 18:37:36 -08001344 EXPECT_EQ(c1.type, c2.type);
1345 EXPECT_EQ(c1.rejected, c2.rejected);
1346 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001347
1348 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1349 if (IsAudioContent(&c1)) {
1350 const AudioContentDescription* acd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001351 c1.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001352 const AudioContentDescription* acd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001353 c2.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001354 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1355 }
1356
1357 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1358 if (IsVideoContent(&c1)) {
1359 const VideoContentDescription* vcd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001360 c1.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001361 const VideoContentDescription* vcd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001362 c2.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001363 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1364 }
1365
1366 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
1367 if (IsDataContent(&c1)) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001368 const DataContentDescription* dcd1 = c1.media_description()->as_data();
1369 const DataContentDescription* dcd2 = c2.media_description()->as_data();
zstein4b2e0822017-02-17 19:48:38 -08001370 CompareDataContentDescription(dcd1, dcd2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001371 }
Amit Hilbucha2012042018-12-03 11:35:05 -08001372
1373 CompareSimulcastDescription(
1374 c1.media_description()->simulcast_description(),
1375 c2.media_description()->simulcast_description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001376 }
1377
1378 // group
1379 const cricket::ContentGroups groups1 = desc1.groups();
1380 const cricket::ContentGroups groups2 = desc2.groups();
1381 EXPECT_EQ(groups1.size(), groups1.size());
1382 if (groups1.size() != groups2.size()) {
1383 ADD_FAILURE();
1384 return;
1385 }
1386 for (size_t i = 0; i < groups1.size(); ++i) {
1387 const cricket::ContentGroup group1 = groups1.at(i);
1388 const cricket::ContentGroup group2 = groups2.at(i);
1389 EXPECT_EQ(group1.semantics(), group2.semantics());
1390 const cricket::ContentNames names1 = group1.content_names();
1391 const cricket::ContentNames names2 = group2.content_names();
1392 EXPECT_EQ(names1.size(), names2.size());
1393 if (names1.size() != names2.size()) {
1394 ADD_FAILURE();
1395 return;
1396 }
1397 cricket::ContentNames::const_iterator iter1 = names1.begin();
1398 cricket::ContentNames::const_iterator iter2 = names2.begin();
1399 while (iter1 != names1.end()) {
1400 EXPECT_EQ(*iter1++, *iter2++);
1401 }
1402 }
1403
1404 // transport info
1405 const cricket::TransportInfos transports1 = desc1.transport_infos();
1406 const cricket::TransportInfos transports2 = desc2.transport_infos();
1407 EXPECT_EQ(transports1.size(), transports2.size());
1408 if (transports1.size() != transports2.size()) {
1409 ADD_FAILURE();
1410 return;
1411 }
1412 for (size_t i = 0; i < transports1.size(); ++i) {
1413 const cricket::TransportInfo transport1 = transports1.at(i);
1414 const cricket::TransportInfo transport2 = transports2.at(i);
1415 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001416 EXPECT_EQ(transport1.description.ice_ufrag,
1417 transport2.description.ice_ufrag);
Yves Gerey665174f2018-06-19 15:03:05 +02001418 EXPECT_EQ(transport1.description.ice_pwd, transport2.description.ice_pwd);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07001419 EXPECT_EQ(transport1.description.ice_mode,
1420 transport2.description.ice_mode);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001421 if (transport1.description.identity_fingerprint) {
1422 EXPECT_EQ(*transport1.description.identity_fingerprint,
1423 *transport2.description.identity_fingerprint);
1424 } else {
1425 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1426 transport2.description.identity_fingerprint.get());
1427 }
1428 EXPECT_EQ(transport1.description.transport_options,
1429 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001430 }
deadbeefc80741f2015-10-22 13:14:45 -07001431
1432 // global attributes
1433 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
Johannes Kron9581bc42018-10-23 10:17:39 +02001434 EXPECT_EQ(desc1.extmap_allow_mixed(), desc2.extmap_allow_mixed());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001435 }
1436
Yves Gerey665174f2018-06-19 15:03:05 +02001437 bool CompareSessionDescription(const JsepSessionDescription& desc1,
1438 const JsepSessionDescription& desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001439 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1440 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1441 CompareSessionDescription(*desc1.description(), *desc2.description());
1442 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1443 return false;
1444 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1445 const IceCandidateCollection* cc1 = desc1.candidates(i);
1446 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-12 18:37:36 -08001447 if (cc1->count() != cc2->count()) {
1448 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001449 return false;
deadbeef25ed4352016-12-12 18:37:36 -08001450 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001451 for (size_t j = 0; j < cc1->count(); ++j) {
1452 const IceCandidateInterface* c1 = cc1->at(j);
1453 const IceCandidateInterface* c2 = cc2->at(j);
1454 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1455 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1456 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1457 }
1458 }
1459 return true;
1460 }
1461
1462 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1463 // them with invalid keywords so that the parser will just ignore them.
1464 bool RemoveCandidateUfragPwd(std::string* sdp) {
1465 const char ice_ufrag[] = "a=ice-ufrag";
1466 const char ice_ufragx[] = "a=xice-ufrag";
1467 const char ice_pwd[] = "a=ice-pwd";
1468 const char ice_pwdx[] = "a=xice-pwd";
Yves Gerey665174f2018-06-19 15:03:05 +02001469 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag), ice_ufragx,
1470 strlen(ice_ufragx), sdp);
1471 rtc::replace_substrs(ice_pwd, strlen(ice_pwd), ice_pwdx, strlen(ice_pwdx),
1472 sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001473 return true;
1474 }
1475
1476 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
Yves Gerey665174f2018-06-19 15:03:05 +02001477 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc,
1478 int mline_index,
1479 const std::string& ufrag,
1480 const std::string& pwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001481 std::string content_name;
1482 if (mline_index == 0) {
1483 content_name = kAudioContentName;
1484 } else if (mline_index == 1) {
1485 content_name = kVideoContentName;
1486 } else {
nissec80e7412017-01-11 05:56:46 -08001487 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001488 }
Yves Gerey665174f2018-06-19 15:03:05 +02001489 TransportInfo transport_info(content_name,
1490 TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001491 SessionDescription* desc =
1492 const_cast<SessionDescription*>(jdesc->description());
1493 desc->RemoveTransportInfoByName(content_name);
1494 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
1495 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1496 const IceCandidateCollection* cc = jdesc_.candidates(i);
1497 for (size_t j = 0; j < cc->count(); ++j) {
1498 if (cc->at(j)->sdp_mline_index() == mline_index) {
Yves Gerey665174f2018-06-19 15:03:05 +02001499 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(ufrag);
1500 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001501 }
1502 }
1503 }
1504 return true;
1505 }
1506
1507 void AddIceOptions(const std::string& content_name,
1508 const std::vector<std::string>& transport_options) {
1509 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1510 cricket::TransportInfo transport_info =
1511 *(desc_.GetTransportInfoByName(content_name));
1512 desc_.RemoveTransportInfoByName(content_name);
1513 transport_info.description.transport_options = transport_options;
1514 desc_.AddTransportInfo(transport_info);
1515 }
1516
deadbeef3f7219b2015-12-28 15:17:14 -08001517 void SetIceUfragPwd(const std::string& content_name,
1518 const std::string& ice_ufrag,
1519 const std::string& ice_pwd) {
1520 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1521 cricket::TransportInfo transport_info =
1522 *(desc_.GetTransportInfoByName(content_name));
1523 desc_.RemoveTransportInfoByName(content_name);
1524 transport_info.description.ice_ufrag = ice_ufrag;
1525 transport_info.description.ice_pwd = ice_pwd;
1526 desc_.AddTransportInfo(transport_info);
1527 }
1528
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001529 void AddFingerprint() {
1530 desc_.RemoveTransportInfoByName(kAudioContentName);
1531 desc_.RemoveTransportInfoByName(kVideoContentName);
Steve Anton4905edb2018-10-15 19:27:44 -07001532 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, kIdentityDigest);
deadbeef46eed762016-01-28 13:24:37 -08001533 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1534 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001535 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1536 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001537 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1538 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1539 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001540 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1541 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001542 cricket::CONNECTIONROLE_NONE, &fingerprint))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001543 }
1544
jbauch5869f502017-06-29 12:31:36 -07001545 void AddExtmap(bool encrypted) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001546 audio_desc_ = audio_desc_->Copy();
1547 video_desc_ = video_desc_->Copy();
jbauch5869f502017-06-29 12:31:36 -07001548 audio_desc_->AddRtpHeaderExtension(
1549 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1550 video_desc_->AddRtpHeaderExtension(
1551 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001552 desc_.RemoveContentByName(kAudioContentName);
1553 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001554 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1555 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001556 }
1557
1558 void RemoveCryptos() {
1559 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1560 video_desc_->set_cryptos(std::vector<CryptoParams>());
1561 }
1562
Seth Hampson5897a6e2018-04-03 11:16:33 -07001563 // Removes everything in StreamParams from the session description that is
1564 // used for a=ssrc lines.
1565 void RemoveSsrcSignalingFromStreamParams() {
1566 for (cricket::ContentInfo content_info : jdesc_.description()->contents()) {
1567 // With Unified Plan there should be one StreamParams per m= section.
1568 StreamParams& stream =
1569 content_info.media_description()->mutable_streams()[0];
1570 stream.ssrcs.clear();
1571 stream.ssrc_groups.clear();
1572 stream.cname.clear();
1573 }
1574 }
1575
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001576 // Removes all a=ssrc lines from the SDP string, except for the
1577 // "a=ssrc:... cname:..." lines.
1578 void RemoveSsrcMsidLinesFromSdpString(std::string* sdp_string) {
1579 const char kAttributeSsrc[] = "a=ssrc";
1580 const char kAttributeCname[] = "cname";
1581 size_t ssrc_line_pos = sdp_string->find(kAttributeSsrc);
1582 while (ssrc_line_pos != std::string::npos) {
1583 size_t beg_line_pos = sdp_string->rfind('\n', ssrc_line_pos);
1584 size_t end_line_pos = sdp_string->find('\n', ssrc_line_pos);
1585 size_t cname_pos = sdp_string->find(kAttributeCname, ssrc_line_pos);
1586 if (cname_pos == std::string::npos || cname_pos > end_line_pos) {
1587 // Only erase a=ssrc lines that don't contain "cname".
1588 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1589 ssrc_line_pos = sdp_string->find(kAttributeSsrc, beg_line_pos);
1590 } else {
1591 // Skip the "a=ssrc:... cname" line and find the next "a=ssrc" line.
1592 ssrc_line_pos = sdp_string->find(kAttributeSsrc, end_line_pos);
1593 }
1594 }
1595 }
1596
Seth Hampson5897a6e2018-04-03 11:16:33 -07001597 // Removes all a=ssrc lines from the SDP string.
1598 void RemoveSsrcLinesFromSdpString(std::string* sdp_string) {
1599 const char kAttributeSsrc[] = "a=ssrc";
1600 while (sdp_string->find(kAttributeSsrc) != std::string::npos) {
1601 size_t pos_ssrc_attribute = sdp_string->find(kAttributeSsrc);
1602 size_t beg_line_pos = sdp_string->rfind('\n', pos_ssrc_attribute);
1603 size_t end_line_pos = sdp_string->find('\n', pos_ssrc_attribute);
1604 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1605 }
1606 }
1607
Steve Anton4e70a722017-11-28 14:57:10 -08001608 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001609 audio_desc_->set_direction(direction);
1610 video_desc_->set_direction(direction);
1611 std::string new_sdp = kSdpFullString;
1612 ReplaceDirection(direction, &new_sdp);
1613
Yves Gerey665174f2018-06-19 15:03:05 +02001614 if (!jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001615 jdesc_.session_version())) {
1616 return false;
1617 }
Steve Antone831b8c2018-02-01 12:22:16 -08001618 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001619 EXPECT_EQ(new_sdp, message);
1620 return true;
1621 }
1622
1623 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001624 audio_desc_ = audio_desc_->Copy();
1625 video_desc_ = video_desc_->Copy();
zhihuang38989e52017-03-21 11:04:53 -07001626
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001627 desc_.RemoveContentByName(kAudioContentName);
1628 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001629 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001630 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001631 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001632 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001633 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1634 audio_rejected ? "" : kPwdVoice);
1635 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1636 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001637
1638 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001639 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1640
Steve Antona3a92c22017-12-07 10:27:41 -08001641 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001642 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001643 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001644 EXPECT_EQ(new_sdp, message);
1645 return true;
1646 }
1647
zstein4b2e0822017-02-17 19:48:38 -08001648 void AddSctpDataChannel(bool use_sctpmap) {
kwibergd1fe2812016-04-27 06:47:29 -07001649 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001650 data_desc_ = data.get();
zstein4b2e0822017-02-17 19:48:38 -08001651 data_desc_->set_use_sctpmap(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001652 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
solenberg9fa49752016-10-08 13:02:44 -07001653 DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07001654 cricket::kGoogleSctpDataCodecName);
wu@webrtc.org78187522013-10-07 23:32:02 +00001655 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1656 data_desc_->AddCodec(codec);
Steve Anton5adfafd2017-12-20 16:34:00 -08001657 desc_.AddContent(kDataContentName, MediaProtocolType::kSctp,
1658 data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001659 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1660 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001661 }
1662
1663 void AddRtpDataChannel() {
kwibergd1fe2812016-04-27 06:47:29 -07001664 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001665 data_desc_ = data.get();
1666
deadbeef67cf2c12016-04-13 10:07:16 -07001667 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001668 StreamParams data_stream;
1669 data_stream.id = kDataChannelMsid;
1670 data_stream.cname = kDataChannelCname;
Seth Hampson845e8782018-03-02 11:34:10 -08001671 data_stream.set_stream_ids({kDataChannelLabel});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001672 data_stream.ssrcs.push_back(kDataChannelSsrc);
1673 data_desc_->AddStream(data_stream);
Yves Gerey665174f2018-06-19 15:03:05 +02001674 data_desc_->AddCrypto(
1675 CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
1676 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001677 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
Steve Anton5adfafd2017-12-20 16:34:00 -08001678 desc_.AddContent(kDataContentName, MediaProtocolType::kRtp, data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001679 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1680 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001681 }
1682
Steve Anton4e70a722017-11-28 14:57:10 -08001683 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001684 std::string new_sdp = kSdpFullString;
1685 ReplaceDirection(direction, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001686 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001687
1688 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1689
1690 audio_desc_->set_direction(direction);
1691 video_desc_->set_direction(direction);
Yves Gerey665174f2018-06-19 15:03:05 +02001692 if (!jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001693 jdesc_.session_version())) {
1694 return false;
1695 }
1696 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1697 return true;
1698 }
1699
1700 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001701 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001702 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001703 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001704 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001705
Steve Antonb1c1de12017-12-21 15:14:30 -08001706 audio_desc_ = audio_desc_->Copy();
1707 video_desc_ = video_desc_->Copy();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001708 desc_.RemoveContentByName(kAudioContentName);
1709 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001710 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001711 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001712 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001713 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001714 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1715 audio_rejected ? "" : kPwdVoice);
1716 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1717 video_rejected ? "" : kPwdVideo);
Steve Antona3a92c22017-12-07 10:27:41 -08001718 JsepSessionDescription jdesc_no_candidates(kDummyType);
deadbeef3f7219b2015-12-28 15:17:14 -08001719 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1720 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001721 return false;
1722 }
deadbeef3f7219b2015-12-28 15:17:14 -08001723 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001724 return true;
1725 }
1726
Yves Gerey665174f2018-06-19 15:03:05 +02001727 void TestDeserializeExtmap(bool session_level,
1728 bool media_level,
1729 bool encrypted) {
jbauch5869f502017-06-29 12:31:36 -07001730 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08001731 JsepSessionDescription new_jdesc(SdpType::kOffer);
Yves Gerey665174f2018-06-19 15:03:05 +02001732 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001733 jdesc_.session_version()));
Steve Antona3a92c22017-12-07 10:27:41 -08001734 JsepSessionDescription jdesc_with_extmap(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001735 std::string sdp_with_extmap = kSdpString;
1736 if (session_level) {
jbauch5869f502017-06-29 12:31:36 -07001737 InjectAfter(kSessionTime,
1738 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1739 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001740 &sdp_with_extmap);
1741 }
1742 if (media_level) {
jbauch5869f502017-06-29 12:31:36 -07001743 InjectAfter(kAttributeIcePwdVoice,
1744 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1745 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001746 &sdp_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07001747 InjectAfter(kAttributeIcePwdVideo,
1748 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1749 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001750 &sdp_with_extmap);
1751 }
1752 // The extmap can't be present at the same time in both session level and
1753 // media level.
1754 if (session_level && media_level) {
1755 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02001756 EXPECT_FALSE(
1757 webrtc::SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001758 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1759 } else {
1760 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1761 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1762 }
1763 }
1764
1765 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
Yves Gerey665174f2018-06-19 15:03:05 +02001766 const std::string& name,
1767 int expected_value) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001768 cricket::CodecParameterMap::const_iterator found = params.find(name);
1769 ASSERT_TRUE(found != params.end());
Jonas Olsson6b1985d2018-07-05 11:59:48 +02001770 EXPECT_EQ(found->second, rtc::ToString(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001771 }
1772
1773 void TestDeserializeCodecParams(const CodecParams& params,
1774 JsepSessionDescription* jdesc_output) {
1775 std::string sdp =
1776 "v=0\r\n"
1777 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1778 "s=-\r\n"
1779 "t=0 0\r\n"
1780 // Include semantics for WebRTC Media Streams since it is supported by
1781 // this parser, and will be added to the SDP when serializing a session
1782 // description.
1783 "a=msid-semantic: WMS\r\n"
1784 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001785 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001786 // Pltype 111 listed before 103 and 104 in the map.
1787 "a=rtpmap:111 opus/48000/2\r\n"
1788 // Pltype 103 listed before 104.
1789 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001790 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001791 "a=fmtp:111 0-15,66,70\r\n"
1792 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001793 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001794 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001795 << "; sprop-stereo=" << params.sprop_stereo
1796 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001797 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001798 << "a=ptime:" << params.ptime << "\r\n"
1799 << "a=maxptime:" << params.max_ptime << "\r\n";
1800 sdp += os.str();
1801
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001802 os.clear();
1803 os.str("");
1804 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001805 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001806 << "a=rtpmap:99 VP8/90000\r\n"
1807 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001808 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001809 sdp += os.str();
1810
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001811 // Deserialize
1812 SdpParseError error;
1813 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1814
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001815 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001816 GetFirstAudioContentDescription(jdesc_output->description());
1817 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001818 ASSERT_FALSE(acd->codecs().empty());
1819 cricket::AudioCodec opus = acd->codecs()[0];
1820 EXPECT_EQ("opus", opus.name);
1821 EXPECT_EQ(111, opus.id);
1822 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1823 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1824 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1825 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001826 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1827 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001828 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1829 cricket::AudioCodec codec = acd->codecs()[i];
1830 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1831 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001832 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001833
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001834 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001835 GetFirstVideoContentDescription(jdesc_output->description());
1836 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001837 ASSERT_FALSE(vcd->codecs().empty());
1838 cricket::VideoCodec vp8 = vcd->codecs()[0];
1839 EXPECT_EQ("VP8", vp8.name);
1840 EXPECT_EQ(99, vp8.id);
1841 cricket::VideoCodec rtx = vcd->codecs()[1];
1842 EXPECT_EQ("RTX", rtx.name);
1843 EXPECT_EQ(95, rtx.id);
1844 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001845 }
1846
1847 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1848 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001849 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001850 "v=0\r\n"
1851 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1852 "s=-\r\n"
1853 "t=0 0\r\n"
1854 // Include semantics for WebRTC Media Streams since it is supported by
1855 // this parser, and will be added to the SDP when serializing a session
1856 // description.
1857 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001858 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001859 "a=rtpmap:111 opus/48000/2\r\n";
1860 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001861 "m=video 3457 RTP/SAVPF 101\r\n"
1862 "a=rtpmap:101 VP8/90000\r\n"
1863 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001864 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001865 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001866 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001867 os << sdp_session_and_audio;
Yves Gerey665174f2018-06-19 15:03:05 +02001868 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001869 os << sdp_video;
Yves Gerey665174f2018-06-19 15:03:05 +02001870 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001871 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001872 // Deserialize
1873 SdpParseError error;
1874 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001875 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001876 GetFirstAudioContentDescription(jdesc_output->description());
1877 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001878 ASSERT_FALSE(acd->codecs().empty());
1879 cricket::AudioCodec opus = acd->codecs()[0];
1880 EXPECT_EQ(111, opus.id);
Yves Gerey665174f2018-06-19 15:03:05 +02001881 EXPECT_TRUE(opus.HasFeedbackParam(cricket::FeedbackParam(
1882 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001883
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001884 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001885 GetFirstVideoContentDescription(jdesc_output->description());
1886 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001887 ASSERT_FALSE(vcd->codecs().empty());
1888 cricket::VideoCodec vp8 = vcd->codecs()[0];
1889 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1890 vp8.name.c_str());
1891 EXPECT_EQ(101, vp8.id);
Yves Gerey665174f2018-06-19 15:03:05 +02001892 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1893 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
1894 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1895 cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli)));
1896 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1897 cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty)));
1898 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1899 cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001900 }
1901
1902 // Two SDP messages can mean the same thing but be different strings, e.g.
1903 // some of the lines can be serialized in different order.
1904 // However, a deserialized description can be compared field by field and has
1905 // no order. If deserializer has already been tested, serializing then
1906 // deserializing and comparing JsepSessionDescription will test
1907 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 12:22:16 -08001908 void TestSerialize(const JsepSessionDescription& jdesc) {
1909 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 10:27:41 -08001910 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001911 SdpParseError error;
1912 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1913 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1914 }
1915
zhihuang38989e52017-03-21 11:04:53 -07001916 // Calling 'Initialize' with a copy of the inner SessionDescription will
1917 // create a copy of the JsepSessionDescription without candidates. The
1918 // 'connection address' field, previously set from the candidates, must also
1919 // be reset.
1920 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
1921 rtc::SocketAddress audio_addr("0.0.0.0", 9);
1922 rtc::SocketAddress video_addr("0.0.0.0", 9);
1923 audio_desc_->set_connection_address(audio_addr);
1924 video_desc_->set_connection_address(video_addr);
1925 ASSERT_TRUE(jdesc->Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1926 }
1927
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001928 protected:
1929 SessionDescription desc_;
1930 AudioContentDescription* audio_desc_;
1931 VideoContentDescription* video_desc_;
1932 DataContentDescription* data_desc_;
1933 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07001934 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001935 JsepSessionDescription jdesc_;
1936};
1937
1938void TestMismatch(const std::string& string1, const std::string& string2) {
1939 int position = 0;
1940 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1941 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001942 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001943 break;
1944 }
1945 }
1946 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1947 << " character\n"
1948 << " 1: " << string1.substr(position, 20) << "\n"
1949 << " 2: " << string2.substr(position, 20) << "\n";
1950}
1951
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001952TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1953 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 12:22:16 -08001954 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001955 TestMismatch(std::string(kSdpFullString), message);
1956}
1957
1958TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 10:27:41 -08001959 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 12:22:16 -08001960 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001961}
1962
1963// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1964// the case in a DTLS offer.
1965TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1966 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08001967 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001968 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08001969 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001970
1971 std::string sdp_with_fingerprint = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02001972 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1973 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001974
1975 EXPECT_EQ(sdp_with_fingerprint, message);
1976}
1977
1978// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1979// be the case in a DTLS answer.
1980TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1981 AddFingerprint();
1982 RemoveCryptos();
Steve Antona3a92c22017-12-07 10:27:41 -08001983 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001984 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08001985 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001986
1987 std::string sdp_with_fingerprint = kSdpString;
1988 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1989 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
Yves Gerey665174f2018-06-19 15:03:05 +02001990 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1991 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001992
1993 EXPECT_EQ(sdp_with_fingerprint, message);
1994}
1995
1996TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1997 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08001998 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001999 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08002000 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002001 EXPECT_EQ(std::string(kSdpString), message);
2002}
2003
2004TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
2005 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2006 group.AddContentName(kAudioContentName);
2007 group.AddContentName(kVideoContentName);
2008 desc_.AddGroup(group);
Yves Gerey665174f2018-06-19 15:03:05 +02002009 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002010 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002011 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002012 std::string sdp_with_bundle = kSdpFullString;
2013 InjectAfter(kSessionTime,
2014 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2015 &sdp_with_bundle);
2016 EXPECT_EQ(sdp_with_bundle, message);
2017}
2018
2019TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 15:14:30 -08002020 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002021 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002022 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002023 acd->set_bandwidth(50 * 1000);
Yves Gerey665174f2018-06-19 15:03:05 +02002024 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002025 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002026 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002027 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002028 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002029 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002030 InjectAfter("c=IN IP4 74.125.127.126\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002031 &sdp_with_bandwidth);
2032 EXPECT_EQ(sdp_with_bandwidth, message);
2033}
2034
2035TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
2036 std::vector<std::string> transport_options;
2037 transport_options.push_back(kIceOption1);
2038 transport_options.push_back(kIceOption3);
2039 AddIceOptions(kAudioContentName, transport_options);
2040 transport_options.clear();
2041 transport_options.push_back(kIceOption2);
2042 transport_options.push_back(kIceOption3);
2043 AddIceOptions(kVideoContentName, transport_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002044 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002045 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002046 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002047 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002048 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002049 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002050 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002051 &sdp_with_ice_options);
2052 EXPECT_EQ(sdp_with_ice_options, message);
2053}
2054
2055TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002056 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002057}
2058
2059TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002060 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002061}
2062
2063TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002064 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002065}
2066
2067TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2068 EXPECT_TRUE(TestSerializeRejected(true, false));
2069}
2070
2071TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2072 EXPECT_TRUE(TestSerializeRejected(false, true));
2073}
2074
2075TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2076 EXPECT_TRUE(TestSerializeRejected(true, true));
2077}
2078
2079TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
2080 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002081 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002082
zhihuang38989e52017-03-21 11:04:53 -07002083 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002084 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002085
2086 std::string expected_sdp = kSdpString;
2087 expected_sdp.append(kSdpRtpDataChannelString);
2088 EXPECT_EQ(expected_sdp, message);
2089}
2090
2091TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08002092 bool use_sctpmap = true;
2093 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002094 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002095
zhihuang38989e52017-03-21 11:04:53 -07002096 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002097 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002098
2099 std::string expected_sdp = kSdpString;
2100 expected_sdp.append(kSdpSctpDataChannelString);
2101 EXPECT_EQ(message, expected_sdp);
2102}
2103
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002104TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08002105 bool use_sctpmap = true;
2106 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002107 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002108 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antonb1c1de12017-12-21 15:14:30 -08002109 DataContentDescription* dcdesc =
2110 jsep_desc.description()
2111 ->GetContentDescriptionByName(kDataContentName)
2112 ->as_data();
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002113
2114 const int kNewPort = 1234;
solenberg9fa49752016-10-08 13:02:44 -07002115 cricket::DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07002116 cricket::kGoogleSctpDataCodecName);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002117 codec.SetParam(cricket::kCodecParamPort, kNewPort);
2118 dcdesc->AddOrReplaceCodec(codec);
2119
Steve Antone831b8c2018-02-01 12:22:16 -08002120 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002121
2122 std::string expected_sdp = kSdpString;
2123 expected_sdp.append(kSdpSctpDataChannelString);
2124
2125 char default_portstr[16];
2126 char new_portstr[16];
Niels Mölleraba06332018-10-16 15:14:15 +02002127 snprintf(default_portstr, sizeof(default_portstr), "%d", kDefaultSctpPort);
2128 snprintf(new_portstr, sizeof(new_portstr), "%d", kNewPort);
Yves Gerey665174f2018-06-19 15:03:05 +02002129 rtc::replace_substrs(default_portstr, strlen(default_portstr), new_portstr,
2130 strlen(new_portstr), &expected_sdp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002131
2132 EXPECT_EQ(expected_sdp, message);
2133}
2134
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002135TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002136 JsepSessionDescription jsep_desc(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002137 AddRtpDataChannel();
Yves Gerey665174f2018-06-19 15:03:05 +02002138 data_desc_->set_bandwidth(100 * 1000);
zhihuang38989e52017-03-21 11:04:53 -07002139 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002140 std::string message = webrtc::SdpSerialize(jsep_desc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002141
2142 std::string expected_sdp = kSdpString;
2143 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002144 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00002145 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02002146 "b=AS:100\r\n", &expected_sdp);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002147 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002148}
2149
Johannes Kron0854eb62018-10-10 22:33:20 +02002150TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002151 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002152 TestSerialize(jdesc_);
2153}
2154
2155TEST_F(WebRtcSdpTest, SerializeMediaContentDescriptionWithExtmapAllowMixed) {
2156 cricket::MediaContentDescription* video_desc =
2157 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2158 ASSERT_TRUE(video_desc);
2159 cricket::MediaContentDescription* audio_desc =
2160 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2161 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002162 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002163 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002164 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002165 cricket::MediaContentDescription::kMedia);
2166 TestSerialize(jdesc_);
2167}
2168
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002169TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002170 bool encrypted = false;
2171 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002172 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002173 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 12:22:16 -08002174 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002175
2176 std::string sdp_with_extmap = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002177 InjectAfter("a=mid:audio_content_name\r\n", kExtmap, &sdp_with_extmap);
2178 InjectAfter("a=mid:video_content_name\r\n", kExtmap, &sdp_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002179
2180 EXPECT_EQ(sdp_with_extmap, message);
2181}
2182
jbauch5869f502017-06-29 12:31:36 -07002183TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2184 bool encrypted = true;
2185 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002186 JsepSessionDescription desc_with_extmap(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002187 ASSERT_TRUE(
2188 desc_with_extmap.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 12:22:16 -08002189 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07002190}
2191
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002192TEST_F(WebRtcSdpTest, SerializeCandidates) {
2193 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002194 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002195
2196 Candidate candidate_with_ufrag(candidates_.front());
2197 candidate_with_ufrag.set_username("ABC");
2198 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2199 candidate_with_ufrag));
2200 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2201 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002202
2203 Candidate candidate_with_network_info(candidates_.front());
2204 candidate_with_network_info.set_network_id(1);
2205 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2206 candidate_with_network_info));
2207 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2208 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2209 candidate_with_network_info.set_network_cost(999);
2210 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2211 candidate_with_network_info));
2212 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2213 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2214 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002215}
2216
Zach Steinb336c272018-08-09 01:16:13 -07002217TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) {
2218 rtc::SocketAddress address("a.test", 1234);
2219 cricket::Candidate candidate(
2220 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
2221 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
2222 JsepIceCandidate jcandidate(std::string("audio_content_name"), 0, candidate);
2223 std::string message = webrtc::SdpSerializeCandidate(jcandidate);
2224 EXPECT_EQ(std::string(kRawHostnameCandidate), message);
2225}
2226
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002227// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2228// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002229TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002230 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002231 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2232 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2233 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002234 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002235 std::unique_ptr<IceCandidateInterface> jcandidate(
2236 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002237
2238 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2239 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2240}
2241
htaa6b99442016-04-12 10:29:17 -07002242TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002243 cricket::VideoCodec h264_codec("H264");
2244 h264_codec.SetParam("profile-level-id", "42e01f");
2245 h264_codec.SetParam("level-asymmetry-allowed", "1");
2246 h264_codec.SetParam("packetization-mode", "1");
2247 video_desc_->AddCodec(h264_codec);
2248
htaa6b99442016-04-12 10:29:17 -07002249 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
2250
Steve Antone831b8c2018-02-01 12:22:16 -08002251 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 10:29:17 -07002252 size_t after_pt = message.find(" H264/90000");
2253 ASSERT_NE(after_pt, std::string::npos);
2254 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2255 ASSERT_NE(before_pt, std::string::npos);
2256 before_pt += strlen("a=rtpmap:");
2257 std::string pt = message.substr(before_pt, after_pt - before_pt);
2258 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2259 std::string to_find = "a=fmtp:" + pt + " ";
2260 size_t fmtp_pos = message.find(to_find);
2261 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
2262 size_t fmtp_endpos = message.find("\n", fmtp_pos);
2263 ASSERT_NE(std::string::npos, fmtp_endpos);
2264 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2265 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2266 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2267 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002268 // Check that there are no spaces after semicolons.
2269 // https://bugs.webrtc.org/5793
2270 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002271}
2272
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002273TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 10:27:41 -08002274 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002275 // Deserialize
2276 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2277 // Verify
2278 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2279}
2280
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002281TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 10:27:41 -08002282 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002283 const char kSdpWithoutMline[] =
Yves Gerey665174f2018-06-19 15:03:05 +02002284 "v=0\r\n"
2285 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2286 "s=-\r\n"
2287 "t=0 0\r\n"
2288 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002289 // Deserialize
2290 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2291 EXPECT_EQ(0u, jdesc.description()->contents().size());
2292}
2293
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002294TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 10:27:41 -08002295 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002296 std::string sdp_without_carriage_return = kSdpFullString;
2297 Replace("\r\n", "\n", &sdp_without_carriage_return);
2298 // Deserialize
2299 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2300 // Verify
2301 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2302}
2303
2304TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2305 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002306 JsepSessionDescription jdesc_no_candidates(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002307 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
2308 kSessionVersion));
Steve Antona3a92c22017-12-07 10:27:41 -08002309 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002310 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2311 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2312}
2313
2314TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2315 static const char kSdpNoRtpmapString[] =
2316 "v=0\r\n"
2317 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2318 "s=-\r\n"
2319 "t=0 0\r\n"
2320 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2321 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002322 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002323 // The rtpmap line for static payload codec is optional.
2324 "a=rtpmap:18 G729/16000\r\n"
2325 "a=rtpmap:103 ISAC/16000\r\n";
2326
Steve Antona3a92c22017-12-07 10:27:41 -08002327 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002328 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2329 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002330 jdesc.description()
2331 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2332 ->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002333 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002334 // The codecs in the AudioContentDescription should be in the same order as
2335 // the payload types (<fmt>s) on the m= line.
2336 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2337 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002338 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002339 EXPECT_EQ(ref_codecs, audio->codecs());
2340}
2341
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002342TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2343 static const char kSdpNoRtpmapString[] =
2344 "v=0\r\n"
2345 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2346 "s=-\r\n"
2347 "t=0 0\r\n"
2348 "m=audio 49232 RTP/AVP 18 103\r\n"
2349 "a=fmtp:18 annexb=yes\r\n"
2350 "a=rtpmap:103 ISAC/16000\r\n";
2351
Steve Antona3a92c22017-12-07 10:27:41 -08002352 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002353 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2354 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002355 jdesc.description()
2356 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2357 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002358
2359 cricket::AudioCodec g729 = audio->codecs()[0];
2360 EXPECT_EQ("G729", g729.name);
2361 EXPECT_EQ(8000, g729.clockrate);
2362 EXPECT_EQ(18, g729.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002363 cricket::CodecParameterMap::iterator found = g729.params.find("annexb");
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002364 ASSERT_TRUE(found != g729.params.end());
2365 EXPECT_EQ(found->second, "yes");
2366
2367 cricket::AudioCodec isac = audio->codecs()[1];
2368 EXPECT_EQ("ISAC", isac.name);
2369 EXPECT_EQ(103, isac.id);
2370 EXPECT_EQ(16000, isac.clockrate);
2371}
2372
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002373// Ensure that we can deserialize SDP with a=fingerprint properly.
2374TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2375 // Add a DTLS a=fingerprint attribute to our session description.
2376 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002377 JsepSessionDescription new_jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002378 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002379 jdesc_.session_version()));
2380
Steve Antona3a92c22017-12-07 10:27:41 -08002381 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002382 std::string sdp_with_fingerprint = kSdpString;
2383 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2384 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2385 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2386 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2387}
2388
2389TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 10:27:41 -08002390 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002391 std::string sdp_with_bundle = kSdpFullString;
2392 InjectAfter(kSessionTime,
2393 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2394 &sdp_with_bundle);
2395 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2396 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2397 group.AddContentName(kAudioContentName);
2398 group.AddContentName(kVideoContentName);
2399 desc_.AddGroup(group);
Yves Gerey665174f2018-06-19 15:03:05 +02002400 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002401 jdesc_.session_version()));
2402 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2403}
2404
2405TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002406 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002407 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002408 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002409 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002410 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002411 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002412 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 15:14:30 -08002413 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002414 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002415 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002416 acd->set_bandwidth(50 * 1000);
Yves Gerey665174f2018-06-19 15:03:05 +02002417 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002418 jdesc_.session_version()));
2419 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2420}
2421
2422TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 10:27:41 -08002423 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002424 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002425 InjectAfter(kSessionTime, "a=ice-options:iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002426 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002427 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002428 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002429 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002430 &sdp_with_ice_options);
2431 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2432 std::vector<std::string> transport_options;
2433 transport_options.push_back(kIceOption3);
2434 transport_options.push_back(kIceOption1);
2435 AddIceOptions(kAudioContentName, transport_options);
2436 transport_options.clear();
2437 transport_options.push_back(kIceOption3);
2438 transport_options.push_back(kIceOption2);
2439 AddIceOptions(kVideoContentName, transport_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002440 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002441 jdesc_.session_version()));
2442 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2443}
2444
2445TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2446 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 10:27:41 -08002447 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002448 std::string sdp_with_ufrag_pwd = kSdpFullString;
2449 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2450 // Add session level ufrag and pwd
2451 InjectAfter(kSessionTime,
Yves Gerey665174f2018-06-19 15:03:05 +02002452 "a=ice-pwd:session+level+icepwd\r\n"
2453 "a=ice-ufrag:session+level+iceufrag\r\n",
2454 &sdp_with_ufrag_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002455 // Add media level ufrag and pwd for audio
Yves Gerey665174f2018-06-19 15:03:05 +02002456 InjectAfter(
2457 "a=mid:audio_content_name\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002458 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2459 &sdp_with_ufrag_pwd);
2460 // Update the candidate ufrag and pwd to the expected ones.
Yves Gerey665174f2018-06-19 15:03:05 +02002461 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, "media+level+iceufrag",
2462 "media+level+icepwd"));
2463 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, "session+level+iceufrag",
2464 "session+level+icepwd"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002465 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2466 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2467}
2468
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002469TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002470 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002471}
2472
2473TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002474 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002475}
2476
2477TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002478 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002479}
2480
2481TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2482 EXPECT_TRUE(TestDeserializeRejected(true, false));
2483}
2484
2485TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2486 EXPECT_TRUE(TestDeserializeRejected(false, true));
2487}
2488
2489TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2490 EXPECT_TRUE(TestDeserializeRejected(true, true));
2491}
2492
2493// Tests that we can still handle the sdp uses mslabel and label instead of
2494// msid for backward compatibility.
2495TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07002496 jdesc_.description()->set_msid_supported(false);
Steve Antona3a92c22017-12-07 10:27:41 -08002497 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002498 std::string sdp_without_msid = kSdpFullString;
2499 Replace("msid", "xmsid", &sdp_without_msid);
2500 // Deserialize
2501 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2502 // Verify
2503 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
Henrik Boström5b147782018-12-04 11:25:05 +01002504 EXPECT_FALSE(jdesc.description()->msid_signaling() &
2505 ~cricket::kMsidSignalingSsrcAttribute);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002506}
2507
Johannes Kron0854eb62018-10-10 22:33:20 +02002508TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002509 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002510 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2511 InjectAfter("t=0 0\r\n", kExtmapAllowMixed, &sdp_with_extmap_allow_mixed);
2512 // Deserialize
2513 JsepSessionDescription jdesc_deserialized(kDummyType);
2514 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2515 // Verify
2516 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2517}
2518
2519TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002520 jdesc_.description()->set_extmap_allow_mixed(false);
Johannes Kron0854eb62018-10-10 22:33:20 +02002521 std::string sdp_without_extmap_allow_mixed = kSdpFullString;
2522 // Deserialize
2523 JsepSessionDescription jdesc_deserialized(kDummyType);
2524 EXPECT_TRUE(
2525 SdpDeserialize(sdp_without_extmap_allow_mixed, &jdesc_deserialized));
2526 // Verify
2527 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2528}
2529
2530TEST_F(WebRtcSdpTest, DeserializeMediaContentDescriptionWithExtmapAllowMixed) {
2531 cricket::MediaContentDescription* video_desc =
2532 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2533 ASSERT_TRUE(video_desc);
2534 cricket::MediaContentDescription* audio_desc =
2535 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2536 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002537 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002538 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002539 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002540 cricket::MediaContentDescription::kMedia);
2541
2542 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2543 InjectAfter("a=mid:audio_content_name\r\n", kExtmapAllowMixed,
2544 &sdp_with_extmap_allow_mixed);
2545 InjectAfter("a=mid:video_content_name\r\n", kExtmapAllowMixed,
2546 &sdp_with_extmap_allow_mixed);
2547
2548 // Deserialize
2549 JsepSessionDescription jdesc_deserialized(kDummyType);
2550 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2551 // Verify
2552 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2553}
2554
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002555TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2556 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2557
2558 std::string sdp = kSdpOneCandidate;
2559 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2560 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2561 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2562 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002563 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002564
2565 // Candidate line without generation extension.
2566 sdp = kSdpOneCandidate;
2567 Replace(" generation 2", "", &sdp);
2568 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2569 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2570 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2571 Candidate expected = jcandidate_->candidate();
2572 expected.set_generation(0);
2573 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2574
honghaiza0c44ea2016-03-23 16:07:48 -07002575 // Candidate with network id and/or cost.
2576 sdp = kSdpOneCandidate;
2577 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2578 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2579 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2580 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2581 expected = jcandidate_->candidate();
2582 expected.set_network_id(2);
2583 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2584 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2585 // Add network cost
2586 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2587 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2588 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2589 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2590
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002591 sdp = kSdpTcpActiveCandidate;
2592 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2593 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002594 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002595 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2596 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2597 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002598 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2599 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
Yves Gerey665174f2018-06-19 15:03:05 +02002600 EXPECT_TRUE(
2601 jcandidate.candidate().IsEquivalent(jcandidate_template->candidate()));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002602 sdp = kSdpTcpPassiveCandidate;
2603 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2604 sdp = kSdpTcpSOCandidate;
2605 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002606}
2607
2608// This test verifies the deserialization of candidate-attribute
2609// as per RFC 5245. Candiate-attribute will be of the format
2610// candidate:<blah>. This format will be used when candidates
2611// are trickled.
2612TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2613 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2614
2615 std::string candidate_attribute = kRawCandidate;
2616 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2617 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2618 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2619 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2620 EXPECT_EQ(2u, jcandidate.candidate().generation());
2621
2622 // Candidate line without generation extension.
2623 candidate_attribute = kRawCandidate;
2624 Replace(" generation 2", "", &candidate_attribute);
2625 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2626 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2627 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2628 Candidate expected = jcandidate_->candidate();
2629 expected.set_generation(0);
2630 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2631
2632 // Candidate line without candidate:
2633 candidate_attribute = kRawCandidate;
2634 Replace("candidate:", "", &candidate_attribute);
2635 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2636
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002637 // Candidate line with IPV6 address.
2638 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
Zach Steinb336c272018-08-09 01:16:13 -07002639
2640 // Candidate line with hostname address.
2641 EXPECT_TRUE(SdpDeserializeCandidate(kRawHostnameCandidate, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002642}
2643
2644// This test verifies that the deserialization of an invalid candidate string
2645// fails.
2646TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
Yves Gerey665174f2018-06-19 15:03:05 +02002647 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002648
2649 std::string candidate_attribute = kRawCandidate;
2650 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002651 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002652
2653 candidate_attribute = kSdpOneCandidate;
2654 candidate_attribute.replace(0, 1, "x");
2655 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2656
2657 candidate_attribute = kRawCandidate;
2658 candidate_attribute.append("\r\n");
2659 candidate_attribute.append(kRawCandidate);
2660 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2661
2662 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002663}
2664
2665TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2666 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002667 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002668 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2669
2670 std::string sdp_with_data = kSdpString;
2671 sdp_with_data.append(kSdpRtpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002672 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002673
2674 // Deserialize
2675 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2676 // Verify
2677 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2678}
2679
2680TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002681 bool use_sctpmap = true;
2682 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002683 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002684 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2685
2686 std::string sdp_with_data = kSdpString;
2687 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002688 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002689
lally@webrtc.org36300852015-02-24 20:19:35 +00002690 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2691 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2692 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2693
2694 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002695 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2696 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002697 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2698 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2699
2700 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002701 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2702 kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002703 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2704 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2705}
2706
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002707TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002708 bool use_sctpmap = false;
2709 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002710 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002711 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2712
2713 std::string sdp_with_data = kSdpString;
2714 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002715 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002716
lally@webrtc.org36300852015-02-24 20:19:35 +00002717 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002718 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2719 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002720
lally@webrtc.org36300852015-02-24 20:19:35 +00002721 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002722 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2723 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002724 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2725 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002726
lally@webrtc.org36300852015-02-24 20:19:35 +00002727 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002728 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2729 kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002730 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2731 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2732}
2733
lally69f57602015-10-08 10:15:04 -07002734TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002735 bool use_sctpmap = false;
2736 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002737 JsepSessionDescription jdesc(kDummyType);
lally69f57602015-10-08 10:15:04 -07002738 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2739
2740 std::string sdp_with_data = kSdpString;
2741 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002742 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 10:15:04 -07002743
2744 // Verify with DTLS/SCTP.
2745 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2746 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2747
2748 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002749 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2750 kUdpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002751 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2752 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2753
2754 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002755 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2756 kTcpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002757 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2758 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2759}
2760
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002761// Test to check the behaviour if sctp-port is specified
2762// on the m= line and in a=sctp-port.
2763TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002764 bool use_sctpmap = true;
2765 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002766 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002767 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2768
2769 std::string sdp_with_data = kSdpString;
2770 // Append m= attributes
2771 sdp_with_data.append(kSdpSctpDataChannelString);
2772 // Append a=sctp-port attribute
2773 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 10:27:41 -08002774 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002775
2776 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2777}
2778
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002779// For crbug/344475.
2780TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2781 std::string sdp_with_data = kSdpString;
2782 sdp_with_data.append(kSdpSctpDataChannelString);
2783 // Remove the "\n" at the end.
2784 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 10:27:41 -08002785 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002786
2787 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2788 // No crash is a pass.
2789}
2790
Steve Anton36b29d12017-10-30 09:57:42 -07002791void MutateJsepSctpPort(JsepSessionDescription* jdesc,
zstein4b2e0822017-02-17 19:48:38 -08002792 const SessionDescription& desc) {
wu@webrtc.org78187522013-10-07 23:32:02 +00002793 // take our pre-built session description and change the SCTP port.
zstein4b2e0822017-02-17 19:48:38 -08002794 cricket::SessionDescription* mutant = desc.Copy();
Steve Antonb1c1de12017-12-21 15:14:30 -08002795 DataContentDescription* dcdesc =
2796 mutant->GetContentDescriptionByName(kDataContentName)->as_data();
wu@webrtc.org78187522013-10-07 23:32:02 +00002797 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002798 EXPECT_EQ(1U, codecs.size());
solenberg9fa49752016-10-08 13:02:44 -07002799 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002800 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002801 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002802
2803 // note: mutant's owned by jdesc now.
Steve Anton36b29d12017-10-30 09:57:42 -07002804 ASSERT_TRUE(jdesc->Initialize(mutant, kSessionId, kSessionVersion));
wu@webrtc.org78187522013-10-07 23:32:02 +00002805 mutant = NULL;
zstein4b2e0822017-02-17 19:48:38 -08002806}
2807
2808TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
2809 bool use_sctpmap = true;
2810 AddSctpDataChannel(use_sctpmap);
2811
2812 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 10:27:41 -08002813 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002814 MutateJsepSctpPort(&jdesc, desc_);
wu@webrtc.org78187522013-10-07 23:32:02 +00002815
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002816 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002817 std::string sdp_with_data = kSdpString;
2818 sdp_with_data.append(kSdpSctpDataChannelString);
zstein4b2e0822017-02-17 19:48:38 -08002819 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2820 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2821 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002822 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:02 +00002823
2824 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2825 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08002826}
2827
2828TEST_F(WebRtcSdpTest,
2829 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
2830 bool use_sctpmap = false;
2831 AddSctpDataChannel(use_sctpmap);
2832
Steve Antona3a92c22017-12-07 10:27:41 -08002833 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002834 MutateJsepSctpPort(&jdesc, desc_);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002835
2836 // We need to test the deserialized JsepSessionDescription from
2837 // kSdpSctpDataChannelStringWithSctpPort for
2838 // draft-ietf-mmusic-sctp-sdp-07
2839 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08002840 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002841 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
zstein4b2e0822017-02-17 19:48:38 -08002842 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2843 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2844 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002845 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002846
2847 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2848 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002849}
2850
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002851TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002852 // We want to test that deserializing data content limits bandwidth
2853 // settings (it should never be greater than the default).
2854 // This should prevent someone from using unlimited data bandwidth through
2855 // JS and "breaking the Internet".
2856 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002857 std::string sdp_with_bandwidth = kSdpString;
2858 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02002859 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002860 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002861 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002862
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002863 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2864}
2865
2866TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08002867 bool use_sctpmap = true;
2868 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002869 JsepSessionDescription jdesc(kDummyType);
Steve Antonb1c1de12017-12-21 15:14:30 -08002870 DataContentDescription* dcd = GetFirstDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002871 dcd->set_bandwidth(100 * 1000);
2872 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2873
2874 std::string sdp_with_bandwidth = kSdpString;
2875 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02002876 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002877 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002878 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002879
2880 // SCTP has congestion control, so we shouldn't limit the bandwidth
2881 // as we do for RTP.
2882 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002883 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2884}
2885
Yves Gerey665174f2018-06-19 15:03:05 +02002886class WebRtcSdpExtmapTest : public WebRtcSdpTest,
2887 public testing::WithParamInterface<bool> {};
jbauch5869f502017-06-29 12:31:36 -07002888
2889TEST_P(WebRtcSdpExtmapTest,
Yves Gerey665174f2018-06-19 15:03:05 +02002890 DeserializeSessionDescriptionWithSessionLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002891 bool encrypted = GetParam();
2892 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002893}
2894
Yves Gerey665174f2018-06-19 15:03:05 +02002895TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002896 bool encrypted = GetParam();
2897 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002898}
2899
Yves Gerey665174f2018-06-19 15:03:05 +02002900TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithInvalidExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002901 bool encrypted = GetParam();
2902 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002903}
2904
jbauch5869f502017-06-29 12:31:36 -07002905INSTANTIATE_TEST_CASE_P(Encrypted,
2906 WebRtcSdpExtmapTest,
2907 ::testing::Values(false, true));
2908
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002909TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 10:27:41 -08002910 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002911 std::string sdp = kSdpFullString;
2912 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2913 // Deserialize
2914 SdpParseError error;
2915 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-16 17:54:10 -08002916 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002917 EXPECT_EQ(lastline, error.line);
2918 EXPECT_EQ("Invalid SDP line.", error.description);
2919}
2920
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002921TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2922 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2923 std::string new_sdp = kSdpOneCandidate;
2924 Replace("udp", "unsupported_transport", &new_sdp);
2925 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2926 new_sdp = kSdpOneCandidate;
2927 Replace("udp", "uDP", &new_sdp);
2928 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2929 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2930 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2931 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2932}
2933
honghaiza54a0802015-12-16 18:37:23 -08002934TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002935 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08002936 EXPECT_TRUE(
2937 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002938 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2939 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2940 Candidate ref_candidate = jcandidate_->candidate();
2941 ref_candidate.set_username("user_rtp");
2942 ref_candidate.set_password("password_rtp");
2943 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2944}
2945
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002946TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08002947 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002948
2949 // Deserialize
2950 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2951
2952 // Verify
2953 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002954 jdesc.description()
2955 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2956 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002957 EXPECT_TRUE(audio->conference_mode());
2958
2959 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 15:14:30 -08002960 jdesc.description()
2961 ->GetContentDescriptionByName(cricket::CN_VIDEO)
2962 ->as_video();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002963 EXPECT_TRUE(video->conference_mode());
2964}
2965
deadbeefd45aea82017-09-16 01:24:29 -07002966TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08002967 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 01:24:29 -07002968
2969 // We tested deserialization already above, so just test that if we serialize
2970 // and deserialize the flag doesn't disappear.
2971 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 12:22:16 -08002972 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 01:24:29 -07002973 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
2974
2975 // Verify.
2976 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002977 jdesc.description()
2978 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2979 ->as_audio();
deadbeefd45aea82017-09-16 01:24:29 -07002980 EXPECT_TRUE(audio->conference_mode());
2981
2982 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 15:14:30 -08002983 jdesc.description()
2984 ->GetContentDescriptionByName(cricket::CN_VIDEO)
2985 ->as_video();
deadbeefd45aea82017-09-16 01:24:29 -07002986 EXPECT_TRUE(video->conference_mode());
2987}
2988
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002989TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2990 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002991 const char kSdpEmptyType[] = " =candidate";
2992 const char kSdpEqualAsPlus[] = "a+candidate";
2993 const char kSdpSpaceAfterEqual[] = "a= candidate";
2994 const char kSdpUpperType[] = "A=candidate";
2995 const char kSdpEmptyLine[] = "";
2996 const char kSdpMissingValue[] = "a=";
2997
Yves Gerey665174f2018-06-19 15:03:05 +02002998 const char kSdpBrokenFingerprint[] =
2999 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003000 "4AAD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB";
Yves Gerey665174f2018-06-19 15:03:05 +02003001 const char kSdpExtraField[] =
3002 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003003 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB XXX";
Yves Gerey665174f2018-06-19 15:03:05 +02003004 const char kSdpMissingSpace[] =
3005 "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003006 "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 +00003007 // MD5 is not allowed in fingerprints.
Yves Gerey665174f2018-06-19 15:03:05 +02003008 const char kSdpMd5[] =
3009 "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003010 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003011
3012 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003013 ExpectParseFailure("v=", kSdpDestroyer);
3014 ExpectParseFailure("o=", kSdpDestroyer);
3015 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003016 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003017 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003018
3019 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003020 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
3021 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003022
3023 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003024 ExpectParseFailure("a=candidate", kSdpEmptyType);
3025 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
3026 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
3027 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003028
3029 // Bogus fingerprint replacing a=sendrev. We selected this attribute
3030 // because it's orthogonal to what we are replacing and hence
3031 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003032 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
3033 ExpectParseFailure("a=sendrecv", kSdpExtraField);
3034 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
3035 ExpectParseFailure("a=sendrecv", kSdpMd5);
3036
3037 // Empty Line
3038 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
3039 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003040}
3041
3042TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
3043 // ssrc
3044 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08003045 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003046 // crypto
3047 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
3048 // rtpmap
3049 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
3050 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
3051 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
3052 // candidate
3053 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
3054 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
3055 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
3056 ExpectParseFailure("rport 2346", "rport badvalue");
3057 ExpectParseFailure("rport 2346 generation 2",
3058 "rport 2346 generation badvalue");
3059 // m line
3060 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
3061 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
3062
3063 // bandwidth
3064 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003065 "b=AS:badvalue\r\n", "b=AS:badvalue");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003066 // rtcp-fb
3067 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3068 "a=rtcp-fb:badvalue nack\r\n",
3069 "a=rtcp-fb:badvalue nack");
3070 // extmap
3071 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3072 "a=extmap:badvalue http://example.com\r\n",
3073 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003074}
3075
3076TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 10:27:41 -08003077 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003078
3079 const char kSdpWithReorderedPlTypesString[] =
3080 "v=0\r\n"
3081 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3082 "s=-\r\n"
3083 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00003084 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
Yves Gerey665174f2018-06-19 15:03:05 +02003085 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
3086 // in the map.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003087 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003088 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003089
3090 // Deserialize
3091 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
3092
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003093 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003094 GetFirstAudioContentDescription(jdesc_output.description());
3095 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003096 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003097 EXPECT_EQ("ISAC", acd->codecs()[0].name);
3098 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003099 EXPECT_EQ(104, acd->codecs()[0].id);
3100}
3101
3102TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 10:27:41 -08003103 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003104 CodecParams params;
3105 params.max_ptime = 40;
3106 params.ptime = 30;
3107 params.min_ptime = 10;
3108 params.sprop_stereo = 1;
3109 params.stereo = 1;
3110 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003111 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003112 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 12:22:16 -08003113 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003114}
3115
3116TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
3117 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 10:27:41 -08003118 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003119 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003120 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003121}
3122
3123TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
3124 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 10:27:41 -08003125 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003126 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003127 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003128}
3129
3130TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 10:27:41 -08003131 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003132
3133 const char kSdpWithFmtpString[] =
3134 "v=0\r\n"
3135 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3136 "s=-\r\n"
3137 "t=0 0\r\n"
3138 "m=video 3457 RTP/SAVPF 120\r\n"
3139 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07003140 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3141
3142 // Deserialize
3143 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07003144 EXPECT_TRUE(
3145 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07003146
Donald Curtis0e07f922015-05-15 09:21:23 -07003147 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003148 GetFirstVideoContentDescription(jdesc_output.description());
3149 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 09:21:23 -07003150 ASSERT_FALSE(vcd->codecs().empty());
3151 cricket::VideoCodec vp8 = vcd->codecs()[0];
3152 EXPECT_EQ("VP8", vp8.name);
3153 EXPECT_EQ(120, vp8.id);
3154 cricket::CodecParameterMap::iterator found =
3155 vp8.params.find("x-google-min-bitrate");
3156 ASSERT_TRUE(found != vp8.params.end());
3157 EXPECT_EQ(found->second, "10");
3158 found = vp8.params.find("x-google-max-quantization");
3159 ASSERT_TRUE(found != vp8.params.end());
3160 EXPECT_EQ(found->second, "40");
3161}
3162
johan2d8d23e2016-06-03 01:22:42 -07003163TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 10:27:41 -08003164 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 01:22:42 -07003165
3166 const char kSdpWithFmtpString[] =
3167 "v=0\r\n"
3168 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3169 "s=-\r\n"
3170 "t=0 0\r\n"
3171 "m=video 49170 RTP/AVP 98\r\n"
3172 "a=rtpmap:98 H264/90000\r\n"
3173 "a=fmtp:98 profile-level-id=42A01E; "
3174 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3175
3176 // Deserialize.
3177 SdpParseError error;
3178 EXPECT_TRUE(
3179 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3180
johan2d8d23e2016-06-03 01:22:42 -07003181 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003182 GetFirstVideoContentDescription(jdesc_output.description());
3183 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 01:22:42 -07003184 ASSERT_FALSE(vcd->codecs().empty());
3185 cricket::VideoCodec h264 = vcd->codecs()[0];
3186 EXPECT_EQ("H264", h264.name);
3187 EXPECT_EQ(98, h264.id);
3188 cricket::CodecParameterMap::const_iterator found =
3189 h264.params.find("profile-level-id");
3190 ASSERT_TRUE(found != h264.params.end());
3191 EXPECT_EQ(found->second, "42A01E");
3192 found = h264.params.find("sprop-parameter-sets");
3193 ASSERT_TRUE(found != h264.params.end());
3194 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3195}
3196
Donald Curtis0e07f922015-05-15 09:21:23 -07003197TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 10:27:41 -08003198 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 09:21:23 -07003199
3200 const char kSdpWithFmtpString[] =
3201 "v=0\r\n"
3202 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3203 "s=-\r\n"
3204 "t=0 0\r\n"
3205 "m=video 3457 RTP/SAVPF 120\r\n"
3206 "a=rtpmap:120 VP8/90000\r\n"
3207 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003208
3209 // Deserialize
3210 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02003211 EXPECT_TRUE(
3212 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003213
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003214 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003215 GetFirstVideoContentDescription(jdesc_output.description());
3216 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003217 ASSERT_FALSE(vcd->codecs().empty());
3218 cricket::VideoCodec vp8 = vcd->codecs()[0];
3219 EXPECT_EQ("VP8", vp8.name);
3220 EXPECT_EQ(120, vp8.id);
3221 cricket::CodecParameterMap::iterator found =
3222 vp8.params.find("x-google-min-bitrate");
3223 ASSERT_TRUE(found != vp8.params.end());
3224 EXPECT_EQ(found->second, "10");
3225 found = vp8.params.find("x-google-max-quantization");
3226 ASSERT_TRUE(found != vp8.params.end());
3227 EXPECT_EQ(found->second, "40");
3228}
3229
ossuaa4b0772017-01-30 07:41:18 -08003230TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003231 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003232
3233 cricket::AudioCodecs codecs = acd->codecs();
3234 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3235 acd->set_codecs(codecs);
3236
Yves Gerey665174f2018-06-19 15:03:05 +02003237 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003238 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003239 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003240 std::string sdp_with_fmtp = kSdpFullString;
3241 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3242 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3243 &sdp_with_fmtp);
3244 EXPECT_EQ(sdp_with_fmtp, message);
3245}
3246
3247TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003248 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003249
3250 cricket::AudioCodecs codecs = acd->codecs();
3251 codecs[0].params["stereo"] = "1";
3252 acd->set_codecs(codecs);
3253
Yves Gerey665174f2018-06-19 15:03:05 +02003254 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003255 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003256 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003257 std::string sdp_with_fmtp = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003258 InjectAfter("a=rtpmap:111 opus/48000/2\r\n", "a=fmtp:111 stereo=1\r\n",
ossuaa4b0772017-01-30 07:41:18 -08003259 &sdp_with_fmtp);
3260 EXPECT_EQ(sdp_with_fmtp, message);
3261}
3262
3263TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003264 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003265
3266 cricket::AudioCodecs codecs = acd->codecs();
3267 codecs[0].params["ptime"] = "20";
3268 codecs[0].params["maxptime"] = "120";
3269 acd->set_codecs(codecs);
3270
Yves Gerey665174f2018-06-19 15:03:05 +02003271 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003272 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003273 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003274 std::string sdp_with_fmtp = kSdpFullString;
3275 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3276 "a=maxptime:120\r\n" // No comma here. String merging!
3277 "a=ptime:20\r\n",
3278 &sdp_with_fmtp);
3279 EXPECT_EQ(sdp_with_fmtp, message);
3280}
3281
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003282TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003283 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003284
3285 cricket::VideoCodecs codecs = vcd->codecs();
3286 codecs[0].params["x-google-min-bitrate"] = "10";
3287 vcd->set_codecs(codecs);
3288
Yves Gerey665174f2018-06-19 15:03:05 +02003289 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003290 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003291 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003292 std::string sdp_with_fmtp = kSdpFullString;
3293 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003294 "a=fmtp:120 x-google-min-bitrate=10\r\n", &sdp_with_fmtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003295 EXPECT_EQ(sdp_with_fmtp, message);
3296}
3297
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003298TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) {
3299 // Deserialize the baseline description, making sure it's ICE full.
Steve Antona3a92c22017-12-07 10:27:41 -08003300 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003301 std::string sdp_with_icelite = kSdpFullString;
3302 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3303 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3304 const cricket::TransportInfo* tinfo1 =
3305 desc->GetTransportInfoByName("audio_content_name");
3306 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3307 const cricket::TransportInfo* tinfo2 =
3308 desc->GetTransportInfoByName("video_content_name");
3309 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003310
3311 // Add "a=ice-lite" and deserialize, making sure it's ICE lite.
Yves Gerey665174f2018-06-19 15:03:05 +02003312 InjectAfter(kSessionTime, "a=ice-lite\r\n", &sdp_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003313 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3314 desc = jdesc_with_icelite.description();
3315 const cricket::TransportInfo* atinfo =
3316 desc->GetTransportInfoByName("audio_content_name");
3317 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3318 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003319 desc->GetTransportInfoByName("video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003320 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003321
3322 // Now that we know deserialization works, we can use TestSerialize to test
3323 // serialization.
3324 TestSerialize(jdesc_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003325}
3326
3327// Verifies that the candidates in the input SDP are parsed and serialized
3328// correctly in the output SDP.
3329TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3330 std::string sdp_with_data = kSdpString;
3331 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 10:27:41 -08003332 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003333
3334 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 12:22:16 -08003335 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003336}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003337
3338TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3339 AddFingerprint();
3340 TransportInfo audio_transport_info =
3341 *(desc_.GetTransportInfoByName(kAudioContentName));
3342 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3343 audio_transport_info.description.connection_role);
3344 audio_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003345 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003346
3347 TransportInfo video_transport_info =
3348 *(desc_.GetTransportInfoByName(kVideoContentName));
3349 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3350 video_transport_info.description.connection_role);
3351 video_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003352 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003353
3354 desc_.RemoveTransportInfoByName(kAudioContentName);
3355 desc_.RemoveTransportInfoByName(kVideoContentName);
3356
3357 desc_.AddTransportInfo(audio_transport_info);
3358 desc_.AddTransportInfo(video_transport_info);
3359
Yves Gerey665174f2018-06-19 15:03:05 +02003360 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003361 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003362 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003363 std::string sdp_with_dtlssetup = kSdpFullString;
3364
3365 // Fingerprint attribute is necessary to add DTLS setup attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003366 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_dtlssetup);
3367 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003368 // Now adding |setup| attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003369 InjectAfter(kFingerprint, "a=setup:active\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003370 EXPECT_EQ(sdp_with_dtlssetup, message);
3371}
3372
3373TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
Steve Antona3a92c22017-12-07 10:27:41 -08003374 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003375 std::string sdp_with_dtlssetup = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003376 InjectAfter(kSessionTime, "a=setup:actpass\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003377 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3378 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3379 const cricket::TransportInfo* atinfo =
3380 desc->GetTransportInfoByName("audio_content_name");
3381 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3382 atinfo->description.connection_role);
3383 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003384 desc->GetTransportInfoByName("video_content_name");
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003385 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3386 vtinfo->description.connection_role);
3387}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003388
3389// Verifies that the order of the serialized m-lines follows the order of the
3390// ContentInfo in SessionDescription, and vise versa for deserialization.
3391TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 10:27:41 -08003392 JsepSessionDescription jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02003393 const std::string media_content_sdps[3] = {kSdpAudioString, kSdpVideoString,
3394 kSdpSctpDataChannelString};
3395 const cricket::MediaType media_types[3] = {cricket::MEDIA_TYPE_AUDIO,
3396 cricket::MEDIA_TYPE_VIDEO,
3397 cricket::MEDIA_TYPE_DATA};
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003398
3399 // Verifies all 6 permutations.
3400 for (size_t i = 0; i < 6; ++i) {
3401 size_t media_content_in_sdp[3];
3402 // The index of the first media content.
3403 media_content_in_sdp[0] = i / 2;
3404 // The index of the second media content.
3405 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3406 // The index of the third media content.
3407 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3408
3409 std::string sdp_string = kSdpSessionString;
3410 for (size_t i = 0; i < 3; ++i)
3411 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3412
3413 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3414 cricket::SessionDescription* desc = jdesc.description();
3415 EXPECT_EQ(3u, desc->contents().size());
3416
3417 for (size_t i = 0; i < 3; ++i) {
3418 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 15:14:30 -08003419 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003420 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3421 }
3422
Steve Antone831b8c2018-02-01 12:22:16 -08003423 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003424 EXPECT_EQ(sdp_string, serialized_sdp);
3425 }
3426}
deadbeef9d3584c2016-02-16 17:54:10 -08003427
deadbeef25ed4352016-12-12 18:37:36 -08003428TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3429 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 10:27:41 -08003430 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003431 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003432 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3433 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3434}
3435
deadbeef12771a12017-01-03 13:53:47 -08003436// The semantics of "a=bundle-only" are only defined when it's used in
3437// combination with a 0 port on the m= line. We should ignore it if used with a
3438// nonzero port.
3439TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3440 // Make the base bundle-only description but unset the bundle-only flag.
3441 MakeBundleOnlyDescription();
3442 jdesc_.description()->contents()[1].bundle_only = false;
3443
3444 std::string modified_sdp = kBundleOnlySdpFullString;
3445 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08003446 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003447 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3448 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003449}
3450
3451TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3452 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003453 TestSerialize(jdesc_);
deadbeef25ed4352016-12-12 18:37:36 -08003454}
3455
deadbeef9d3584c2016-02-16 17:54:10 -08003456TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3457 MakePlanBDescription();
3458
Steve Antona3a92c22017-12-07 10:27:41 -08003459 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003460 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3461
3462 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3463}
3464
3465TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3466 MakePlanBDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003467 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-16 17:54:10 -08003468}
3469
3470TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3471 MakeUnifiedPlanDescription();
3472
Steve Antona3a92c22017-12-07 10:27:41 -08003473 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003474 EXPECT_TRUE(
3475 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3476
3477 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3478}
3479
3480TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3481 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003482 TestSerialize(jdesc_);
3483}
3484
Seth Hampson5b4f0752018-04-02 16:31:36 -07003485// This tests deserializing a Unified Plan SDP that is compatible with both
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003486// Unified Plan and Plan B style SDP, meaning that it contains both "a=ssrc
3487// msid" lines and "a=msid " lines. It tests the case for audio/video tracks
Seth Hampson5b4f0752018-04-02 16:31:36 -07003488// with no stream ids and multiple stream ids. For parsing this, the Unified
3489// Plan a=msid lines should take priority, because the Plan B style a=ssrc msid
3490// lines do not support multiple stream ids and no stream ids.
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003491TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionSpecialMsid) {
3492 // Create both msid lines for Plan B and Unified Plan support.
3493 MakeUnifiedPlanDescriptionMultipleStreamIds(
3494 cricket::kMsidSignalingMediaSection |
3495 cricket::kMsidSignalingSsrcAttribute);
Seth Hampson5b4f0752018-04-02 16:31:36 -07003496
3497 JsepSessionDescription deserialized_description(kDummyType);
3498 EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid,
3499 &deserialized_description));
3500
3501 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
Henrik Boström5b147782018-12-04 11:25:05 +01003502 EXPECT_EQ(cricket::kMsidSignalingMediaSection |
3503 cricket::kMsidSignalingSsrcAttribute,
3504 deserialized_description.description()->msid_signaling());
Seth Hampson5b4f0752018-04-02 16:31:36 -07003505}
3506
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003507// Tests the serialization of a Unified Plan SDP that is compatible for both
3508// Unified Plan and Plan B style SDPs, meaning that it contains both "a=ssrc
3509// msid" lines and "a=msid " lines. It tests the case for no stream ids and
3510// multiple stream ids.
3511TEST_F(WebRtcSdpTest, SerializeSessionDescriptionSpecialMsid) {
3512 // Create both msid lines for Plan B and Unified Plan support.
3513 MakeUnifiedPlanDescriptionMultipleStreamIds(
3514 cricket::kMsidSignalingMediaSection |
3515 cricket::kMsidSignalingSsrcAttribute);
3516 std::string serialized_sdp = webrtc::SdpSerialize(jdesc_);
3517 // We explicitly test that the serialized SDP string is equal to the hard
3518 // coded SDP string. This is necessary, because in the parser "a=msid" lines
3519 // take priority over "a=ssrc msid" lines. This means if we just used
3520 // TestSerialize(), it could serialize an SDP that omits "a=ssrc msid" lines,
3521 // and still pass, because the deserialized version would be the same.
3522 EXPECT_EQ(kUnifiedPlanSdpFullStringWithSpecialMsid, serialized_sdp);
3523}
3524
3525// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3526// that signal stream IDs) is deserialized appropriately. It tests the case for
3527// no stream ids and multiple stream ids.
3528TEST_F(WebRtcSdpTest, UnifiedPlanDeserializeSessionDescriptionSpecialMsid) {
3529 // Only create a=msid lines for strictly Unified Plan stream ID support.
3530 MakeUnifiedPlanDescriptionMultipleStreamIds(
3531 cricket::kMsidSignalingMediaSection);
3532
3533 JsepSessionDescription deserialized_description(kDummyType);
3534 std::string unified_plan_sdp_string =
3535 kUnifiedPlanSdpFullStringWithSpecialMsid;
3536 RemoveSsrcMsidLinesFromSdpString(&unified_plan_sdp_string);
3537 EXPECT_TRUE(
3538 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3539
3540 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3541}
3542
3543// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3544// that signal stream IDs) is serialized appropriately. It tests the case for no
3545// stream ids and multiple stream ids.
3546TEST_F(WebRtcSdpTest, UnifiedPlanSerializeSessionDescriptionSpecialMsid) {
3547 // Only create a=msid lines for strictly Unified Plan stream ID support.
3548 MakeUnifiedPlanDescriptionMultipleStreamIds(
3549 cricket::kMsidSignalingMediaSection);
3550
Seth Hampson5b4f0752018-04-02 16:31:36 -07003551 TestSerialize(jdesc_);
3552}
3553
Seth Hampson5897a6e2018-04-03 11:16:33 -07003554// This tests that a Unified Plan SDP with no a=ssrc lines is
3555// serialized/deserialized appropriately. In this case the
3556// MediaContentDescription will contain a StreamParams object that doesn't have
3557// any SSRCs. Vice versa, this will be created upon deserializing an SDP with no
3558// SSRC lines.
3559TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3560 MakeUnifiedPlanDescription();
3561 RemoveSsrcSignalingFromStreamParams();
3562 std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString;
3563 RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string);
3564
3565 JsepSessionDescription deserialized_description(kDummyType);
3566 EXPECT_TRUE(
3567 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3568 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3569}
3570
3571TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3572 MakeUnifiedPlanDescription();
3573 RemoveSsrcSignalingFromStreamParams();
3574
3575 TestSerialize(jdesc_);
3576}
3577
Steve Antone831b8c2018-02-01 12:22:16 -08003578TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
3579 JsepSessionDescription jsep_desc(kDummyType);
3580 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
3581 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3582}
3583
3584TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
3585 JsepSessionDescription jsep_desc(kDummyType);
3586 std::string sdp = kSdpSessionString;
3587 sdp += kSdpSctpDataChannelString;
3588 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3589 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3590}
3591
3592TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
3593 JsepSessionDescription jsep_desc(kDummyType);
3594 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
3595 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
3596 jsep_desc.description()->msid_signaling());
3597}
3598
3599TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
3600 JsepSessionDescription jsep_desc(kDummyType);
3601 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
3602 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
3603 jsep_desc.description()->msid_signaling());
3604}
3605
3606const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
3607const char kSsrcAttributeMsidLine[] =
3608 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
3609
3610TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
3611 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
3612 std::string sdp = webrtc::SdpSerialize(jdesc_);
3613
3614 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3615 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3616}
3617
3618TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
3619 jdesc_.description()->set_msid_signaling(
3620 cricket::kMsidSignalingSsrcAttribute);
3621 std::string sdp = webrtc::SdpSerialize(jdesc_);
3622
3623 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
3624 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3625}
3626
3627TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
3628 jdesc_.description()->set_msid_signaling(
3629 cricket::kMsidSignalingMediaSection |
3630 cricket::kMsidSignalingSsrcAttribute);
3631 std::string sdp = webrtc::SdpSerialize(jdesc_);
3632
3633 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3634 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-16 17:54:10 -08003635}
deadbeef7e146cb2016-09-28 10:04:34 -07003636
3637// Regression test for heap overflow bug:
3638// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3639TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 10:04:34 -07003640 // The issue occurs when the sctp-port attribute is found in a video
3641 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 12:43:58 -08003642 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 10:04:34 -07003643 "v=0\r\n"
3644 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3645 "s=-\r\n"
3646 "t=0 0\r\n"
3647 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3648 "a=sctp-port 5000\r\n"
3649 "a=fmtp:108 foo=10\r\n";
3650
3651 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3652 "sctp-port");
3653}
deadbeefb2362572016-12-13 16:37:06 -08003654
3655// Regression test for integer overflow bug:
3656// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3657TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003658 // Bandwidth attribute is the max signed 32-bit int, which will get
3659 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003660 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003661 "v=0\r\n"
3662 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3663 "s=-\r\n"
3664 "t=0 0\r\n"
3665 "m=video 3457 RTP/SAVPF 120\r\n"
3666 "b=AS:2147483647\r\n"
3667 "foo=fail\r\n";
3668
3669 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3670}
deadbeef7bcdb692017-01-20 12:43:58 -08003671
deadbeefbc88c6b2017-08-02 11:26:34 -07003672// Similar to the above, except that negative values are illegal, not just
3673// error-prone as large values are.
3674// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3675TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3676 static const char kSdpWithNegativeBandwidth[] =
3677 "v=0\r\n"
3678 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3679 "s=-\r\n"
3680 "t=0 0\r\n"
3681 "m=video 3457 RTP/SAVPF 120\r\n"
3682 "b=AS:-1000\r\n";
3683
3684 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3685}
3686
deadbeef3e8016e2017-08-03 17:49:30 -07003687// An exception to the above rule: a value of -1 for b=AS should just be
3688// ignored, resulting in "kAutoBandwidth" in the deserialized object.
3689// Applications historically may be using "b=AS:-1" to mean "no bandwidth
3690// limit", but this is now what ommitting the attribute entirely will do, so
3691// ignoring it will have the intended effect.
3692TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
3693 static const char kSdpWithBandwidthOfNegativeOne[] =
3694 "v=0\r\n"
3695 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3696 "s=-\r\n"
3697 "t=0 0\r\n"
3698 "m=video 3457 RTP/SAVPF 120\r\n"
3699 "b=AS:-1\r\n";
3700
Steve Antona3a92c22017-12-07 10:27:41 -08003701 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-03 17:49:30 -07003702 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-03 17:49:30 -07003703 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003704 GetFirstVideoContentDescription(jdesc_output.description());
3705 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-03 17:49:30 -07003706 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
3707}
3708
deadbeef7bcdb692017-01-20 12:43:58 -08003709// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3710// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3711// Regression test for:
3712// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3713TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3714 // Important piece is "ufrag foo pwd bar".
3715 static const char kSdpWithIceCredentialsInCandidateString[] =
3716 "v=0\r\n"
3717 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3718 "s=-\r\n"
3719 "t=0 0\r\n"
3720 "m=audio 9 RTP/SAVPF 111\r\n"
3721 "c=IN IP4 0.0.0.0\r\n"
3722 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3723 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3724 "a=rtpmap:111 opus/48000/2\r\n"
3725 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3726 "generation 2 ufrag foo pwd bar\r\n";
3727
Steve Antona3a92c22017-12-07 10:27:41 -08003728 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 12:43:58 -08003729 EXPECT_TRUE(
3730 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
3731 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3732 ASSERT_NE(nullptr, candidates);
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003733 ASSERT_EQ(1U, candidates->count());
deadbeef7bcdb692017-01-20 12:43:58 -08003734 cricket::Candidate c = candidates->at(0)->candidate();
3735 EXPECT_EQ("ufrag_voice", c.username());
3736 EXPECT_EQ("pwd_voice", c.password());
3737}
deadbeef90f1e1e2017-02-10 12:35:05 -08003738
Johannes Kron211856b2018-09-06 12:12:28 +02003739// Test that attribute lines "a=ice-ufrag-something"/"a=ice-pwd-something" are
3740// ignored, and only the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3741// Regression test for:
3742// https://bugs.chromium.org/p/webrtc/issues/detail?id=9712
3743TEST_F(WebRtcSdpTest, AttributeWithPartialMatchingNameIsIgnored) {
3744 static const char kSdpWithFooIceCredentials[] =
3745 "v=0\r\n"
3746 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3747 "s=-\r\n"
3748 "t=0 0\r\n"
3749 "m=audio 9 RTP/SAVPF 111\r\n"
3750 "c=IN IP4 0.0.0.0\r\n"
3751 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3752 "a=ice-ufrag-something:foo\r\na=ice-pwd-something:bar\r\n"
3753 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3754 "a=rtpmap:111 opus/48000/2\r\n"
3755 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3756 "generation 2\r\n";
3757
3758 JsepSessionDescription jdesc_output(kDummyType);
3759 EXPECT_TRUE(SdpDeserialize(kSdpWithFooIceCredentials, &jdesc_output));
3760 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3761 ASSERT_NE(nullptr, candidates);
3762 ASSERT_EQ(1U, candidates->count());
3763 cricket::Candidate c = candidates->at(0)->candidate();
3764 EXPECT_EQ("ufrag_voice", c.username());
3765 EXPECT_EQ("pwd_voice", c.password());
3766}
3767
deadbeef90f1e1e2017-02-10 12:35:05 -08003768// Test that SDP with an invalid port number in "a=candidate" lines is
3769// rejected, without crashing.
3770// Regression test for:
3771// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
3772TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
3773 static const char kSdpWithInvalidCandidatePort[] =
3774 "v=0\r\n"
3775 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3776 "s=-\r\n"
3777 "t=0 0\r\n"
3778 "m=audio 9 RTP/SAVPF 111\r\n"
3779 "c=IN IP4 0.0.0.0\r\n"
3780 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3781 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3782 "a=rtpmap:111 opus/48000/2\r\n"
3783 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
3784 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
3785
Steve Antona3a92c22017-12-07 10:27:41 -08003786 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 12:35:05 -08003787 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
3788}
deadbeefa4549d62017-02-10 17:26:22 -08003789
3790// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
3791// Regression test for:
3792// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
3793TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
3794 static const char kSdpWithMissingTrackId[] =
3795 "v=0\r\n"
3796 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3797 "s=-\r\n"
3798 "t=0 0\r\n"
3799 "m=audio 9 RTP/SAVPF 111\r\n"
3800 "c=IN IP4 0.0.0.0\r\n"
3801 "a=rtpmap:111 opus/48000/2\r\n"
3802 "a=msid:stream_id \r\n";
3803
Steve Antona3a92c22017-12-07 10:27:41 -08003804 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003805 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
3806}
3807
3808TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
3809 static const char kSdpWithMissingStreamId[] =
3810 "v=0\r\n"
3811 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3812 "s=-\r\n"
3813 "t=0 0\r\n"
3814 "m=audio 9 RTP/SAVPF 111\r\n"
3815 "c=IN IP4 0.0.0.0\r\n"
3816 "a=rtpmap:111 opus/48000/2\r\n"
3817 "a=msid: track_id\r\n";
3818
Steve Antona3a92c22017-12-07 10:27:41 -08003819 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003820 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
3821}
zhihuang38989e52017-03-21 11:04:53 -07003822
3823// Tests that if both session-level address and media-level address exist, use
3824// the media-level address.
3825TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 10:27:41 -08003826 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003827
3828 // Sesssion-level address.
3829 std::string sdp = kSdpFullString;
3830 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3831 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3832
3833 const auto& content1 = jsep_desc.description()->contents()[0];
3834 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 15:14:30 -08003835 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003836 const auto& content2 = jsep_desc.description()->contents()[1];
3837 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 15:14:30 -08003838 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003839}
3840
3841// Tests that the session-level connection address will be used if the media
3842// level-addresses are not specified.
3843TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 10:27:41 -08003844 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003845
3846 // Sesssion-level address.
3847 std::string sdp = kSdpString;
3848 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3849 // Remove the media level addresses.
3850 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3851 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3852 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3853
3854 const auto& content1 = jsep_desc.description()->contents()[0];
3855 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003856 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003857 const auto& content2 = jsep_desc.description()->contents()[1];
3858 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003859 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003860}
3861
3862TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 10:27:41 -08003863 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003864
3865 std::string sdp = kSdpString;
3866 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3867 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
3868 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
3869 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
3870 &sdp);
3871 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
3872 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
3873 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
3874 &sdp);
3875 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3876 const auto& content1 = jsep_desc.description()->contents()[0];
3877 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003878 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003879 const auto& content2 = jsep_desc.description()->contents()[1];
3880 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003881 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003882}
3883
3884// Test that the invalid or unsupprted connection data cannot be parsed.
3885TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 10:27:41 -08003886 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003887 std::string sdp = kSdpString;
3888 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3889
3890 // Unsupported multicast IPv4 address.
3891 sdp = kSdpFullString;
3892 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
3893 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3894
3895 // Unsupported multicast IPv6 address.
3896 sdp = kSdpFullString;
3897 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
3898 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3899
3900 // Mismatched address type.
3901 sdp = kSdpFullString;
3902 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
3903 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3904
3905 sdp = kSdpFullString;
3906 Replace("c=IN IP4 74.125.224.39\r\n",
3907 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
3908 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3909}
3910
3911TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 10:27:41 -08003912 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003913 MakeDescriptionWithoutCandidates(&expected_jsep);
3914 // Serialization.
Steve Antone831b8c2018-02-01 12:22:16 -08003915 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 11:04:53 -07003916 // Deserialization.
Steve Antona3a92c22017-12-07 10:27:41 -08003917 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003918 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 15:14:30 -08003919 auto audio_desc = jdesc.description()
3920 ->GetContentByName(kAudioContentName)
3921 ->media_description();
3922 auto video_desc = jdesc.description()
3923 ->GetContentByName(kVideoContentName)
3924 ->media_description();
zhihuang38989e52017-03-21 11:04:53 -07003925 EXPECT_EQ(audio_desc_->connection_address().ToString(),
3926 audio_desc->connection_address().ToString());
3927 EXPECT_EQ(video_desc_->connection_address().ToString(),
3928 video_desc->connection_address().ToString());
3929}
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07003930
3931// RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be
3932// used (i.e., a single space as the session name)." So we should accept that.
3933TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) {
3934 JsepSessionDescription jsep_desc(kDummyType);
3935 std::string sdp = kSdpString;
3936 Replace("s=-\r\n", "s= \r\n", &sdp);
3937 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3938}
Amit Hilbucha2012042018-12-03 11:35:05 -08003939
3940// Simulcast malformed input test for invalid format.
3941TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_EmptyAttribute) {
3942 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
3943 "a=simulcast:\r\n", "a=simulcast:");
3944}
3945
3946// Tests that duplicate simulcast entries in the SDP triggers a parse failure.
3947TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_DuplicateAttribute) {
3948 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
3949 "a=simulcast:send 1\r\na=simulcast:recv 2\r\n",
3950 "a=simulcast:");
3951}
3952
3953// Validates that deserialization uses the a=simulcast: attribute
3954TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttribute) {
3955 std::string sdp = kSdpFullString;
3956 sdp += "a=simulcast:send 1,2;3 recv 4;5;6\r\n";
3957 JsepSessionDescription output(kDummyType);
3958 SdpParseError error;
3959 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
3960 const cricket::ContentInfos& contents = output.description()->contents();
3961 const cricket::MediaContentDescription* media =
3962 contents.back().media_description();
3963 EXPECT_TRUE(media->HasSimulcast());
3964 EXPECT_EQ(2ul, media->simulcast_description().send_layers().size());
3965 EXPECT_EQ(3ul, media->simulcast_description().receive_layers().size());
3966}
3967
3968// Simulcast serialization integration test.
3969// This test will serialize and deserialize the description and compare.
3970// More detailed tests for parsing simulcast can be found in
3971// unit tests for SdpSerializer.
3972TEST_F(WebRtcSdpTest, SerializeSimulcast_ComplexSerialization) {
3973 MakeUnifiedPlanDescription();
3974 auto description = jdesc_.description();
3975 auto media = description->GetContentDescriptionByName(kVideoContentName3);
3976 SimulcastDescription& simulcast = media->simulcast_description();
3977 simulcast.send_layers().AddLayerWithAlternatives(
3978 {SimulcastLayer("2", false), SimulcastLayer("1", true)});
3979 simulcast.send_layers().AddLayerWithAlternatives(
3980 {SimulcastLayer("4", false), SimulcastLayer("3", false)});
3981
3982 simulcast.receive_layers().AddLayerWithAlternatives(
3983 {SimulcastLayer("6", false), SimulcastLayer("7", false)});
3984 simulcast.receive_layers().AddLayer(SimulcastLayer("8", true));
3985 simulcast.receive_layers().AddLayerWithAlternatives(
3986 {SimulcastLayer("9", false), SimulcastLayer("10", true),
3987 SimulcastLayer("11", false)});
3988
3989 TestSerialize(jdesc_);
3990}