blob: 0ecba4c25e5ae764e05e84a9e12c623240f4ee03 [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 Hilbuchc57d5732018-12-11 15:30:11 -080063using cricket::RidDescription;
64using cricket::RidDirection;
Amit Hilbucha2012042018-12-03 11:35:05 -080065using cricket::SimulcastDescription;
66using cricket::SimulcastLayer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000067using cricket::StreamParams;
68using cricket::STUN_PORT_TYPE;
69using cricket::TransportDescription;
70using cricket::TransportInfo;
71using cricket::VideoCodec;
72using cricket::VideoContentDescription;
73using webrtc::IceCandidateCollection;
74using webrtc::IceCandidateInterface;
75using webrtc::JsepIceCandidate;
76using webrtc::JsepSessionDescription;
isheriff6f8d6862016-05-26 11:24:55 -070077using webrtc::RtpExtension;
Steve Anton4e70a722017-11-28 14:57:10 -080078using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079using webrtc::SdpParseError;
Steve Antona3a92c22017-12-07 10:27:41 -080080using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000081using webrtc::SessionDescriptionInterface;
82
83typedef std::vector<AudioCodec> AudioCodecs;
84typedef std::vector<Candidate> Candidates;
85
Peter Boström0c4e06b2015-10-07 12:23:21 +020086static const uint32_t kDefaultSctpPort = 5000;
zstein4b2e0822017-02-17 19:48:38 -080087static const char kDefaultSctpPortStr[] = "5000";
88static const uint16_t kUnusualSctpPort = 9556;
89static const char kUnusualSctpPortStr[] = "9556";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020091static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 15:17:14 -080092static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000093static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 15:17:14 -080094static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020096static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000097static const char kCandidateFoundation1[] = "a0+B/1";
98static const char kCandidateFoundation2[] = "a0+B/2";
99static const char kCandidateFoundation3[] = "a0+B/3";
100static const char kCandidateFoundation4[] = "a0+B/4";
101static const char kAttributeCryptoVoice[] =
102 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
103 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
104 "dummy_session_params\r\n";
105static const char kAttributeCryptoVideo[] =
106 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
107 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
Yves Gerey665174f2018-06-19 15:03:05 +0200108static const char kFingerprint[] =
109 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000110 "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 +0200111static const char kExtmapAllowMixed[] = "a=extmap-allow-mixed\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000112static const int kExtmapId = 1;
113static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
114static const char kExtmap[] =
115 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
116static const char kExtmapWithDirectionAndAttribute[] =
117 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
jbauch5869f502017-06-29 12:31:36 -0700118static const char kExtmapWithDirectionAndAttributeEncrypted[] =
119 "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt "
120 "http://example.com/082005/ext.htm#ttime a1 a2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121
Peter Boström0c4e06b2015-10-07 12:23:21 +0200122static const uint8_t kIdentityDigest[] = {
123 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
124 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125
lally@webrtc.org34807282015-02-24 20:19:39 +0000126static const char kDtlsSctp[] = "DTLS/SCTP";
127static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
128static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +0000129
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000130struct CodecParams {
131 int max_ptime;
132 int ptime;
133 int min_ptime;
134 int sprop_stereo;
135 int stereo;
136 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000137 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000138};
139
deadbeef9d3584c2016-02-16 17:54:10 -0800140// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
141// instead of "a=crypto", and have an explicit test for adding "a=crypto".
142// Currently it's the other way around.
143
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000144// Reference sdp string
145static const char kSdpFullString[] =
146 "v=0\r\n"
147 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
148 "s=-\r\n"
149 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800150 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000151 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
152 "c=IN IP4 74.125.127.126\r\n"
153 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
154 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
155 "generation 2\r\n"
156 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
157 "generation 2\r\n"
158 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
159 "generation 2\r\n"
160 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
161 "generation 2\r\n"
162 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
163 "raddr 192.168.1.5 rport 2346 "
164 "generation 2\r\n"
165 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
166 "raddr 192.168.1.5 rport 2348 "
167 "generation 2\r\n"
168 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
169 "a=mid:audio_content_name\r\n"
170 "a=sendrecv\r\n"
171 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800172 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000173 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
174 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
175 "dummy_session_params\r\n"
176 "a=rtpmap:111 opus/48000/2\r\n"
177 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000178 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000179 "a=ssrc:1 cname:stream_1_cname\r\n"
180 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
181 "a=ssrc:1 mslabel:local_stream_1\r\n"
182 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000183 "m=video 3457 RTP/SAVPF 120\r\n"
184 "c=IN IP4 74.125.224.39\r\n"
185 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
186 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
187 "generation 2\r\n"
188 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
189 "generation 2\r\n"
190 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
191 "generation 2\r\n"
192 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
193 "generation 2\r\n"
194 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
195 "generation 2\r\n"
196 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
197 "generation 2\r\n"
198 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
199 "a=mid:video_content_name\r\n"
200 "a=sendrecv\r\n"
201 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
202 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
203 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800204 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000205 "a=ssrc:2 cname:stream_1_cname\r\n"
206 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
207 "a=ssrc:2 mslabel:local_stream_1\r\n"
208 "a=ssrc:2 label:video_track_id_1\r\n"
209 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800210 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800212 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213
214// SDP reference string without the candidates.
215static const char kSdpString[] =
216 "v=0\r\n"
217 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
218 "s=-\r\n"
219 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800220 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000221 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000222 "c=IN IP4 0.0.0.0\r\n"
223 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000224 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
225 "a=mid:audio_content_name\r\n"
226 "a=sendrecv\r\n"
227 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800228 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000229 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
230 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
231 "dummy_session_params\r\n"
232 "a=rtpmap:111 opus/48000/2\r\n"
233 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000234 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000235 "a=ssrc:1 cname:stream_1_cname\r\n"
236 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
237 "a=ssrc:1 mslabel:local_stream_1\r\n"
238 "a=ssrc:1 label:audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000239 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000240 "c=IN IP4 0.0.0.0\r\n"
241 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000242 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
243 "a=mid:video_content_name\r\n"
244 "a=sendrecv\r\n"
245 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
246 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
247 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800248 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000249 "a=ssrc:2 cname:stream_1_cname\r\n"
250 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
251 "a=ssrc:2 mslabel:local_stream_1\r\n"
252 "a=ssrc:2 label:video_track_id_1\r\n"
253 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800254 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000255 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800256 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000257
258static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000259 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000260 "c=IN IP4 0.0.0.0\r\n"
261 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000262 "a=ice-ufrag:ufrag_data\r\n"
263 "a=ice-pwd:pwd_data\r\n"
264 "a=mid:data_content_name\r\n"
265 "a=sendrecv\r\n"
266 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
267 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
268 "a=rtpmap:101 google-data/90000\r\n"
269 "a=ssrc:10 cname:data_channel_cname\r\n"
270 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
271 "a=ssrc:10 mslabel:data_channel\r\n"
272 "a=ssrc:10 label:data_channeld0\r\n";
273
274static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000275 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000276 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000277 "a=ice-ufrag:ufrag_data\r\n"
278 "a=ice-pwd:pwd_data\r\n"
279 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000280 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000281
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000282// draft-ietf-mmusic-sctp-sdp-12
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000283static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000284 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
285 "a=max-message-size=100000\r\n"
286 "a=sctp-port 5000\r\n"
287 "c=IN IP4 0.0.0.0\r\n"
288 "a=ice-ufrag:ufrag_data\r\n"
289 "a=ice-pwd:pwd_data\r\n"
290 "a=mid:data_content_name\r\n";
291
lally69f57602015-10-08 10:15:04 -0700292static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
293 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
294 "a=max-message-size=100000\r\n"
295 "a=sctp-port:5000\r\n"
296 "c=IN IP4 0.0.0.0\r\n"
297 "a=ice-ufrag:ufrag_data\r\n"
298 "a=ice-pwd:pwd_data\r\n"
299 "a=mid:data_content_name\r\n";
300
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000301static const char kSdpSctpDataChannelWithCandidatesString[] =
302 "m=application 2345 DTLS/SCTP 5000\r\n"
303 "c=IN IP4 74.125.127.126\r\n"
304 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
305 "generation 2\r\n"
306 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
307 "generation 2\r\n"
308 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
309 "raddr 192.168.1.5 rport 2346 "
310 "generation 2\r\n"
311 "a=ice-ufrag:ufrag_data\r\n"
312 "a=ice-pwd:pwd_data\r\n"
313 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000314 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000315
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000316static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000317 "v=0\r\n"
318 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
319 "s=-\r\n"
320 "t=0 0\r\n"
321 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000322 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000323 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000324 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000325 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000326 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000327 "a=x-google-flag:conference\r\n";
328
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000329static const char kSdpSessionString[] =
330 "v=0\r\n"
331 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
332 "s=-\r\n"
333 "t=0 0\r\n"
334 "a=msid-semantic: WMS local_stream\r\n";
335
336static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000337 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000338 "c=IN IP4 0.0.0.0\r\n"
339 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000340 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
341 "a=mid:audio_content_name\r\n"
342 "a=sendrecv\r\n"
343 "a=rtpmap:111 opus/48000/2\r\n"
344 "a=ssrc:1 cname:stream_1_cname\r\n"
345 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
346 "a=ssrc:1 mslabel:local_stream\r\n"
347 "a=ssrc:1 label:audio_track_id_1\r\n";
348
349static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000350 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000351 "c=IN IP4 0.0.0.0\r\n"
352 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000353 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
354 "a=mid:video_content_name\r\n"
355 "a=sendrecv\r\n"
356 "a=rtpmap:120 VP8/90000\r\n"
357 "a=ssrc:2 cname:stream_1_cname\r\n"
358 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
359 "a=ssrc:2 mslabel:local_stream\r\n"
360 "a=ssrc:2 label:video_track_id_1\r\n";
361
deadbeef25ed4352016-12-12 18:37:36 -0800362// Reference sdp string using bundle-only.
363static const char kBundleOnlySdpFullString[] =
364 "v=0\r\n"
365 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
366 "s=-\r\n"
367 "t=0 0\r\n"
368 "a=group:BUNDLE audio_content_name video_content_name\r\n"
369 "a=msid-semantic: WMS local_stream_1\r\n"
370 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
371 "c=IN IP4 74.125.127.126\r\n"
372 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
373 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
374 "generation 2\r\n"
375 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
376 "generation 2\r\n"
377 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
378 "generation 2\r\n"
379 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
380 "generation 2\r\n"
381 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
382 "raddr 192.168.1.5 rport 2346 "
383 "generation 2\r\n"
384 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
385 "raddr 192.168.1.5 rport 2348 "
386 "generation 2\r\n"
387 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
388 "a=mid:audio_content_name\r\n"
389 "a=sendrecv\r\n"
390 "a=rtcp-mux\r\n"
391 "a=rtcp-rsize\r\n"
392 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
393 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
394 "dummy_session_params\r\n"
395 "a=rtpmap:111 opus/48000/2\r\n"
396 "a=rtpmap:103 ISAC/16000\r\n"
397 "a=rtpmap:104 ISAC/32000\r\n"
398 "a=ssrc:1 cname:stream_1_cname\r\n"
399 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
400 "a=ssrc:1 mslabel:local_stream_1\r\n"
401 "a=ssrc:1 label:audio_track_id_1\r\n"
402 "m=video 0 RTP/SAVPF 120\r\n"
403 "c=IN IP4 0.0.0.0\r\n"
404 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
405 "a=bundle-only\r\n"
406 "a=mid:video_content_name\r\n"
407 "a=sendrecv\r\n"
408 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
409 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
410 "a=rtpmap:120 VP8/90000\r\n"
411 "a=ssrc-group:FEC 2 3\r\n"
412 "a=ssrc:2 cname:stream_1_cname\r\n"
413 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
414 "a=ssrc:2 mslabel:local_stream_1\r\n"
415 "a=ssrc:2 label:video_track_id_1\r\n"
416 "a=ssrc:3 cname:stream_1_cname\r\n"
417 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
418 "a=ssrc:3 mslabel:local_stream_1\r\n"
419 "a=ssrc:3 label:video_track_id_1\r\n";
420
deadbeef9d3584c2016-02-16 17:54:10 -0800421// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
422// tracks.
423static const char kPlanBSdpFullString[] =
424 "v=0\r\n"
425 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
426 "s=-\r\n"
427 "t=0 0\r\n"
428 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
429 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
430 "c=IN IP4 74.125.127.126\r\n"
431 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
432 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
433 "generation 2\r\n"
434 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
435 "generation 2\r\n"
436 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
437 "generation 2\r\n"
438 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
439 "generation 2\r\n"
440 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
441 "raddr 192.168.1.5 rport 2346 "
442 "generation 2\r\n"
443 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
444 "raddr 192.168.1.5 rport 2348 "
445 "generation 2\r\n"
446 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
447 "a=mid:audio_content_name\r\n"
448 "a=sendrecv\r\n"
449 "a=rtcp-mux\r\n"
450 "a=rtcp-rsize\r\n"
451 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
452 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
453 "dummy_session_params\r\n"
454 "a=rtpmap:111 opus/48000/2\r\n"
455 "a=rtpmap:103 ISAC/16000\r\n"
456 "a=rtpmap:104 ISAC/32000\r\n"
457 "a=ssrc:1 cname:stream_1_cname\r\n"
458 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
459 "a=ssrc:1 mslabel:local_stream_1\r\n"
460 "a=ssrc:1 label:audio_track_id_1\r\n"
461 "a=ssrc:4 cname:stream_2_cname\r\n"
462 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
463 "a=ssrc:4 mslabel:local_stream_2\r\n"
464 "a=ssrc:4 label:audio_track_id_2\r\n"
465 "m=video 3457 RTP/SAVPF 120\r\n"
466 "c=IN IP4 74.125.224.39\r\n"
467 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
468 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
469 "generation 2\r\n"
470 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
471 "generation 2\r\n"
472 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
473 "generation 2\r\n"
474 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
475 "generation 2\r\n"
476 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
477 "generation 2\r\n"
478 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
479 "generation 2\r\n"
480 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
481 "a=mid:video_content_name\r\n"
482 "a=sendrecv\r\n"
483 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
484 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
485 "a=rtpmap:120 VP8/90000\r\n"
486 "a=ssrc-group:FEC 2 3\r\n"
487 "a=ssrc:2 cname:stream_1_cname\r\n"
488 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
489 "a=ssrc:2 mslabel:local_stream_1\r\n"
490 "a=ssrc:2 label:video_track_id_1\r\n"
491 "a=ssrc:3 cname:stream_1_cname\r\n"
492 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
493 "a=ssrc:3 mslabel:local_stream_1\r\n"
494 "a=ssrc:3 label:video_track_id_1\r\n"
495 "a=ssrc:5 cname:stream_2_cname\r\n"
496 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
497 "a=ssrc:5 mslabel:local_stream_2\r\n"
498 "a=ssrc:5 label:video_track_id_2\r\n"
499 "a=ssrc:6 cname:stream_2_cname\r\n"
500 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
501 "a=ssrc:6 mslabel:local_stream_2\r\n"
502 "a=ssrc:6 label:video_track_id_3\r\n";
503
504// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
505// tracks.
506static const char kUnifiedPlanSdpFullString[] =
507 "v=0\r\n"
508 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
509 "s=-\r\n"
510 "t=0 0\r\n"
511 "a=msid-semantic: WMS local_stream_1\r\n"
512 // Audio track 1, stream 1 (with candidates).
513 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
514 "c=IN IP4 74.125.127.126\r\n"
515 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
516 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
517 "generation 2\r\n"
518 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
519 "generation 2\r\n"
520 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
521 "generation 2\r\n"
522 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
523 "generation 2\r\n"
524 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
525 "raddr 192.168.1.5 rport 2346 "
526 "generation 2\r\n"
527 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
528 "raddr 192.168.1.5 rport 2348 "
529 "generation 2\r\n"
530 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
531 "a=mid:audio_content_name\r\n"
532 "a=msid:local_stream_1 audio_track_id_1\r\n"
533 "a=sendrecv\r\n"
534 "a=rtcp-mux\r\n"
535 "a=rtcp-rsize\r\n"
536 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
537 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
538 "dummy_session_params\r\n"
539 "a=rtpmap:111 opus/48000/2\r\n"
540 "a=rtpmap:103 ISAC/16000\r\n"
541 "a=rtpmap:104 ISAC/32000\r\n"
542 "a=ssrc:1 cname:stream_1_cname\r\n"
543 // Video track 1, stream 1 (with candidates).
544 "m=video 3457 RTP/SAVPF 120\r\n"
545 "c=IN IP4 74.125.224.39\r\n"
546 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
547 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
548 "generation 2\r\n"
549 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
550 "generation 2\r\n"
551 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
552 "generation 2\r\n"
553 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
554 "generation 2\r\n"
555 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
556 "generation 2\r\n"
557 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
558 "generation 2\r\n"
559 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
560 "a=mid:video_content_name\r\n"
561 "a=msid:local_stream_1 video_track_id_1\r\n"
562 "a=sendrecv\r\n"
563 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
564 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
565 "a=rtpmap:120 VP8/90000\r\n"
566 "a=ssrc-group:FEC 2 3\r\n"
567 "a=ssrc:2 cname:stream_1_cname\r\n"
568 "a=ssrc:3 cname:stream_1_cname\r\n"
569 // Audio track 2, stream 2.
570 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
571 "c=IN IP4 0.0.0.0\r\n"
572 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
573 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
574 "a=mid:audio_content_name_2\r\n"
575 "a=msid:local_stream_2 audio_track_id_2\r\n"
576 "a=sendrecv\r\n"
577 "a=rtcp-mux\r\n"
578 "a=rtcp-rsize\r\n"
579 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
580 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
581 "dummy_session_params\r\n"
582 "a=rtpmap:111 opus/48000/2\r\n"
583 "a=rtpmap:103 ISAC/16000\r\n"
584 "a=rtpmap:104 ISAC/32000\r\n"
585 "a=ssrc:4 cname:stream_2_cname\r\n"
586 // Video track 2, stream 2.
587 "m=video 9 RTP/SAVPF 120\r\n"
588 "c=IN IP4 0.0.0.0\r\n"
589 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
590 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
591 "a=mid:video_content_name_2\r\n"
592 "a=msid:local_stream_2 video_track_id_2\r\n"
593 "a=sendrecv\r\n"
594 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
595 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
596 "a=rtpmap:120 VP8/90000\r\n"
597 "a=ssrc:5 cname:stream_2_cname\r\n"
598 // Video track 3, stream 2.
599 "m=video 9 RTP/SAVPF 120\r\n"
600 "c=IN IP4 0.0.0.0\r\n"
601 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
602 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
603 "a=mid:video_content_name_3\r\n"
604 "a=msid:local_stream_2 video_track_id_3\r\n"
605 "a=sendrecv\r\n"
606 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
607 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
608 "a=rtpmap:120 VP8/90000\r\n"
609 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000610
Seth Hampson5b4f0752018-04-02 16:31:36 -0700611// Unified Plan SDP reference string:
612// - audio track 1 has 1 a=msid lines
613// - audio track 2 has 2 a=msid lines
614// - audio track 3 has 1 a=msid line with the special "-" marker signifying that
615// there are 0 media stream ids.
616// This Unified Plan SDP represents a SDP that signals the msid using both
617// a=msid and a=ssrc msid semantics.
618static const char kUnifiedPlanSdpFullStringWithSpecialMsid[] =
619 "v=0\r\n"
620 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
621 "s=-\r\n"
622 "t=0 0\r\n"
623 "a=msid-semantic: WMS local_stream_1\r\n"
624 // Audio track 1, with 1 stream id.
625 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
626 "c=IN IP4 74.125.127.126\r\n"
627 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
628 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
629 "generation 2\r\n"
630 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
631 "generation 2\r\n"
632 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
633 "generation 2\r\n"
634 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
635 "generation 2\r\n"
636 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
637 "raddr 192.168.1.5 rport 2346 "
638 "generation 2\r\n"
639 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
640 "raddr 192.168.1.5 rport 2348 "
641 "generation 2\r\n"
642 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
643 "a=mid:audio_content_name\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700644 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700645 "a=msid:local_stream_1 audio_track_id_1\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700646 "a=rtcp-mux\r\n"
647 "a=rtcp-rsize\r\n"
648 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
649 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
650 "dummy_session_params\r\n"
651 "a=rtpmap:111 opus/48000/2\r\n"
652 "a=rtpmap:103 ISAC/16000\r\n"
653 "a=rtpmap:104 ISAC/32000\r\n"
654 "a=ssrc:1 cname:stream_1_cname\r\n"
655 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
656 "a=ssrc:1 mslabel:local_stream_1\r\n"
657 "a=ssrc:1 label:audio_track_id_1\r\n"
658 // Audio track 2, with two stream ids.
659 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
660 "c=IN IP4 0.0.0.0\r\n"
661 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
662 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
663 "a=mid:audio_content_name_2\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700664 "a=sendrecv\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700665 "a=msid:local_stream_1 audio_track_id_2\r\n"
666 "a=msid:local_stream_2 audio_track_id_2\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700667 "a=rtcp-mux\r\n"
668 "a=rtcp-rsize\r\n"
669 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
670 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
671 "dummy_session_params\r\n"
672 "a=rtpmap:111 opus/48000/2\r\n"
673 "a=rtpmap:103 ISAC/16000\r\n"
674 "a=rtpmap:104 ISAC/32000\r\n"
675 "a=ssrc:4 cname:stream_1_cname\r\n"
676 // The support for Plan B msid signaling only includes the
677 // first media stream id "local_stream_1."
678 "a=ssrc:4 msid:local_stream_1 audio_track_id_2\r\n"
679 "a=ssrc:4 mslabel:local_stream_1\r\n"
680 "a=ssrc:4 label:audio_track_id_2\r\n"
681 // Audio track 3, with no stream ids.
682 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
683 "c=IN IP4 0.0.0.0\r\n"
684 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
685 "a=ice-ufrag:ufrag_voice_3\r\na=ice-pwd:pwd_voice_3\r\n"
686 "a=mid:audio_content_name_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700687 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700688 "a=msid:- audio_track_id_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700689 "a=rtcp-mux\r\n"
690 "a=rtcp-rsize\r\n"
691 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
692 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
693 "dummy_session_params\r\n"
694 "a=rtpmap:111 opus/48000/2\r\n"
695 "a=rtpmap:103 ISAC/16000\r\n"
696 "a=rtpmap:104 ISAC/32000\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700697 "a=ssrc:7 cname:stream_2_cname\r\n"
698 "a=ssrc:7 msid:- audio_track_id_3\r\n"
699 "a=ssrc:7 mslabel:-\r\n"
700 "a=ssrc:7 label:audio_track_id_3\r\n";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700701
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800702// SDP string for unified plan without SSRCs
703static const char kUnifiedPlanSdpFullStringNoSsrc[] =
704 "v=0\r\n"
705 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
706 "s=-\r\n"
707 "t=0 0\r\n"
708 "a=msid-semantic: WMS local_stream_1\r\n"
709 // Audio track 1, stream 1 (with candidates).
710 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
711 "c=IN IP4 74.125.127.126\r\n"
712 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
713 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
714 "generation 2\r\n"
715 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
716 "generation 2\r\n"
717 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
718 "generation 2\r\n"
719 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
720 "generation 2\r\n"
721 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
722 "raddr 192.168.1.5 rport 2346 "
723 "generation 2\r\n"
724 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
725 "raddr 192.168.1.5 rport 2348 "
726 "generation 2\r\n"
727 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
728 "a=mid:audio_content_name\r\n"
729 "a=msid:local_stream_1 audio_track_id_1\r\n"
730 "a=sendrecv\r\n"
731 "a=rtcp-mux\r\n"
732 "a=rtcp-rsize\r\n"
733 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
734 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
735 "dummy_session_params\r\n"
736 "a=rtpmap:111 opus/48000/2\r\n"
737 "a=rtpmap:103 ISAC/16000\r\n"
738 "a=rtpmap:104 ISAC/32000\r\n"
739 // Video track 1, stream 1 (with candidates).
740 "m=video 3457 RTP/SAVPF 120\r\n"
741 "c=IN IP4 74.125.224.39\r\n"
742 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
743 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
744 "generation 2\r\n"
745 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
746 "generation 2\r\n"
747 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
748 "generation 2\r\n"
749 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
750 "generation 2\r\n"
751 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
752 "generation 2\r\n"
753 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
754 "generation 2\r\n"
755 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
756 "a=mid:video_content_name\r\n"
757 "a=msid:local_stream_1 video_track_id_1\r\n"
758 "a=sendrecv\r\n"
759 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
760 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
761 "a=rtpmap:120 VP8/90000\r\n"
762 // Audio track 2, stream 2.
763 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
764 "c=IN IP4 0.0.0.0\r\n"
765 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
766 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
767 "a=mid:audio_content_name_2\r\n"
768 "a=msid:local_stream_2 audio_track_id_2\r\n"
769 "a=sendrecv\r\n"
770 "a=rtcp-mux\r\n"
771 "a=rtcp-rsize\r\n"
772 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
773 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
774 "dummy_session_params\r\n"
775 "a=rtpmap:111 opus/48000/2\r\n"
776 "a=rtpmap:103 ISAC/16000\r\n"
777 "a=rtpmap:104 ISAC/32000\r\n"
778 // Video track 2, stream 2.
779 "m=video 9 RTP/SAVPF 120\r\n"
780 "c=IN IP4 0.0.0.0\r\n"
781 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
782 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
783 "a=mid:video_content_name_2\r\n"
784 "a=msid:local_stream_2 video_track_id_2\r\n"
785 "a=sendrecv\r\n"
786 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
787 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
788 "a=rtpmap:120 VP8/90000\r\n"
789 // Video track 3, stream 2.
790 "m=video 9 RTP/SAVPF 120\r\n"
791 "c=IN IP4 0.0.0.0\r\n"
792 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
793 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
794 "a=mid:video_content_name_3\r\n"
795 "a=msid:local_stream_2 video_track_id_3\r\n"
796 "a=sendrecv\r\n"
797 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
798 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
799 "a=rtpmap:120 VP8/90000\r\n";
800
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000801// One candidate reference string as per W3c spec.
802// candidate:<blah> not a=candidate:<blah>CRLF
803static const char kRawCandidate[] =
804 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
805// One candidate reference string.
806static const char kSdpOneCandidate[] =
807 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
808 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000809
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000810static const char kSdpTcpActiveCandidate[] =
811 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
812 "tcptype active generation 2";
813static const char kSdpTcpPassiveCandidate[] =
814 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
815 "tcptype passive generation 2";
816static const char kSdpTcpSOCandidate[] =
817 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
818 "tcptype so generation 2";
819static const char kSdpTcpInvalidCandidate[] =
820 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
821 "tcptype invalid generation 2";
822
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000823// One candidate reference string with IPV6 address.
824static const char kRawIPV6Candidate[] =
825 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 12:04:36 -0700826 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000827
828// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800829static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000830 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800831 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000832
Zach Steinb336c272018-08-09 01:16:13 -0700833static const char kRawHostnameCandidate[] =
834 "candidate:a0+B/1 1 udp 2130706432 a.test 1234 typ host generation 2";
835
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000836// Session id and version
837static const char kSessionId[] = "18446744069414584320";
838static const char kSessionVersion[] = "18446462598732840960";
839
deadbeef9d3584c2016-02-16 17:54:10 -0800840// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000841static const char kIceOption1[] = "iceoption1";
842static const char kIceOption2[] = "iceoption2";
843static const char kIceOption3[] = "iceoption3";
844
deadbeef9d3584c2016-02-16 17:54:10 -0800845// ICE ufrags/passwords.
846static const char kUfragVoice[] = "ufrag_voice";
847static const char kPwdVoice[] = "pwd_voice";
848static const char kUfragVideo[] = "ufrag_video";
849static const char kPwdVideo[] = "pwd_video";
850static const char kUfragData[] = "ufrag_data";
851static const char kPwdData[] = "pwd_data";
852
853// Extra ufrags/passwords for extra unified plan m= sections.
854static const char kUfragVoice2[] = "ufrag_voice_2";
855static const char kPwdVoice2[] = "pwd_voice_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700856static const char kUfragVoice3[] = "ufrag_voice_3";
857static const char kPwdVoice3[] = "pwd_voice_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800858static const char kUfragVideo2[] = "ufrag_video_2";
859static const char kPwdVideo2[] = "pwd_video_2";
860static const char kUfragVideo3[] = "ufrag_video_3";
861static const char kPwdVideo3[] = "pwd_video_3";
862
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000863// Content name
864static const char kAudioContentName[] = "audio_content_name";
865static const char kVideoContentName[] = "video_content_name";
866static const char kDataContentName[] = "data_content_name";
867
deadbeef9d3584c2016-02-16 17:54:10 -0800868// Extra content names for extra unified plan m= sections.
869static const char kAudioContentName2[] = "audio_content_name_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700870static const char kAudioContentName3[] = "audio_content_name_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800871static const char kVideoContentName2[] = "video_content_name_2";
872static const char kVideoContentName3[] = "video_content_name_3";
873
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000874// MediaStream 1
Seth Hampson845e8782018-03-02 11:34:10 -0800875static const char kStreamId1[] = "local_stream_1";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876static const char kStream1Cname[] = "stream_1_cname";
877static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200878static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000879static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800880static const uint32_t kVideoTrack1Ssrc1 = 2;
881static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000882
883// MediaStream 2
Seth Hampson845e8782018-03-02 11:34:10 -0800884static const char kStreamId2[] = "local_stream_2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000885static const char kStream2Cname[] = "stream_2_cname";
886static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200887static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800888static const char kVideoTrackId2[] = "video_track_id_2";
889static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800891static const uint32_t kVideoTrack3Ssrc = 6;
Seth Hampson5b4f0752018-04-02 16:31:36 -0700892static const char kAudioTrackId3[] = "audio_track_id_3";
893static const uint32_t kAudioTrack3Ssrc = 7;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000894
895// DataChannel
896static const char kDataChannelLabel[] = "data_channel";
897static const char kDataChannelMsid[] = "data_channeld0";
898static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200899static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000900
901// Candidate
902static const char kDummyMid[] = "dummy_mid";
903static const int kDummyIndex = 123;
904
905// Misc
Steve Antona3a92c22017-12-07 10:27:41 -0800906static SdpType kDummyType = SdpType::kOffer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000907
908// Helper functions
909
910static bool SdpDeserialize(const std::string& message,
911 JsepSessionDescription* jdesc) {
912 return webrtc::SdpDeserialize(message, jdesc, NULL);
913}
914
915static bool SdpDeserializeCandidate(const std::string& message,
916 JsepIceCandidate* candidate) {
917 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
918}
919
920// Add some extra |newlines| to the |message| after |line|.
921static void InjectAfter(const std::string& line,
922 const std::string& newlines,
923 std::string* message) {
924 const std::string tmp = line + newlines;
Yves Gerey665174f2018-06-19 15:03:05 +0200925 rtc::replace_substrs(line.c_str(), line.length(), tmp.c_str(), tmp.length(),
926 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000927}
928
929static void Replace(const std::string& line,
930 const std::string& newlines,
931 std::string* message) {
Yves Gerey665174f2018-06-19 15:03:05 +0200932 rtc::replace_substrs(line.c_str(), line.length(), newlines.c_str(),
933 newlines.length(), message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000934}
935
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000936// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
937// message.
938static void ExpectParseFailure(const std::string& bad_sdp,
939 const std::string& bad_part) {
Steve Antona3a92c22017-12-07 10:27:41 -0800940 JsepSessionDescription desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000941 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000942 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000943 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000944 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
945}
946
947// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
948static void ExpectParseFailure(const char* good_part, const char* bad_part) {
949 std::string bad_sdp = kSdpFullString;
950 Replace(good_part, bad_part, &bad_sdp);
951 ExpectParseFailure(bad_sdp, bad_part);
952}
953
954// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
955static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
956 const std::string& newlines,
957 const std::string& bad_part) {
958 std::string bad_sdp = kSdpFullString;
959 InjectAfter(injectpoint, newlines, &bad_sdp);
960 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000961}
962
Steve Anton4e70a722017-11-28 14:57:10 -0800963static void ReplaceDirection(RtpTransceiverDirection direction,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000964 std::string* message) {
965 std::string new_direction;
966 switch (direction) {
Steve Anton4e70a722017-11-28 14:57:10 -0800967 case RtpTransceiverDirection::kInactive:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000968 new_direction = "a=inactive";
969 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800970 case RtpTransceiverDirection::kSendOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000971 new_direction = "a=sendonly";
972 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800973 case RtpTransceiverDirection::kRecvOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000974 new_direction = "a=recvonly";
975 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800976 case RtpTransceiverDirection::kSendRecv:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000977 default:
978 new_direction = "a=sendrecv";
979 break;
980 }
981 Replace("a=sendrecv", new_direction, message);
982}
983
Yves Gerey665174f2018-06-19 15:03:05 +0200984static void ReplaceRejected(bool audio_rejected,
985 bool video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000986 std::string* message) {
987 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800988 Replace("m=audio 9", "m=audio 0", message);
989 Replace(kAttributeIceUfragVoice, "", message);
990 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000991 }
992 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800993 Replace("m=video 9", "m=video 0", message);
994 Replace(kAttributeIceUfragVideo, "", message);
995 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000996 }
997}
998
999// WebRtcSdpTest
1000
1001class WebRtcSdpTest : public testing::Test {
1002 public:
Steve Antona3a92c22017-12-07 10:27:41 -08001003 WebRtcSdpTest() : jdesc_(kDummyType) {
phoglund37ebcf02016-01-08 05:04:57 -08001004#ifdef WEBRTC_ANDROID
1005 webrtc::InitializeAndroidObjects();
1006#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001007 // AudioContentDescription
1008 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -08001009 StreamParams audio_stream;
1010 audio_stream.id = kAudioTrackId1;
1011 audio_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001012 audio_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -08001013 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
1014 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 11:04:53 -07001015 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
1016 audio_desc_->set_connection_address(audio_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -08001017 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001018
1019 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -08001020 video_desc_ = CreateVideoContentDescription();
1021 StreamParams video_stream;
1022 video_stream.id = kVideoTrackId1;
1023 video_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001024 video_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -08001025 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
1026 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
1027 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
1028 video_stream.ssrc_groups.push_back(ssrc_group);
1029 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 11:04:53 -07001030 rtc::SocketAddress video_addr("74.125.224.39", 3457);
1031 video_desc_->set_connection_address(video_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -08001032 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001033
1034 // TransportInfo
deadbeef9d3584c2016-02-16 17:54:10 -08001035 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1036 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice))));
1037 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1038 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001039
1040 // v4 host
1041 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001042 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001043 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001044 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1045 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001046 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001047 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001048 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1049 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001050 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001051 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001052 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1053 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001054 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001055 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001056 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1057 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001058
1059 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001060 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001061 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1062 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001063 cricket::LOCAL_PORT_TYPE,
1064 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001065 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001066 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1067 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001068 cricket::LOCAL_PORT_TYPE,
1069 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001070 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001071 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1072 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001073 cricket::LOCAL_PORT_TYPE,
1074 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001075 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001076 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1077 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001078 cricket::LOCAL_PORT_TYPE,
1079 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001080
1081 // stun
1082 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001083 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
1084 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001085 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1086 address_stun, kCandidatePriority, "", "",
1087 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001088 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001089 candidate9.set_related_address(rel_address_stun);
1090
1091 address_stun.SetPort(port_stun++);
1092 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001093 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1094 address_stun, kCandidatePriority, "", "",
1095 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001096 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001097 candidate10.set_related_address(rel_address_stun);
1098
1099 // relay
1100 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001101 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001102 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1103 address_relay, kCandidatePriority, "", "",
1104 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001105 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001106 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001107 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1108 address_relay, kCandidatePriority, "", "",
1109 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001110 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001111
1112 // voice
1113 candidates_.push_back(candidate1);
1114 candidates_.push_back(candidate2);
1115 candidates_.push_back(candidate5);
1116 candidates_.push_back(candidate6);
1117 candidates_.push_back(candidate9);
1118 candidates_.push_back(candidate10);
1119
1120 // video
1121 candidates_.push_back(candidate3);
1122 candidates_.push_back(candidate4);
1123 candidates_.push_back(candidate7);
1124 candidates_.push_back(candidate8);
1125 candidates_.push_back(candidate11);
1126 candidates_.push_back(candidate12);
1127
Yves Gerey665174f2018-06-19 15:03:05 +02001128 jcandidate_.reset(
1129 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001130
1131 // Set up JsepSessionDescription.
1132 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
1133 std::string mline_id;
1134 int mline_index = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001135 for (size_t i = 0; i < candidates_.size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001136 // In this test, the audio m line index will be 0, and the video m line
1137 // will be 1.
1138 bool is_video = (i > 5);
1139 mline_id = is_video ? "video_content_name" : "audio_content_name";
1140 mline_index = is_video ? 1 : 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001141 JsepIceCandidate jice(mline_id, mline_index, candidates_.at(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001142 jdesc_.AddCandidate(&jice);
1143 }
1144 }
1145
Seth Hampson5b4f0752018-04-02 16:31:36 -07001146 void RemoveVideoCandidates() {
deadbeef25ed4352016-12-12 18:37:36 -08001147 const IceCandidateCollection* video_candidates_collection =
1148 jdesc_.candidates(1);
1149 ASSERT_NE(nullptr, video_candidates_collection);
1150 std::vector<cricket::Candidate> video_candidates;
1151 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1152 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1153 c.set_transport_name("video_content_name");
1154 video_candidates.push_back(c);
1155 }
1156 jdesc_.RemoveCandidates(video_candidates);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001157 }
1158
1159 // Turns the existing reference description into a description using
1160 // a=bundle-only. This means no transport attributes and a 0 port value on
1161 // the m= sections not associated with the BUNDLE-tag.
1162 void MakeBundleOnlyDescription() {
1163 RemoveVideoCandidates();
deadbeef25ed4352016-12-12 18:37:36 -08001164
1165 // And the rest of the transport attributes.
1166 desc_.transport_infos()[1].description.ice_ufrag.clear();
1167 desc_.transport_infos()[1].description.ice_pwd.clear();
1168 desc_.transport_infos()[1].description.connection_role =
1169 cricket::CONNECTIONROLE_NONE;
1170
1171 // Set bundle-only flag.
1172 desc_.contents()[1].bundle_only = true;
1173
1174 // Add BUNDLE group.
1175 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1176 group.AddContentName(kAudioContentName);
1177 group.AddContentName(kVideoContentName);
1178 desc_.AddGroup(group);
1179
1180 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1181 jdesc_.session_version()));
1182 }
1183
deadbeef9d3584c2016-02-16 17:54:10 -08001184 // Turns the existing reference description into a plan B description,
1185 // with 2 audio tracks and 3 video tracks.
1186 void MakePlanBDescription() {
Steve Antonb1c1de12017-12-21 15:14:30 -08001187 audio_desc_ = audio_desc_->Copy();
1188 video_desc_ = video_desc_->Copy();
deadbeef9d3584c2016-02-16 17:54:10 -08001189
1190 StreamParams audio_track_2;
1191 audio_track_2.id = kAudioTrackId2;
1192 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001193 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001194 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1195 audio_desc_->AddStream(audio_track_2);
1196
1197 StreamParams video_track_2;
1198 video_track_2.id = kVideoTrackId2;
1199 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001200 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001201 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1202 video_desc_->AddStream(video_track_2);
1203
1204 StreamParams video_track_3;
1205 video_track_3.id = kVideoTrackId3;
1206 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001207 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001208 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1209 video_desc_->AddStream(video_track_3);
1210
1211 desc_.RemoveContentByName(kAudioContentName);
1212 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001213 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1214 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001215
1216 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1217 jdesc_.session_version()));
1218 }
1219
1220 // Turns the existing reference description into a unified plan description,
1221 // with 2 audio tracks and 3 video tracks.
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001222 void MakeUnifiedPlanDescription(bool use_ssrcs = true) {
deadbeef9d3584c2016-02-16 17:54:10 -08001223 // Audio track 2.
1224 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1225 StreamParams audio_track_2;
1226 audio_track_2.id = kAudioTrackId2;
Seth Hampson845e8782018-03-02 11:34:10 -08001227 audio_track_2.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001228 if (use_ssrcs) {
1229 audio_track_2.cname = kStream2Cname;
1230 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1231 }
deadbeef9d3584c2016-02-16 17:54:10 -08001232 audio_desc_2->AddStream(audio_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001233 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
deadbeef9d3584c2016-02-16 17:54:10 -08001234 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1235 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
deadbeef9d3584c2016-02-16 17:54:10 -08001236 // Video track 2, in stream 2.
1237 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1238 StreamParams video_track_2;
1239 video_track_2.id = kVideoTrackId2;
Seth Hampson845e8782018-03-02 11:34:10 -08001240 video_track_2.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001241 if (use_ssrcs) {
1242 video_track_2.cname = kStream2Cname;
1243 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1244 }
deadbeef9d3584c2016-02-16 17:54:10 -08001245 video_desc_2->AddStream(video_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001246 desc_.AddContent(kVideoContentName2, MediaProtocolType::kRtp, video_desc_2);
deadbeef9d3584c2016-02-16 17:54:10 -08001247 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1248 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2))));
1249
1250 // Video track 3, in stream 2.
1251 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1252 StreamParams video_track_3;
1253 video_track_3.id = kVideoTrackId3;
Seth Hampson845e8782018-03-02 11:34:10 -08001254 video_track_3.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001255 if (use_ssrcs) {
1256 video_track_3.cname = kStream2Cname;
1257 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1258 }
deadbeef9d3584c2016-02-16 17:54:10 -08001259 video_desc_3->AddStream(video_track_3);
Steve Anton5adfafd2017-12-20 16:34:00 -08001260 desc_.AddContent(kVideoContentName3, MediaProtocolType::kRtp, video_desc_3);
deadbeef9d3584c2016-02-16 17:54:10 -08001261 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1262 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3))));
Steve Antone831b8c2018-02-01 12:22:16 -08001263 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
deadbeef9d3584c2016-02-16 17:54:10 -08001264
1265 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1266 jdesc_.session_version()));
1267 }
1268
1269 // Creates an audio content description with no streams, and some default
1270 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001271 AudioContentDescription* CreateAudioContentDescription() {
1272 AudioContentDescription* audio = new AudioContentDescription();
1273 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -08001274 audio->set_rtcp_reduced_size(true);
Yves Gerey665174f2018-06-19 15:03:05 +02001275 audio->AddCrypto(CryptoParams(
1276 1, "AES_CM_128_HMAC_SHA1_32",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001277 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1278 "dummy_session_params"));
1279 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef67cf2c12016-04-13 10:07:16 -07001280 AudioCodec opus(111, "opus", 48000, 0, 2);
deadbeef9d3584c2016-02-16 17:54:10 -08001281 audio->AddCodec(opus);
ossue1405ad2017-01-23 08:55:48 -08001282 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1283 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001284 return audio;
1285 }
1286
Seth Hampson5b4f0752018-04-02 16:31:36 -07001287 // Turns the existing reference description into a unified plan description,
1288 // with 3 audio MediaContentDescriptions with special StreamParams that
1289 // contain 0 or multiple stream ids: - audio track 1 has 1 media stream id -
1290 // audio track 2 has 2 media stream ids - audio track 3 has 0 media stream ids
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001291 void MakeUnifiedPlanDescriptionMultipleStreamIds(const int msid_signaling) {
Seth Hampson5b4f0752018-04-02 16:31:36 -07001292 desc_.RemoveContentByName(kVideoContentName);
1293 desc_.RemoveTransportInfoByName(kVideoContentName);
1294 RemoveVideoCandidates();
1295
1296 // Audio track 2 has 2 media stream ids.
1297 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1298 StreamParams audio_track_2;
1299 audio_track_2.id = kAudioTrackId2;
1300 audio_track_2.cname = kStream1Cname;
1301 audio_track_2.set_stream_ids({kStreamId1, kStreamId2});
1302 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1303 audio_desc_2->AddStream(audio_track_2);
1304 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
1305 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1306 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
1307
1308 // Audio track 3 has no stream ids.
1309 AudioContentDescription* audio_desc_3 = CreateAudioContentDescription();
1310 StreamParams audio_track_3;
1311 audio_track_3.id = kAudioTrackId3;
1312 audio_track_3.cname = kStream2Cname;
1313 audio_track_3.set_stream_ids({});
1314 audio_track_3.ssrcs.push_back(kAudioTrack3Ssrc);
1315 audio_desc_3->AddStream(audio_track_3);
1316 desc_.AddContent(kAudioContentName3, MediaProtocolType::kRtp, audio_desc_3);
1317 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1318 kAudioContentName3, TransportDescription(kUfragVoice3, kPwdVoice3))));
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001319 desc_.set_msid_signaling(msid_signaling);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001320 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1321 jdesc_.session_version()));
1322 }
1323
Seth Hampson5897a6e2018-04-03 11:16:33 -07001324 // Turns the existing reference description into a unified plan description
1325 // with one audio MediaContentDescription that contains one StreamParams with
1326 // 0 ssrcs.
1327 void MakeUnifiedPlanDescriptionNoSsrcSignaling() {
1328 desc_.RemoveContentByName(kVideoContentName);
1329 desc_.RemoveContentByName(kAudioContentName);
1330 desc_.RemoveTransportInfoByName(kVideoContentName);
1331 RemoveVideoCandidates();
1332
1333 AudioContentDescription* audio_desc = CreateAudioContentDescription();
1334 StreamParams audio_track;
1335 audio_track.id = kAudioTrackId1;
1336 audio_track.set_stream_ids({kStreamId1});
1337 audio_desc->AddStream(audio_track);
1338 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc);
1339
1340 // Enable signaling a=msid lines.
1341 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
1342 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1343 jdesc_.session_version()));
1344 }
1345
deadbeef9d3584c2016-02-16 17:54:10 -08001346 // Creates a video content description with no streams, and some default
1347 // configuration.
1348 VideoContentDescription* CreateVideoContentDescription() {
1349 VideoContentDescription* video = new VideoContentDescription();
1350 video->AddCrypto(CryptoParams(
1351 1, "AES_CM_128_HMAC_SHA1_80",
1352 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1353 video->set_protocol(cricket::kMediaProtocolSavpf);
1354 video->AddCodec(
perkj26752742016-10-24 01:21:16 -07001355 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-16 17:54:10 -08001356 return video;
1357 }
1358
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001359 template <class MCD>
Yves Gerey665174f2018-06-19 15:03:05 +02001360 void CompareMediaContentDescription(const MCD* cd1, const MCD* cd2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001361 // type
1362 EXPECT_EQ(cd1->type(), cd1->type());
1363
1364 // content direction
1365 EXPECT_EQ(cd1->direction(), cd2->direction());
1366
1367 // rtcp_mux
1368 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1369
deadbeef13871492015-12-09 12:37:51 -08001370 // rtcp_reduced_size
1371 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1372
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001373 // cryptos
1374 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1375 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1376 ADD_FAILURE();
1377 return;
1378 }
Yves Gerey665174f2018-06-19 15:03:05 +02001379 for (size_t i = 0; i < cd1->cryptos().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001380 const CryptoParams c1 = cd1->cryptos().at(i);
1381 const CryptoParams c2 = cd2->cryptos().at(i);
1382 EXPECT_TRUE(c1.Matches(c2));
1383 EXPECT_EQ(c1.key_params, c2.key_params);
1384 EXPECT_EQ(c1.session_params, c2.session_params);
1385 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001386
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001387 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001388 // Use an equivalence class here, for old and new versions of the
1389 // protocol description.
Yves Gerey665174f2018-06-19 15:03:05 +02001390 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp ||
1391 cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1392 cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
lally@webrtc.org36300852015-02-24 20:19:35 +00001393 const bool cd2_is_also_dtls_sctp =
Yves Gerey665174f2018-06-19 15:03:05 +02001394 cd2->protocol() == cricket::kMediaProtocolDtlsSctp ||
1395 cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1396 cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
lally@webrtc.org36300852015-02-24 20:19:35 +00001397 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001398 } else {
1399 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1400 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001401
1402 // codecs
1403 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1404
1405 // bandwidth
1406 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1407
1408 // streams
1409 EXPECT_EQ(cd1->streams(), cd2->streams());
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001410 EXPECT_EQ(cd1->has_receive_stream(), cd2->has_receive_stream());
1411 if (cd1->has_receive_stream() && cd2->has_receive_stream()) {
1412 EXPECT_EQ(cd1->receive_stream(), cd2->receive_stream());
1413 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001414
Johannes Kron0854eb62018-10-10 22:33:20 +02001415 // extmap-allow-mixed
Johannes Kron9581bc42018-10-23 10:17:39 +02001416 EXPECT_EQ(cd1->extmap_allow_mixed_enum(), cd2->extmap_allow_mixed_enum());
Johannes Kron0854eb62018-10-10 22:33:20 +02001417
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001418 // extmap
1419 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1420 cd2->rtp_header_extensions().size());
Yves Gerey665174f2018-06-19 15:03:05 +02001421 for (size_t i = 0; i < cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 11:24:55 -07001422 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1423 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001424 EXPECT_EQ(ext1.uri, ext2.uri);
1425 EXPECT_EQ(ext1.id, ext2.id);
jbauch5869f502017-06-29 12:31:36 -07001426 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001427 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001428 }
1429
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001430 void CompareRidDescriptionIds(const std::vector<RidDescription>& rids,
1431 const std::vector<std::string>& ids) {
1432 // Order of elements does not matter, only equivalence of sets.
1433 EXPECT_EQ(rids.size(), ids.size());
1434 for (const std::string& id : ids) {
1435 EXPECT_EQ(1l, std::count_if(rids.begin(), rids.end(),
1436 [id](const RidDescription& rid) {
1437 return rid.rid == id;
1438 }));
1439 }
1440 }
1441
Amit Hilbucha2012042018-12-03 11:35:05 -08001442 void CompareSimulcastDescription(const SimulcastDescription& simulcast1,
1443 const SimulcastDescription& simulcast2) {
1444 EXPECT_EQ(simulcast1.send_layers().size(), simulcast2.send_layers().size());
1445 EXPECT_EQ(simulcast1.receive_layers().size(),
1446 simulcast2.receive_layers().size());
1447 }
1448
zstein4b2e0822017-02-17 19:48:38 -08001449 void CompareDataContentDescription(const DataContentDescription* dcd1,
1450 const DataContentDescription* dcd2) {
1451 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
1452 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
1453 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001454
1455 void CompareSessionDescription(const SessionDescription& desc1,
1456 const SessionDescription& desc2) {
1457 // Compare content descriptions.
1458 if (desc1.contents().size() != desc2.contents().size()) {
1459 ADD_FAILURE();
1460 return;
1461 }
Yves Gerey665174f2018-06-19 15:03:05 +02001462 for (size_t i = 0; i < desc1.contents().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001463 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1464 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-12 18:37:36 -08001465 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001466 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-12 18:37:36 -08001467 EXPECT_EQ(c1.type, c2.type);
1468 EXPECT_EQ(c1.rejected, c2.rejected);
1469 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001470
1471 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1472 if (IsAudioContent(&c1)) {
1473 const AudioContentDescription* acd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001474 c1.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001475 const AudioContentDescription* acd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001476 c2.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001477 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1478 }
1479
1480 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1481 if (IsVideoContent(&c1)) {
1482 const VideoContentDescription* vcd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001483 c1.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001484 const VideoContentDescription* vcd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001485 c2.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001486 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1487 }
1488
1489 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
1490 if (IsDataContent(&c1)) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001491 const DataContentDescription* dcd1 = c1.media_description()->as_data();
1492 const DataContentDescription* dcd2 = c2.media_description()->as_data();
zstein4b2e0822017-02-17 19:48:38 -08001493 CompareDataContentDescription(dcd1, dcd2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001494 }
Amit Hilbucha2012042018-12-03 11:35:05 -08001495
1496 CompareSimulcastDescription(
1497 c1.media_description()->simulcast_description(),
1498 c2.media_description()->simulcast_description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001499 }
1500
1501 // group
1502 const cricket::ContentGroups groups1 = desc1.groups();
1503 const cricket::ContentGroups groups2 = desc2.groups();
1504 EXPECT_EQ(groups1.size(), groups1.size());
1505 if (groups1.size() != groups2.size()) {
1506 ADD_FAILURE();
1507 return;
1508 }
1509 for (size_t i = 0; i < groups1.size(); ++i) {
1510 const cricket::ContentGroup group1 = groups1.at(i);
1511 const cricket::ContentGroup group2 = groups2.at(i);
1512 EXPECT_EQ(group1.semantics(), group2.semantics());
1513 const cricket::ContentNames names1 = group1.content_names();
1514 const cricket::ContentNames names2 = group2.content_names();
1515 EXPECT_EQ(names1.size(), names2.size());
1516 if (names1.size() != names2.size()) {
1517 ADD_FAILURE();
1518 return;
1519 }
1520 cricket::ContentNames::const_iterator iter1 = names1.begin();
1521 cricket::ContentNames::const_iterator iter2 = names2.begin();
1522 while (iter1 != names1.end()) {
1523 EXPECT_EQ(*iter1++, *iter2++);
1524 }
1525 }
1526
1527 // transport info
1528 const cricket::TransportInfos transports1 = desc1.transport_infos();
1529 const cricket::TransportInfos transports2 = desc2.transport_infos();
1530 EXPECT_EQ(transports1.size(), transports2.size());
1531 if (transports1.size() != transports2.size()) {
1532 ADD_FAILURE();
1533 return;
1534 }
1535 for (size_t i = 0; i < transports1.size(); ++i) {
1536 const cricket::TransportInfo transport1 = transports1.at(i);
1537 const cricket::TransportInfo transport2 = transports2.at(i);
1538 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001539 EXPECT_EQ(transport1.description.ice_ufrag,
1540 transport2.description.ice_ufrag);
Yves Gerey665174f2018-06-19 15:03:05 +02001541 EXPECT_EQ(transport1.description.ice_pwd, transport2.description.ice_pwd);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07001542 EXPECT_EQ(transport1.description.ice_mode,
1543 transport2.description.ice_mode);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001544 if (transport1.description.identity_fingerprint) {
1545 EXPECT_EQ(*transport1.description.identity_fingerprint,
1546 *transport2.description.identity_fingerprint);
1547 } else {
1548 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1549 transport2.description.identity_fingerprint.get());
1550 }
1551 EXPECT_EQ(transport1.description.transport_options,
1552 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001553 }
deadbeefc80741f2015-10-22 13:14:45 -07001554
1555 // global attributes
1556 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
Johannes Kron9581bc42018-10-23 10:17:39 +02001557 EXPECT_EQ(desc1.extmap_allow_mixed(), desc2.extmap_allow_mixed());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001558 }
1559
Yves Gerey665174f2018-06-19 15:03:05 +02001560 bool CompareSessionDescription(const JsepSessionDescription& desc1,
1561 const JsepSessionDescription& desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001562 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1563 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1564 CompareSessionDescription(*desc1.description(), *desc2.description());
1565 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1566 return false;
1567 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1568 const IceCandidateCollection* cc1 = desc1.candidates(i);
1569 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-12 18:37:36 -08001570 if (cc1->count() != cc2->count()) {
1571 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001572 return false;
deadbeef25ed4352016-12-12 18:37:36 -08001573 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001574 for (size_t j = 0; j < cc1->count(); ++j) {
1575 const IceCandidateInterface* c1 = cc1->at(j);
1576 const IceCandidateInterface* c2 = cc2->at(j);
1577 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1578 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1579 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1580 }
1581 }
1582 return true;
1583 }
1584
1585 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1586 // them with invalid keywords so that the parser will just ignore them.
1587 bool RemoveCandidateUfragPwd(std::string* sdp) {
1588 const char ice_ufrag[] = "a=ice-ufrag";
1589 const char ice_ufragx[] = "a=xice-ufrag";
1590 const char ice_pwd[] = "a=ice-pwd";
1591 const char ice_pwdx[] = "a=xice-pwd";
Yves Gerey665174f2018-06-19 15:03:05 +02001592 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag), ice_ufragx,
1593 strlen(ice_ufragx), sdp);
1594 rtc::replace_substrs(ice_pwd, strlen(ice_pwd), ice_pwdx, strlen(ice_pwdx),
1595 sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001596 return true;
1597 }
1598
1599 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
Yves Gerey665174f2018-06-19 15:03:05 +02001600 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc,
1601 int mline_index,
1602 const std::string& ufrag,
1603 const std::string& pwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001604 std::string content_name;
1605 if (mline_index == 0) {
1606 content_name = kAudioContentName;
1607 } else if (mline_index == 1) {
1608 content_name = kVideoContentName;
1609 } else {
nissec80e7412017-01-11 05:56:46 -08001610 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001611 }
Yves Gerey665174f2018-06-19 15:03:05 +02001612 TransportInfo transport_info(content_name,
1613 TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001614 SessionDescription* desc =
1615 const_cast<SessionDescription*>(jdesc->description());
1616 desc->RemoveTransportInfoByName(content_name);
1617 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
1618 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1619 const IceCandidateCollection* cc = jdesc_.candidates(i);
1620 for (size_t j = 0; j < cc->count(); ++j) {
1621 if (cc->at(j)->sdp_mline_index() == mline_index) {
Yves Gerey665174f2018-06-19 15:03:05 +02001622 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(ufrag);
1623 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001624 }
1625 }
1626 }
1627 return true;
1628 }
1629
1630 void AddIceOptions(const std::string& content_name,
1631 const std::vector<std::string>& transport_options) {
1632 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1633 cricket::TransportInfo transport_info =
1634 *(desc_.GetTransportInfoByName(content_name));
1635 desc_.RemoveTransportInfoByName(content_name);
1636 transport_info.description.transport_options = transport_options;
1637 desc_.AddTransportInfo(transport_info);
1638 }
1639
deadbeef3f7219b2015-12-28 15:17:14 -08001640 void SetIceUfragPwd(const std::string& content_name,
1641 const std::string& ice_ufrag,
1642 const std::string& ice_pwd) {
1643 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1644 cricket::TransportInfo transport_info =
1645 *(desc_.GetTransportInfoByName(content_name));
1646 desc_.RemoveTransportInfoByName(content_name);
1647 transport_info.description.ice_ufrag = ice_ufrag;
1648 transport_info.description.ice_pwd = ice_pwd;
1649 desc_.AddTransportInfo(transport_info);
1650 }
1651
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001652 void AddFingerprint() {
1653 desc_.RemoveTransportInfoByName(kAudioContentName);
1654 desc_.RemoveTransportInfoByName(kVideoContentName);
Steve Anton4905edb2018-10-15 19:27:44 -07001655 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, kIdentityDigest);
deadbeef46eed762016-01-28 13:24:37 -08001656 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1657 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001658 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1659 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001660 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1661 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1662 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001663 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1664 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001665 cricket::CONNECTIONROLE_NONE, &fingerprint))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001666 }
1667
jbauch5869f502017-06-29 12:31:36 -07001668 void AddExtmap(bool encrypted) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001669 audio_desc_ = audio_desc_->Copy();
1670 video_desc_ = video_desc_->Copy();
jbauch5869f502017-06-29 12:31:36 -07001671 audio_desc_->AddRtpHeaderExtension(
1672 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1673 video_desc_->AddRtpHeaderExtension(
1674 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001675 desc_.RemoveContentByName(kAudioContentName);
1676 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001677 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1678 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001679 }
1680
1681 void RemoveCryptos() {
1682 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1683 video_desc_->set_cryptos(std::vector<CryptoParams>());
1684 }
1685
Seth Hampson5897a6e2018-04-03 11:16:33 -07001686 // Removes everything in StreamParams from the session description that is
1687 // used for a=ssrc lines.
1688 void RemoveSsrcSignalingFromStreamParams() {
1689 for (cricket::ContentInfo content_info : jdesc_.description()->contents()) {
1690 // With Unified Plan there should be one StreamParams per m= section.
1691 StreamParams& stream =
1692 content_info.media_description()->mutable_streams()[0];
1693 stream.ssrcs.clear();
1694 stream.ssrc_groups.clear();
1695 stream.cname.clear();
1696 }
1697 }
1698
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001699 // Removes all a=ssrc lines from the SDP string, except for the
1700 // "a=ssrc:... cname:..." lines.
1701 void RemoveSsrcMsidLinesFromSdpString(std::string* sdp_string) {
1702 const char kAttributeSsrc[] = "a=ssrc";
1703 const char kAttributeCname[] = "cname";
1704 size_t ssrc_line_pos = sdp_string->find(kAttributeSsrc);
1705 while (ssrc_line_pos != std::string::npos) {
1706 size_t beg_line_pos = sdp_string->rfind('\n', ssrc_line_pos);
1707 size_t end_line_pos = sdp_string->find('\n', ssrc_line_pos);
1708 size_t cname_pos = sdp_string->find(kAttributeCname, ssrc_line_pos);
1709 if (cname_pos == std::string::npos || cname_pos > end_line_pos) {
1710 // Only erase a=ssrc lines that don't contain "cname".
1711 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1712 ssrc_line_pos = sdp_string->find(kAttributeSsrc, beg_line_pos);
1713 } else {
1714 // Skip the "a=ssrc:... cname" line and find the next "a=ssrc" line.
1715 ssrc_line_pos = sdp_string->find(kAttributeSsrc, end_line_pos);
1716 }
1717 }
1718 }
1719
Seth Hampson5897a6e2018-04-03 11:16:33 -07001720 // Removes all a=ssrc lines from the SDP string.
1721 void RemoveSsrcLinesFromSdpString(std::string* sdp_string) {
1722 const char kAttributeSsrc[] = "a=ssrc";
1723 while (sdp_string->find(kAttributeSsrc) != std::string::npos) {
1724 size_t pos_ssrc_attribute = sdp_string->find(kAttributeSsrc);
1725 size_t beg_line_pos = sdp_string->rfind('\n', pos_ssrc_attribute);
1726 size_t end_line_pos = sdp_string->find('\n', pos_ssrc_attribute);
1727 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1728 }
1729 }
1730
Steve Anton4e70a722017-11-28 14:57:10 -08001731 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001732 audio_desc_->set_direction(direction);
1733 video_desc_->set_direction(direction);
1734 std::string new_sdp = kSdpFullString;
1735 ReplaceDirection(direction, &new_sdp);
1736
Yves Gerey665174f2018-06-19 15:03:05 +02001737 if (!jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001738 jdesc_.session_version())) {
1739 return false;
1740 }
Steve Antone831b8c2018-02-01 12:22:16 -08001741 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001742 EXPECT_EQ(new_sdp, message);
1743 return true;
1744 }
1745
1746 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001747 audio_desc_ = audio_desc_->Copy();
1748 video_desc_ = video_desc_->Copy();
zhihuang38989e52017-03-21 11:04:53 -07001749
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001750 desc_.RemoveContentByName(kAudioContentName);
1751 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001752 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001753 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001754 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001755 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001756 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1757 audio_rejected ? "" : kPwdVoice);
1758 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1759 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001760
1761 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001762 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1763
Steve Antona3a92c22017-12-07 10:27:41 -08001764 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001765 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001766 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001767 EXPECT_EQ(new_sdp, message);
1768 return true;
1769 }
1770
zstein4b2e0822017-02-17 19:48:38 -08001771 void AddSctpDataChannel(bool use_sctpmap) {
kwibergd1fe2812016-04-27 06:47:29 -07001772 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001773 data_desc_ = data.get();
zstein4b2e0822017-02-17 19:48:38 -08001774 data_desc_->set_use_sctpmap(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001775 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
solenberg9fa49752016-10-08 13:02:44 -07001776 DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07001777 cricket::kGoogleSctpDataCodecName);
wu@webrtc.org78187522013-10-07 23:32:02 +00001778 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1779 data_desc_->AddCodec(codec);
Steve Anton5adfafd2017-12-20 16:34:00 -08001780 desc_.AddContent(kDataContentName, MediaProtocolType::kSctp,
1781 data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001782 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1783 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001784 }
1785
1786 void AddRtpDataChannel() {
kwibergd1fe2812016-04-27 06:47:29 -07001787 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001788 data_desc_ = data.get();
1789
deadbeef67cf2c12016-04-13 10:07:16 -07001790 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001791 StreamParams data_stream;
1792 data_stream.id = kDataChannelMsid;
1793 data_stream.cname = kDataChannelCname;
Seth Hampson845e8782018-03-02 11:34:10 -08001794 data_stream.set_stream_ids({kDataChannelLabel});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001795 data_stream.ssrcs.push_back(kDataChannelSsrc);
1796 data_desc_->AddStream(data_stream);
Yves Gerey665174f2018-06-19 15:03:05 +02001797 data_desc_->AddCrypto(
1798 CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
1799 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001800 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
Steve Anton5adfafd2017-12-20 16:34:00 -08001801 desc_.AddContent(kDataContentName, MediaProtocolType::kRtp, data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001802 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1803 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001804 }
1805
Steve Anton4e70a722017-11-28 14:57:10 -08001806 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001807 std::string new_sdp = kSdpFullString;
1808 ReplaceDirection(direction, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001809 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001810
1811 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1812
1813 audio_desc_->set_direction(direction);
1814 video_desc_->set_direction(direction);
Yves Gerey665174f2018-06-19 15:03:05 +02001815 if (!jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001816 jdesc_.session_version())) {
1817 return false;
1818 }
1819 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1820 return true;
1821 }
1822
1823 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001824 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001825 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001826 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001827 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001828
Steve Antonb1c1de12017-12-21 15:14:30 -08001829 audio_desc_ = audio_desc_->Copy();
1830 video_desc_ = video_desc_->Copy();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001831 desc_.RemoveContentByName(kAudioContentName);
1832 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001833 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001834 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001835 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001836 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001837 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1838 audio_rejected ? "" : kPwdVoice);
1839 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1840 video_rejected ? "" : kPwdVideo);
Steve Antona3a92c22017-12-07 10:27:41 -08001841 JsepSessionDescription jdesc_no_candidates(kDummyType);
deadbeef3f7219b2015-12-28 15:17:14 -08001842 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1843 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001844 return false;
1845 }
deadbeef3f7219b2015-12-28 15:17:14 -08001846 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001847 return true;
1848 }
1849
Yves Gerey665174f2018-06-19 15:03:05 +02001850 void TestDeserializeExtmap(bool session_level,
1851 bool media_level,
1852 bool encrypted) {
jbauch5869f502017-06-29 12:31:36 -07001853 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08001854 JsepSessionDescription new_jdesc(SdpType::kOffer);
Yves Gerey665174f2018-06-19 15:03:05 +02001855 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001856 jdesc_.session_version()));
Steve Antona3a92c22017-12-07 10:27:41 -08001857 JsepSessionDescription jdesc_with_extmap(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001858 std::string sdp_with_extmap = kSdpString;
1859 if (session_level) {
jbauch5869f502017-06-29 12:31:36 -07001860 InjectAfter(kSessionTime,
1861 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1862 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001863 &sdp_with_extmap);
1864 }
1865 if (media_level) {
jbauch5869f502017-06-29 12:31:36 -07001866 InjectAfter(kAttributeIcePwdVoice,
1867 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1868 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001869 &sdp_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07001870 InjectAfter(kAttributeIcePwdVideo,
1871 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1872 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001873 &sdp_with_extmap);
1874 }
1875 // The extmap can't be present at the same time in both session level and
1876 // media level.
1877 if (session_level && media_level) {
1878 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02001879 EXPECT_FALSE(
1880 webrtc::SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001881 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1882 } else {
1883 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1884 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1885 }
1886 }
1887
1888 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
Yves Gerey665174f2018-06-19 15:03:05 +02001889 const std::string& name,
1890 int expected_value) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001891 cricket::CodecParameterMap::const_iterator found = params.find(name);
1892 ASSERT_TRUE(found != params.end());
Jonas Olsson6b1985d2018-07-05 11:59:48 +02001893 EXPECT_EQ(found->second, rtc::ToString(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001894 }
1895
1896 void TestDeserializeCodecParams(const CodecParams& params,
1897 JsepSessionDescription* jdesc_output) {
1898 std::string sdp =
1899 "v=0\r\n"
1900 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1901 "s=-\r\n"
1902 "t=0 0\r\n"
1903 // Include semantics for WebRTC Media Streams since it is supported by
1904 // this parser, and will be added to the SDP when serializing a session
1905 // description.
1906 "a=msid-semantic: WMS\r\n"
1907 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001908 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001909 // Pltype 111 listed before 103 and 104 in the map.
1910 "a=rtpmap:111 opus/48000/2\r\n"
1911 // Pltype 103 listed before 104.
1912 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001913 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001914 "a=fmtp:111 0-15,66,70\r\n"
1915 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001916 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001917 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001918 << "; sprop-stereo=" << params.sprop_stereo
1919 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001920 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001921 << "a=ptime:" << params.ptime << "\r\n"
1922 << "a=maxptime:" << params.max_ptime << "\r\n";
1923 sdp += os.str();
1924
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001925 os.clear();
1926 os.str("");
1927 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001928 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001929 << "a=rtpmap:99 VP8/90000\r\n"
1930 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001931 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001932 sdp += os.str();
1933
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001934 // Deserialize
1935 SdpParseError error;
1936 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1937
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001938 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001939 GetFirstAudioContentDescription(jdesc_output->description());
1940 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001941 ASSERT_FALSE(acd->codecs().empty());
1942 cricket::AudioCodec opus = acd->codecs()[0];
1943 EXPECT_EQ("opus", opus.name);
1944 EXPECT_EQ(111, opus.id);
1945 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1946 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1947 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1948 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001949 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1950 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001951 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1952 cricket::AudioCodec codec = acd->codecs()[i];
1953 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1954 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001955 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001956
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001957 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001958 GetFirstVideoContentDescription(jdesc_output->description());
1959 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001960 ASSERT_FALSE(vcd->codecs().empty());
1961 cricket::VideoCodec vp8 = vcd->codecs()[0];
1962 EXPECT_EQ("VP8", vp8.name);
1963 EXPECT_EQ(99, vp8.id);
1964 cricket::VideoCodec rtx = vcd->codecs()[1];
1965 EXPECT_EQ("RTX", rtx.name);
1966 EXPECT_EQ(95, rtx.id);
1967 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001968 }
1969
1970 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1971 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001972 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001973 "v=0\r\n"
1974 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1975 "s=-\r\n"
1976 "t=0 0\r\n"
1977 // Include semantics for WebRTC Media Streams since it is supported by
1978 // this parser, and will be added to the SDP when serializing a session
1979 // description.
1980 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001981 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001982 "a=rtpmap:111 opus/48000/2\r\n";
1983 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001984 "m=video 3457 RTP/SAVPF 101\r\n"
1985 "a=rtpmap:101 VP8/90000\r\n"
1986 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001987 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001988 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001989 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001990 os << sdp_session_and_audio;
Yves Gerey665174f2018-06-19 15:03:05 +02001991 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001992 os << sdp_video;
Yves Gerey665174f2018-06-19 15:03:05 +02001993 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001994 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001995 // Deserialize
1996 SdpParseError error;
1997 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001998 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001999 GetFirstAudioContentDescription(jdesc_output->description());
2000 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002001 ASSERT_FALSE(acd->codecs().empty());
2002 cricket::AudioCodec opus = acd->codecs()[0];
2003 EXPECT_EQ(111, opus.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002004 EXPECT_TRUE(opus.HasFeedbackParam(cricket::FeedbackParam(
2005 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002006
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002007 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08002008 GetFirstVideoContentDescription(jdesc_output->description());
2009 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002010 ASSERT_FALSE(vcd->codecs().empty());
2011 cricket::VideoCodec vp8 = vcd->codecs()[0];
2012 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
2013 vp8.name.c_str());
2014 EXPECT_EQ(101, vp8.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002015 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2016 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
2017 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2018 cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli)));
2019 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2020 cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty)));
2021 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2022 cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002023 }
2024
2025 // Two SDP messages can mean the same thing but be different strings, e.g.
2026 // some of the lines can be serialized in different order.
2027 // However, a deserialized description can be compared field by field and has
2028 // no order. If deserializer has already been tested, serializing then
2029 // deserializing and comparing JsepSessionDescription will test
2030 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 12:22:16 -08002031 void TestSerialize(const JsepSessionDescription& jdesc) {
2032 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 10:27:41 -08002033 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002034 SdpParseError error;
2035 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
2036 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
2037 }
2038
zhihuang38989e52017-03-21 11:04:53 -07002039 // Calling 'Initialize' with a copy of the inner SessionDescription will
2040 // create a copy of the JsepSessionDescription without candidates. The
2041 // 'connection address' field, previously set from the candidates, must also
2042 // be reset.
2043 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
2044 rtc::SocketAddress audio_addr("0.0.0.0", 9);
2045 rtc::SocketAddress video_addr("0.0.0.0", 9);
2046 audio_desc_->set_connection_address(audio_addr);
2047 video_desc_->set_connection_address(video_addr);
2048 ASSERT_TRUE(jdesc->Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2049 }
2050
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002051 protected:
2052 SessionDescription desc_;
2053 AudioContentDescription* audio_desc_;
2054 VideoContentDescription* video_desc_;
2055 DataContentDescription* data_desc_;
2056 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07002057 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002058 JsepSessionDescription jdesc_;
2059};
2060
2061void TestMismatch(const std::string& string1, const std::string& string2) {
2062 int position = 0;
2063 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
2064 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002065 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002066 break;
2067 }
2068 }
2069 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
2070 << " character\n"
2071 << " 1: " << string1.substr(position, 20) << "\n"
2072 << " 2: " << string2.substr(position, 20) << "\n";
2073}
2074
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002075TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
2076 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 12:22:16 -08002077 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002078 TestMismatch(std::string(kSdpFullString), message);
2079}
2080
2081TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 10:27:41 -08002082 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 12:22:16 -08002083 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002084}
2085
2086// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
2087// the case in a DTLS offer.
2088TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
2089 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002090 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002091 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08002092 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002093
2094 std::string sdp_with_fingerprint = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002095 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2096 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002097
2098 EXPECT_EQ(sdp_with_fingerprint, message);
2099}
2100
2101// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
2102// be the case in a DTLS answer.
2103TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
2104 AddFingerprint();
2105 RemoveCryptos();
Steve Antona3a92c22017-12-07 10:27:41 -08002106 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002107 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08002108 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002109
2110 std::string sdp_with_fingerprint = kSdpString;
2111 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
2112 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
Yves Gerey665174f2018-06-19 15:03:05 +02002113 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2114 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002115
2116 EXPECT_EQ(sdp_with_fingerprint, message);
2117}
2118
2119TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
2120 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002121 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002122 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08002123 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002124 EXPECT_EQ(std::string(kSdpString), message);
2125}
2126
2127TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
2128 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2129 group.AddContentName(kAudioContentName);
2130 group.AddContentName(kVideoContentName);
2131 desc_.AddGroup(group);
Yves Gerey665174f2018-06-19 15:03:05 +02002132 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002134 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002135 std::string sdp_with_bundle = kSdpFullString;
2136 InjectAfter(kSessionTime,
2137 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2138 &sdp_with_bundle);
2139 EXPECT_EQ(sdp_with_bundle, message);
2140}
2141
2142TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 15:14:30 -08002143 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002144 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002145 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002146 acd->set_bandwidth(50 * 1000);
Yves Gerey665174f2018-06-19 15:03:05 +02002147 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002148 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002149 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002150 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002151 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002152 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002153 InjectAfter("c=IN IP4 74.125.127.126\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002154 &sdp_with_bandwidth);
2155 EXPECT_EQ(sdp_with_bandwidth, message);
2156}
2157
2158TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
2159 std::vector<std::string> transport_options;
2160 transport_options.push_back(kIceOption1);
2161 transport_options.push_back(kIceOption3);
2162 AddIceOptions(kAudioContentName, transport_options);
2163 transport_options.clear();
2164 transport_options.push_back(kIceOption2);
2165 transport_options.push_back(kIceOption3);
2166 AddIceOptions(kVideoContentName, transport_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002167 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002168 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002169 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002170 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002171 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002172 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002173 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002174 &sdp_with_ice_options);
2175 EXPECT_EQ(sdp_with_ice_options, message);
2176}
2177
2178TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002179 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002180}
2181
2182TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002183 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002184}
2185
2186TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002187 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002188}
2189
2190TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2191 EXPECT_TRUE(TestSerializeRejected(true, false));
2192}
2193
2194TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2195 EXPECT_TRUE(TestSerializeRejected(false, true));
2196}
2197
2198TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2199 EXPECT_TRUE(TestSerializeRejected(true, true));
2200}
2201
2202TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
2203 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002204 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002205
zhihuang38989e52017-03-21 11:04:53 -07002206 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002207 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002208
2209 std::string expected_sdp = kSdpString;
2210 expected_sdp.append(kSdpRtpDataChannelString);
2211 EXPECT_EQ(expected_sdp, message);
2212}
2213
2214TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08002215 bool use_sctpmap = true;
2216 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002217 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002218
zhihuang38989e52017-03-21 11:04:53 -07002219 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002220 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002221
2222 std::string expected_sdp = kSdpString;
2223 expected_sdp.append(kSdpSctpDataChannelString);
2224 EXPECT_EQ(message, expected_sdp);
2225}
2226
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002227TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08002228 bool use_sctpmap = true;
2229 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002230 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002231 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antonb1c1de12017-12-21 15:14:30 -08002232 DataContentDescription* dcdesc =
2233 jsep_desc.description()
2234 ->GetContentDescriptionByName(kDataContentName)
2235 ->as_data();
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002236
2237 const int kNewPort = 1234;
solenberg9fa49752016-10-08 13:02:44 -07002238 cricket::DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07002239 cricket::kGoogleSctpDataCodecName);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002240 codec.SetParam(cricket::kCodecParamPort, kNewPort);
2241 dcdesc->AddOrReplaceCodec(codec);
2242
Steve Antone831b8c2018-02-01 12:22:16 -08002243 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002244
2245 std::string expected_sdp = kSdpString;
2246 expected_sdp.append(kSdpSctpDataChannelString);
2247
2248 char default_portstr[16];
2249 char new_portstr[16];
Niels Mölleraba06332018-10-16 15:14:15 +02002250 snprintf(default_portstr, sizeof(default_portstr), "%d", kDefaultSctpPort);
2251 snprintf(new_portstr, sizeof(new_portstr), "%d", kNewPort);
Yves Gerey665174f2018-06-19 15:03:05 +02002252 rtc::replace_substrs(default_portstr, strlen(default_portstr), new_portstr,
2253 strlen(new_portstr), &expected_sdp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002254
2255 EXPECT_EQ(expected_sdp, message);
2256}
2257
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002258TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002259 JsepSessionDescription jsep_desc(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002260 AddRtpDataChannel();
Yves Gerey665174f2018-06-19 15:03:05 +02002261 data_desc_->set_bandwidth(100 * 1000);
zhihuang38989e52017-03-21 11:04:53 -07002262 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002263 std::string message = webrtc::SdpSerialize(jsep_desc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002264
2265 std::string expected_sdp = kSdpString;
2266 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002267 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00002268 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02002269 "b=AS:100\r\n", &expected_sdp);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002270 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002271}
2272
Johannes Kron0854eb62018-10-10 22:33:20 +02002273TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002274 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002275 TestSerialize(jdesc_);
2276}
2277
2278TEST_F(WebRtcSdpTest, SerializeMediaContentDescriptionWithExtmapAllowMixed) {
2279 cricket::MediaContentDescription* video_desc =
2280 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2281 ASSERT_TRUE(video_desc);
2282 cricket::MediaContentDescription* audio_desc =
2283 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2284 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002285 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002286 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002287 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002288 cricket::MediaContentDescription::kMedia);
2289 TestSerialize(jdesc_);
2290}
2291
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002292TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002293 bool encrypted = false;
2294 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002295 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002296 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 12:22:16 -08002297 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002298
2299 std::string sdp_with_extmap = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002300 InjectAfter("a=mid:audio_content_name\r\n", kExtmap, &sdp_with_extmap);
2301 InjectAfter("a=mid:video_content_name\r\n", kExtmap, &sdp_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002302
2303 EXPECT_EQ(sdp_with_extmap, message);
2304}
2305
jbauch5869f502017-06-29 12:31:36 -07002306TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2307 bool encrypted = true;
2308 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002309 JsepSessionDescription desc_with_extmap(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002310 ASSERT_TRUE(
2311 desc_with_extmap.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 12:22:16 -08002312 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07002313}
2314
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002315TEST_F(WebRtcSdpTest, SerializeCandidates) {
2316 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002317 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002318
2319 Candidate candidate_with_ufrag(candidates_.front());
2320 candidate_with_ufrag.set_username("ABC");
2321 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2322 candidate_with_ufrag));
2323 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2324 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002325
2326 Candidate candidate_with_network_info(candidates_.front());
2327 candidate_with_network_info.set_network_id(1);
2328 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2329 candidate_with_network_info));
2330 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2331 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2332 candidate_with_network_info.set_network_cost(999);
2333 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2334 candidate_with_network_info));
2335 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2336 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2337 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002338}
2339
Zach Steinb336c272018-08-09 01:16:13 -07002340TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) {
2341 rtc::SocketAddress address("a.test", 1234);
2342 cricket::Candidate candidate(
2343 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
2344 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
2345 JsepIceCandidate jcandidate(std::string("audio_content_name"), 0, candidate);
2346 std::string message = webrtc::SdpSerializeCandidate(jcandidate);
2347 EXPECT_EQ(std::string(kRawHostnameCandidate), message);
2348}
2349
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002350// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2351// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002352TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002353 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002354 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2355 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2356 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002357 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002358 std::unique_ptr<IceCandidateInterface> jcandidate(
2359 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002360
2361 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2362 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2363}
2364
htaa6b99442016-04-12 10:29:17 -07002365TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002366 cricket::VideoCodec h264_codec("H264");
2367 h264_codec.SetParam("profile-level-id", "42e01f");
2368 h264_codec.SetParam("level-asymmetry-allowed", "1");
2369 h264_codec.SetParam("packetization-mode", "1");
2370 video_desc_->AddCodec(h264_codec);
2371
htaa6b99442016-04-12 10:29:17 -07002372 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
2373
Steve Antone831b8c2018-02-01 12:22:16 -08002374 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 10:29:17 -07002375 size_t after_pt = message.find(" H264/90000");
2376 ASSERT_NE(after_pt, std::string::npos);
2377 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2378 ASSERT_NE(before_pt, std::string::npos);
2379 before_pt += strlen("a=rtpmap:");
2380 std::string pt = message.substr(before_pt, after_pt - before_pt);
2381 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2382 std::string to_find = "a=fmtp:" + pt + " ";
2383 size_t fmtp_pos = message.find(to_find);
2384 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
2385 size_t fmtp_endpos = message.find("\n", fmtp_pos);
2386 ASSERT_NE(std::string::npos, fmtp_endpos);
2387 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2388 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2389 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2390 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002391 // Check that there are no spaces after semicolons.
2392 // https://bugs.webrtc.org/5793
2393 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002394}
2395
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002396TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 10:27:41 -08002397 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002398 // Deserialize
2399 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2400 // Verify
2401 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2402}
2403
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002404TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 10:27:41 -08002405 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002406 const char kSdpWithoutMline[] =
Yves Gerey665174f2018-06-19 15:03:05 +02002407 "v=0\r\n"
2408 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2409 "s=-\r\n"
2410 "t=0 0\r\n"
2411 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002412 // Deserialize
2413 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2414 EXPECT_EQ(0u, jdesc.description()->contents().size());
2415}
2416
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002417TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 10:27:41 -08002418 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002419 std::string sdp_without_carriage_return = kSdpFullString;
2420 Replace("\r\n", "\n", &sdp_without_carriage_return);
2421 // Deserialize
2422 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2423 // Verify
2424 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2425}
2426
2427TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2428 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002429 JsepSessionDescription jdesc_no_candidates(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002430 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
2431 kSessionVersion));
Steve Antona3a92c22017-12-07 10:27:41 -08002432 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002433 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2434 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2435}
2436
2437TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2438 static const char kSdpNoRtpmapString[] =
2439 "v=0\r\n"
2440 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2441 "s=-\r\n"
2442 "t=0 0\r\n"
2443 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2444 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002445 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002446 // The rtpmap line for static payload codec is optional.
2447 "a=rtpmap:18 G729/16000\r\n"
2448 "a=rtpmap:103 ISAC/16000\r\n";
2449
Steve Antona3a92c22017-12-07 10:27:41 -08002450 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002451 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2452 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002453 jdesc.description()
2454 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2455 ->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002456 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002457 // The codecs in the AudioContentDescription should be in the same order as
2458 // the payload types (<fmt>s) on the m= line.
2459 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2460 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002461 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002462 EXPECT_EQ(ref_codecs, audio->codecs());
2463}
2464
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002465TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2466 static const char kSdpNoRtpmapString[] =
2467 "v=0\r\n"
2468 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2469 "s=-\r\n"
2470 "t=0 0\r\n"
2471 "m=audio 49232 RTP/AVP 18 103\r\n"
2472 "a=fmtp:18 annexb=yes\r\n"
2473 "a=rtpmap:103 ISAC/16000\r\n";
2474
Steve Antona3a92c22017-12-07 10:27:41 -08002475 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002476 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2477 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002478 jdesc.description()
2479 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2480 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002481
2482 cricket::AudioCodec g729 = audio->codecs()[0];
2483 EXPECT_EQ("G729", g729.name);
2484 EXPECT_EQ(8000, g729.clockrate);
2485 EXPECT_EQ(18, g729.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002486 cricket::CodecParameterMap::iterator found = g729.params.find("annexb");
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002487 ASSERT_TRUE(found != g729.params.end());
2488 EXPECT_EQ(found->second, "yes");
2489
2490 cricket::AudioCodec isac = audio->codecs()[1];
2491 EXPECT_EQ("ISAC", isac.name);
2492 EXPECT_EQ(103, isac.id);
2493 EXPECT_EQ(16000, isac.clockrate);
2494}
2495
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002496// Ensure that we can deserialize SDP with a=fingerprint properly.
2497TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2498 // Add a DTLS a=fingerprint attribute to our session description.
2499 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002500 JsepSessionDescription new_jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002501 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002502 jdesc_.session_version()));
2503
Steve Antona3a92c22017-12-07 10:27:41 -08002504 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002505 std::string sdp_with_fingerprint = kSdpString;
2506 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2507 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2508 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2509 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2510}
2511
2512TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 10:27:41 -08002513 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002514 std::string sdp_with_bundle = kSdpFullString;
2515 InjectAfter(kSessionTime,
2516 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2517 &sdp_with_bundle);
2518 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2519 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2520 group.AddContentName(kAudioContentName);
2521 group.AddContentName(kVideoContentName);
2522 desc_.AddGroup(group);
Yves Gerey665174f2018-06-19 15:03:05 +02002523 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002524 jdesc_.session_version()));
2525 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2526}
2527
2528TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002529 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002530 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002531 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002532 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002533 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002534 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002535 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 15:14:30 -08002536 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002537 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002538 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002539 acd->set_bandwidth(50 * 1000);
Yves Gerey665174f2018-06-19 15:03:05 +02002540 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002541 jdesc_.session_version()));
2542 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2543}
2544
2545TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 10:27:41 -08002546 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002547 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002548 InjectAfter(kSessionTime, "a=ice-options:iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002549 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002550 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002551 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002552 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002553 &sdp_with_ice_options);
2554 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2555 std::vector<std::string> transport_options;
2556 transport_options.push_back(kIceOption3);
2557 transport_options.push_back(kIceOption1);
2558 AddIceOptions(kAudioContentName, transport_options);
2559 transport_options.clear();
2560 transport_options.push_back(kIceOption3);
2561 transport_options.push_back(kIceOption2);
2562 AddIceOptions(kVideoContentName, transport_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002563 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002564 jdesc_.session_version()));
2565 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2566}
2567
2568TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2569 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 10:27:41 -08002570 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002571 std::string sdp_with_ufrag_pwd = kSdpFullString;
2572 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2573 // Add session level ufrag and pwd
2574 InjectAfter(kSessionTime,
Yves Gerey665174f2018-06-19 15:03:05 +02002575 "a=ice-pwd:session+level+icepwd\r\n"
2576 "a=ice-ufrag:session+level+iceufrag\r\n",
2577 &sdp_with_ufrag_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002578 // Add media level ufrag and pwd for audio
Yves Gerey665174f2018-06-19 15:03:05 +02002579 InjectAfter(
2580 "a=mid:audio_content_name\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002581 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2582 &sdp_with_ufrag_pwd);
2583 // Update the candidate ufrag and pwd to the expected ones.
Yves Gerey665174f2018-06-19 15:03:05 +02002584 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, "media+level+iceufrag",
2585 "media+level+icepwd"));
2586 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, "session+level+iceufrag",
2587 "session+level+icepwd"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002588 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2589 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2590}
2591
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002592TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002593 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002594}
2595
2596TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002597 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002598}
2599
2600TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002601 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002602}
2603
2604TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2605 EXPECT_TRUE(TestDeserializeRejected(true, false));
2606}
2607
2608TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2609 EXPECT_TRUE(TestDeserializeRejected(false, true));
2610}
2611
2612TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2613 EXPECT_TRUE(TestDeserializeRejected(true, true));
2614}
2615
2616// Tests that we can still handle the sdp uses mslabel and label instead of
2617// msid for backward compatibility.
2618TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07002619 jdesc_.description()->set_msid_supported(false);
Steve Antona3a92c22017-12-07 10:27:41 -08002620 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002621 std::string sdp_without_msid = kSdpFullString;
2622 Replace("msid", "xmsid", &sdp_without_msid);
2623 // Deserialize
2624 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2625 // Verify
2626 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
Henrik Boström5b147782018-12-04 11:25:05 +01002627 EXPECT_FALSE(jdesc.description()->msid_signaling() &
2628 ~cricket::kMsidSignalingSsrcAttribute);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002629}
2630
Johannes Kron0854eb62018-10-10 22:33:20 +02002631TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002632 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002633 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2634 InjectAfter("t=0 0\r\n", kExtmapAllowMixed, &sdp_with_extmap_allow_mixed);
2635 // Deserialize
2636 JsepSessionDescription jdesc_deserialized(kDummyType);
2637 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2638 // Verify
2639 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2640}
2641
2642TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002643 jdesc_.description()->set_extmap_allow_mixed(false);
Johannes Kron0854eb62018-10-10 22:33:20 +02002644 std::string sdp_without_extmap_allow_mixed = kSdpFullString;
2645 // Deserialize
2646 JsepSessionDescription jdesc_deserialized(kDummyType);
2647 EXPECT_TRUE(
2648 SdpDeserialize(sdp_without_extmap_allow_mixed, &jdesc_deserialized));
2649 // Verify
2650 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2651}
2652
2653TEST_F(WebRtcSdpTest, DeserializeMediaContentDescriptionWithExtmapAllowMixed) {
2654 cricket::MediaContentDescription* video_desc =
2655 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2656 ASSERT_TRUE(video_desc);
2657 cricket::MediaContentDescription* audio_desc =
2658 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2659 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002660 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002661 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002662 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002663 cricket::MediaContentDescription::kMedia);
2664
2665 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2666 InjectAfter("a=mid:audio_content_name\r\n", kExtmapAllowMixed,
2667 &sdp_with_extmap_allow_mixed);
2668 InjectAfter("a=mid:video_content_name\r\n", kExtmapAllowMixed,
2669 &sdp_with_extmap_allow_mixed);
2670
2671 // Deserialize
2672 JsepSessionDescription jdesc_deserialized(kDummyType);
2673 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2674 // Verify
2675 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2676}
2677
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002678TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2679 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2680
2681 std::string sdp = kSdpOneCandidate;
2682 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2683 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2684 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2685 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002686 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002687
2688 // Candidate line without generation extension.
2689 sdp = kSdpOneCandidate;
2690 Replace(" generation 2", "", &sdp);
2691 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2692 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2693 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2694 Candidate expected = jcandidate_->candidate();
2695 expected.set_generation(0);
2696 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2697
honghaiza0c44ea2016-03-23 16:07:48 -07002698 // Candidate with network id and/or cost.
2699 sdp = kSdpOneCandidate;
2700 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2701 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2702 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2703 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2704 expected = jcandidate_->candidate();
2705 expected.set_network_id(2);
2706 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2707 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2708 // Add network cost
2709 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2710 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2711 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2712 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2713
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002714 sdp = kSdpTcpActiveCandidate;
2715 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2716 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002717 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002718 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2719 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2720 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002721 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2722 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
Yves Gerey665174f2018-06-19 15:03:05 +02002723 EXPECT_TRUE(
2724 jcandidate.candidate().IsEquivalent(jcandidate_template->candidate()));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002725 sdp = kSdpTcpPassiveCandidate;
2726 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2727 sdp = kSdpTcpSOCandidate;
2728 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002729}
2730
2731// This test verifies the deserialization of candidate-attribute
2732// as per RFC 5245. Candiate-attribute will be of the format
2733// candidate:<blah>. This format will be used when candidates
2734// are trickled.
2735TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2736 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2737
2738 std::string candidate_attribute = kRawCandidate;
2739 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2740 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2741 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2742 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2743 EXPECT_EQ(2u, jcandidate.candidate().generation());
2744
2745 // Candidate line without generation extension.
2746 candidate_attribute = kRawCandidate;
2747 Replace(" generation 2", "", &candidate_attribute);
2748 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2749 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2750 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2751 Candidate expected = jcandidate_->candidate();
2752 expected.set_generation(0);
2753 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2754
2755 // Candidate line without candidate:
2756 candidate_attribute = kRawCandidate;
2757 Replace("candidate:", "", &candidate_attribute);
2758 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2759
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002760 // Candidate line with IPV6 address.
2761 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
Zach Steinb336c272018-08-09 01:16:13 -07002762
2763 // Candidate line with hostname address.
2764 EXPECT_TRUE(SdpDeserializeCandidate(kRawHostnameCandidate, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002765}
2766
2767// This test verifies that the deserialization of an invalid candidate string
2768// fails.
2769TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
Yves Gerey665174f2018-06-19 15:03:05 +02002770 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002771
2772 std::string candidate_attribute = kRawCandidate;
2773 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002774 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002775
2776 candidate_attribute = kSdpOneCandidate;
2777 candidate_attribute.replace(0, 1, "x");
2778 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2779
2780 candidate_attribute = kRawCandidate;
2781 candidate_attribute.append("\r\n");
2782 candidate_attribute.append(kRawCandidate);
2783 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2784
2785 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002786}
2787
2788TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2789 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002790 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002791 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2792
2793 std::string sdp_with_data = kSdpString;
2794 sdp_with_data.append(kSdpRtpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002795 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002796
2797 // Deserialize
2798 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2799 // Verify
2800 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2801}
2802
2803TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002804 bool use_sctpmap = true;
2805 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002806 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002807 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2808
2809 std::string sdp_with_data = kSdpString;
2810 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002811 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002812
lally@webrtc.org36300852015-02-24 20:19:35 +00002813 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2814 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2815 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2816
2817 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002818 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2819 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002820 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2821 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2822
2823 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002824 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2825 kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002826 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2827 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2828}
2829
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002830TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002831 bool use_sctpmap = false;
2832 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002833 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002834 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2835
2836 std::string sdp_with_data = kSdpString;
2837 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002838 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002839
lally@webrtc.org36300852015-02-24 20:19:35 +00002840 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002841 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2842 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002843
lally@webrtc.org36300852015-02-24 20:19:35 +00002844 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002845 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2846 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002847 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2848 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002849
lally@webrtc.org36300852015-02-24 20:19:35 +00002850 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002851 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2852 kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002853 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2854 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2855}
2856
lally69f57602015-10-08 10:15:04 -07002857TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002858 bool use_sctpmap = false;
2859 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002860 JsepSessionDescription jdesc(kDummyType);
lally69f57602015-10-08 10:15:04 -07002861 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2862
2863 std::string sdp_with_data = kSdpString;
2864 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002865 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 10:15:04 -07002866
2867 // Verify with DTLS/SCTP.
2868 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2869 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2870
2871 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002872 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2873 kUdpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002874 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2875 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2876
2877 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002878 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2879 kTcpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002880 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2881 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2882}
2883
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002884// Test to check the behaviour if sctp-port is specified
2885// on the m= line and in a=sctp-port.
2886TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002887 bool use_sctpmap = true;
2888 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002889 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002890 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2891
2892 std::string sdp_with_data = kSdpString;
2893 // Append m= attributes
2894 sdp_with_data.append(kSdpSctpDataChannelString);
2895 // Append a=sctp-port attribute
2896 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 10:27:41 -08002897 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002898
2899 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2900}
2901
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002902// For crbug/344475.
2903TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2904 std::string sdp_with_data = kSdpString;
2905 sdp_with_data.append(kSdpSctpDataChannelString);
2906 // Remove the "\n" at the end.
2907 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 10:27:41 -08002908 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002909
2910 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2911 // No crash is a pass.
2912}
2913
Steve Anton36b29d12017-10-30 09:57:42 -07002914void MutateJsepSctpPort(JsepSessionDescription* jdesc,
zstein4b2e0822017-02-17 19:48:38 -08002915 const SessionDescription& desc) {
wu@webrtc.org78187522013-10-07 23:32:02 +00002916 // take our pre-built session description and change the SCTP port.
zstein4b2e0822017-02-17 19:48:38 -08002917 cricket::SessionDescription* mutant = desc.Copy();
Steve Antonb1c1de12017-12-21 15:14:30 -08002918 DataContentDescription* dcdesc =
2919 mutant->GetContentDescriptionByName(kDataContentName)->as_data();
wu@webrtc.org78187522013-10-07 23:32:02 +00002920 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002921 EXPECT_EQ(1U, codecs.size());
solenberg9fa49752016-10-08 13:02:44 -07002922 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002923 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002924 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002925
2926 // note: mutant's owned by jdesc now.
Steve Anton36b29d12017-10-30 09:57:42 -07002927 ASSERT_TRUE(jdesc->Initialize(mutant, kSessionId, kSessionVersion));
wu@webrtc.org78187522013-10-07 23:32:02 +00002928 mutant = NULL;
zstein4b2e0822017-02-17 19:48:38 -08002929}
2930
2931TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
2932 bool use_sctpmap = true;
2933 AddSctpDataChannel(use_sctpmap);
2934
2935 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 10:27:41 -08002936 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002937 MutateJsepSctpPort(&jdesc, desc_);
wu@webrtc.org78187522013-10-07 23:32:02 +00002938
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002939 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002940 std::string sdp_with_data = kSdpString;
2941 sdp_with_data.append(kSdpSctpDataChannelString);
zstein4b2e0822017-02-17 19:48:38 -08002942 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2943 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2944 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002945 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:02 +00002946
2947 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2948 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08002949}
2950
2951TEST_F(WebRtcSdpTest,
2952 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
2953 bool use_sctpmap = false;
2954 AddSctpDataChannel(use_sctpmap);
2955
Steve Antona3a92c22017-12-07 10:27:41 -08002956 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002957 MutateJsepSctpPort(&jdesc, desc_);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002958
2959 // We need to test the deserialized JsepSessionDescription from
2960 // kSdpSctpDataChannelStringWithSctpPort for
2961 // draft-ietf-mmusic-sctp-sdp-07
2962 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08002963 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002964 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
zstein4b2e0822017-02-17 19:48:38 -08002965 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2966 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2967 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002968 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002969
2970 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2971 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002972}
2973
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002974TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002975 // We want to test that deserializing data content limits bandwidth
2976 // settings (it should never be greater than the default).
2977 // This should prevent someone from using unlimited data bandwidth through
2978 // JS and "breaking the Internet".
2979 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002980 std::string sdp_with_bandwidth = kSdpString;
2981 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02002982 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002983 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002984 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002985
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002986 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2987}
2988
2989TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08002990 bool use_sctpmap = true;
2991 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002992 JsepSessionDescription jdesc(kDummyType);
Steve Antonb1c1de12017-12-21 15:14:30 -08002993 DataContentDescription* dcd = GetFirstDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002994 dcd->set_bandwidth(100 * 1000);
2995 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2996
2997 std::string sdp_with_bandwidth = kSdpString;
2998 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02002999 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003000 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08003001 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003002
3003 // SCTP has congestion control, so we shouldn't limit the bandwidth
3004 // as we do for RTP.
3005 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003006 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
3007}
3008
Yves Gerey665174f2018-06-19 15:03:05 +02003009class WebRtcSdpExtmapTest : public WebRtcSdpTest,
3010 public testing::WithParamInterface<bool> {};
jbauch5869f502017-06-29 12:31:36 -07003011
3012TEST_P(WebRtcSdpExtmapTest,
Yves Gerey665174f2018-06-19 15:03:05 +02003013 DeserializeSessionDescriptionWithSessionLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003014 bool encrypted = GetParam();
3015 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003016}
3017
Yves Gerey665174f2018-06-19 15:03:05 +02003018TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003019 bool encrypted = GetParam();
3020 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003021}
3022
Yves Gerey665174f2018-06-19 15:03:05 +02003023TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithInvalidExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003024 bool encrypted = GetParam();
3025 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003026}
3027
jbauch5869f502017-06-29 12:31:36 -07003028INSTANTIATE_TEST_CASE_P(Encrypted,
3029 WebRtcSdpExtmapTest,
3030 ::testing::Values(false, true));
3031
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003032TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 10:27:41 -08003033 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003034 std::string sdp = kSdpFullString;
3035 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
3036 // Deserialize
3037 SdpParseError error;
3038 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-16 17:54:10 -08003039 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003040 EXPECT_EQ(lastline, error.line);
3041 EXPECT_EQ("Invalid SDP line.", error.description);
3042}
3043
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003044TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
3045 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
3046 std::string new_sdp = kSdpOneCandidate;
3047 Replace("udp", "unsupported_transport", &new_sdp);
3048 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3049 new_sdp = kSdpOneCandidate;
3050 Replace("udp", "uDP", &new_sdp);
3051 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3052 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3053 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3054 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
3055}
3056
honghaiza54a0802015-12-16 18:37:23 -08003057TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003058 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08003059 EXPECT_TRUE(
3060 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003061 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3062 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3063 Candidate ref_candidate = jcandidate_->candidate();
3064 ref_candidate.set_username("user_rtp");
3065 ref_candidate.set_password("password_rtp");
3066 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
3067}
3068
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003069TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08003070 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003071
3072 // Deserialize
3073 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
3074
3075 // Verify
3076 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08003077 jdesc.description()
3078 ->GetContentDescriptionByName(cricket::CN_AUDIO)
3079 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003080 EXPECT_TRUE(audio->conference_mode());
3081
3082 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 15:14:30 -08003083 jdesc.description()
3084 ->GetContentDescriptionByName(cricket::CN_VIDEO)
3085 ->as_video();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003086 EXPECT_TRUE(video->conference_mode());
3087}
3088
deadbeefd45aea82017-09-16 01:24:29 -07003089TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08003090 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 01:24:29 -07003091
3092 // We tested deserialization already above, so just test that if we serialize
3093 // and deserialize the flag doesn't disappear.
3094 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 12:22:16 -08003095 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 01:24:29 -07003096 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
3097
3098 // Verify.
3099 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08003100 jdesc.description()
3101 ->GetContentDescriptionByName(cricket::CN_AUDIO)
3102 ->as_audio();
deadbeefd45aea82017-09-16 01:24:29 -07003103 EXPECT_TRUE(audio->conference_mode());
3104
3105 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 15:14:30 -08003106 jdesc.description()
3107 ->GetContentDescriptionByName(cricket::CN_VIDEO)
3108 ->as_video();
deadbeefd45aea82017-09-16 01:24:29 -07003109 EXPECT_TRUE(video->conference_mode());
3110}
3111
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003112TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
3113 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003114 const char kSdpEmptyType[] = " =candidate";
3115 const char kSdpEqualAsPlus[] = "a+candidate";
3116 const char kSdpSpaceAfterEqual[] = "a= candidate";
3117 const char kSdpUpperType[] = "A=candidate";
3118 const char kSdpEmptyLine[] = "";
3119 const char kSdpMissingValue[] = "a=";
3120
Yves Gerey665174f2018-06-19 15:03:05 +02003121 const char kSdpBrokenFingerprint[] =
3122 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003123 "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 +02003124 const char kSdpExtraField[] =
3125 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003126 "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 +02003127 const char kSdpMissingSpace[] =
3128 "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003129 "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 +00003130 // MD5 is not allowed in fingerprints.
Yves Gerey665174f2018-06-19 15:03:05 +02003131 const char kSdpMd5[] =
3132 "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003133 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003134
3135 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003136 ExpectParseFailure("v=", kSdpDestroyer);
3137 ExpectParseFailure("o=", kSdpDestroyer);
3138 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003139 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003140 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003141
3142 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003143 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
3144 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003145
3146 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003147 ExpectParseFailure("a=candidate", kSdpEmptyType);
3148 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
3149 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
3150 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003151
3152 // Bogus fingerprint replacing a=sendrev. We selected this attribute
3153 // because it's orthogonal to what we are replacing and hence
3154 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003155 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
3156 ExpectParseFailure("a=sendrecv", kSdpExtraField);
3157 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
3158 ExpectParseFailure("a=sendrecv", kSdpMd5);
3159
3160 // Empty Line
3161 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
3162 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003163}
3164
3165TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
3166 // ssrc
3167 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08003168 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003169 // crypto
3170 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
3171 // rtpmap
3172 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
3173 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
3174 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
3175 // candidate
3176 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
3177 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
3178 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
3179 ExpectParseFailure("rport 2346", "rport badvalue");
3180 ExpectParseFailure("rport 2346 generation 2",
3181 "rport 2346 generation badvalue");
3182 // m line
3183 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
3184 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
3185
3186 // bandwidth
3187 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003188 "b=AS:badvalue\r\n", "b=AS:badvalue");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003189 // rtcp-fb
3190 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3191 "a=rtcp-fb:badvalue nack\r\n",
3192 "a=rtcp-fb:badvalue nack");
3193 // extmap
3194 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3195 "a=extmap:badvalue http://example.com\r\n",
3196 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003197}
3198
3199TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 10:27:41 -08003200 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003201
3202 const char kSdpWithReorderedPlTypesString[] =
3203 "v=0\r\n"
3204 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3205 "s=-\r\n"
3206 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00003207 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
Yves Gerey665174f2018-06-19 15:03:05 +02003208 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
3209 // in the map.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003210 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003211 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003212
3213 // Deserialize
3214 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
3215
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003216 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003217 GetFirstAudioContentDescription(jdesc_output.description());
3218 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003219 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003220 EXPECT_EQ("ISAC", acd->codecs()[0].name);
3221 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003222 EXPECT_EQ(104, acd->codecs()[0].id);
3223}
3224
3225TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 10:27:41 -08003226 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003227 CodecParams params;
3228 params.max_ptime = 40;
3229 params.ptime = 30;
3230 params.min_ptime = 10;
3231 params.sprop_stereo = 1;
3232 params.stereo = 1;
3233 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003234 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003235 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 12:22:16 -08003236 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003237}
3238
3239TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
3240 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 10:27:41 -08003241 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003242 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003243 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003244}
3245
3246TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
3247 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 10:27:41 -08003248 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003249 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003250 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003251}
3252
3253TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 10:27:41 -08003254 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003255
3256 const char kSdpWithFmtpString[] =
3257 "v=0\r\n"
3258 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3259 "s=-\r\n"
3260 "t=0 0\r\n"
3261 "m=video 3457 RTP/SAVPF 120\r\n"
3262 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07003263 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3264
3265 // Deserialize
3266 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07003267 EXPECT_TRUE(
3268 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07003269
Donald Curtis0e07f922015-05-15 09:21:23 -07003270 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003271 GetFirstVideoContentDescription(jdesc_output.description());
3272 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 09:21:23 -07003273 ASSERT_FALSE(vcd->codecs().empty());
3274 cricket::VideoCodec vp8 = vcd->codecs()[0];
3275 EXPECT_EQ("VP8", vp8.name);
3276 EXPECT_EQ(120, vp8.id);
3277 cricket::CodecParameterMap::iterator found =
3278 vp8.params.find("x-google-min-bitrate");
3279 ASSERT_TRUE(found != vp8.params.end());
3280 EXPECT_EQ(found->second, "10");
3281 found = vp8.params.find("x-google-max-quantization");
3282 ASSERT_TRUE(found != vp8.params.end());
3283 EXPECT_EQ(found->second, "40");
3284}
3285
johan2d8d23e2016-06-03 01:22:42 -07003286TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 10:27:41 -08003287 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 01:22:42 -07003288
3289 const char kSdpWithFmtpString[] =
3290 "v=0\r\n"
3291 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3292 "s=-\r\n"
3293 "t=0 0\r\n"
3294 "m=video 49170 RTP/AVP 98\r\n"
3295 "a=rtpmap:98 H264/90000\r\n"
3296 "a=fmtp:98 profile-level-id=42A01E; "
3297 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3298
3299 // Deserialize.
3300 SdpParseError error;
3301 EXPECT_TRUE(
3302 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3303
johan2d8d23e2016-06-03 01:22:42 -07003304 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003305 GetFirstVideoContentDescription(jdesc_output.description());
3306 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 01:22:42 -07003307 ASSERT_FALSE(vcd->codecs().empty());
3308 cricket::VideoCodec h264 = vcd->codecs()[0];
3309 EXPECT_EQ("H264", h264.name);
3310 EXPECT_EQ(98, h264.id);
3311 cricket::CodecParameterMap::const_iterator found =
3312 h264.params.find("profile-level-id");
3313 ASSERT_TRUE(found != h264.params.end());
3314 EXPECT_EQ(found->second, "42A01E");
3315 found = h264.params.find("sprop-parameter-sets");
3316 ASSERT_TRUE(found != h264.params.end());
3317 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3318}
3319
Donald Curtis0e07f922015-05-15 09:21:23 -07003320TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 10:27:41 -08003321 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 09:21:23 -07003322
3323 const char kSdpWithFmtpString[] =
3324 "v=0\r\n"
3325 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3326 "s=-\r\n"
3327 "t=0 0\r\n"
3328 "m=video 3457 RTP/SAVPF 120\r\n"
3329 "a=rtpmap:120 VP8/90000\r\n"
3330 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003331
3332 // Deserialize
3333 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02003334 EXPECT_TRUE(
3335 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003336
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003337 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003338 GetFirstVideoContentDescription(jdesc_output.description());
3339 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003340 ASSERT_FALSE(vcd->codecs().empty());
3341 cricket::VideoCodec vp8 = vcd->codecs()[0];
3342 EXPECT_EQ("VP8", vp8.name);
3343 EXPECT_EQ(120, vp8.id);
3344 cricket::CodecParameterMap::iterator found =
3345 vp8.params.find("x-google-min-bitrate");
3346 ASSERT_TRUE(found != vp8.params.end());
3347 EXPECT_EQ(found->second, "10");
3348 found = vp8.params.find("x-google-max-quantization");
3349 ASSERT_TRUE(found != vp8.params.end());
3350 EXPECT_EQ(found->second, "40");
3351}
3352
ossuaa4b0772017-01-30 07:41:18 -08003353TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003354 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003355
3356 cricket::AudioCodecs codecs = acd->codecs();
3357 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3358 acd->set_codecs(codecs);
3359
Yves Gerey665174f2018-06-19 15:03:05 +02003360 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003361 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003362 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003363 std::string sdp_with_fmtp = kSdpFullString;
3364 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3365 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3366 &sdp_with_fmtp);
3367 EXPECT_EQ(sdp_with_fmtp, message);
3368}
3369
3370TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003371 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003372
3373 cricket::AudioCodecs codecs = acd->codecs();
3374 codecs[0].params["stereo"] = "1";
3375 acd->set_codecs(codecs);
3376
Yves Gerey665174f2018-06-19 15:03:05 +02003377 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003378 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003379 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003380 std::string sdp_with_fmtp = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003381 InjectAfter("a=rtpmap:111 opus/48000/2\r\n", "a=fmtp:111 stereo=1\r\n",
ossuaa4b0772017-01-30 07:41:18 -08003382 &sdp_with_fmtp);
3383 EXPECT_EQ(sdp_with_fmtp, message);
3384}
3385
3386TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003387 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003388
3389 cricket::AudioCodecs codecs = acd->codecs();
3390 codecs[0].params["ptime"] = "20";
3391 codecs[0].params["maxptime"] = "120";
3392 acd->set_codecs(codecs);
3393
Yves Gerey665174f2018-06-19 15:03:05 +02003394 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003395 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003396 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003397 std::string sdp_with_fmtp = kSdpFullString;
3398 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3399 "a=maxptime:120\r\n" // No comma here. String merging!
3400 "a=ptime:20\r\n",
3401 &sdp_with_fmtp);
3402 EXPECT_EQ(sdp_with_fmtp, message);
3403}
3404
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003405TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003406 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003407
3408 cricket::VideoCodecs codecs = vcd->codecs();
3409 codecs[0].params["x-google-min-bitrate"] = "10";
3410 vcd->set_codecs(codecs);
3411
Yves Gerey665174f2018-06-19 15:03:05 +02003412 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003413 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003414 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003415 std::string sdp_with_fmtp = kSdpFullString;
3416 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003417 "a=fmtp:120 x-google-min-bitrate=10\r\n", &sdp_with_fmtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003418 EXPECT_EQ(sdp_with_fmtp, message);
3419}
3420
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003421TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) {
3422 // Deserialize the baseline description, making sure it's ICE full.
Steve Antona3a92c22017-12-07 10:27:41 -08003423 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003424 std::string sdp_with_icelite = kSdpFullString;
3425 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3426 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3427 const cricket::TransportInfo* tinfo1 =
3428 desc->GetTransportInfoByName("audio_content_name");
3429 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3430 const cricket::TransportInfo* tinfo2 =
3431 desc->GetTransportInfoByName("video_content_name");
3432 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003433
3434 // Add "a=ice-lite" and deserialize, making sure it's ICE lite.
Yves Gerey665174f2018-06-19 15:03:05 +02003435 InjectAfter(kSessionTime, "a=ice-lite\r\n", &sdp_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003436 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3437 desc = jdesc_with_icelite.description();
3438 const cricket::TransportInfo* atinfo =
3439 desc->GetTransportInfoByName("audio_content_name");
3440 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3441 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003442 desc->GetTransportInfoByName("video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003443 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003444
3445 // Now that we know deserialization works, we can use TestSerialize to test
3446 // serialization.
3447 TestSerialize(jdesc_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003448}
3449
3450// Verifies that the candidates in the input SDP are parsed and serialized
3451// correctly in the output SDP.
3452TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3453 std::string sdp_with_data = kSdpString;
3454 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 10:27:41 -08003455 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003456
3457 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 12:22:16 -08003458 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003459}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003460
3461TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3462 AddFingerprint();
3463 TransportInfo audio_transport_info =
3464 *(desc_.GetTransportInfoByName(kAudioContentName));
3465 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3466 audio_transport_info.description.connection_role);
3467 audio_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003468 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003469
3470 TransportInfo video_transport_info =
3471 *(desc_.GetTransportInfoByName(kVideoContentName));
3472 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3473 video_transport_info.description.connection_role);
3474 video_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003475 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003476
3477 desc_.RemoveTransportInfoByName(kAudioContentName);
3478 desc_.RemoveTransportInfoByName(kVideoContentName);
3479
3480 desc_.AddTransportInfo(audio_transport_info);
3481 desc_.AddTransportInfo(video_transport_info);
3482
Yves Gerey665174f2018-06-19 15:03:05 +02003483 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003484 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003485 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003486 std::string sdp_with_dtlssetup = kSdpFullString;
3487
3488 // Fingerprint attribute is necessary to add DTLS setup attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003489 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_dtlssetup);
3490 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003491 // Now adding |setup| attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003492 InjectAfter(kFingerprint, "a=setup:active\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003493 EXPECT_EQ(sdp_with_dtlssetup, message);
3494}
3495
3496TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
Steve Antona3a92c22017-12-07 10:27:41 -08003497 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003498 std::string sdp_with_dtlssetup = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003499 InjectAfter(kSessionTime, "a=setup:actpass\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003500 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3501 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3502 const cricket::TransportInfo* atinfo =
3503 desc->GetTransportInfoByName("audio_content_name");
3504 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3505 atinfo->description.connection_role);
3506 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003507 desc->GetTransportInfoByName("video_content_name");
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003508 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3509 vtinfo->description.connection_role);
3510}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003511
3512// Verifies that the order of the serialized m-lines follows the order of the
3513// ContentInfo in SessionDescription, and vise versa for deserialization.
3514TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 10:27:41 -08003515 JsepSessionDescription jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02003516 const std::string media_content_sdps[3] = {kSdpAudioString, kSdpVideoString,
3517 kSdpSctpDataChannelString};
3518 const cricket::MediaType media_types[3] = {cricket::MEDIA_TYPE_AUDIO,
3519 cricket::MEDIA_TYPE_VIDEO,
3520 cricket::MEDIA_TYPE_DATA};
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003521
3522 // Verifies all 6 permutations.
3523 for (size_t i = 0; i < 6; ++i) {
3524 size_t media_content_in_sdp[3];
3525 // The index of the first media content.
3526 media_content_in_sdp[0] = i / 2;
3527 // The index of the second media content.
3528 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3529 // The index of the third media content.
3530 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3531
3532 std::string sdp_string = kSdpSessionString;
3533 for (size_t i = 0; i < 3; ++i)
3534 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3535
3536 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3537 cricket::SessionDescription* desc = jdesc.description();
3538 EXPECT_EQ(3u, desc->contents().size());
3539
3540 for (size_t i = 0; i < 3; ++i) {
3541 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 15:14:30 -08003542 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003543 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3544 }
3545
Steve Antone831b8c2018-02-01 12:22:16 -08003546 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003547 EXPECT_EQ(sdp_string, serialized_sdp);
3548 }
3549}
deadbeef9d3584c2016-02-16 17:54:10 -08003550
deadbeef25ed4352016-12-12 18:37:36 -08003551TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3552 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 10:27:41 -08003553 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003554 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003555 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3556 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3557}
3558
deadbeef12771a12017-01-03 13:53:47 -08003559// The semantics of "a=bundle-only" are only defined when it's used in
3560// combination with a 0 port on the m= line. We should ignore it if used with a
3561// nonzero port.
3562TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3563 // Make the base bundle-only description but unset the bundle-only flag.
3564 MakeBundleOnlyDescription();
3565 jdesc_.description()->contents()[1].bundle_only = false;
3566
3567 std::string modified_sdp = kBundleOnlySdpFullString;
3568 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08003569 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003570 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3571 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003572}
3573
3574TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3575 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003576 TestSerialize(jdesc_);
deadbeef25ed4352016-12-12 18:37:36 -08003577}
3578
deadbeef9d3584c2016-02-16 17:54:10 -08003579TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3580 MakePlanBDescription();
3581
Steve Antona3a92c22017-12-07 10:27:41 -08003582 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003583 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3584
3585 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3586}
3587
3588TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3589 MakePlanBDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003590 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-16 17:54:10 -08003591}
3592
3593TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3594 MakeUnifiedPlanDescription();
3595
Steve Antona3a92c22017-12-07 10:27:41 -08003596 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003597 EXPECT_TRUE(
3598 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3599
3600 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3601}
3602
3603TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3604 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003605 TestSerialize(jdesc_);
3606}
3607
Seth Hampson5b4f0752018-04-02 16:31:36 -07003608// This tests deserializing a Unified Plan SDP that is compatible with both
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003609// Unified Plan and Plan B style SDP, meaning that it contains both "a=ssrc
3610// msid" lines and "a=msid " lines. It tests the case for audio/video tracks
Seth Hampson5b4f0752018-04-02 16:31:36 -07003611// with no stream ids and multiple stream ids. For parsing this, the Unified
3612// Plan a=msid lines should take priority, because the Plan B style a=ssrc msid
3613// lines do not support multiple stream ids and no stream ids.
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003614TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionSpecialMsid) {
3615 // Create both msid lines for Plan B and Unified Plan support.
3616 MakeUnifiedPlanDescriptionMultipleStreamIds(
3617 cricket::kMsidSignalingMediaSection |
3618 cricket::kMsidSignalingSsrcAttribute);
Seth Hampson5b4f0752018-04-02 16:31:36 -07003619
3620 JsepSessionDescription deserialized_description(kDummyType);
3621 EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid,
3622 &deserialized_description));
3623
3624 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
Henrik Boström5b147782018-12-04 11:25:05 +01003625 EXPECT_EQ(cricket::kMsidSignalingMediaSection |
3626 cricket::kMsidSignalingSsrcAttribute,
3627 deserialized_description.description()->msid_signaling());
Seth Hampson5b4f0752018-04-02 16:31:36 -07003628}
3629
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003630// Tests the serialization of a Unified Plan SDP that is compatible for both
3631// Unified Plan and Plan B style SDPs, meaning that it contains both "a=ssrc
3632// msid" lines and "a=msid " lines. It tests the case for no stream ids and
3633// multiple stream ids.
3634TEST_F(WebRtcSdpTest, SerializeSessionDescriptionSpecialMsid) {
3635 // Create both msid lines for Plan B and Unified Plan support.
3636 MakeUnifiedPlanDescriptionMultipleStreamIds(
3637 cricket::kMsidSignalingMediaSection |
3638 cricket::kMsidSignalingSsrcAttribute);
3639 std::string serialized_sdp = webrtc::SdpSerialize(jdesc_);
3640 // We explicitly test that the serialized SDP string is equal to the hard
3641 // coded SDP string. This is necessary, because in the parser "a=msid" lines
3642 // take priority over "a=ssrc msid" lines. This means if we just used
3643 // TestSerialize(), it could serialize an SDP that omits "a=ssrc msid" lines,
3644 // and still pass, because the deserialized version would be the same.
3645 EXPECT_EQ(kUnifiedPlanSdpFullStringWithSpecialMsid, serialized_sdp);
3646}
3647
3648// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3649// that signal stream IDs) is deserialized appropriately. It tests the case for
3650// no stream ids and multiple stream ids.
3651TEST_F(WebRtcSdpTest, UnifiedPlanDeserializeSessionDescriptionSpecialMsid) {
3652 // Only create a=msid lines for strictly Unified Plan stream ID support.
3653 MakeUnifiedPlanDescriptionMultipleStreamIds(
3654 cricket::kMsidSignalingMediaSection);
3655
3656 JsepSessionDescription deserialized_description(kDummyType);
3657 std::string unified_plan_sdp_string =
3658 kUnifiedPlanSdpFullStringWithSpecialMsid;
3659 RemoveSsrcMsidLinesFromSdpString(&unified_plan_sdp_string);
3660 EXPECT_TRUE(
3661 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3662
3663 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3664}
3665
3666// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3667// that signal stream IDs) is serialized appropriately. It tests the case for no
3668// stream ids and multiple stream ids.
3669TEST_F(WebRtcSdpTest, UnifiedPlanSerializeSessionDescriptionSpecialMsid) {
3670 // Only create a=msid lines for strictly Unified Plan stream ID support.
3671 MakeUnifiedPlanDescriptionMultipleStreamIds(
3672 cricket::kMsidSignalingMediaSection);
3673
Seth Hampson5b4f0752018-04-02 16:31:36 -07003674 TestSerialize(jdesc_);
3675}
3676
Seth Hampson5897a6e2018-04-03 11:16:33 -07003677// This tests that a Unified Plan SDP with no a=ssrc lines is
3678// serialized/deserialized appropriately. In this case the
3679// MediaContentDescription will contain a StreamParams object that doesn't have
3680// any SSRCs. Vice versa, this will be created upon deserializing an SDP with no
3681// SSRC lines.
3682TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3683 MakeUnifiedPlanDescription();
3684 RemoveSsrcSignalingFromStreamParams();
3685 std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString;
3686 RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string);
3687
3688 JsepSessionDescription deserialized_description(kDummyType);
3689 EXPECT_TRUE(
3690 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3691 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3692}
3693
3694TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3695 MakeUnifiedPlanDescription();
3696 RemoveSsrcSignalingFromStreamParams();
3697
3698 TestSerialize(jdesc_);
3699}
3700
Steve Antone831b8c2018-02-01 12:22:16 -08003701TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
3702 JsepSessionDescription jsep_desc(kDummyType);
3703 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
3704 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3705}
3706
3707TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
3708 JsepSessionDescription jsep_desc(kDummyType);
3709 std::string sdp = kSdpSessionString;
3710 sdp += kSdpSctpDataChannelString;
3711 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3712 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3713}
3714
3715TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
3716 JsepSessionDescription jsep_desc(kDummyType);
3717 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
3718 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
3719 jsep_desc.description()->msid_signaling());
3720}
3721
3722TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
3723 JsepSessionDescription jsep_desc(kDummyType);
3724 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
3725 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
3726 jsep_desc.description()->msid_signaling());
3727}
3728
3729const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
3730const char kSsrcAttributeMsidLine[] =
3731 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
3732
3733TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
3734 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
3735 std::string sdp = webrtc::SdpSerialize(jdesc_);
3736
3737 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3738 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3739}
3740
3741TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
3742 jdesc_.description()->set_msid_signaling(
3743 cricket::kMsidSignalingSsrcAttribute);
3744 std::string sdp = webrtc::SdpSerialize(jdesc_);
3745
3746 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
3747 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3748}
3749
3750TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
3751 jdesc_.description()->set_msid_signaling(
3752 cricket::kMsidSignalingMediaSection |
3753 cricket::kMsidSignalingSsrcAttribute);
3754 std::string sdp = webrtc::SdpSerialize(jdesc_);
3755
3756 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3757 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-16 17:54:10 -08003758}
deadbeef7e146cb2016-09-28 10:04:34 -07003759
3760// Regression test for heap overflow bug:
3761// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3762TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 10:04:34 -07003763 // The issue occurs when the sctp-port attribute is found in a video
3764 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 12:43:58 -08003765 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 10:04:34 -07003766 "v=0\r\n"
3767 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3768 "s=-\r\n"
3769 "t=0 0\r\n"
3770 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3771 "a=sctp-port 5000\r\n"
3772 "a=fmtp:108 foo=10\r\n";
3773
3774 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3775 "sctp-port");
3776}
deadbeefb2362572016-12-13 16:37:06 -08003777
3778// Regression test for integer overflow bug:
3779// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3780TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003781 // Bandwidth attribute is the max signed 32-bit int, which will get
3782 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003783 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003784 "v=0\r\n"
3785 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3786 "s=-\r\n"
3787 "t=0 0\r\n"
3788 "m=video 3457 RTP/SAVPF 120\r\n"
3789 "b=AS:2147483647\r\n"
3790 "foo=fail\r\n";
3791
3792 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3793}
deadbeef7bcdb692017-01-20 12:43:58 -08003794
deadbeefbc88c6b2017-08-02 11:26:34 -07003795// Similar to the above, except that negative values are illegal, not just
3796// error-prone as large values are.
3797// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3798TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3799 static const char kSdpWithNegativeBandwidth[] =
3800 "v=0\r\n"
3801 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3802 "s=-\r\n"
3803 "t=0 0\r\n"
3804 "m=video 3457 RTP/SAVPF 120\r\n"
3805 "b=AS:-1000\r\n";
3806
3807 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3808}
3809
deadbeef3e8016e2017-08-03 17:49:30 -07003810// An exception to the above rule: a value of -1 for b=AS should just be
3811// ignored, resulting in "kAutoBandwidth" in the deserialized object.
3812// Applications historically may be using "b=AS:-1" to mean "no bandwidth
3813// limit", but this is now what ommitting the attribute entirely will do, so
3814// ignoring it will have the intended effect.
3815TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
3816 static const char kSdpWithBandwidthOfNegativeOne[] =
3817 "v=0\r\n"
3818 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3819 "s=-\r\n"
3820 "t=0 0\r\n"
3821 "m=video 3457 RTP/SAVPF 120\r\n"
3822 "b=AS:-1\r\n";
3823
Steve Antona3a92c22017-12-07 10:27:41 -08003824 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-03 17:49:30 -07003825 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-03 17:49:30 -07003826 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003827 GetFirstVideoContentDescription(jdesc_output.description());
3828 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-03 17:49:30 -07003829 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
3830}
3831
deadbeef7bcdb692017-01-20 12:43:58 -08003832// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3833// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3834// Regression test for:
3835// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3836TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3837 // Important piece is "ufrag foo pwd bar".
3838 static const char kSdpWithIceCredentialsInCandidateString[] =
3839 "v=0\r\n"
3840 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3841 "s=-\r\n"
3842 "t=0 0\r\n"
3843 "m=audio 9 RTP/SAVPF 111\r\n"
3844 "c=IN IP4 0.0.0.0\r\n"
3845 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3846 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3847 "a=rtpmap:111 opus/48000/2\r\n"
3848 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3849 "generation 2 ufrag foo pwd bar\r\n";
3850
Steve Antona3a92c22017-12-07 10:27:41 -08003851 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 12:43:58 -08003852 EXPECT_TRUE(
3853 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
3854 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3855 ASSERT_NE(nullptr, candidates);
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003856 ASSERT_EQ(1U, candidates->count());
deadbeef7bcdb692017-01-20 12:43:58 -08003857 cricket::Candidate c = candidates->at(0)->candidate();
3858 EXPECT_EQ("ufrag_voice", c.username());
3859 EXPECT_EQ("pwd_voice", c.password());
3860}
deadbeef90f1e1e2017-02-10 12:35:05 -08003861
Johannes Kron211856b2018-09-06 12:12:28 +02003862// Test that attribute lines "a=ice-ufrag-something"/"a=ice-pwd-something" are
3863// ignored, and only the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3864// Regression test for:
3865// https://bugs.chromium.org/p/webrtc/issues/detail?id=9712
3866TEST_F(WebRtcSdpTest, AttributeWithPartialMatchingNameIsIgnored) {
3867 static const char kSdpWithFooIceCredentials[] =
3868 "v=0\r\n"
3869 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3870 "s=-\r\n"
3871 "t=0 0\r\n"
3872 "m=audio 9 RTP/SAVPF 111\r\n"
3873 "c=IN IP4 0.0.0.0\r\n"
3874 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3875 "a=ice-ufrag-something:foo\r\na=ice-pwd-something:bar\r\n"
3876 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3877 "a=rtpmap:111 opus/48000/2\r\n"
3878 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3879 "generation 2\r\n";
3880
3881 JsepSessionDescription jdesc_output(kDummyType);
3882 EXPECT_TRUE(SdpDeserialize(kSdpWithFooIceCredentials, &jdesc_output));
3883 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3884 ASSERT_NE(nullptr, candidates);
3885 ASSERT_EQ(1U, candidates->count());
3886 cricket::Candidate c = candidates->at(0)->candidate();
3887 EXPECT_EQ("ufrag_voice", c.username());
3888 EXPECT_EQ("pwd_voice", c.password());
3889}
3890
deadbeef90f1e1e2017-02-10 12:35:05 -08003891// Test that SDP with an invalid port number in "a=candidate" lines is
3892// rejected, without crashing.
3893// Regression test for:
3894// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
3895TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
3896 static const char kSdpWithInvalidCandidatePort[] =
3897 "v=0\r\n"
3898 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3899 "s=-\r\n"
3900 "t=0 0\r\n"
3901 "m=audio 9 RTP/SAVPF 111\r\n"
3902 "c=IN IP4 0.0.0.0\r\n"
3903 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3904 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3905 "a=rtpmap:111 opus/48000/2\r\n"
3906 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
3907 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
3908
Steve Antona3a92c22017-12-07 10:27:41 -08003909 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 12:35:05 -08003910 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
3911}
deadbeefa4549d62017-02-10 17:26:22 -08003912
3913// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
3914// Regression test for:
3915// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
3916TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
3917 static const char kSdpWithMissingTrackId[] =
3918 "v=0\r\n"
3919 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3920 "s=-\r\n"
3921 "t=0 0\r\n"
3922 "m=audio 9 RTP/SAVPF 111\r\n"
3923 "c=IN IP4 0.0.0.0\r\n"
3924 "a=rtpmap:111 opus/48000/2\r\n"
3925 "a=msid:stream_id \r\n";
3926
Steve Antona3a92c22017-12-07 10:27:41 -08003927 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003928 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
3929}
3930
3931TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
3932 static const char kSdpWithMissingStreamId[] =
3933 "v=0\r\n"
3934 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3935 "s=-\r\n"
3936 "t=0 0\r\n"
3937 "m=audio 9 RTP/SAVPF 111\r\n"
3938 "c=IN IP4 0.0.0.0\r\n"
3939 "a=rtpmap:111 opus/48000/2\r\n"
3940 "a=msid: track_id\r\n";
3941
Steve Antona3a92c22017-12-07 10:27:41 -08003942 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003943 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
3944}
zhihuang38989e52017-03-21 11:04:53 -07003945
3946// Tests that if both session-level address and media-level address exist, use
3947// the media-level address.
3948TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 10:27:41 -08003949 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003950
3951 // Sesssion-level address.
3952 std::string sdp = kSdpFullString;
3953 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3954 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3955
3956 const auto& content1 = jsep_desc.description()->contents()[0];
3957 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 15:14:30 -08003958 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003959 const auto& content2 = jsep_desc.description()->contents()[1];
3960 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 15:14:30 -08003961 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003962}
3963
3964// Tests that the session-level connection address will be used if the media
3965// level-addresses are not specified.
3966TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 10:27:41 -08003967 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003968
3969 // Sesssion-level address.
3970 std::string sdp = kSdpString;
3971 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3972 // Remove the media level addresses.
3973 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3974 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3975 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3976
3977 const auto& content1 = jsep_desc.description()->contents()[0];
3978 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003979 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003980 const auto& content2 = jsep_desc.description()->contents()[1];
3981 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003982 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003983}
3984
3985TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 10:27:41 -08003986 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003987
3988 std::string sdp = kSdpString;
3989 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3990 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
3991 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
3992 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
3993 &sdp);
3994 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
3995 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
3996 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
3997 &sdp);
3998 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3999 const auto& content1 = jsep_desc.description()->contents()[0];
4000 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004001 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004002 const auto& content2 = jsep_desc.description()->contents()[1];
4003 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004004 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004005}
4006
4007// Test that the invalid or unsupprted connection data cannot be parsed.
4008TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 10:27:41 -08004009 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004010 std::string sdp = kSdpString;
4011 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4012
4013 // Unsupported multicast IPv4 address.
4014 sdp = kSdpFullString;
4015 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
4016 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4017
4018 // Unsupported multicast IPv6 address.
4019 sdp = kSdpFullString;
4020 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
4021 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4022
4023 // Mismatched address type.
4024 sdp = kSdpFullString;
4025 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
4026 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4027
4028 sdp = kSdpFullString;
4029 Replace("c=IN IP4 74.125.224.39\r\n",
4030 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
4031 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4032}
4033
4034TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 10:27:41 -08004035 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004036 MakeDescriptionWithoutCandidates(&expected_jsep);
4037 // Serialization.
Steve Antone831b8c2018-02-01 12:22:16 -08004038 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 11:04:53 -07004039 // Deserialization.
Steve Antona3a92c22017-12-07 10:27:41 -08004040 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004041 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 15:14:30 -08004042 auto audio_desc = jdesc.description()
4043 ->GetContentByName(kAudioContentName)
4044 ->media_description();
4045 auto video_desc = jdesc.description()
4046 ->GetContentByName(kVideoContentName)
4047 ->media_description();
zhihuang38989e52017-03-21 11:04:53 -07004048 EXPECT_EQ(audio_desc_->connection_address().ToString(),
4049 audio_desc->connection_address().ToString());
4050 EXPECT_EQ(video_desc_->connection_address().ToString(),
4051 video_desc->connection_address().ToString());
4052}
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07004053
4054// RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be
4055// used (i.e., a single space as the session name)." So we should accept that.
4056TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) {
4057 JsepSessionDescription jsep_desc(kDummyType);
4058 std::string sdp = kSdpString;
4059 Replace("s=-\r\n", "s= \r\n", &sdp);
4060 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4061}
Amit Hilbucha2012042018-12-03 11:35:05 -08004062
4063// Simulcast malformed input test for invalid format.
4064TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_EmptyAttribute) {
4065 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
4066 "a=simulcast:\r\n", "a=simulcast:");
4067}
4068
4069// Tests that duplicate simulcast entries in the SDP triggers a parse failure.
4070TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_DuplicateAttribute) {
4071 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
4072 "a=simulcast:send 1\r\na=simulcast:recv 2\r\n",
4073 "a=simulcast:");
4074}
4075
4076// Validates that deserialization uses the a=simulcast: attribute
4077TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttribute) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004078 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4079 sdp += "a=rid:1 send\r\n";
4080 sdp += "a=rid:2 send\r\n";
4081 sdp += "a=rid:3 send\r\n";
4082 sdp += "a=rid:4 recv\r\n";
4083 sdp += "a=rid:5 recv\r\n";
4084 sdp += "a=rid:6 recv\r\n";
Amit Hilbucha2012042018-12-03 11:35:05 -08004085 sdp += "a=simulcast:send 1,2;3 recv 4;5;6\r\n";
4086 JsepSessionDescription output(kDummyType);
4087 SdpParseError error;
4088 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4089 const cricket::ContentInfos& contents = output.description()->contents();
4090 const cricket::MediaContentDescription* media =
4091 contents.back().media_description();
4092 EXPECT_TRUE(media->HasSimulcast());
4093 EXPECT_EQ(2ul, media->simulcast_description().send_layers().size());
4094 EXPECT_EQ(3ul, media->simulcast_description().receive_layers().size());
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004095 EXPECT_FALSE(media->streams().empty());
4096 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4097 CompareRidDescriptionIds(rids, {"1", "2", "3"});
4098 ASSERT_TRUE(media->has_receive_stream());
4099 CompareRidDescriptionIds(media->receive_stream().rids(), {"4", "5", "6"});
4100}
4101
4102// Validates that deserialization removes rids that do not appear in SDP
4103TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttributeRemovesUnknownRids) {
4104 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4105 sdp += "a=rid:1 send\r\n";
4106 sdp += "a=rid:3 send\r\n";
4107 sdp += "a=rid:4 recv\r\n";
4108 sdp += "a=simulcast:send 1,2;3 recv 4;5,6\r\n";
4109 JsepSessionDescription output(kDummyType);
4110 SdpParseError error;
4111 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4112 const cricket::ContentInfos& contents = output.description()->contents();
4113 const cricket::MediaContentDescription* media =
4114 contents.back().media_description();
4115 EXPECT_TRUE(media->HasSimulcast());
4116 const SimulcastDescription& simulcast = media->simulcast_description();
4117 EXPECT_EQ(2ul, simulcast.send_layers().size());
4118 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4119
4120 std::vector<SimulcastLayer> all_send_layers =
4121 simulcast.send_layers().GetAllLayers();
4122 EXPECT_EQ(2ul, all_send_layers.size());
4123 EXPECT_EQ(0, std::count_if(all_send_layers.begin(), all_send_layers.end(),
4124 [](const SimulcastLayer& layer) {
4125 return layer.rid == "2";
4126 }));
4127
4128 std::vector<SimulcastLayer> all_receive_layers =
4129 simulcast.receive_layers().GetAllLayers();
4130 ASSERT_EQ(1ul, all_receive_layers.size());
4131 EXPECT_EQ("4", all_receive_layers[0].rid);
4132
4133 EXPECT_FALSE(media->streams().empty());
4134 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4135 CompareRidDescriptionIds(rids, {"1", "3"});
4136 ASSERT_TRUE(media->has_receive_stream());
4137 CompareRidDescriptionIds(media->receive_stream().rids(), {"4"});
4138}
4139
4140// Validates that Simulcast removes rids that appear in both send and receive.
4141TEST_F(WebRtcSdpTest,
4142 TestDeserializeSimulcastAttributeRemovesDuplicateSendReceive) {
4143 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4144 sdp += "a=rid:1 send\r\n";
4145 sdp += "a=rid:2 send\r\n";
4146 sdp += "a=rid:3 send\r\n";
4147 sdp += "a=rid:4 recv\r\n";
4148 sdp += "a=simulcast:send 1;2;3 recv 2;4\r\n";
4149 JsepSessionDescription output(kDummyType);
4150 SdpParseError error;
4151 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4152 const cricket::ContentInfos& contents = output.description()->contents();
4153 const cricket::MediaContentDescription* media =
4154 contents.back().media_description();
4155 EXPECT_TRUE(media->HasSimulcast());
4156 const SimulcastDescription& simulcast = media->simulcast_description();
4157 EXPECT_EQ(2ul, simulcast.send_layers().size());
4158 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4159 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4160 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4161
4162 EXPECT_FALSE(media->streams().empty());
4163 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4164 CompareRidDescriptionIds(rids, {"1", "3"});
4165 ASSERT_TRUE(media->has_receive_stream());
4166 CompareRidDescriptionIds(media->receive_stream().rids(), {"4"});
4167}
4168
4169// Ignores empty rid line.
4170TEST_F(WebRtcSdpTest, TestDeserializeIgnoresEmptyRidLines) {
4171 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4172 sdp += "a=rid:1 send\r\n";
4173 sdp += "a=rid:2 send\r\n";
4174 sdp += "a=rid\r\n"; // Should ignore this line.
4175 sdp += "a=rid:\r\n"; // Should ignore this line.
4176 sdp += "a=simulcast:send 1;2\r\n";
4177 JsepSessionDescription output(kDummyType);
4178 SdpParseError error;
4179 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4180 const cricket::ContentInfos& contents = output.description()->contents();
4181 const cricket::MediaContentDescription* media =
4182 contents.back().media_description();
4183 EXPECT_TRUE(media->HasSimulcast());
4184 const SimulcastDescription& simulcast = media->simulcast_description();
4185 EXPECT_TRUE(simulcast.receive_layers().empty());
4186 EXPECT_EQ(2ul, simulcast.send_layers().size());
4187 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4188
4189 EXPECT_FALSE(media->streams().empty());
4190 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4191 CompareRidDescriptionIds(rids, {"1", "2"});
4192 ASSERT_FALSE(media->has_receive_stream());
4193}
4194
4195// Ignores malformed rid lines.
4196TEST_F(WebRtcSdpTest, TestDeserializeIgnoresMalformedRidLines) {
4197 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4198 sdp += "a=rid:1 send pt=\r\n"; // Should ignore this line.
4199 sdp += "a=rid:2 receive\r\n"; // Should ignore this line.
4200 sdp += "a=rid:3 max-width=720;pt=120\r\n"; // Should ignore this line.
4201 sdp += "a=rid:4\r\n"; // Should ignore this line.
4202 sdp += "a=rid:5 send\r\n";
4203 sdp += "a=simulcast:send 1,2,3;4,5\r\n";
4204 JsepSessionDescription output(kDummyType);
4205 SdpParseError error;
4206 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4207 const cricket::ContentInfos& contents = output.description()->contents();
4208 const cricket::MediaContentDescription* media =
4209 contents.back().media_description();
4210 EXPECT_TRUE(media->HasSimulcast());
4211 const SimulcastDescription& simulcast = media->simulcast_description();
4212 EXPECT_TRUE(simulcast.receive_layers().empty());
4213 EXPECT_EQ(1ul, simulcast.send_layers().size());
4214 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4215
4216 EXPECT_FALSE(media->streams().empty());
4217 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4218 CompareRidDescriptionIds(rids, {"5"});
4219 ASSERT_FALSE(media->has_receive_stream());
4220}
4221
4222// Removes RIDs that specify a different format than the m= section.
4223TEST_F(WebRtcSdpTest, TestDeserializeRemovesRidsWithInvalidCodec) {
4224 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4225 sdp += "a=rid:1 send pt=121,120\r\n"; // Should remove 121 and keep RID.
4226 sdp += "a=rid:2 send pt=121\r\n"; // Should remove RID altogether.
4227 sdp += "a=simulcast:send 1;2\r\n";
4228 JsepSessionDescription output(kDummyType);
4229 SdpParseError error;
4230 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4231 const cricket::ContentInfos& contents = output.description()->contents();
4232 const cricket::MediaContentDescription* media =
4233 contents.back().media_description();
4234 EXPECT_TRUE(media->HasSimulcast());
4235 const SimulcastDescription& simulcast = media->simulcast_description();
4236 EXPECT_TRUE(simulcast.receive_layers().empty());
4237 EXPECT_EQ(1ul, simulcast.send_layers().size());
4238 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4239 EXPECT_EQ("1", simulcast.send_layers()[0][0].rid);
4240 EXPECT_EQ(1ul, media->streams().size());
4241 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4242 EXPECT_EQ(1ul, rids.size());
4243 EXPECT_EQ("1", rids[0].rid);
4244 EXPECT_EQ(1ul, rids[0].payload_types.size());
4245 EXPECT_EQ(120, rids[0].payload_types[0]);
4246
4247 ASSERT_FALSE(media->has_receive_stream());
4248}
4249
4250// Ignores duplicate rid lines
4251TEST_F(WebRtcSdpTest, TestDeserializeIgnoresDuplicateRidLines) {
4252 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4253 sdp += "a=rid:1 send\r\n";
4254 sdp += "a=rid:2 send\r\n";
4255 sdp += "a=rid:2 send\r\n";
4256 sdp += "a=rid:3 send\r\n";
4257 sdp += "a=rid:4 recv\r\n";
4258 sdp += "a=simulcast:send 1,2;3 recv 4\r\n";
4259 JsepSessionDescription output(kDummyType);
4260 SdpParseError error;
4261 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4262 const cricket::ContentInfos& contents = output.description()->contents();
4263 const cricket::MediaContentDescription* media =
4264 contents.back().media_description();
4265 EXPECT_TRUE(media->HasSimulcast());
4266 const SimulcastDescription& simulcast = media->simulcast_description();
4267 EXPECT_EQ(2ul, simulcast.send_layers().size());
4268 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4269 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4270 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4271
4272 EXPECT_FALSE(media->streams().empty());
4273 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4274 CompareRidDescriptionIds(rids, {"1", "3"});
4275 ASSERT_TRUE(media->has_receive_stream());
4276 CompareRidDescriptionIds(media->receive_stream().rids(), {"4"});
Amit Hilbucha2012042018-12-03 11:35:05 -08004277}
4278
4279// Simulcast serialization integration test.
4280// This test will serialize and deserialize the description and compare.
4281// More detailed tests for parsing simulcast can be found in
4282// unit tests for SdpSerializer.
4283TEST_F(WebRtcSdpTest, SerializeSimulcast_ComplexSerialization) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004284 MakeUnifiedPlanDescription(/* use_ssrcs = */ false);
Amit Hilbucha2012042018-12-03 11:35:05 -08004285 auto description = jdesc_.description();
4286 auto media = description->GetContentDescriptionByName(kVideoContentName3);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004287 ASSERT_EQ(media->streams().size(), 1ul);
4288 StreamParams& send_stream = media->mutable_streams()[0];
4289 std::vector<RidDescription> send_rids;
4290 send_rids.push_back(RidDescription("1", RidDirection::kSend));
4291 send_rids.push_back(RidDescription("2", RidDirection::kSend));
4292 send_rids.push_back(RidDescription("3", RidDirection::kSend));
4293 send_rids.push_back(RidDescription("4", RidDirection::kSend));
4294 send_stream.set_rids(send_rids);
4295 StreamParams recv_stream;
4296 std::vector<RidDescription> recv_rids;
4297 recv_rids.push_back(RidDescription("6", RidDirection::kReceive));
4298 recv_rids.push_back(RidDescription("7", RidDirection::kReceive));
4299 recv_rids.push_back(RidDescription("8", RidDirection::kReceive));
4300 recv_rids.push_back(RidDescription("9", RidDirection::kReceive));
4301 recv_rids.push_back(RidDescription("10", RidDirection::kReceive));
4302 recv_rids.push_back(RidDescription("11", RidDirection::kReceive));
4303 recv_stream.set_rids(recv_rids);
4304 media->set_receive_stream(recv_stream);
4305
Amit Hilbucha2012042018-12-03 11:35:05 -08004306 SimulcastDescription& simulcast = media->simulcast_description();
4307 simulcast.send_layers().AddLayerWithAlternatives(
4308 {SimulcastLayer("2", false), SimulcastLayer("1", true)});
4309 simulcast.send_layers().AddLayerWithAlternatives(
4310 {SimulcastLayer("4", false), SimulcastLayer("3", false)});
4311
4312 simulcast.receive_layers().AddLayerWithAlternatives(
4313 {SimulcastLayer("6", false), SimulcastLayer("7", false)});
4314 simulcast.receive_layers().AddLayer(SimulcastLayer("8", true));
4315 simulcast.receive_layers().AddLayerWithAlternatives(
4316 {SimulcastLayer("9", false), SimulcastLayer("10", true),
4317 SimulcastLayer("11", false)});
4318
4319 TestSerialize(jdesc_);
4320}