blob: 20022302335a8ae77d1270fc7bb690dd887acbf9 [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;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063using cricket::StreamParams;
64using cricket::STUN_PORT_TYPE;
65using cricket::TransportDescription;
66using cricket::TransportInfo;
67using cricket::VideoCodec;
68using cricket::VideoContentDescription;
69using webrtc::IceCandidateCollection;
70using webrtc::IceCandidateInterface;
71using webrtc::JsepIceCandidate;
72using webrtc::JsepSessionDescription;
isheriff6f8d6862016-05-26 11:24:55 -070073using webrtc::RtpExtension;
Steve Anton4e70a722017-11-28 14:57:10 -080074using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075using webrtc::SdpParseError;
Steve Antona3a92c22017-12-07 10:27:41 -080076using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077using webrtc::SessionDescriptionInterface;
78
79typedef std::vector<AudioCodec> AudioCodecs;
80typedef std::vector<Candidate> Candidates;
81
Peter Boström0c4e06b2015-10-07 12:23:21 +020082static const uint32_t kDefaultSctpPort = 5000;
zstein4b2e0822017-02-17 19:48:38 -080083static const char kDefaultSctpPortStr[] = "5000";
84static const uint16_t kUnusualSctpPort = 9556;
85static const char kUnusualSctpPortStr[] = "9556";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000086static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020087static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 15:17:14 -080088static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000089static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 15:17:14 -080090static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020092static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000093static const char kCandidateFoundation1[] = "a0+B/1";
94static const char kCandidateFoundation2[] = "a0+B/2";
95static const char kCandidateFoundation3[] = "a0+B/3";
96static const char kCandidateFoundation4[] = "a0+B/4";
97static const char kAttributeCryptoVoice[] =
98 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
99 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
100 "dummy_session_params\r\n";
101static const char kAttributeCryptoVideo[] =
102 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
103 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
Yves Gerey665174f2018-06-19 15:03:05 +0200104static const char kFingerprint[] =
105 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000106 "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 +0200107static const char kExtmapAllowMixed[] = "a=extmap-allow-mixed\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000108static const int kExtmapId = 1;
109static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
110static const char kExtmap[] =
111 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
112static const char kExtmapWithDirectionAndAttribute[] =
113 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
jbauch5869f502017-06-29 12:31:36 -0700114static const char kExtmapWithDirectionAndAttributeEncrypted[] =
115 "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt "
116 "http://example.com/082005/ext.htm#ttime a1 a2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000117
Peter Boström0c4e06b2015-10-07 12:23:21 +0200118static const uint8_t kIdentityDigest[] = {
119 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
120 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121
lally@webrtc.org34807282015-02-24 20:19:39 +0000122static const char kDtlsSctp[] = "DTLS/SCTP";
123static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
124static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +0000125
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000126struct CodecParams {
127 int max_ptime;
128 int ptime;
129 int min_ptime;
130 int sprop_stereo;
131 int stereo;
132 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000133 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000134};
135
deadbeef9d3584c2016-02-16 17:54:10 -0800136// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
137// instead of "a=crypto", and have an explicit test for adding "a=crypto".
138// Currently it's the other way around.
139
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000140// Reference sdp string
141static const char kSdpFullString[] =
142 "v=0\r\n"
143 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
144 "s=-\r\n"
145 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800146 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000147 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
148 "c=IN IP4 74.125.127.126\r\n"
149 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
150 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
151 "generation 2\r\n"
152 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
153 "generation 2\r\n"
154 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
155 "generation 2\r\n"
156 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
157 "generation 2\r\n"
158 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
159 "raddr 192.168.1.5 rport 2346 "
160 "generation 2\r\n"
161 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
162 "raddr 192.168.1.5 rport 2348 "
163 "generation 2\r\n"
164 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
165 "a=mid:audio_content_name\r\n"
166 "a=sendrecv\r\n"
167 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800168 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000169 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
170 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
171 "dummy_session_params\r\n"
172 "a=rtpmap:111 opus/48000/2\r\n"
173 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000174 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000175 "a=ssrc:1 cname:stream_1_cname\r\n"
176 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
177 "a=ssrc:1 mslabel:local_stream_1\r\n"
178 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000179 "m=video 3457 RTP/SAVPF 120\r\n"
180 "c=IN IP4 74.125.224.39\r\n"
181 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
182 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
183 "generation 2\r\n"
184 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
185 "generation 2\r\n"
186 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
187 "generation 2\r\n"
188 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
189 "generation 2\r\n"
190 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
191 "generation 2\r\n"
192 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
193 "generation 2\r\n"
194 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
195 "a=mid:video_content_name\r\n"
196 "a=sendrecv\r\n"
197 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
198 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
199 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800200 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000201 "a=ssrc:2 cname:stream_1_cname\r\n"
202 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
203 "a=ssrc:2 mslabel:local_stream_1\r\n"
204 "a=ssrc:2 label:video_track_id_1\r\n"
205 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800206 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000207 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800208 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000209
210// SDP reference string without the candidates.
211static const char kSdpString[] =
212 "v=0\r\n"
213 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
214 "s=-\r\n"
215 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800216 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000217 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000218 "c=IN IP4 0.0.0.0\r\n"
219 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000220 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
221 "a=mid:audio_content_name\r\n"
222 "a=sendrecv\r\n"
223 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800224 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000225 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
226 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
227 "dummy_session_params\r\n"
228 "a=rtpmap:111 opus/48000/2\r\n"
229 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000230 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000231 "a=ssrc:1 cname:stream_1_cname\r\n"
232 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
233 "a=ssrc:1 mslabel:local_stream_1\r\n"
234 "a=ssrc:1 label:audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000235 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000236 "c=IN IP4 0.0.0.0\r\n"
237 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000238 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
239 "a=mid:video_content_name\r\n"
240 "a=sendrecv\r\n"
241 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
242 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
243 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800244 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000245 "a=ssrc:2 cname:stream_1_cname\r\n"
246 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
247 "a=ssrc:2 mslabel:local_stream_1\r\n"
248 "a=ssrc:2 label:video_track_id_1\r\n"
249 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800250 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000251 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800252 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000253
254static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000255 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000256 "c=IN IP4 0.0.0.0\r\n"
257 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000258 "a=ice-ufrag:ufrag_data\r\n"
259 "a=ice-pwd:pwd_data\r\n"
260 "a=mid:data_content_name\r\n"
261 "a=sendrecv\r\n"
262 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
263 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
264 "a=rtpmap:101 google-data/90000\r\n"
265 "a=ssrc:10 cname:data_channel_cname\r\n"
266 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
267 "a=ssrc:10 mslabel:data_channel\r\n"
268 "a=ssrc:10 label:data_channeld0\r\n";
269
270static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000271 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000272 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000273 "a=ice-ufrag:ufrag_data\r\n"
274 "a=ice-pwd:pwd_data\r\n"
275 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000276 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000277
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000278// draft-ietf-mmusic-sctp-sdp-12
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000279static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000280 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
281 "a=max-message-size=100000\r\n"
282 "a=sctp-port 5000\r\n"
283 "c=IN IP4 0.0.0.0\r\n"
284 "a=ice-ufrag:ufrag_data\r\n"
285 "a=ice-pwd:pwd_data\r\n"
286 "a=mid:data_content_name\r\n";
287
lally69f57602015-10-08 10:15:04 -0700288static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
289 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
290 "a=max-message-size=100000\r\n"
291 "a=sctp-port:5000\r\n"
292 "c=IN IP4 0.0.0.0\r\n"
293 "a=ice-ufrag:ufrag_data\r\n"
294 "a=ice-pwd:pwd_data\r\n"
295 "a=mid:data_content_name\r\n";
296
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000297static const char kSdpSctpDataChannelWithCandidatesString[] =
298 "m=application 2345 DTLS/SCTP 5000\r\n"
299 "c=IN IP4 74.125.127.126\r\n"
300 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
301 "generation 2\r\n"
302 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
303 "generation 2\r\n"
304 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
305 "raddr 192.168.1.5 rport 2346 "
306 "generation 2\r\n"
307 "a=ice-ufrag:ufrag_data\r\n"
308 "a=ice-pwd:pwd_data\r\n"
309 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000310 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000312static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000313 "v=0\r\n"
314 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
315 "s=-\r\n"
316 "t=0 0\r\n"
317 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000318 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000319 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000320 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000321 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000322 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000323 "a=x-google-flag:conference\r\n";
324
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000325static const char kSdpSessionString[] =
326 "v=0\r\n"
327 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
328 "s=-\r\n"
329 "t=0 0\r\n"
330 "a=msid-semantic: WMS local_stream\r\n";
331
332static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000333 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000334 "c=IN IP4 0.0.0.0\r\n"
335 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000336 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
337 "a=mid:audio_content_name\r\n"
338 "a=sendrecv\r\n"
339 "a=rtpmap:111 opus/48000/2\r\n"
340 "a=ssrc:1 cname:stream_1_cname\r\n"
341 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
342 "a=ssrc:1 mslabel:local_stream\r\n"
343 "a=ssrc:1 label:audio_track_id_1\r\n";
344
345static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000346 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000347 "c=IN IP4 0.0.0.0\r\n"
348 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000349 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
350 "a=mid:video_content_name\r\n"
351 "a=sendrecv\r\n"
352 "a=rtpmap:120 VP8/90000\r\n"
353 "a=ssrc:2 cname:stream_1_cname\r\n"
354 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
355 "a=ssrc:2 mslabel:local_stream\r\n"
356 "a=ssrc:2 label:video_track_id_1\r\n";
357
deadbeef25ed4352016-12-12 18:37:36 -0800358// Reference sdp string using bundle-only.
359static const char kBundleOnlySdpFullString[] =
360 "v=0\r\n"
361 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
362 "s=-\r\n"
363 "t=0 0\r\n"
364 "a=group:BUNDLE audio_content_name video_content_name\r\n"
365 "a=msid-semantic: WMS local_stream_1\r\n"
366 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
367 "c=IN IP4 74.125.127.126\r\n"
368 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
369 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
370 "generation 2\r\n"
371 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
372 "generation 2\r\n"
373 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
374 "generation 2\r\n"
375 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
376 "generation 2\r\n"
377 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
378 "raddr 192.168.1.5 rport 2346 "
379 "generation 2\r\n"
380 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
381 "raddr 192.168.1.5 rport 2348 "
382 "generation 2\r\n"
383 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
384 "a=mid:audio_content_name\r\n"
385 "a=sendrecv\r\n"
386 "a=rtcp-mux\r\n"
387 "a=rtcp-rsize\r\n"
388 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
389 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
390 "dummy_session_params\r\n"
391 "a=rtpmap:111 opus/48000/2\r\n"
392 "a=rtpmap:103 ISAC/16000\r\n"
393 "a=rtpmap:104 ISAC/32000\r\n"
394 "a=ssrc:1 cname:stream_1_cname\r\n"
395 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
396 "a=ssrc:1 mslabel:local_stream_1\r\n"
397 "a=ssrc:1 label:audio_track_id_1\r\n"
398 "m=video 0 RTP/SAVPF 120\r\n"
399 "c=IN IP4 0.0.0.0\r\n"
400 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
401 "a=bundle-only\r\n"
402 "a=mid:video_content_name\r\n"
403 "a=sendrecv\r\n"
404 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
405 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
406 "a=rtpmap:120 VP8/90000\r\n"
407 "a=ssrc-group:FEC 2 3\r\n"
408 "a=ssrc:2 cname:stream_1_cname\r\n"
409 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
410 "a=ssrc:2 mslabel:local_stream_1\r\n"
411 "a=ssrc:2 label:video_track_id_1\r\n"
412 "a=ssrc:3 cname:stream_1_cname\r\n"
413 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
414 "a=ssrc:3 mslabel:local_stream_1\r\n"
415 "a=ssrc:3 label:video_track_id_1\r\n";
416
deadbeef9d3584c2016-02-16 17:54:10 -0800417// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
418// tracks.
419static const char kPlanBSdpFullString[] =
420 "v=0\r\n"
421 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
422 "s=-\r\n"
423 "t=0 0\r\n"
424 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
425 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
426 "c=IN IP4 74.125.127.126\r\n"
427 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
428 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
429 "generation 2\r\n"
430 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
431 "generation 2\r\n"
432 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
433 "generation 2\r\n"
434 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
435 "generation 2\r\n"
436 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
437 "raddr 192.168.1.5 rport 2346 "
438 "generation 2\r\n"
439 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
440 "raddr 192.168.1.5 rport 2348 "
441 "generation 2\r\n"
442 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
443 "a=mid:audio_content_name\r\n"
444 "a=sendrecv\r\n"
445 "a=rtcp-mux\r\n"
446 "a=rtcp-rsize\r\n"
447 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
448 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
449 "dummy_session_params\r\n"
450 "a=rtpmap:111 opus/48000/2\r\n"
451 "a=rtpmap:103 ISAC/16000\r\n"
452 "a=rtpmap:104 ISAC/32000\r\n"
453 "a=ssrc:1 cname:stream_1_cname\r\n"
454 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
455 "a=ssrc:1 mslabel:local_stream_1\r\n"
456 "a=ssrc:1 label:audio_track_id_1\r\n"
457 "a=ssrc:4 cname:stream_2_cname\r\n"
458 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
459 "a=ssrc:4 mslabel:local_stream_2\r\n"
460 "a=ssrc:4 label:audio_track_id_2\r\n"
461 "m=video 3457 RTP/SAVPF 120\r\n"
462 "c=IN IP4 74.125.224.39\r\n"
463 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
464 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
465 "generation 2\r\n"
466 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
467 "generation 2\r\n"
468 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
469 "generation 2\r\n"
470 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
471 "generation 2\r\n"
472 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
473 "generation 2\r\n"
474 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
475 "generation 2\r\n"
476 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
477 "a=mid:video_content_name\r\n"
478 "a=sendrecv\r\n"
479 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
480 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
481 "a=rtpmap:120 VP8/90000\r\n"
482 "a=ssrc-group:FEC 2 3\r\n"
483 "a=ssrc:2 cname:stream_1_cname\r\n"
484 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
485 "a=ssrc:2 mslabel:local_stream_1\r\n"
486 "a=ssrc:2 label:video_track_id_1\r\n"
487 "a=ssrc:3 cname:stream_1_cname\r\n"
488 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
489 "a=ssrc:3 mslabel:local_stream_1\r\n"
490 "a=ssrc:3 label:video_track_id_1\r\n"
491 "a=ssrc:5 cname:stream_2_cname\r\n"
492 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
493 "a=ssrc:5 mslabel:local_stream_2\r\n"
494 "a=ssrc:5 label:video_track_id_2\r\n"
495 "a=ssrc:6 cname:stream_2_cname\r\n"
496 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
497 "a=ssrc:6 mslabel:local_stream_2\r\n"
498 "a=ssrc:6 label:video_track_id_3\r\n";
499
500// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
501// tracks.
502static const char kUnifiedPlanSdpFullString[] =
503 "v=0\r\n"
504 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
505 "s=-\r\n"
506 "t=0 0\r\n"
507 "a=msid-semantic: WMS local_stream_1\r\n"
508 // Audio track 1, stream 1 (with candidates).
509 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
510 "c=IN IP4 74.125.127.126\r\n"
511 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
512 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
513 "generation 2\r\n"
514 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
515 "generation 2\r\n"
516 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
517 "generation 2\r\n"
518 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
519 "generation 2\r\n"
520 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
521 "raddr 192.168.1.5 rport 2346 "
522 "generation 2\r\n"
523 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
524 "raddr 192.168.1.5 rport 2348 "
525 "generation 2\r\n"
526 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
527 "a=mid:audio_content_name\r\n"
528 "a=msid:local_stream_1 audio_track_id_1\r\n"
529 "a=sendrecv\r\n"
530 "a=rtcp-mux\r\n"
531 "a=rtcp-rsize\r\n"
532 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
533 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
534 "dummy_session_params\r\n"
535 "a=rtpmap:111 opus/48000/2\r\n"
536 "a=rtpmap:103 ISAC/16000\r\n"
537 "a=rtpmap:104 ISAC/32000\r\n"
538 "a=ssrc:1 cname:stream_1_cname\r\n"
539 // Video track 1, stream 1 (with candidates).
540 "m=video 3457 RTP/SAVPF 120\r\n"
541 "c=IN IP4 74.125.224.39\r\n"
542 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
543 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
544 "generation 2\r\n"
545 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
546 "generation 2\r\n"
547 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
548 "generation 2\r\n"
549 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
550 "generation 2\r\n"
551 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
552 "generation 2\r\n"
553 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
554 "generation 2\r\n"
555 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
556 "a=mid:video_content_name\r\n"
557 "a=msid:local_stream_1 video_track_id_1\r\n"
558 "a=sendrecv\r\n"
559 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
560 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
561 "a=rtpmap:120 VP8/90000\r\n"
562 "a=ssrc-group:FEC 2 3\r\n"
563 "a=ssrc:2 cname:stream_1_cname\r\n"
564 "a=ssrc:3 cname:stream_1_cname\r\n"
565 // Audio track 2, stream 2.
566 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
567 "c=IN IP4 0.0.0.0\r\n"
568 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
569 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
570 "a=mid:audio_content_name_2\r\n"
571 "a=msid:local_stream_2 audio_track_id_2\r\n"
572 "a=sendrecv\r\n"
573 "a=rtcp-mux\r\n"
574 "a=rtcp-rsize\r\n"
575 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
576 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
577 "dummy_session_params\r\n"
578 "a=rtpmap:111 opus/48000/2\r\n"
579 "a=rtpmap:103 ISAC/16000\r\n"
580 "a=rtpmap:104 ISAC/32000\r\n"
581 "a=ssrc:4 cname:stream_2_cname\r\n"
582 // Video track 2, stream 2.
583 "m=video 9 RTP/SAVPF 120\r\n"
584 "c=IN IP4 0.0.0.0\r\n"
585 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
586 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
587 "a=mid:video_content_name_2\r\n"
588 "a=msid:local_stream_2 video_track_id_2\r\n"
589 "a=sendrecv\r\n"
590 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
591 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
592 "a=rtpmap:120 VP8/90000\r\n"
593 "a=ssrc:5 cname:stream_2_cname\r\n"
594 // Video track 3, stream 2.
595 "m=video 9 RTP/SAVPF 120\r\n"
596 "c=IN IP4 0.0.0.0\r\n"
597 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
598 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
599 "a=mid:video_content_name_3\r\n"
600 "a=msid:local_stream_2 video_track_id_3\r\n"
601 "a=sendrecv\r\n"
602 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
603 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
604 "a=rtpmap:120 VP8/90000\r\n"
605 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000606
Seth Hampson5b4f0752018-04-02 16:31:36 -0700607// Unified Plan SDP reference string:
608// - audio track 1 has 1 a=msid lines
609// - audio track 2 has 2 a=msid lines
610// - audio track 3 has 1 a=msid line with the special "-" marker signifying that
611// there are 0 media stream ids.
612// This Unified Plan SDP represents a SDP that signals the msid using both
613// a=msid and a=ssrc msid semantics.
614static const char kUnifiedPlanSdpFullStringWithSpecialMsid[] =
615 "v=0\r\n"
616 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
617 "s=-\r\n"
618 "t=0 0\r\n"
619 "a=msid-semantic: WMS local_stream_1\r\n"
620 // Audio track 1, with 1 stream id.
621 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
622 "c=IN IP4 74.125.127.126\r\n"
623 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
624 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
625 "generation 2\r\n"
626 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
627 "generation 2\r\n"
628 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
629 "generation 2\r\n"
630 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
631 "generation 2\r\n"
632 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
633 "raddr 192.168.1.5 rport 2346 "
634 "generation 2\r\n"
635 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
636 "raddr 192.168.1.5 rport 2348 "
637 "generation 2\r\n"
638 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
639 "a=mid:audio_content_name\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700640 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700641 "a=msid:local_stream_1 audio_track_id_1\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700642 "a=rtcp-mux\r\n"
643 "a=rtcp-rsize\r\n"
644 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
645 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
646 "dummy_session_params\r\n"
647 "a=rtpmap:111 opus/48000/2\r\n"
648 "a=rtpmap:103 ISAC/16000\r\n"
649 "a=rtpmap:104 ISAC/32000\r\n"
650 "a=ssrc:1 cname:stream_1_cname\r\n"
651 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
652 "a=ssrc:1 mslabel:local_stream_1\r\n"
653 "a=ssrc:1 label:audio_track_id_1\r\n"
654 // Audio track 2, with two stream ids.
655 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
656 "c=IN IP4 0.0.0.0\r\n"
657 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
658 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
659 "a=mid:audio_content_name_2\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700660 "a=sendrecv\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700661 "a=msid:local_stream_1 audio_track_id_2\r\n"
662 "a=msid:local_stream_2 audio_track_id_2\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700663 "a=rtcp-mux\r\n"
664 "a=rtcp-rsize\r\n"
665 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
666 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
667 "dummy_session_params\r\n"
668 "a=rtpmap:111 opus/48000/2\r\n"
669 "a=rtpmap:103 ISAC/16000\r\n"
670 "a=rtpmap:104 ISAC/32000\r\n"
671 "a=ssrc:4 cname:stream_1_cname\r\n"
672 // The support for Plan B msid signaling only includes the
673 // first media stream id "local_stream_1."
674 "a=ssrc:4 msid:local_stream_1 audio_track_id_2\r\n"
675 "a=ssrc:4 mslabel:local_stream_1\r\n"
676 "a=ssrc:4 label:audio_track_id_2\r\n"
677 // Audio track 3, with no stream ids.
678 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
679 "c=IN IP4 0.0.0.0\r\n"
680 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
681 "a=ice-ufrag:ufrag_voice_3\r\na=ice-pwd:pwd_voice_3\r\n"
682 "a=mid:audio_content_name_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700683 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700684 "a=msid:- audio_track_id_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700685 "a=rtcp-mux\r\n"
686 "a=rtcp-rsize\r\n"
687 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
688 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
689 "dummy_session_params\r\n"
690 "a=rtpmap:111 opus/48000/2\r\n"
691 "a=rtpmap:103 ISAC/16000\r\n"
692 "a=rtpmap:104 ISAC/32000\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700693 "a=ssrc:7 cname:stream_2_cname\r\n"
694 "a=ssrc:7 msid:- audio_track_id_3\r\n"
695 "a=ssrc:7 mslabel:-\r\n"
696 "a=ssrc:7 label:audio_track_id_3\r\n";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700697
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000698// One candidate reference string as per W3c spec.
699// candidate:<blah> not a=candidate:<blah>CRLF
700static const char kRawCandidate[] =
701 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
702// One candidate reference string.
703static const char kSdpOneCandidate[] =
704 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
705 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000706
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000707static const char kSdpTcpActiveCandidate[] =
708 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
709 "tcptype active generation 2";
710static const char kSdpTcpPassiveCandidate[] =
711 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
712 "tcptype passive generation 2";
713static const char kSdpTcpSOCandidate[] =
714 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
715 "tcptype so generation 2";
716static const char kSdpTcpInvalidCandidate[] =
717 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
718 "tcptype invalid generation 2";
719
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000720// One candidate reference string with IPV6 address.
721static const char kRawIPV6Candidate[] =
722 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 12:04:36 -0700723 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000724
725// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800726static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000727 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800728 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000729
Zach Steinb336c272018-08-09 01:16:13 -0700730static const char kRawHostnameCandidate[] =
731 "candidate:a0+B/1 1 udp 2130706432 a.test 1234 typ host generation 2";
732
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000733// Session id and version
734static const char kSessionId[] = "18446744069414584320";
735static const char kSessionVersion[] = "18446462598732840960";
736
deadbeef9d3584c2016-02-16 17:54:10 -0800737// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000738static const char kIceOption1[] = "iceoption1";
739static const char kIceOption2[] = "iceoption2";
740static const char kIceOption3[] = "iceoption3";
741
deadbeef9d3584c2016-02-16 17:54:10 -0800742// ICE ufrags/passwords.
743static const char kUfragVoice[] = "ufrag_voice";
744static const char kPwdVoice[] = "pwd_voice";
745static const char kUfragVideo[] = "ufrag_video";
746static const char kPwdVideo[] = "pwd_video";
747static const char kUfragData[] = "ufrag_data";
748static const char kPwdData[] = "pwd_data";
749
750// Extra ufrags/passwords for extra unified plan m= sections.
751static const char kUfragVoice2[] = "ufrag_voice_2";
752static const char kPwdVoice2[] = "pwd_voice_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700753static const char kUfragVoice3[] = "ufrag_voice_3";
754static const char kPwdVoice3[] = "pwd_voice_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800755static const char kUfragVideo2[] = "ufrag_video_2";
756static const char kPwdVideo2[] = "pwd_video_2";
757static const char kUfragVideo3[] = "ufrag_video_3";
758static const char kPwdVideo3[] = "pwd_video_3";
759
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000760// Content name
761static const char kAudioContentName[] = "audio_content_name";
762static const char kVideoContentName[] = "video_content_name";
763static const char kDataContentName[] = "data_content_name";
764
deadbeef9d3584c2016-02-16 17:54:10 -0800765// Extra content names for extra unified plan m= sections.
766static const char kAudioContentName2[] = "audio_content_name_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700767static const char kAudioContentName3[] = "audio_content_name_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800768static const char kVideoContentName2[] = "video_content_name_2";
769static const char kVideoContentName3[] = "video_content_name_3";
770
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000771// MediaStream 1
Seth Hampson845e8782018-03-02 11:34:10 -0800772static const char kStreamId1[] = "local_stream_1";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000773static const char kStream1Cname[] = "stream_1_cname";
774static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200775static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000776static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800777static const uint32_t kVideoTrack1Ssrc1 = 2;
778static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000779
780// MediaStream 2
Seth Hampson845e8782018-03-02 11:34:10 -0800781static const char kStreamId2[] = "local_stream_2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000782static const char kStream2Cname[] = "stream_2_cname";
783static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200784static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800785static const char kVideoTrackId2[] = "video_track_id_2";
786static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000787static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800788static const uint32_t kVideoTrack3Ssrc = 6;
Seth Hampson5b4f0752018-04-02 16:31:36 -0700789static const char kAudioTrackId3[] = "audio_track_id_3";
790static const uint32_t kAudioTrack3Ssrc = 7;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000791
792// DataChannel
793static const char kDataChannelLabel[] = "data_channel";
794static const char kDataChannelMsid[] = "data_channeld0";
795static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200796static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000797
798// Candidate
799static const char kDummyMid[] = "dummy_mid";
800static const int kDummyIndex = 123;
801
802// Misc
Steve Antona3a92c22017-12-07 10:27:41 -0800803static SdpType kDummyType = SdpType::kOffer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804
805// Helper functions
806
807static bool SdpDeserialize(const std::string& message,
808 JsepSessionDescription* jdesc) {
809 return webrtc::SdpDeserialize(message, jdesc, NULL);
810}
811
812static bool SdpDeserializeCandidate(const std::string& message,
813 JsepIceCandidate* candidate) {
814 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
815}
816
817// Add some extra |newlines| to the |message| after |line|.
818static void InjectAfter(const std::string& line,
819 const std::string& newlines,
820 std::string* message) {
821 const std::string tmp = line + newlines;
Yves Gerey665174f2018-06-19 15:03:05 +0200822 rtc::replace_substrs(line.c_str(), line.length(), tmp.c_str(), tmp.length(),
823 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000824}
825
826static void Replace(const std::string& line,
827 const std::string& newlines,
828 std::string* message) {
Yves Gerey665174f2018-06-19 15:03:05 +0200829 rtc::replace_substrs(line.c_str(), line.length(), newlines.c_str(),
830 newlines.length(), message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000831}
832
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000833// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
834// message.
835static void ExpectParseFailure(const std::string& bad_sdp,
836 const std::string& bad_part) {
Steve Antona3a92c22017-12-07 10:27:41 -0800837 JsepSessionDescription desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000838 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000839 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000841 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
842}
843
844// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
845static void ExpectParseFailure(const char* good_part, const char* bad_part) {
846 std::string bad_sdp = kSdpFullString;
847 Replace(good_part, bad_part, &bad_sdp);
848 ExpectParseFailure(bad_sdp, bad_part);
849}
850
851// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
852static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
853 const std::string& newlines,
854 const std::string& bad_part) {
855 std::string bad_sdp = kSdpFullString;
856 InjectAfter(injectpoint, newlines, &bad_sdp);
857 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000858}
859
Steve Anton4e70a722017-11-28 14:57:10 -0800860static void ReplaceDirection(RtpTransceiverDirection direction,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000861 std::string* message) {
862 std::string new_direction;
863 switch (direction) {
Steve Anton4e70a722017-11-28 14:57:10 -0800864 case RtpTransceiverDirection::kInactive:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000865 new_direction = "a=inactive";
866 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800867 case RtpTransceiverDirection::kSendOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000868 new_direction = "a=sendonly";
869 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800870 case RtpTransceiverDirection::kRecvOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000871 new_direction = "a=recvonly";
872 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800873 case RtpTransceiverDirection::kSendRecv:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000874 default:
875 new_direction = "a=sendrecv";
876 break;
877 }
878 Replace("a=sendrecv", new_direction, message);
879}
880
Yves Gerey665174f2018-06-19 15:03:05 +0200881static void ReplaceRejected(bool audio_rejected,
882 bool video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883 std::string* message) {
884 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800885 Replace("m=audio 9", "m=audio 0", message);
886 Replace(kAttributeIceUfragVoice, "", message);
887 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000888 }
889 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800890 Replace("m=video 9", "m=video 0", message);
891 Replace(kAttributeIceUfragVideo, "", message);
892 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000893 }
894}
895
896// WebRtcSdpTest
897
898class WebRtcSdpTest : public testing::Test {
899 public:
Steve Antona3a92c22017-12-07 10:27:41 -0800900 WebRtcSdpTest() : jdesc_(kDummyType) {
phoglund37ebcf02016-01-08 05:04:57 -0800901#ifdef WEBRTC_ANDROID
902 webrtc::InitializeAndroidObjects();
903#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000904 // AudioContentDescription
905 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -0800906 StreamParams audio_stream;
907 audio_stream.id = kAudioTrackId1;
908 audio_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -0800909 audio_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -0800910 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
911 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 11:04:53 -0700912 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
913 audio_desc_->set_connection_address(audio_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -0800914 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915
916 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -0800917 video_desc_ = CreateVideoContentDescription();
918 StreamParams video_stream;
919 video_stream.id = kVideoTrackId1;
920 video_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -0800921 video_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -0800922 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
923 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
924 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
925 video_stream.ssrc_groups.push_back(ssrc_group);
926 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 11:04:53 -0700927 rtc::SocketAddress video_addr("74.125.224.39", 3457);
928 video_desc_->set_connection_address(video_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -0800929 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000930
931 // TransportInfo
deadbeef9d3584c2016-02-16 17:54:10 -0800932 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
933 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice))));
934 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
935 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000936
937 // v4 host
938 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000939 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000940 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000941 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
942 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000943 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000944 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000945 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
946 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000947 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000948 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000949 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
950 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000951 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000952 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000953 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
954 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000955
956 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000957 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000958 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
959 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000960 cricket::LOCAL_PORT_TYPE,
961 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000962 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000963 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
964 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000965 cricket::LOCAL_PORT_TYPE,
966 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000967 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000968 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
969 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000970 cricket::LOCAL_PORT_TYPE,
971 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000972 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000973 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
974 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000975 cricket::LOCAL_PORT_TYPE,
976 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000977
978 // stun
979 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000980 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
981 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000982 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
983 address_stun, kCandidatePriority, "", "",
984 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000985 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000986 candidate9.set_related_address(rel_address_stun);
987
988 address_stun.SetPort(port_stun++);
989 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000990 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
991 address_stun, kCandidatePriority, "", "",
992 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000993 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000994 candidate10.set_related_address(rel_address_stun);
995
996 // relay
997 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000998 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000999 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1000 address_relay, kCandidatePriority, "", "",
1001 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001002 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001003 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001004 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1005 address_relay, kCandidatePriority, "", "",
1006 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001007 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001008
1009 // voice
1010 candidates_.push_back(candidate1);
1011 candidates_.push_back(candidate2);
1012 candidates_.push_back(candidate5);
1013 candidates_.push_back(candidate6);
1014 candidates_.push_back(candidate9);
1015 candidates_.push_back(candidate10);
1016
1017 // video
1018 candidates_.push_back(candidate3);
1019 candidates_.push_back(candidate4);
1020 candidates_.push_back(candidate7);
1021 candidates_.push_back(candidate8);
1022 candidates_.push_back(candidate11);
1023 candidates_.push_back(candidate12);
1024
Yves Gerey665174f2018-06-19 15:03:05 +02001025 jcandidate_.reset(
1026 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001027
1028 // Set up JsepSessionDescription.
1029 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
1030 std::string mline_id;
1031 int mline_index = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001032 for (size_t i = 0; i < candidates_.size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001033 // In this test, the audio m line index will be 0, and the video m line
1034 // will be 1.
1035 bool is_video = (i > 5);
1036 mline_id = is_video ? "video_content_name" : "audio_content_name";
1037 mline_index = is_video ? 1 : 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001038 JsepIceCandidate jice(mline_id, mline_index, candidates_.at(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001039 jdesc_.AddCandidate(&jice);
1040 }
1041 }
1042
Seth Hampson5b4f0752018-04-02 16:31:36 -07001043 void RemoveVideoCandidates() {
deadbeef25ed4352016-12-12 18:37:36 -08001044 const IceCandidateCollection* video_candidates_collection =
1045 jdesc_.candidates(1);
1046 ASSERT_NE(nullptr, video_candidates_collection);
1047 std::vector<cricket::Candidate> video_candidates;
1048 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1049 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1050 c.set_transport_name("video_content_name");
1051 video_candidates.push_back(c);
1052 }
1053 jdesc_.RemoveCandidates(video_candidates);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001054 }
1055
1056 // Turns the existing reference description into a description using
1057 // a=bundle-only. This means no transport attributes and a 0 port value on
1058 // the m= sections not associated with the BUNDLE-tag.
1059 void MakeBundleOnlyDescription() {
1060 RemoveVideoCandidates();
deadbeef25ed4352016-12-12 18:37:36 -08001061
1062 // And the rest of the transport attributes.
1063 desc_.transport_infos()[1].description.ice_ufrag.clear();
1064 desc_.transport_infos()[1].description.ice_pwd.clear();
1065 desc_.transport_infos()[1].description.connection_role =
1066 cricket::CONNECTIONROLE_NONE;
1067
1068 // Set bundle-only flag.
1069 desc_.contents()[1].bundle_only = true;
1070
1071 // Add BUNDLE group.
1072 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1073 group.AddContentName(kAudioContentName);
1074 group.AddContentName(kVideoContentName);
1075 desc_.AddGroup(group);
1076
1077 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1078 jdesc_.session_version()));
1079 }
1080
deadbeef9d3584c2016-02-16 17:54:10 -08001081 // Turns the existing reference description into a plan B description,
1082 // with 2 audio tracks and 3 video tracks.
1083 void MakePlanBDescription() {
Steve Antonb1c1de12017-12-21 15:14:30 -08001084 audio_desc_ = audio_desc_->Copy();
1085 video_desc_ = video_desc_->Copy();
deadbeef9d3584c2016-02-16 17:54:10 -08001086
1087 StreamParams audio_track_2;
1088 audio_track_2.id = kAudioTrackId2;
1089 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001090 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001091 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1092 audio_desc_->AddStream(audio_track_2);
1093
1094 StreamParams video_track_2;
1095 video_track_2.id = kVideoTrackId2;
1096 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001097 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001098 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1099 video_desc_->AddStream(video_track_2);
1100
1101 StreamParams video_track_3;
1102 video_track_3.id = kVideoTrackId3;
1103 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001104 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001105 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1106 video_desc_->AddStream(video_track_3);
1107
1108 desc_.RemoveContentByName(kAudioContentName);
1109 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001110 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1111 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001112
1113 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1114 jdesc_.session_version()));
1115 }
1116
1117 // Turns the existing reference description into a unified plan description,
1118 // with 2 audio tracks and 3 video tracks.
1119 void MakeUnifiedPlanDescription() {
1120 // Audio track 2.
1121 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1122 StreamParams audio_track_2;
1123 audio_track_2.id = kAudioTrackId2;
1124 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001125 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001126 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1127 audio_desc_2->AddStream(audio_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001128 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
deadbeef9d3584c2016-02-16 17:54:10 -08001129 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1130 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
deadbeef9d3584c2016-02-16 17:54:10 -08001131 // Video track 2, in stream 2.
1132 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1133 StreamParams video_track_2;
1134 video_track_2.id = kVideoTrackId2;
1135 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001136 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001137 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1138 video_desc_2->AddStream(video_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001139 desc_.AddContent(kVideoContentName2, MediaProtocolType::kRtp, video_desc_2);
deadbeef9d3584c2016-02-16 17:54:10 -08001140 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1141 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2))));
1142
1143 // Video track 3, in stream 2.
1144 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1145 StreamParams video_track_3;
1146 video_track_3.id = kVideoTrackId3;
1147 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001148 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001149 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1150 video_desc_3->AddStream(video_track_3);
Steve Anton5adfafd2017-12-20 16:34:00 -08001151 desc_.AddContent(kVideoContentName3, MediaProtocolType::kRtp, video_desc_3);
deadbeef9d3584c2016-02-16 17:54:10 -08001152 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1153 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3))));
Steve Antone831b8c2018-02-01 12:22:16 -08001154 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
deadbeef9d3584c2016-02-16 17:54:10 -08001155
1156 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1157 jdesc_.session_version()));
1158 }
1159
1160 // Creates an audio content description with no streams, and some default
1161 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001162 AudioContentDescription* CreateAudioContentDescription() {
1163 AudioContentDescription* audio = new AudioContentDescription();
1164 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -08001165 audio->set_rtcp_reduced_size(true);
Yves Gerey665174f2018-06-19 15:03:05 +02001166 audio->AddCrypto(CryptoParams(
1167 1, "AES_CM_128_HMAC_SHA1_32",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001168 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1169 "dummy_session_params"));
1170 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef67cf2c12016-04-13 10:07:16 -07001171 AudioCodec opus(111, "opus", 48000, 0, 2);
deadbeef9d3584c2016-02-16 17:54:10 -08001172 audio->AddCodec(opus);
ossue1405ad2017-01-23 08:55:48 -08001173 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1174 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001175 return audio;
1176 }
1177
Seth Hampson5b4f0752018-04-02 16:31:36 -07001178 // Turns the existing reference description into a unified plan description,
1179 // with 3 audio MediaContentDescriptions with special StreamParams that
1180 // contain 0 or multiple stream ids: - audio track 1 has 1 media stream id -
1181 // audio track 2 has 2 media stream ids - audio track 3 has 0 media stream ids
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001182 void MakeUnifiedPlanDescriptionMultipleStreamIds(const int msid_signaling) {
Seth Hampson5b4f0752018-04-02 16:31:36 -07001183 desc_.RemoveContentByName(kVideoContentName);
1184 desc_.RemoveTransportInfoByName(kVideoContentName);
1185 RemoveVideoCandidates();
1186
1187 // Audio track 2 has 2 media stream ids.
1188 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1189 StreamParams audio_track_2;
1190 audio_track_2.id = kAudioTrackId2;
1191 audio_track_2.cname = kStream1Cname;
1192 audio_track_2.set_stream_ids({kStreamId1, kStreamId2});
1193 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1194 audio_desc_2->AddStream(audio_track_2);
1195 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
1196 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1197 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
1198
1199 // Audio track 3 has no stream ids.
1200 AudioContentDescription* audio_desc_3 = CreateAudioContentDescription();
1201 StreamParams audio_track_3;
1202 audio_track_3.id = kAudioTrackId3;
1203 audio_track_3.cname = kStream2Cname;
1204 audio_track_3.set_stream_ids({});
1205 audio_track_3.ssrcs.push_back(kAudioTrack3Ssrc);
1206 audio_desc_3->AddStream(audio_track_3);
1207 desc_.AddContent(kAudioContentName3, MediaProtocolType::kRtp, audio_desc_3);
1208 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1209 kAudioContentName3, TransportDescription(kUfragVoice3, kPwdVoice3))));
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001210 desc_.set_msid_signaling(msid_signaling);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001211 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1212 jdesc_.session_version()));
1213 }
1214
Seth Hampson5897a6e2018-04-03 11:16:33 -07001215 // Turns the existing reference description into a unified plan description
1216 // with one audio MediaContentDescription that contains one StreamParams with
1217 // 0 ssrcs.
1218 void MakeUnifiedPlanDescriptionNoSsrcSignaling() {
1219 desc_.RemoveContentByName(kVideoContentName);
1220 desc_.RemoveContentByName(kAudioContentName);
1221 desc_.RemoveTransportInfoByName(kVideoContentName);
1222 RemoveVideoCandidates();
1223
1224 AudioContentDescription* audio_desc = CreateAudioContentDescription();
1225 StreamParams audio_track;
1226 audio_track.id = kAudioTrackId1;
1227 audio_track.set_stream_ids({kStreamId1});
1228 audio_desc->AddStream(audio_track);
1229 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc);
1230
1231 // Enable signaling a=msid lines.
1232 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
1233 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1234 jdesc_.session_version()));
1235 }
1236
deadbeef9d3584c2016-02-16 17:54:10 -08001237 // Creates a video content description with no streams, and some default
1238 // configuration.
1239 VideoContentDescription* CreateVideoContentDescription() {
1240 VideoContentDescription* video = new VideoContentDescription();
1241 video->AddCrypto(CryptoParams(
1242 1, "AES_CM_128_HMAC_SHA1_80",
1243 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1244 video->set_protocol(cricket::kMediaProtocolSavpf);
1245 video->AddCodec(
perkj26752742016-10-24 01:21:16 -07001246 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-16 17:54:10 -08001247 return video;
1248 }
1249
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001250 template <class MCD>
Yves Gerey665174f2018-06-19 15:03:05 +02001251 void CompareMediaContentDescription(const MCD* cd1, const MCD* cd2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001252 // type
1253 EXPECT_EQ(cd1->type(), cd1->type());
1254
1255 // content direction
1256 EXPECT_EQ(cd1->direction(), cd2->direction());
1257
1258 // rtcp_mux
1259 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1260
deadbeef13871492015-12-09 12:37:51 -08001261 // rtcp_reduced_size
1262 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1263
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001264 // cryptos
1265 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1266 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1267 ADD_FAILURE();
1268 return;
1269 }
Yves Gerey665174f2018-06-19 15:03:05 +02001270 for (size_t i = 0; i < cd1->cryptos().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001271 const CryptoParams c1 = cd1->cryptos().at(i);
1272 const CryptoParams c2 = cd2->cryptos().at(i);
1273 EXPECT_TRUE(c1.Matches(c2));
1274 EXPECT_EQ(c1.key_params, c2.key_params);
1275 EXPECT_EQ(c1.session_params, c2.session_params);
1276 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001277
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001278 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001279 // Use an equivalence class here, for old and new versions of the
1280 // protocol description.
Yves Gerey665174f2018-06-19 15:03:05 +02001281 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp ||
1282 cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1283 cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
lally@webrtc.org36300852015-02-24 20:19:35 +00001284 const bool cd2_is_also_dtls_sctp =
Yves Gerey665174f2018-06-19 15:03:05 +02001285 cd2->protocol() == cricket::kMediaProtocolDtlsSctp ||
1286 cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1287 cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
lally@webrtc.org36300852015-02-24 20:19:35 +00001288 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001289 } else {
1290 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1291 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001292
1293 // codecs
1294 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1295
1296 // bandwidth
1297 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1298
1299 // streams
1300 EXPECT_EQ(cd1->streams(), cd2->streams());
1301
Johannes Kron0854eb62018-10-10 22:33:20 +02001302 // extmap-allow-mixed
Johannes Kron9581bc42018-10-23 10:17:39 +02001303 EXPECT_EQ(cd1->extmap_allow_mixed_enum(), cd2->extmap_allow_mixed_enum());
Johannes Kron0854eb62018-10-10 22:33:20 +02001304
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001305 // extmap
1306 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1307 cd2->rtp_header_extensions().size());
Yves Gerey665174f2018-06-19 15:03:05 +02001308 for (size_t i = 0; i < cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 11:24:55 -07001309 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1310 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001311 EXPECT_EQ(ext1.uri, ext2.uri);
1312 EXPECT_EQ(ext1.id, ext2.id);
jbauch5869f502017-06-29 12:31:36 -07001313 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001314 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001315 }
1316
zstein4b2e0822017-02-17 19:48:38 -08001317 void CompareDataContentDescription(const DataContentDescription* dcd1,
1318 const DataContentDescription* dcd2) {
1319 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
1320 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
1321 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001322
1323 void CompareSessionDescription(const SessionDescription& desc1,
1324 const SessionDescription& desc2) {
1325 // Compare content descriptions.
1326 if (desc1.contents().size() != desc2.contents().size()) {
1327 ADD_FAILURE();
1328 return;
1329 }
Yves Gerey665174f2018-06-19 15:03:05 +02001330 for (size_t i = 0; i < desc1.contents().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001331 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1332 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-12 18:37:36 -08001333 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001334 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-12 18:37:36 -08001335 EXPECT_EQ(c1.type, c2.type);
1336 EXPECT_EQ(c1.rejected, c2.rejected);
1337 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001338
1339 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1340 if (IsAudioContent(&c1)) {
1341 const AudioContentDescription* acd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001342 c1.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001343 const AudioContentDescription* acd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001344 c2.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001345 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1346 }
1347
1348 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1349 if (IsVideoContent(&c1)) {
1350 const VideoContentDescription* vcd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001351 c1.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001352 const VideoContentDescription* vcd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001353 c2.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001354 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1355 }
1356
1357 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
1358 if (IsDataContent(&c1)) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001359 const DataContentDescription* dcd1 = c1.media_description()->as_data();
1360 const DataContentDescription* dcd2 = c2.media_description()->as_data();
zstein4b2e0822017-02-17 19:48:38 -08001361 CompareDataContentDescription(dcd1, dcd2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001362 }
1363 }
1364
1365 // group
1366 const cricket::ContentGroups groups1 = desc1.groups();
1367 const cricket::ContentGroups groups2 = desc2.groups();
1368 EXPECT_EQ(groups1.size(), groups1.size());
1369 if (groups1.size() != groups2.size()) {
1370 ADD_FAILURE();
1371 return;
1372 }
1373 for (size_t i = 0; i < groups1.size(); ++i) {
1374 const cricket::ContentGroup group1 = groups1.at(i);
1375 const cricket::ContentGroup group2 = groups2.at(i);
1376 EXPECT_EQ(group1.semantics(), group2.semantics());
1377 const cricket::ContentNames names1 = group1.content_names();
1378 const cricket::ContentNames names2 = group2.content_names();
1379 EXPECT_EQ(names1.size(), names2.size());
1380 if (names1.size() != names2.size()) {
1381 ADD_FAILURE();
1382 return;
1383 }
1384 cricket::ContentNames::const_iterator iter1 = names1.begin();
1385 cricket::ContentNames::const_iterator iter2 = names2.begin();
1386 while (iter1 != names1.end()) {
1387 EXPECT_EQ(*iter1++, *iter2++);
1388 }
1389 }
1390
1391 // transport info
1392 const cricket::TransportInfos transports1 = desc1.transport_infos();
1393 const cricket::TransportInfos transports2 = desc2.transport_infos();
1394 EXPECT_EQ(transports1.size(), transports2.size());
1395 if (transports1.size() != transports2.size()) {
1396 ADD_FAILURE();
1397 return;
1398 }
1399 for (size_t i = 0; i < transports1.size(); ++i) {
1400 const cricket::TransportInfo transport1 = transports1.at(i);
1401 const cricket::TransportInfo transport2 = transports2.at(i);
1402 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001403 EXPECT_EQ(transport1.description.ice_ufrag,
1404 transport2.description.ice_ufrag);
Yves Gerey665174f2018-06-19 15:03:05 +02001405 EXPECT_EQ(transport1.description.ice_pwd, transport2.description.ice_pwd);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07001406 EXPECT_EQ(transport1.description.ice_mode,
1407 transport2.description.ice_mode);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001408 if (transport1.description.identity_fingerprint) {
1409 EXPECT_EQ(*transport1.description.identity_fingerprint,
1410 *transport2.description.identity_fingerprint);
1411 } else {
1412 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1413 transport2.description.identity_fingerprint.get());
1414 }
1415 EXPECT_EQ(transport1.description.transport_options,
1416 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001417 }
deadbeefc80741f2015-10-22 13:14:45 -07001418
1419 // global attributes
1420 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
Johannes Kron9581bc42018-10-23 10:17:39 +02001421 EXPECT_EQ(desc1.extmap_allow_mixed(), desc2.extmap_allow_mixed());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001422 }
1423
Yves Gerey665174f2018-06-19 15:03:05 +02001424 bool CompareSessionDescription(const JsepSessionDescription& desc1,
1425 const JsepSessionDescription& desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001426 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1427 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1428 CompareSessionDescription(*desc1.description(), *desc2.description());
1429 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1430 return false;
1431 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1432 const IceCandidateCollection* cc1 = desc1.candidates(i);
1433 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-12 18:37:36 -08001434 if (cc1->count() != cc2->count()) {
1435 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001436 return false;
deadbeef25ed4352016-12-12 18:37:36 -08001437 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001438 for (size_t j = 0; j < cc1->count(); ++j) {
1439 const IceCandidateInterface* c1 = cc1->at(j);
1440 const IceCandidateInterface* c2 = cc2->at(j);
1441 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1442 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1443 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1444 }
1445 }
1446 return true;
1447 }
1448
1449 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1450 // them with invalid keywords so that the parser will just ignore them.
1451 bool RemoveCandidateUfragPwd(std::string* sdp) {
1452 const char ice_ufrag[] = "a=ice-ufrag";
1453 const char ice_ufragx[] = "a=xice-ufrag";
1454 const char ice_pwd[] = "a=ice-pwd";
1455 const char ice_pwdx[] = "a=xice-pwd";
Yves Gerey665174f2018-06-19 15:03:05 +02001456 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag), ice_ufragx,
1457 strlen(ice_ufragx), sdp);
1458 rtc::replace_substrs(ice_pwd, strlen(ice_pwd), ice_pwdx, strlen(ice_pwdx),
1459 sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001460 return true;
1461 }
1462
1463 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
Yves Gerey665174f2018-06-19 15:03:05 +02001464 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc,
1465 int mline_index,
1466 const std::string& ufrag,
1467 const std::string& pwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001468 std::string content_name;
1469 if (mline_index == 0) {
1470 content_name = kAudioContentName;
1471 } else if (mline_index == 1) {
1472 content_name = kVideoContentName;
1473 } else {
nissec80e7412017-01-11 05:56:46 -08001474 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001475 }
Yves Gerey665174f2018-06-19 15:03:05 +02001476 TransportInfo transport_info(content_name,
1477 TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001478 SessionDescription* desc =
1479 const_cast<SessionDescription*>(jdesc->description());
1480 desc->RemoveTransportInfoByName(content_name);
1481 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
1482 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1483 const IceCandidateCollection* cc = jdesc_.candidates(i);
1484 for (size_t j = 0; j < cc->count(); ++j) {
1485 if (cc->at(j)->sdp_mline_index() == mline_index) {
Yves Gerey665174f2018-06-19 15:03:05 +02001486 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(ufrag);
1487 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001488 }
1489 }
1490 }
1491 return true;
1492 }
1493
1494 void AddIceOptions(const std::string& content_name,
1495 const std::vector<std::string>& transport_options) {
1496 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1497 cricket::TransportInfo transport_info =
1498 *(desc_.GetTransportInfoByName(content_name));
1499 desc_.RemoveTransportInfoByName(content_name);
1500 transport_info.description.transport_options = transport_options;
1501 desc_.AddTransportInfo(transport_info);
1502 }
1503
deadbeef3f7219b2015-12-28 15:17:14 -08001504 void SetIceUfragPwd(const std::string& content_name,
1505 const std::string& ice_ufrag,
1506 const std::string& ice_pwd) {
1507 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1508 cricket::TransportInfo transport_info =
1509 *(desc_.GetTransportInfoByName(content_name));
1510 desc_.RemoveTransportInfoByName(content_name);
1511 transport_info.description.ice_ufrag = ice_ufrag;
1512 transport_info.description.ice_pwd = ice_pwd;
1513 desc_.AddTransportInfo(transport_info);
1514 }
1515
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001516 void AddFingerprint() {
1517 desc_.RemoveTransportInfoByName(kAudioContentName);
1518 desc_.RemoveTransportInfoByName(kVideoContentName);
Steve Anton4905edb2018-10-15 19:27:44 -07001519 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, kIdentityDigest);
deadbeef46eed762016-01-28 13:24:37 -08001520 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1521 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001522 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1523 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001524 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1525 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1526 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001527 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1528 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001529 cricket::CONNECTIONROLE_NONE, &fingerprint))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001530 }
1531
jbauch5869f502017-06-29 12:31:36 -07001532 void AddExtmap(bool encrypted) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001533 audio_desc_ = audio_desc_->Copy();
1534 video_desc_ = video_desc_->Copy();
jbauch5869f502017-06-29 12:31:36 -07001535 audio_desc_->AddRtpHeaderExtension(
1536 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1537 video_desc_->AddRtpHeaderExtension(
1538 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001539 desc_.RemoveContentByName(kAudioContentName);
1540 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001541 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1542 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001543 }
1544
1545 void RemoveCryptos() {
1546 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1547 video_desc_->set_cryptos(std::vector<CryptoParams>());
1548 }
1549
Seth Hampson5897a6e2018-04-03 11:16:33 -07001550 // Removes everything in StreamParams from the session description that is
1551 // used for a=ssrc lines.
1552 void RemoveSsrcSignalingFromStreamParams() {
1553 for (cricket::ContentInfo content_info : jdesc_.description()->contents()) {
1554 // With Unified Plan there should be one StreamParams per m= section.
1555 StreamParams& stream =
1556 content_info.media_description()->mutable_streams()[0];
1557 stream.ssrcs.clear();
1558 stream.ssrc_groups.clear();
1559 stream.cname.clear();
1560 }
1561 }
1562
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001563 // Removes all a=ssrc lines from the SDP string, except for the
1564 // "a=ssrc:... cname:..." lines.
1565 void RemoveSsrcMsidLinesFromSdpString(std::string* sdp_string) {
1566 const char kAttributeSsrc[] = "a=ssrc";
1567 const char kAttributeCname[] = "cname";
1568 size_t ssrc_line_pos = sdp_string->find(kAttributeSsrc);
1569 while (ssrc_line_pos != std::string::npos) {
1570 size_t beg_line_pos = sdp_string->rfind('\n', ssrc_line_pos);
1571 size_t end_line_pos = sdp_string->find('\n', ssrc_line_pos);
1572 size_t cname_pos = sdp_string->find(kAttributeCname, ssrc_line_pos);
1573 if (cname_pos == std::string::npos || cname_pos > end_line_pos) {
1574 // Only erase a=ssrc lines that don't contain "cname".
1575 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1576 ssrc_line_pos = sdp_string->find(kAttributeSsrc, beg_line_pos);
1577 } else {
1578 // Skip the "a=ssrc:... cname" line and find the next "a=ssrc" line.
1579 ssrc_line_pos = sdp_string->find(kAttributeSsrc, end_line_pos);
1580 }
1581 }
1582 }
1583
Seth Hampson5897a6e2018-04-03 11:16:33 -07001584 // Removes all a=ssrc lines from the SDP string.
1585 void RemoveSsrcLinesFromSdpString(std::string* sdp_string) {
1586 const char kAttributeSsrc[] = "a=ssrc";
1587 while (sdp_string->find(kAttributeSsrc) != std::string::npos) {
1588 size_t pos_ssrc_attribute = sdp_string->find(kAttributeSsrc);
1589 size_t beg_line_pos = sdp_string->rfind('\n', pos_ssrc_attribute);
1590 size_t end_line_pos = sdp_string->find('\n', pos_ssrc_attribute);
1591 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1592 }
1593 }
1594
Steve Anton4e70a722017-11-28 14:57:10 -08001595 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001596 audio_desc_->set_direction(direction);
1597 video_desc_->set_direction(direction);
1598 std::string new_sdp = kSdpFullString;
1599 ReplaceDirection(direction, &new_sdp);
1600
Yves Gerey665174f2018-06-19 15:03:05 +02001601 if (!jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001602 jdesc_.session_version())) {
1603 return false;
1604 }
Steve Antone831b8c2018-02-01 12:22:16 -08001605 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001606 EXPECT_EQ(new_sdp, message);
1607 return true;
1608 }
1609
1610 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001611 audio_desc_ = audio_desc_->Copy();
1612 video_desc_ = video_desc_->Copy();
zhihuang38989e52017-03-21 11:04:53 -07001613
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001614 desc_.RemoveContentByName(kAudioContentName);
1615 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001616 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001617 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001618 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001619 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001620 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1621 audio_rejected ? "" : kPwdVoice);
1622 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1623 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001624
1625 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001626 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1627
Steve Antona3a92c22017-12-07 10:27:41 -08001628 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001629 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001630 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001631 EXPECT_EQ(new_sdp, message);
1632 return true;
1633 }
1634
zstein4b2e0822017-02-17 19:48:38 -08001635 void AddSctpDataChannel(bool use_sctpmap) {
kwibergd1fe2812016-04-27 06:47:29 -07001636 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001637 data_desc_ = data.get();
zstein4b2e0822017-02-17 19:48:38 -08001638 data_desc_->set_use_sctpmap(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001639 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
solenberg9fa49752016-10-08 13:02:44 -07001640 DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07001641 cricket::kGoogleSctpDataCodecName);
wu@webrtc.org78187522013-10-07 23:32:02 +00001642 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1643 data_desc_->AddCodec(codec);
Steve Anton5adfafd2017-12-20 16:34:00 -08001644 desc_.AddContent(kDataContentName, MediaProtocolType::kSctp,
1645 data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001646 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1647 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001648 }
1649
1650 void AddRtpDataChannel() {
kwibergd1fe2812016-04-27 06:47:29 -07001651 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001652 data_desc_ = data.get();
1653
deadbeef67cf2c12016-04-13 10:07:16 -07001654 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001655 StreamParams data_stream;
1656 data_stream.id = kDataChannelMsid;
1657 data_stream.cname = kDataChannelCname;
Seth Hampson845e8782018-03-02 11:34:10 -08001658 data_stream.set_stream_ids({kDataChannelLabel});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001659 data_stream.ssrcs.push_back(kDataChannelSsrc);
1660 data_desc_->AddStream(data_stream);
Yves Gerey665174f2018-06-19 15:03:05 +02001661 data_desc_->AddCrypto(
1662 CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
1663 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001664 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
Steve Anton5adfafd2017-12-20 16:34:00 -08001665 desc_.AddContent(kDataContentName, MediaProtocolType::kRtp, data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001666 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1667 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001668 }
1669
Steve Anton4e70a722017-11-28 14:57:10 -08001670 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001671 std::string new_sdp = kSdpFullString;
1672 ReplaceDirection(direction, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001673 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001674
1675 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1676
1677 audio_desc_->set_direction(direction);
1678 video_desc_->set_direction(direction);
Yves Gerey665174f2018-06-19 15:03:05 +02001679 if (!jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001680 jdesc_.session_version())) {
1681 return false;
1682 }
1683 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1684 return true;
1685 }
1686
1687 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001688 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001689 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001690 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001691 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001692
Steve Antonb1c1de12017-12-21 15:14:30 -08001693 audio_desc_ = audio_desc_->Copy();
1694 video_desc_ = video_desc_->Copy();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001695 desc_.RemoveContentByName(kAudioContentName);
1696 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001697 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001698 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001699 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001700 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001701 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1702 audio_rejected ? "" : kPwdVoice);
1703 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1704 video_rejected ? "" : kPwdVideo);
Steve Antona3a92c22017-12-07 10:27:41 -08001705 JsepSessionDescription jdesc_no_candidates(kDummyType);
deadbeef3f7219b2015-12-28 15:17:14 -08001706 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1707 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001708 return false;
1709 }
deadbeef3f7219b2015-12-28 15:17:14 -08001710 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001711 return true;
1712 }
1713
Yves Gerey665174f2018-06-19 15:03:05 +02001714 void TestDeserializeExtmap(bool session_level,
1715 bool media_level,
1716 bool encrypted) {
jbauch5869f502017-06-29 12:31:36 -07001717 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08001718 JsepSessionDescription new_jdesc(SdpType::kOffer);
Yves Gerey665174f2018-06-19 15:03:05 +02001719 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001720 jdesc_.session_version()));
Steve Antona3a92c22017-12-07 10:27:41 -08001721 JsepSessionDescription jdesc_with_extmap(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001722 std::string sdp_with_extmap = kSdpString;
1723 if (session_level) {
jbauch5869f502017-06-29 12:31:36 -07001724 InjectAfter(kSessionTime,
1725 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1726 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001727 &sdp_with_extmap);
1728 }
1729 if (media_level) {
jbauch5869f502017-06-29 12:31:36 -07001730 InjectAfter(kAttributeIcePwdVoice,
1731 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1732 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001733 &sdp_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07001734 InjectAfter(kAttributeIcePwdVideo,
1735 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1736 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001737 &sdp_with_extmap);
1738 }
1739 // The extmap can't be present at the same time in both session level and
1740 // media level.
1741 if (session_level && media_level) {
1742 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02001743 EXPECT_FALSE(
1744 webrtc::SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001745 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1746 } else {
1747 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1748 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1749 }
1750 }
1751
1752 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
Yves Gerey665174f2018-06-19 15:03:05 +02001753 const std::string& name,
1754 int expected_value) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001755 cricket::CodecParameterMap::const_iterator found = params.find(name);
1756 ASSERT_TRUE(found != params.end());
Jonas Olsson6b1985d2018-07-05 11:59:48 +02001757 EXPECT_EQ(found->second, rtc::ToString(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001758 }
1759
1760 void TestDeserializeCodecParams(const CodecParams& params,
1761 JsepSessionDescription* jdesc_output) {
1762 std::string sdp =
1763 "v=0\r\n"
1764 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1765 "s=-\r\n"
1766 "t=0 0\r\n"
1767 // Include semantics for WebRTC Media Streams since it is supported by
1768 // this parser, and will be added to the SDP when serializing a session
1769 // description.
1770 "a=msid-semantic: WMS\r\n"
1771 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001772 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001773 // Pltype 111 listed before 103 and 104 in the map.
1774 "a=rtpmap:111 opus/48000/2\r\n"
1775 // Pltype 103 listed before 104.
1776 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001777 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001778 "a=fmtp:111 0-15,66,70\r\n"
1779 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001780 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001781 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001782 << "; sprop-stereo=" << params.sprop_stereo
1783 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001784 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001785 << "a=ptime:" << params.ptime << "\r\n"
1786 << "a=maxptime:" << params.max_ptime << "\r\n";
1787 sdp += os.str();
1788
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001789 os.clear();
1790 os.str("");
1791 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001792 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001793 << "a=rtpmap:99 VP8/90000\r\n"
1794 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001795 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001796 sdp += os.str();
1797
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001798 // Deserialize
1799 SdpParseError error;
1800 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1801
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001802 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001803 GetFirstAudioContentDescription(jdesc_output->description());
1804 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001805 ASSERT_FALSE(acd->codecs().empty());
1806 cricket::AudioCodec opus = acd->codecs()[0];
1807 EXPECT_EQ("opus", opus.name);
1808 EXPECT_EQ(111, opus.id);
1809 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1810 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1811 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1812 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001813 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1814 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001815 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1816 cricket::AudioCodec codec = acd->codecs()[i];
1817 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1818 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001819 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001820
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001821 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001822 GetFirstVideoContentDescription(jdesc_output->description());
1823 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001824 ASSERT_FALSE(vcd->codecs().empty());
1825 cricket::VideoCodec vp8 = vcd->codecs()[0];
1826 EXPECT_EQ("VP8", vp8.name);
1827 EXPECT_EQ(99, vp8.id);
1828 cricket::VideoCodec rtx = vcd->codecs()[1];
1829 EXPECT_EQ("RTX", rtx.name);
1830 EXPECT_EQ(95, rtx.id);
1831 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001832 }
1833
1834 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1835 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001836 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001837 "v=0\r\n"
1838 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1839 "s=-\r\n"
1840 "t=0 0\r\n"
1841 // Include semantics for WebRTC Media Streams since it is supported by
1842 // this parser, and will be added to the SDP when serializing a session
1843 // description.
1844 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001845 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001846 "a=rtpmap:111 opus/48000/2\r\n";
1847 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001848 "m=video 3457 RTP/SAVPF 101\r\n"
1849 "a=rtpmap:101 VP8/90000\r\n"
1850 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001851 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001852 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001853 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001854 os << sdp_session_and_audio;
Yves Gerey665174f2018-06-19 15:03:05 +02001855 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001856 os << sdp_video;
Yves Gerey665174f2018-06-19 15:03:05 +02001857 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001858 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001859 // Deserialize
1860 SdpParseError error;
1861 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001862 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001863 GetFirstAudioContentDescription(jdesc_output->description());
1864 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001865 ASSERT_FALSE(acd->codecs().empty());
1866 cricket::AudioCodec opus = acd->codecs()[0];
1867 EXPECT_EQ(111, opus.id);
Yves Gerey665174f2018-06-19 15:03:05 +02001868 EXPECT_TRUE(opus.HasFeedbackParam(cricket::FeedbackParam(
1869 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001870
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001871 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001872 GetFirstVideoContentDescription(jdesc_output->description());
1873 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001874 ASSERT_FALSE(vcd->codecs().empty());
1875 cricket::VideoCodec vp8 = vcd->codecs()[0];
1876 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1877 vp8.name.c_str());
1878 EXPECT_EQ(101, vp8.id);
Yves Gerey665174f2018-06-19 15:03:05 +02001879 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1880 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
1881 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1882 cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli)));
1883 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1884 cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty)));
1885 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1886 cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001887 }
1888
1889 // Two SDP messages can mean the same thing but be different strings, e.g.
1890 // some of the lines can be serialized in different order.
1891 // However, a deserialized description can be compared field by field and has
1892 // no order. If deserializer has already been tested, serializing then
1893 // deserializing and comparing JsepSessionDescription will test
1894 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 12:22:16 -08001895 void TestSerialize(const JsepSessionDescription& jdesc) {
1896 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 10:27:41 -08001897 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001898 SdpParseError error;
1899 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1900 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1901 }
1902
zhihuang38989e52017-03-21 11:04:53 -07001903 // Calling 'Initialize' with a copy of the inner SessionDescription will
1904 // create a copy of the JsepSessionDescription without candidates. The
1905 // 'connection address' field, previously set from the candidates, must also
1906 // be reset.
1907 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
1908 rtc::SocketAddress audio_addr("0.0.0.0", 9);
1909 rtc::SocketAddress video_addr("0.0.0.0", 9);
1910 audio_desc_->set_connection_address(audio_addr);
1911 video_desc_->set_connection_address(video_addr);
1912 ASSERT_TRUE(jdesc->Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1913 }
1914
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001915 protected:
1916 SessionDescription desc_;
1917 AudioContentDescription* audio_desc_;
1918 VideoContentDescription* video_desc_;
1919 DataContentDescription* data_desc_;
1920 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07001921 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001922 JsepSessionDescription jdesc_;
1923};
1924
1925void TestMismatch(const std::string& string1, const std::string& string2) {
1926 int position = 0;
1927 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1928 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001929 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001930 break;
1931 }
1932 }
1933 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1934 << " character\n"
1935 << " 1: " << string1.substr(position, 20) << "\n"
1936 << " 2: " << string2.substr(position, 20) << "\n";
1937}
1938
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001939TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1940 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 12:22:16 -08001941 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001942 TestMismatch(std::string(kSdpFullString), message);
1943}
1944
1945TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 10:27:41 -08001946 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 12:22:16 -08001947 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001948}
1949
1950// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1951// the case in a DTLS offer.
1952TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1953 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08001954 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001955 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08001956 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001957
1958 std::string sdp_with_fingerprint = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02001959 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1960 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001961
1962 EXPECT_EQ(sdp_with_fingerprint, message);
1963}
1964
1965// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1966// be the case in a DTLS answer.
1967TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1968 AddFingerprint();
1969 RemoveCryptos();
Steve Antona3a92c22017-12-07 10:27:41 -08001970 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001971 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08001972 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001973
1974 std::string sdp_with_fingerprint = kSdpString;
1975 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1976 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
Yves Gerey665174f2018-06-19 15:03:05 +02001977 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1978 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001979
1980 EXPECT_EQ(sdp_with_fingerprint, message);
1981}
1982
1983TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1984 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08001985 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001986 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001987 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001988 EXPECT_EQ(std::string(kSdpString), message);
1989}
1990
1991TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1992 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1993 group.AddContentName(kAudioContentName);
1994 group.AddContentName(kVideoContentName);
1995 desc_.AddGroup(group);
Yves Gerey665174f2018-06-19 15:03:05 +02001996 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001997 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08001998 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001999 std::string sdp_with_bundle = kSdpFullString;
2000 InjectAfter(kSessionTime,
2001 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2002 &sdp_with_bundle);
2003 EXPECT_EQ(sdp_with_bundle, message);
2004}
2005
2006TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 15:14:30 -08002007 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002008 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002009 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002010 acd->set_bandwidth(50 * 1000);
Yves Gerey665174f2018-06-19 15:03:05 +02002011 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002012 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002013 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002014 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002015 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002016 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002017 InjectAfter("c=IN IP4 74.125.127.126\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002018 &sdp_with_bandwidth);
2019 EXPECT_EQ(sdp_with_bandwidth, message);
2020}
2021
2022TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
2023 std::vector<std::string> transport_options;
2024 transport_options.push_back(kIceOption1);
2025 transport_options.push_back(kIceOption3);
2026 AddIceOptions(kAudioContentName, transport_options);
2027 transport_options.clear();
2028 transport_options.push_back(kIceOption2);
2029 transport_options.push_back(kIceOption3);
2030 AddIceOptions(kVideoContentName, transport_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002031 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002032 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002033 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002034 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002035 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002036 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002037 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002038 &sdp_with_ice_options);
2039 EXPECT_EQ(sdp_with_ice_options, message);
2040}
2041
2042TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002043 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002044}
2045
2046TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002047 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002048}
2049
2050TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002051 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002052}
2053
2054TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2055 EXPECT_TRUE(TestSerializeRejected(true, false));
2056}
2057
2058TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2059 EXPECT_TRUE(TestSerializeRejected(false, true));
2060}
2061
2062TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2063 EXPECT_TRUE(TestSerializeRejected(true, true));
2064}
2065
2066TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
2067 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002068 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002069
zhihuang38989e52017-03-21 11:04:53 -07002070 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002071 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002072
2073 std::string expected_sdp = kSdpString;
2074 expected_sdp.append(kSdpRtpDataChannelString);
2075 EXPECT_EQ(expected_sdp, message);
2076}
2077
2078TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08002079 bool use_sctpmap = true;
2080 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002081 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002082
zhihuang38989e52017-03-21 11:04:53 -07002083 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002084 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002085
2086 std::string expected_sdp = kSdpString;
2087 expected_sdp.append(kSdpSctpDataChannelString);
2088 EXPECT_EQ(message, expected_sdp);
2089}
2090
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002091TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08002092 bool use_sctpmap = true;
2093 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002094 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002095 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antonb1c1de12017-12-21 15:14:30 -08002096 DataContentDescription* dcdesc =
2097 jsep_desc.description()
2098 ->GetContentDescriptionByName(kDataContentName)
2099 ->as_data();
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002100
2101 const int kNewPort = 1234;
solenberg9fa49752016-10-08 13:02:44 -07002102 cricket::DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07002103 cricket::kGoogleSctpDataCodecName);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002104 codec.SetParam(cricket::kCodecParamPort, kNewPort);
2105 dcdesc->AddOrReplaceCodec(codec);
2106
Steve Antone831b8c2018-02-01 12:22:16 -08002107 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002108
2109 std::string expected_sdp = kSdpString;
2110 expected_sdp.append(kSdpSctpDataChannelString);
2111
2112 char default_portstr[16];
2113 char new_portstr[16];
Niels Mölleraba06332018-10-16 15:14:15 +02002114 snprintf(default_portstr, sizeof(default_portstr), "%d", kDefaultSctpPort);
2115 snprintf(new_portstr, sizeof(new_portstr), "%d", kNewPort);
Yves Gerey665174f2018-06-19 15:03:05 +02002116 rtc::replace_substrs(default_portstr, strlen(default_portstr), new_portstr,
2117 strlen(new_portstr), &expected_sdp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002118
2119 EXPECT_EQ(expected_sdp, message);
2120}
2121
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002122TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002123 JsepSessionDescription jsep_desc(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002124 AddRtpDataChannel();
Yves Gerey665174f2018-06-19 15:03:05 +02002125 data_desc_->set_bandwidth(100 * 1000);
zhihuang38989e52017-03-21 11:04:53 -07002126 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002127 std::string message = webrtc::SdpSerialize(jsep_desc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002128
2129 std::string expected_sdp = kSdpString;
2130 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002131 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00002132 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02002133 "b=AS:100\r\n", &expected_sdp);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002134 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002135}
2136
Johannes Kron0854eb62018-10-10 22:33:20 +02002137TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002138 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002139 TestSerialize(jdesc_);
2140}
2141
2142TEST_F(WebRtcSdpTest, SerializeMediaContentDescriptionWithExtmapAllowMixed) {
2143 cricket::MediaContentDescription* video_desc =
2144 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2145 ASSERT_TRUE(video_desc);
2146 cricket::MediaContentDescription* audio_desc =
2147 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2148 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002149 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002150 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002151 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002152 cricket::MediaContentDescription::kMedia);
2153 TestSerialize(jdesc_);
2154}
2155
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002156TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002157 bool encrypted = false;
2158 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002159 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002160 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 12:22:16 -08002161 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002162
2163 std::string sdp_with_extmap = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002164 InjectAfter("a=mid:audio_content_name\r\n", kExtmap, &sdp_with_extmap);
2165 InjectAfter("a=mid:video_content_name\r\n", kExtmap, &sdp_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002166
2167 EXPECT_EQ(sdp_with_extmap, message);
2168}
2169
jbauch5869f502017-06-29 12:31:36 -07002170TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2171 bool encrypted = true;
2172 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002173 JsepSessionDescription desc_with_extmap(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002174 ASSERT_TRUE(
2175 desc_with_extmap.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 12:22:16 -08002176 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07002177}
2178
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002179TEST_F(WebRtcSdpTest, SerializeCandidates) {
2180 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002181 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002182
2183 Candidate candidate_with_ufrag(candidates_.front());
2184 candidate_with_ufrag.set_username("ABC");
2185 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2186 candidate_with_ufrag));
2187 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2188 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002189
2190 Candidate candidate_with_network_info(candidates_.front());
2191 candidate_with_network_info.set_network_id(1);
2192 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2193 candidate_with_network_info));
2194 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2195 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2196 candidate_with_network_info.set_network_cost(999);
2197 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2198 candidate_with_network_info));
2199 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2200 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2201 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002202}
2203
Zach Steinb336c272018-08-09 01:16:13 -07002204TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) {
2205 rtc::SocketAddress address("a.test", 1234);
2206 cricket::Candidate candidate(
2207 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
2208 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
2209 JsepIceCandidate jcandidate(std::string("audio_content_name"), 0, candidate);
2210 std::string message = webrtc::SdpSerializeCandidate(jcandidate);
2211 EXPECT_EQ(std::string(kRawHostnameCandidate), message);
2212}
2213
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002214// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2215// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002216TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002217 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002218 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2219 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2220 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002221 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002222 std::unique_ptr<IceCandidateInterface> jcandidate(
2223 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002224
2225 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2226 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2227}
2228
htaa6b99442016-04-12 10:29:17 -07002229TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002230 cricket::VideoCodec h264_codec("H264");
2231 h264_codec.SetParam("profile-level-id", "42e01f");
2232 h264_codec.SetParam("level-asymmetry-allowed", "1");
2233 h264_codec.SetParam("packetization-mode", "1");
2234 video_desc_->AddCodec(h264_codec);
2235
htaa6b99442016-04-12 10:29:17 -07002236 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
2237
Steve Antone831b8c2018-02-01 12:22:16 -08002238 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 10:29:17 -07002239 size_t after_pt = message.find(" H264/90000");
2240 ASSERT_NE(after_pt, std::string::npos);
2241 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2242 ASSERT_NE(before_pt, std::string::npos);
2243 before_pt += strlen("a=rtpmap:");
2244 std::string pt = message.substr(before_pt, after_pt - before_pt);
2245 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2246 std::string to_find = "a=fmtp:" + pt + " ";
2247 size_t fmtp_pos = message.find(to_find);
2248 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
2249 size_t fmtp_endpos = message.find("\n", fmtp_pos);
2250 ASSERT_NE(std::string::npos, fmtp_endpos);
2251 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2252 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2253 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2254 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002255 // Check that there are no spaces after semicolons.
2256 // https://bugs.webrtc.org/5793
2257 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002258}
2259
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002260TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 10:27:41 -08002261 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002262 // Deserialize
2263 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2264 // Verify
2265 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2266}
2267
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002268TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 10:27:41 -08002269 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002270 const char kSdpWithoutMline[] =
Yves Gerey665174f2018-06-19 15:03:05 +02002271 "v=0\r\n"
2272 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2273 "s=-\r\n"
2274 "t=0 0\r\n"
2275 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002276 // Deserialize
2277 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2278 EXPECT_EQ(0u, jdesc.description()->contents().size());
2279}
2280
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002281TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 10:27:41 -08002282 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002283 std::string sdp_without_carriage_return = kSdpFullString;
2284 Replace("\r\n", "\n", &sdp_without_carriage_return);
2285 // Deserialize
2286 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2287 // Verify
2288 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2289}
2290
2291TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2292 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002293 JsepSessionDescription jdesc_no_candidates(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002294 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
2295 kSessionVersion));
Steve Antona3a92c22017-12-07 10:27:41 -08002296 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002297 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2298 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2299}
2300
2301TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2302 static const char kSdpNoRtpmapString[] =
2303 "v=0\r\n"
2304 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2305 "s=-\r\n"
2306 "t=0 0\r\n"
2307 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2308 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002309 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002310 // The rtpmap line for static payload codec is optional.
2311 "a=rtpmap:18 G729/16000\r\n"
2312 "a=rtpmap:103 ISAC/16000\r\n";
2313
Steve Antona3a92c22017-12-07 10:27:41 -08002314 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002315 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2316 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002317 jdesc.description()
2318 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2319 ->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002320 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002321 // The codecs in the AudioContentDescription should be in the same order as
2322 // the payload types (<fmt>s) on the m= line.
2323 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2324 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002325 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002326 EXPECT_EQ(ref_codecs, audio->codecs());
2327}
2328
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002329TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2330 static const char kSdpNoRtpmapString[] =
2331 "v=0\r\n"
2332 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2333 "s=-\r\n"
2334 "t=0 0\r\n"
2335 "m=audio 49232 RTP/AVP 18 103\r\n"
2336 "a=fmtp:18 annexb=yes\r\n"
2337 "a=rtpmap:103 ISAC/16000\r\n";
2338
Steve Antona3a92c22017-12-07 10:27:41 -08002339 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002340 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2341 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002342 jdesc.description()
2343 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2344 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002345
2346 cricket::AudioCodec g729 = audio->codecs()[0];
2347 EXPECT_EQ("G729", g729.name);
2348 EXPECT_EQ(8000, g729.clockrate);
2349 EXPECT_EQ(18, g729.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002350 cricket::CodecParameterMap::iterator found = g729.params.find("annexb");
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002351 ASSERT_TRUE(found != g729.params.end());
2352 EXPECT_EQ(found->second, "yes");
2353
2354 cricket::AudioCodec isac = audio->codecs()[1];
2355 EXPECT_EQ("ISAC", isac.name);
2356 EXPECT_EQ(103, isac.id);
2357 EXPECT_EQ(16000, isac.clockrate);
2358}
2359
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002360// Ensure that we can deserialize SDP with a=fingerprint properly.
2361TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2362 // Add a DTLS a=fingerprint attribute to our session description.
2363 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002364 JsepSessionDescription new_jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002365 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002366 jdesc_.session_version()));
2367
Steve Antona3a92c22017-12-07 10:27:41 -08002368 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002369 std::string sdp_with_fingerprint = kSdpString;
2370 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2371 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2372 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2373 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2374}
2375
2376TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 10:27:41 -08002377 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002378 std::string sdp_with_bundle = kSdpFullString;
2379 InjectAfter(kSessionTime,
2380 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2381 &sdp_with_bundle);
2382 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2383 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2384 group.AddContentName(kAudioContentName);
2385 group.AddContentName(kVideoContentName);
2386 desc_.AddGroup(group);
Yves Gerey665174f2018-06-19 15:03:05 +02002387 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002388 jdesc_.session_version()));
2389 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2390}
2391
2392TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002393 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002394 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002395 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002396 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002397 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002398 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002399 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 15:14:30 -08002400 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002401 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002402 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002403 acd->set_bandwidth(50 * 1000);
Yves Gerey665174f2018-06-19 15:03:05 +02002404 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002405 jdesc_.session_version()));
2406 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2407}
2408
2409TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 10:27:41 -08002410 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002411 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002412 InjectAfter(kSessionTime, "a=ice-options:iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002413 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002414 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002415 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002416 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002417 &sdp_with_ice_options);
2418 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2419 std::vector<std::string> transport_options;
2420 transport_options.push_back(kIceOption3);
2421 transport_options.push_back(kIceOption1);
2422 AddIceOptions(kAudioContentName, transport_options);
2423 transport_options.clear();
2424 transport_options.push_back(kIceOption3);
2425 transport_options.push_back(kIceOption2);
2426 AddIceOptions(kVideoContentName, transport_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002427 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002428 jdesc_.session_version()));
2429 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2430}
2431
2432TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2433 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 10:27:41 -08002434 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002435 std::string sdp_with_ufrag_pwd = kSdpFullString;
2436 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2437 // Add session level ufrag and pwd
2438 InjectAfter(kSessionTime,
Yves Gerey665174f2018-06-19 15:03:05 +02002439 "a=ice-pwd:session+level+icepwd\r\n"
2440 "a=ice-ufrag:session+level+iceufrag\r\n",
2441 &sdp_with_ufrag_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002442 // Add media level ufrag and pwd for audio
Yves Gerey665174f2018-06-19 15:03:05 +02002443 InjectAfter(
2444 "a=mid:audio_content_name\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002445 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2446 &sdp_with_ufrag_pwd);
2447 // Update the candidate ufrag and pwd to the expected ones.
Yves Gerey665174f2018-06-19 15:03:05 +02002448 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, "media+level+iceufrag",
2449 "media+level+icepwd"));
2450 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, "session+level+iceufrag",
2451 "session+level+icepwd"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002452 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2453 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2454}
2455
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002456TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002457 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002458}
2459
2460TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002461 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002462}
2463
2464TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002465 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002466}
2467
2468TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2469 EXPECT_TRUE(TestDeserializeRejected(true, false));
2470}
2471
2472TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2473 EXPECT_TRUE(TestDeserializeRejected(false, true));
2474}
2475
2476TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2477 EXPECT_TRUE(TestDeserializeRejected(true, true));
2478}
2479
2480// Tests that we can still handle the sdp uses mslabel and label instead of
2481// msid for backward compatibility.
2482TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07002483 jdesc_.description()->set_msid_supported(false);
Steve Antona3a92c22017-12-07 10:27:41 -08002484 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002485 std::string sdp_without_msid = kSdpFullString;
2486 Replace("msid", "xmsid", &sdp_without_msid);
2487 // Deserialize
2488 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2489 // Verify
2490 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2491}
2492
Johannes Kron0854eb62018-10-10 22:33:20 +02002493TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002494 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002495 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2496 InjectAfter("t=0 0\r\n", kExtmapAllowMixed, &sdp_with_extmap_allow_mixed);
2497 // Deserialize
2498 JsepSessionDescription jdesc_deserialized(kDummyType);
2499 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2500 // Verify
2501 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2502}
2503
2504TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002505 jdesc_.description()->set_extmap_allow_mixed(false);
Johannes Kron0854eb62018-10-10 22:33:20 +02002506 std::string sdp_without_extmap_allow_mixed = kSdpFullString;
2507 // Deserialize
2508 JsepSessionDescription jdesc_deserialized(kDummyType);
2509 EXPECT_TRUE(
2510 SdpDeserialize(sdp_without_extmap_allow_mixed, &jdesc_deserialized));
2511 // Verify
2512 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2513}
2514
2515TEST_F(WebRtcSdpTest, DeserializeMediaContentDescriptionWithExtmapAllowMixed) {
2516 cricket::MediaContentDescription* video_desc =
2517 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2518 ASSERT_TRUE(video_desc);
2519 cricket::MediaContentDescription* audio_desc =
2520 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2521 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002522 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002523 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002524 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002525 cricket::MediaContentDescription::kMedia);
2526
2527 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2528 InjectAfter("a=mid:audio_content_name\r\n", kExtmapAllowMixed,
2529 &sdp_with_extmap_allow_mixed);
2530 InjectAfter("a=mid:video_content_name\r\n", kExtmapAllowMixed,
2531 &sdp_with_extmap_allow_mixed);
2532
2533 // Deserialize
2534 JsepSessionDescription jdesc_deserialized(kDummyType);
2535 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2536 // Verify
2537 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2538}
2539
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002540TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2541 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2542
2543 std::string sdp = kSdpOneCandidate;
2544 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2545 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2546 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2547 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002548 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002549
2550 // Candidate line without generation extension.
2551 sdp = kSdpOneCandidate;
2552 Replace(" generation 2", "", &sdp);
2553 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2554 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2555 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2556 Candidate expected = jcandidate_->candidate();
2557 expected.set_generation(0);
2558 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2559
honghaiza0c44ea2016-03-23 16:07:48 -07002560 // Candidate with network id and/or cost.
2561 sdp = kSdpOneCandidate;
2562 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2563 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2564 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2565 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2566 expected = jcandidate_->candidate();
2567 expected.set_network_id(2);
2568 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2569 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2570 // Add network cost
2571 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2572 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2573 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2574 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2575
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002576 sdp = kSdpTcpActiveCandidate;
2577 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2578 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002579 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002580 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2581 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2582 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002583 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2584 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
Yves Gerey665174f2018-06-19 15:03:05 +02002585 EXPECT_TRUE(
2586 jcandidate.candidate().IsEquivalent(jcandidate_template->candidate()));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002587 sdp = kSdpTcpPassiveCandidate;
2588 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2589 sdp = kSdpTcpSOCandidate;
2590 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002591}
2592
2593// This test verifies the deserialization of candidate-attribute
2594// as per RFC 5245. Candiate-attribute will be of the format
2595// candidate:<blah>. This format will be used when candidates
2596// are trickled.
2597TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2598 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2599
2600 std::string candidate_attribute = kRawCandidate;
2601 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2602 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2603 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2604 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2605 EXPECT_EQ(2u, jcandidate.candidate().generation());
2606
2607 // Candidate line without generation extension.
2608 candidate_attribute = kRawCandidate;
2609 Replace(" generation 2", "", &candidate_attribute);
2610 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2611 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2612 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2613 Candidate expected = jcandidate_->candidate();
2614 expected.set_generation(0);
2615 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2616
2617 // Candidate line without candidate:
2618 candidate_attribute = kRawCandidate;
2619 Replace("candidate:", "", &candidate_attribute);
2620 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2621
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002622 // Candidate line with IPV6 address.
2623 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
Zach Steinb336c272018-08-09 01:16:13 -07002624
2625 // Candidate line with hostname address.
2626 EXPECT_TRUE(SdpDeserializeCandidate(kRawHostnameCandidate, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002627}
2628
2629// This test verifies that the deserialization of an invalid candidate string
2630// fails.
2631TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
Yves Gerey665174f2018-06-19 15:03:05 +02002632 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002633
2634 std::string candidate_attribute = kRawCandidate;
2635 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002636 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002637
2638 candidate_attribute = kSdpOneCandidate;
2639 candidate_attribute.replace(0, 1, "x");
2640 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2641
2642 candidate_attribute = kRawCandidate;
2643 candidate_attribute.append("\r\n");
2644 candidate_attribute.append(kRawCandidate);
2645 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2646
2647 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002648}
2649
2650TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2651 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002652 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002653 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2654
2655 std::string sdp_with_data = kSdpString;
2656 sdp_with_data.append(kSdpRtpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002657 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002658
2659 // Deserialize
2660 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2661 // Verify
2662 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2663}
2664
2665TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002666 bool use_sctpmap = true;
2667 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002668 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002669 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2670
2671 std::string sdp_with_data = kSdpString;
2672 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002673 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002674
lally@webrtc.org36300852015-02-24 20:19:35 +00002675 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2676 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2677 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2678
2679 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002680 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2681 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002682 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2683 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2684
2685 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002686 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2687 kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002688 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2689 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2690}
2691
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002692TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002693 bool use_sctpmap = false;
2694 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002695 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002696 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2697
2698 std::string sdp_with_data = kSdpString;
2699 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002700 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002701
lally@webrtc.org36300852015-02-24 20:19:35 +00002702 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002703 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2704 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002705
lally@webrtc.org36300852015-02-24 20:19:35 +00002706 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002707 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2708 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002709 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2710 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002711
lally@webrtc.org36300852015-02-24 20:19:35 +00002712 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002713 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2714 kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002715 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2716 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2717}
2718
lally69f57602015-10-08 10:15:04 -07002719TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002720 bool use_sctpmap = false;
2721 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002722 JsepSessionDescription jdesc(kDummyType);
lally69f57602015-10-08 10:15:04 -07002723 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2724
2725 std::string sdp_with_data = kSdpString;
2726 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002727 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 10:15:04 -07002728
2729 // Verify with DTLS/SCTP.
2730 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2731 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2732
2733 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002734 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2735 kUdpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002736 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2737 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2738
2739 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002740 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2741 kTcpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002742 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2743 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2744}
2745
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002746// Test to check the behaviour if sctp-port is specified
2747// on the m= line and in a=sctp-port.
2748TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002749 bool use_sctpmap = true;
2750 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002751 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002752 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2753
2754 std::string sdp_with_data = kSdpString;
2755 // Append m= attributes
2756 sdp_with_data.append(kSdpSctpDataChannelString);
2757 // Append a=sctp-port attribute
2758 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 10:27:41 -08002759 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002760
2761 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2762}
2763
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002764// For crbug/344475.
2765TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2766 std::string sdp_with_data = kSdpString;
2767 sdp_with_data.append(kSdpSctpDataChannelString);
2768 // Remove the "\n" at the end.
2769 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 10:27:41 -08002770 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002771
2772 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2773 // No crash is a pass.
2774}
2775
Steve Anton36b29d12017-10-30 09:57:42 -07002776void MutateJsepSctpPort(JsepSessionDescription* jdesc,
zstein4b2e0822017-02-17 19:48:38 -08002777 const SessionDescription& desc) {
wu@webrtc.org78187522013-10-07 23:32:02 +00002778 // take our pre-built session description and change the SCTP port.
zstein4b2e0822017-02-17 19:48:38 -08002779 cricket::SessionDescription* mutant = desc.Copy();
Steve Antonb1c1de12017-12-21 15:14:30 -08002780 DataContentDescription* dcdesc =
2781 mutant->GetContentDescriptionByName(kDataContentName)->as_data();
wu@webrtc.org78187522013-10-07 23:32:02 +00002782 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002783 EXPECT_EQ(1U, codecs.size());
solenberg9fa49752016-10-08 13:02:44 -07002784 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002785 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002786 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002787
2788 // note: mutant's owned by jdesc now.
Steve Anton36b29d12017-10-30 09:57:42 -07002789 ASSERT_TRUE(jdesc->Initialize(mutant, kSessionId, kSessionVersion));
wu@webrtc.org78187522013-10-07 23:32:02 +00002790 mutant = NULL;
zstein4b2e0822017-02-17 19:48:38 -08002791}
2792
2793TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
2794 bool use_sctpmap = true;
2795 AddSctpDataChannel(use_sctpmap);
2796
2797 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 10:27:41 -08002798 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002799 MutateJsepSctpPort(&jdesc, desc_);
wu@webrtc.org78187522013-10-07 23:32:02 +00002800
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002801 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002802 std::string sdp_with_data = kSdpString;
2803 sdp_with_data.append(kSdpSctpDataChannelString);
zstein4b2e0822017-02-17 19:48:38 -08002804 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2805 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2806 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002807 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:02 +00002808
2809 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2810 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08002811}
2812
2813TEST_F(WebRtcSdpTest,
2814 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
2815 bool use_sctpmap = false;
2816 AddSctpDataChannel(use_sctpmap);
2817
Steve Antona3a92c22017-12-07 10:27:41 -08002818 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002819 MutateJsepSctpPort(&jdesc, desc_);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002820
2821 // We need to test the deserialized JsepSessionDescription from
2822 // kSdpSctpDataChannelStringWithSctpPort for
2823 // draft-ietf-mmusic-sctp-sdp-07
2824 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08002825 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002826 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
zstein4b2e0822017-02-17 19:48:38 -08002827 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2828 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2829 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002830 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002831
2832 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2833 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002834}
2835
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002836TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002837 // We want to test that deserializing data content limits bandwidth
2838 // settings (it should never be greater than the default).
2839 // This should prevent someone from using unlimited data bandwidth through
2840 // JS and "breaking the Internet".
2841 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002842 std::string sdp_with_bandwidth = kSdpString;
2843 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02002844 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002845 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002846 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002847
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002848 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2849}
2850
2851TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08002852 bool use_sctpmap = true;
2853 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002854 JsepSessionDescription jdesc(kDummyType);
Steve Antonb1c1de12017-12-21 15:14:30 -08002855 DataContentDescription* dcd = GetFirstDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002856 dcd->set_bandwidth(100 * 1000);
2857 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2858
2859 std::string sdp_with_bandwidth = kSdpString;
2860 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02002861 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002862 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002863 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002864
2865 // SCTP has congestion control, so we shouldn't limit the bandwidth
2866 // as we do for RTP.
2867 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002868 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2869}
2870
Yves Gerey665174f2018-06-19 15:03:05 +02002871class WebRtcSdpExtmapTest : public WebRtcSdpTest,
2872 public testing::WithParamInterface<bool> {};
jbauch5869f502017-06-29 12:31:36 -07002873
2874TEST_P(WebRtcSdpExtmapTest,
Yves Gerey665174f2018-06-19 15:03:05 +02002875 DeserializeSessionDescriptionWithSessionLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002876 bool encrypted = GetParam();
2877 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002878}
2879
Yves Gerey665174f2018-06-19 15:03:05 +02002880TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002881 bool encrypted = GetParam();
2882 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002883}
2884
Yves Gerey665174f2018-06-19 15:03:05 +02002885TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithInvalidExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002886 bool encrypted = GetParam();
2887 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002888}
2889
jbauch5869f502017-06-29 12:31:36 -07002890INSTANTIATE_TEST_CASE_P(Encrypted,
2891 WebRtcSdpExtmapTest,
2892 ::testing::Values(false, true));
2893
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002894TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 10:27:41 -08002895 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002896 std::string sdp = kSdpFullString;
2897 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2898 // Deserialize
2899 SdpParseError error;
2900 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-16 17:54:10 -08002901 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002902 EXPECT_EQ(lastline, error.line);
2903 EXPECT_EQ("Invalid SDP line.", error.description);
2904}
2905
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002906TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2907 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2908 std::string new_sdp = kSdpOneCandidate;
2909 Replace("udp", "unsupported_transport", &new_sdp);
2910 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2911 new_sdp = kSdpOneCandidate;
2912 Replace("udp", "uDP", &new_sdp);
2913 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2914 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2915 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2916 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2917}
2918
honghaiza54a0802015-12-16 18:37:23 -08002919TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002920 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08002921 EXPECT_TRUE(
2922 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002923 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2924 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2925 Candidate ref_candidate = jcandidate_->candidate();
2926 ref_candidate.set_username("user_rtp");
2927 ref_candidate.set_password("password_rtp");
2928 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2929}
2930
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002931TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08002932 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002933
2934 // Deserialize
2935 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2936
2937 // Verify
2938 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002939 jdesc.description()
2940 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2941 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002942 EXPECT_TRUE(audio->conference_mode());
2943
2944 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 15:14:30 -08002945 jdesc.description()
2946 ->GetContentDescriptionByName(cricket::CN_VIDEO)
2947 ->as_video();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002948 EXPECT_TRUE(video->conference_mode());
2949}
2950
deadbeefd45aea82017-09-16 01:24:29 -07002951TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08002952 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 01:24:29 -07002953
2954 // We tested deserialization already above, so just test that if we serialize
2955 // and deserialize the flag doesn't disappear.
2956 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 12:22:16 -08002957 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 01:24:29 -07002958 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
2959
2960 // Verify.
2961 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002962 jdesc.description()
2963 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2964 ->as_audio();
deadbeefd45aea82017-09-16 01:24:29 -07002965 EXPECT_TRUE(audio->conference_mode());
2966
2967 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 15:14:30 -08002968 jdesc.description()
2969 ->GetContentDescriptionByName(cricket::CN_VIDEO)
2970 ->as_video();
deadbeefd45aea82017-09-16 01:24:29 -07002971 EXPECT_TRUE(video->conference_mode());
2972}
2973
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002974TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2975 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002976 const char kSdpEmptyType[] = " =candidate";
2977 const char kSdpEqualAsPlus[] = "a+candidate";
2978 const char kSdpSpaceAfterEqual[] = "a= candidate";
2979 const char kSdpUpperType[] = "A=candidate";
2980 const char kSdpEmptyLine[] = "";
2981 const char kSdpMissingValue[] = "a=";
2982
Yves Gerey665174f2018-06-19 15:03:05 +02002983 const char kSdpBrokenFingerprint[] =
2984 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002985 "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 +02002986 const char kSdpExtraField[] =
2987 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002988 "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 +02002989 const char kSdpMissingSpace[] =
2990 "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002991 "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 +00002992 // MD5 is not allowed in fingerprints.
Yves Gerey665174f2018-06-19 15:03:05 +02002993 const char kSdpMd5[] =
2994 "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002995 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002996
2997 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002998 ExpectParseFailure("v=", kSdpDestroyer);
2999 ExpectParseFailure("o=", kSdpDestroyer);
3000 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003001 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003002 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003003
3004 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003005 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
3006 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003007
3008 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003009 ExpectParseFailure("a=candidate", kSdpEmptyType);
3010 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
3011 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
3012 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003013
3014 // Bogus fingerprint replacing a=sendrev. We selected this attribute
3015 // because it's orthogonal to what we are replacing and hence
3016 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003017 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
3018 ExpectParseFailure("a=sendrecv", kSdpExtraField);
3019 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
3020 ExpectParseFailure("a=sendrecv", kSdpMd5);
3021
3022 // Empty Line
3023 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
3024 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003025}
3026
3027TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
3028 // ssrc
3029 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08003030 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003031 // crypto
3032 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
3033 // rtpmap
3034 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
3035 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
3036 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
3037 // candidate
3038 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
3039 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
3040 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
3041 ExpectParseFailure("rport 2346", "rport badvalue");
3042 ExpectParseFailure("rport 2346 generation 2",
3043 "rport 2346 generation badvalue");
3044 // m line
3045 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
3046 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
3047
3048 // bandwidth
3049 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003050 "b=AS:badvalue\r\n", "b=AS:badvalue");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003051 // rtcp-fb
3052 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3053 "a=rtcp-fb:badvalue nack\r\n",
3054 "a=rtcp-fb:badvalue nack");
3055 // extmap
3056 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3057 "a=extmap:badvalue http://example.com\r\n",
3058 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003059}
3060
3061TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 10:27:41 -08003062 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003063
3064 const char kSdpWithReorderedPlTypesString[] =
3065 "v=0\r\n"
3066 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3067 "s=-\r\n"
3068 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00003069 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
Yves Gerey665174f2018-06-19 15:03:05 +02003070 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
3071 // in the map.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003072 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003073 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003074
3075 // Deserialize
3076 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
3077
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003078 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003079 GetFirstAudioContentDescription(jdesc_output.description());
3080 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003081 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003082 EXPECT_EQ("ISAC", acd->codecs()[0].name);
3083 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003084 EXPECT_EQ(104, acd->codecs()[0].id);
3085}
3086
3087TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 10:27:41 -08003088 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003089 CodecParams params;
3090 params.max_ptime = 40;
3091 params.ptime = 30;
3092 params.min_ptime = 10;
3093 params.sprop_stereo = 1;
3094 params.stereo = 1;
3095 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003096 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003097 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 12:22:16 -08003098 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003099}
3100
3101TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
3102 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 10:27:41 -08003103 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003104 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003105 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003106}
3107
3108TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
3109 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 10:27:41 -08003110 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003111 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003112 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003113}
3114
3115TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 10:27:41 -08003116 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003117
3118 const char kSdpWithFmtpString[] =
3119 "v=0\r\n"
3120 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3121 "s=-\r\n"
3122 "t=0 0\r\n"
3123 "m=video 3457 RTP/SAVPF 120\r\n"
3124 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07003125 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3126
3127 // Deserialize
3128 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07003129 EXPECT_TRUE(
3130 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07003131
Donald Curtis0e07f922015-05-15 09:21:23 -07003132 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003133 GetFirstVideoContentDescription(jdesc_output.description());
3134 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 09:21:23 -07003135 ASSERT_FALSE(vcd->codecs().empty());
3136 cricket::VideoCodec vp8 = vcd->codecs()[0];
3137 EXPECT_EQ("VP8", vp8.name);
3138 EXPECT_EQ(120, vp8.id);
3139 cricket::CodecParameterMap::iterator found =
3140 vp8.params.find("x-google-min-bitrate");
3141 ASSERT_TRUE(found != vp8.params.end());
3142 EXPECT_EQ(found->second, "10");
3143 found = vp8.params.find("x-google-max-quantization");
3144 ASSERT_TRUE(found != vp8.params.end());
3145 EXPECT_EQ(found->second, "40");
3146}
3147
johan2d8d23e2016-06-03 01:22:42 -07003148TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 10:27:41 -08003149 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 01:22:42 -07003150
3151 const char kSdpWithFmtpString[] =
3152 "v=0\r\n"
3153 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3154 "s=-\r\n"
3155 "t=0 0\r\n"
3156 "m=video 49170 RTP/AVP 98\r\n"
3157 "a=rtpmap:98 H264/90000\r\n"
3158 "a=fmtp:98 profile-level-id=42A01E; "
3159 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3160
3161 // Deserialize.
3162 SdpParseError error;
3163 EXPECT_TRUE(
3164 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3165
johan2d8d23e2016-06-03 01:22:42 -07003166 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003167 GetFirstVideoContentDescription(jdesc_output.description());
3168 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 01:22:42 -07003169 ASSERT_FALSE(vcd->codecs().empty());
3170 cricket::VideoCodec h264 = vcd->codecs()[0];
3171 EXPECT_EQ("H264", h264.name);
3172 EXPECT_EQ(98, h264.id);
3173 cricket::CodecParameterMap::const_iterator found =
3174 h264.params.find("profile-level-id");
3175 ASSERT_TRUE(found != h264.params.end());
3176 EXPECT_EQ(found->second, "42A01E");
3177 found = h264.params.find("sprop-parameter-sets");
3178 ASSERT_TRUE(found != h264.params.end());
3179 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3180}
3181
Donald Curtis0e07f922015-05-15 09:21:23 -07003182TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 10:27:41 -08003183 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 09:21:23 -07003184
3185 const char kSdpWithFmtpString[] =
3186 "v=0\r\n"
3187 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3188 "s=-\r\n"
3189 "t=0 0\r\n"
3190 "m=video 3457 RTP/SAVPF 120\r\n"
3191 "a=rtpmap:120 VP8/90000\r\n"
3192 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003193
3194 // Deserialize
3195 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02003196 EXPECT_TRUE(
3197 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003198
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003199 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003200 GetFirstVideoContentDescription(jdesc_output.description());
3201 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003202 ASSERT_FALSE(vcd->codecs().empty());
3203 cricket::VideoCodec vp8 = vcd->codecs()[0];
3204 EXPECT_EQ("VP8", vp8.name);
3205 EXPECT_EQ(120, vp8.id);
3206 cricket::CodecParameterMap::iterator found =
3207 vp8.params.find("x-google-min-bitrate");
3208 ASSERT_TRUE(found != vp8.params.end());
3209 EXPECT_EQ(found->second, "10");
3210 found = vp8.params.find("x-google-max-quantization");
3211 ASSERT_TRUE(found != vp8.params.end());
3212 EXPECT_EQ(found->second, "40");
3213}
3214
ossuaa4b0772017-01-30 07:41:18 -08003215TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003216 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003217
3218 cricket::AudioCodecs codecs = acd->codecs();
3219 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3220 acd->set_codecs(codecs);
3221
Yves Gerey665174f2018-06-19 15:03:05 +02003222 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003223 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003224 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003225 std::string sdp_with_fmtp = kSdpFullString;
3226 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3227 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3228 &sdp_with_fmtp);
3229 EXPECT_EQ(sdp_with_fmtp, message);
3230}
3231
3232TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003233 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003234
3235 cricket::AudioCodecs codecs = acd->codecs();
3236 codecs[0].params["stereo"] = "1";
3237 acd->set_codecs(codecs);
3238
Yves Gerey665174f2018-06-19 15:03:05 +02003239 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003240 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003241 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003242 std::string sdp_with_fmtp = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003243 InjectAfter("a=rtpmap:111 opus/48000/2\r\n", "a=fmtp:111 stereo=1\r\n",
ossuaa4b0772017-01-30 07:41:18 -08003244 &sdp_with_fmtp);
3245 EXPECT_EQ(sdp_with_fmtp, message);
3246}
3247
3248TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003249 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003250
3251 cricket::AudioCodecs codecs = acd->codecs();
3252 codecs[0].params["ptime"] = "20";
3253 codecs[0].params["maxptime"] = "120";
3254 acd->set_codecs(codecs);
3255
Yves Gerey665174f2018-06-19 15:03:05 +02003256 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003257 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003258 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003259 std::string sdp_with_fmtp = kSdpFullString;
3260 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3261 "a=maxptime:120\r\n" // No comma here. String merging!
3262 "a=ptime:20\r\n",
3263 &sdp_with_fmtp);
3264 EXPECT_EQ(sdp_with_fmtp, message);
3265}
3266
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003267TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003268 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003269
3270 cricket::VideoCodecs codecs = vcd->codecs();
3271 codecs[0].params["x-google-min-bitrate"] = "10";
3272 vcd->set_codecs(codecs);
3273
Yves Gerey665174f2018-06-19 15:03:05 +02003274 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003275 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003276 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003277 std::string sdp_with_fmtp = kSdpFullString;
3278 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003279 "a=fmtp:120 x-google-min-bitrate=10\r\n", &sdp_with_fmtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003280 EXPECT_EQ(sdp_with_fmtp, message);
3281}
3282
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003283TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) {
3284 // Deserialize the baseline description, making sure it's ICE full.
Steve Antona3a92c22017-12-07 10:27:41 -08003285 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003286 std::string sdp_with_icelite = kSdpFullString;
3287 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3288 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3289 const cricket::TransportInfo* tinfo1 =
3290 desc->GetTransportInfoByName("audio_content_name");
3291 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3292 const cricket::TransportInfo* tinfo2 =
3293 desc->GetTransportInfoByName("video_content_name");
3294 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003295
3296 // Add "a=ice-lite" and deserialize, making sure it's ICE lite.
Yves Gerey665174f2018-06-19 15:03:05 +02003297 InjectAfter(kSessionTime, "a=ice-lite\r\n", &sdp_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003298 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3299 desc = jdesc_with_icelite.description();
3300 const cricket::TransportInfo* atinfo =
3301 desc->GetTransportInfoByName("audio_content_name");
3302 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3303 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003304 desc->GetTransportInfoByName("video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003305 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003306
3307 // Now that we know deserialization works, we can use TestSerialize to test
3308 // serialization.
3309 TestSerialize(jdesc_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003310}
3311
3312// Verifies that the candidates in the input SDP are parsed and serialized
3313// correctly in the output SDP.
3314TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3315 std::string sdp_with_data = kSdpString;
3316 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 10:27:41 -08003317 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003318
3319 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 12:22:16 -08003320 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003321}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003322
3323TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3324 AddFingerprint();
3325 TransportInfo audio_transport_info =
3326 *(desc_.GetTransportInfoByName(kAudioContentName));
3327 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3328 audio_transport_info.description.connection_role);
3329 audio_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003330 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003331
3332 TransportInfo video_transport_info =
3333 *(desc_.GetTransportInfoByName(kVideoContentName));
3334 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3335 video_transport_info.description.connection_role);
3336 video_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003337 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003338
3339 desc_.RemoveTransportInfoByName(kAudioContentName);
3340 desc_.RemoveTransportInfoByName(kVideoContentName);
3341
3342 desc_.AddTransportInfo(audio_transport_info);
3343 desc_.AddTransportInfo(video_transport_info);
3344
Yves Gerey665174f2018-06-19 15:03:05 +02003345 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003346 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003347 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003348 std::string sdp_with_dtlssetup = kSdpFullString;
3349
3350 // Fingerprint attribute is necessary to add DTLS setup attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003351 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_dtlssetup);
3352 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003353 // Now adding |setup| attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003354 InjectAfter(kFingerprint, "a=setup:active\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003355 EXPECT_EQ(sdp_with_dtlssetup, message);
3356}
3357
3358TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
Steve Antona3a92c22017-12-07 10:27:41 -08003359 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003360 std::string sdp_with_dtlssetup = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003361 InjectAfter(kSessionTime, "a=setup:actpass\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003362 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3363 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3364 const cricket::TransportInfo* atinfo =
3365 desc->GetTransportInfoByName("audio_content_name");
3366 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3367 atinfo->description.connection_role);
3368 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003369 desc->GetTransportInfoByName("video_content_name");
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003370 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3371 vtinfo->description.connection_role);
3372}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003373
3374// Verifies that the order of the serialized m-lines follows the order of the
3375// ContentInfo in SessionDescription, and vise versa for deserialization.
3376TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 10:27:41 -08003377 JsepSessionDescription jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02003378 const std::string media_content_sdps[3] = {kSdpAudioString, kSdpVideoString,
3379 kSdpSctpDataChannelString};
3380 const cricket::MediaType media_types[3] = {cricket::MEDIA_TYPE_AUDIO,
3381 cricket::MEDIA_TYPE_VIDEO,
3382 cricket::MEDIA_TYPE_DATA};
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003383
3384 // Verifies all 6 permutations.
3385 for (size_t i = 0; i < 6; ++i) {
3386 size_t media_content_in_sdp[3];
3387 // The index of the first media content.
3388 media_content_in_sdp[0] = i / 2;
3389 // The index of the second media content.
3390 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3391 // The index of the third media content.
3392 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3393
3394 std::string sdp_string = kSdpSessionString;
3395 for (size_t i = 0; i < 3; ++i)
3396 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3397
3398 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3399 cricket::SessionDescription* desc = jdesc.description();
3400 EXPECT_EQ(3u, desc->contents().size());
3401
3402 for (size_t i = 0; i < 3; ++i) {
3403 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 15:14:30 -08003404 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003405 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3406 }
3407
Steve Antone831b8c2018-02-01 12:22:16 -08003408 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003409 EXPECT_EQ(sdp_string, serialized_sdp);
3410 }
3411}
deadbeef9d3584c2016-02-16 17:54:10 -08003412
deadbeef25ed4352016-12-12 18:37:36 -08003413TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3414 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 10:27:41 -08003415 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003416 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003417 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3418 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3419}
3420
deadbeef12771a12017-01-03 13:53:47 -08003421// The semantics of "a=bundle-only" are only defined when it's used in
3422// combination with a 0 port on the m= line. We should ignore it if used with a
3423// nonzero port.
3424TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3425 // Make the base bundle-only description but unset the bundle-only flag.
3426 MakeBundleOnlyDescription();
3427 jdesc_.description()->contents()[1].bundle_only = false;
3428
3429 std::string modified_sdp = kBundleOnlySdpFullString;
3430 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08003431 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003432 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3433 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003434}
3435
3436TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3437 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003438 TestSerialize(jdesc_);
deadbeef25ed4352016-12-12 18:37:36 -08003439}
3440
deadbeef9d3584c2016-02-16 17:54:10 -08003441TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3442 MakePlanBDescription();
3443
Steve Antona3a92c22017-12-07 10:27:41 -08003444 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003445 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3446
3447 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3448}
3449
3450TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3451 MakePlanBDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003452 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-16 17:54:10 -08003453}
3454
3455TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3456 MakeUnifiedPlanDescription();
3457
Steve Antona3a92c22017-12-07 10:27:41 -08003458 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003459 EXPECT_TRUE(
3460 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3461
3462 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3463}
3464
3465TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3466 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003467 TestSerialize(jdesc_);
3468}
3469
Seth Hampson5b4f0752018-04-02 16:31:36 -07003470// This tests deserializing a Unified Plan SDP that is compatible with both
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003471// Unified Plan and Plan B style SDP, meaning that it contains both "a=ssrc
3472// msid" lines and "a=msid " lines. It tests the case for audio/video tracks
Seth Hampson5b4f0752018-04-02 16:31:36 -07003473// with no stream ids and multiple stream ids. For parsing this, the Unified
3474// Plan a=msid lines should take priority, because the Plan B style a=ssrc msid
3475// lines do not support multiple stream ids and no stream ids.
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003476TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionSpecialMsid) {
3477 // Create both msid lines for Plan B and Unified Plan support.
3478 MakeUnifiedPlanDescriptionMultipleStreamIds(
3479 cricket::kMsidSignalingMediaSection |
3480 cricket::kMsidSignalingSsrcAttribute);
Seth Hampson5b4f0752018-04-02 16:31:36 -07003481
3482 JsepSessionDescription deserialized_description(kDummyType);
3483 EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid,
3484 &deserialized_description));
3485
3486 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3487}
3488
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003489// Tests the serialization of a Unified Plan SDP that is compatible for both
3490// Unified Plan and Plan B style SDPs, meaning that it contains both "a=ssrc
3491// msid" lines and "a=msid " lines. It tests the case for no stream ids and
3492// multiple stream ids.
3493TEST_F(WebRtcSdpTest, SerializeSessionDescriptionSpecialMsid) {
3494 // Create both msid lines for Plan B and Unified Plan support.
3495 MakeUnifiedPlanDescriptionMultipleStreamIds(
3496 cricket::kMsidSignalingMediaSection |
3497 cricket::kMsidSignalingSsrcAttribute);
3498 std::string serialized_sdp = webrtc::SdpSerialize(jdesc_);
3499 // We explicitly test that the serialized SDP string is equal to the hard
3500 // coded SDP string. This is necessary, because in the parser "a=msid" lines
3501 // take priority over "a=ssrc msid" lines. This means if we just used
3502 // TestSerialize(), it could serialize an SDP that omits "a=ssrc msid" lines,
3503 // and still pass, because the deserialized version would be the same.
3504 EXPECT_EQ(kUnifiedPlanSdpFullStringWithSpecialMsid, serialized_sdp);
3505}
3506
3507// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3508// that signal stream IDs) is deserialized appropriately. It tests the case for
3509// no stream ids and multiple stream ids.
3510TEST_F(WebRtcSdpTest, UnifiedPlanDeserializeSessionDescriptionSpecialMsid) {
3511 // Only create a=msid lines for strictly Unified Plan stream ID support.
3512 MakeUnifiedPlanDescriptionMultipleStreamIds(
3513 cricket::kMsidSignalingMediaSection);
3514
3515 JsepSessionDescription deserialized_description(kDummyType);
3516 std::string unified_plan_sdp_string =
3517 kUnifiedPlanSdpFullStringWithSpecialMsid;
3518 RemoveSsrcMsidLinesFromSdpString(&unified_plan_sdp_string);
3519 EXPECT_TRUE(
3520 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3521
3522 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3523}
3524
3525// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3526// that signal stream IDs) is serialized appropriately. It tests the case for no
3527// stream ids and multiple stream ids.
3528TEST_F(WebRtcSdpTest, UnifiedPlanSerializeSessionDescriptionSpecialMsid) {
3529 // Only create a=msid lines for strictly Unified Plan stream ID support.
3530 MakeUnifiedPlanDescriptionMultipleStreamIds(
3531 cricket::kMsidSignalingMediaSection);
3532
Seth Hampson5b4f0752018-04-02 16:31:36 -07003533 TestSerialize(jdesc_);
3534}
3535
Seth Hampson5897a6e2018-04-03 11:16:33 -07003536// This tests that a Unified Plan SDP with no a=ssrc lines is
3537// serialized/deserialized appropriately. In this case the
3538// MediaContentDescription will contain a StreamParams object that doesn't have
3539// any SSRCs. Vice versa, this will be created upon deserializing an SDP with no
3540// SSRC lines.
3541TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3542 MakeUnifiedPlanDescription();
3543 RemoveSsrcSignalingFromStreamParams();
3544 std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString;
3545 RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string);
3546
3547 JsepSessionDescription deserialized_description(kDummyType);
3548 EXPECT_TRUE(
3549 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3550 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3551}
3552
3553TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3554 MakeUnifiedPlanDescription();
3555 RemoveSsrcSignalingFromStreamParams();
3556
3557 TestSerialize(jdesc_);
3558}
3559
Steve Antone831b8c2018-02-01 12:22:16 -08003560TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
3561 JsepSessionDescription jsep_desc(kDummyType);
3562 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
3563 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3564}
3565
3566TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
3567 JsepSessionDescription jsep_desc(kDummyType);
3568 std::string sdp = kSdpSessionString;
3569 sdp += kSdpSctpDataChannelString;
3570 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3571 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3572}
3573
3574TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
3575 JsepSessionDescription jsep_desc(kDummyType);
3576 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
3577 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
3578 jsep_desc.description()->msid_signaling());
3579}
3580
3581TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
3582 JsepSessionDescription jsep_desc(kDummyType);
3583 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
3584 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
3585 jsep_desc.description()->msid_signaling());
3586}
3587
3588const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
3589const char kSsrcAttributeMsidLine[] =
3590 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
3591
3592TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
3593 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
3594 std::string sdp = webrtc::SdpSerialize(jdesc_);
3595
3596 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3597 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3598}
3599
3600TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
3601 jdesc_.description()->set_msid_signaling(
3602 cricket::kMsidSignalingSsrcAttribute);
3603 std::string sdp = webrtc::SdpSerialize(jdesc_);
3604
3605 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
3606 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3607}
3608
3609TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
3610 jdesc_.description()->set_msid_signaling(
3611 cricket::kMsidSignalingMediaSection |
3612 cricket::kMsidSignalingSsrcAttribute);
3613 std::string sdp = webrtc::SdpSerialize(jdesc_);
3614
3615 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3616 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-16 17:54:10 -08003617}
deadbeef7e146cb2016-09-28 10:04:34 -07003618
3619// Regression test for heap overflow bug:
3620// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3621TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 10:04:34 -07003622 // The issue occurs when the sctp-port attribute is found in a video
3623 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 12:43:58 -08003624 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 10:04:34 -07003625 "v=0\r\n"
3626 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3627 "s=-\r\n"
3628 "t=0 0\r\n"
3629 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3630 "a=sctp-port 5000\r\n"
3631 "a=fmtp:108 foo=10\r\n";
3632
3633 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3634 "sctp-port");
3635}
deadbeefb2362572016-12-13 16:37:06 -08003636
3637// Regression test for integer overflow bug:
3638// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3639TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003640 // Bandwidth attribute is the max signed 32-bit int, which will get
3641 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003642 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003643 "v=0\r\n"
3644 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3645 "s=-\r\n"
3646 "t=0 0\r\n"
3647 "m=video 3457 RTP/SAVPF 120\r\n"
3648 "b=AS:2147483647\r\n"
3649 "foo=fail\r\n";
3650
3651 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3652}
deadbeef7bcdb692017-01-20 12:43:58 -08003653
deadbeefbc88c6b2017-08-02 11:26:34 -07003654// Similar to the above, except that negative values are illegal, not just
3655// error-prone as large values are.
3656// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3657TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3658 static const char kSdpWithNegativeBandwidth[] =
3659 "v=0\r\n"
3660 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3661 "s=-\r\n"
3662 "t=0 0\r\n"
3663 "m=video 3457 RTP/SAVPF 120\r\n"
3664 "b=AS:-1000\r\n";
3665
3666 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3667}
3668
deadbeef3e8016e2017-08-03 17:49:30 -07003669// An exception to the above rule: a value of -1 for b=AS should just be
3670// ignored, resulting in "kAutoBandwidth" in the deserialized object.
3671// Applications historically may be using "b=AS:-1" to mean "no bandwidth
3672// limit", but this is now what ommitting the attribute entirely will do, so
3673// ignoring it will have the intended effect.
3674TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
3675 static const char kSdpWithBandwidthOfNegativeOne[] =
3676 "v=0\r\n"
3677 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3678 "s=-\r\n"
3679 "t=0 0\r\n"
3680 "m=video 3457 RTP/SAVPF 120\r\n"
3681 "b=AS:-1\r\n";
3682
Steve Antona3a92c22017-12-07 10:27:41 -08003683 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-03 17:49:30 -07003684 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-03 17:49:30 -07003685 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003686 GetFirstVideoContentDescription(jdesc_output.description());
3687 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-03 17:49:30 -07003688 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
3689}
3690
deadbeef7bcdb692017-01-20 12:43:58 -08003691// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3692// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3693// Regression test for:
3694// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3695TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3696 // Important piece is "ufrag foo pwd bar".
3697 static const char kSdpWithIceCredentialsInCandidateString[] =
3698 "v=0\r\n"
3699 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3700 "s=-\r\n"
3701 "t=0 0\r\n"
3702 "m=audio 9 RTP/SAVPF 111\r\n"
3703 "c=IN IP4 0.0.0.0\r\n"
3704 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3705 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3706 "a=rtpmap:111 opus/48000/2\r\n"
3707 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3708 "generation 2 ufrag foo pwd bar\r\n";
3709
Steve Antona3a92c22017-12-07 10:27:41 -08003710 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 12:43:58 -08003711 EXPECT_TRUE(
3712 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
3713 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3714 ASSERT_NE(nullptr, candidates);
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003715 ASSERT_EQ(1U, candidates->count());
deadbeef7bcdb692017-01-20 12:43:58 -08003716 cricket::Candidate c = candidates->at(0)->candidate();
3717 EXPECT_EQ("ufrag_voice", c.username());
3718 EXPECT_EQ("pwd_voice", c.password());
3719}
deadbeef90f1e1e2017-02-10 12:35:05 -08003720
Johannes Kron211856b2018-09-06 12:12:28 +02003721// Test that attribute lines "a=ice-ufrag-something"/"a=ice-pwd-something" are
3722// ignored, and only the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3723// Regression test for:
3724// https://bugs.chromium.org/p/webrtc/issues/detail?id=9712
3725TEST_F(WebRtcSdpTest, AttributeWithPartialMatchingNameIsIgnored) {
3726 static const char kSdpWithFooIceCredentials[] =
3727 "v=0\r\n"
3728 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3729 "s=-\r\n"
3730 "t=0 0\r\n"
3731 "m=audio 9 RTP/SAVPF 111\r\n"
3732 "c=IN IP4 0.0.0.0\r\n"
3733 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3734 "a=ice-ufrag-something:foo\r\na=ice-pwd-something:bar\r\n"
3735 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3736 "a=rtpmap:111 opus/48000/2\r\n"
3737 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3738 "generation 2\r\n";
3739
3740 JsepSessionDescription jdesc_output(kDummyType);
3741 EXPECT_TRUE(SdpDeserialize(kSdpWithFooIceCredentials, &jdesc_output));
3742 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3743 ASSERT_NE(nullptr, candidates);
3744 ASSERT_EQ(1U, candidates->count());
3745 cricket::Candidate c = candidates->at(0)->candidate();
3746 EXPECT_EQ("ufrag_voice", c.username());
3747 EXPECT_EQ("pwd_voice", c.password());
3748}
3749
deadbeef90f1e1e2017-02-10 12:35:05 -08003750// Test that SDP with an invalid port number in "a=candidate" lines is
3751// rejected, without crashing.
3752// Regression test for:
3753// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
3754TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
3755 static const char kSdpWithInvalidCandidatePort[] =
3756 "v=0\r\n"
3757 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3758 "s=-\r\n"
3759 "t=0 0\r\n"
3760 "m=audio 9 RTP/SAVPF 111\r\n"
3761 "c=IN IP4 0.0.0.0\r\n"
3762 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3763 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3764 "a=rtpmap:111 opus/48000/2\r\n"
3765 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
3766 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
3767
Steve Antona3a92c22017-12-07 10:27:41 -08003768 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 12:35:05 -08003769 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
3770}
deadbeefa4549d62017-02-10 17:26:22 -08003771
3772// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
3773// Regression test for:
3774// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
3775TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
3776 static const char kSdpWithMissingTrackId[] =
3777 "v=0\r\n"
3778 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3779 "s=-\r\n"
3780 "t=0 0\r\n"
3781 "m=audio 9 RTP/SAVPF 111\r\n"
3782 "c=IN IP4 0.0.0.0\r\n"
3783 "a=rtpmap:111 opus/48000/2\r\n"
3784 "a=msid:stream_id \r\n";
3785
Steve Antona3a92c22017-12-07 10:27:41 -08003786 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003787 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
3788}
3789
3790TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
3791 static const char kSdpWithMissingStreamId[] =
3792 "v=0\r\n"
3793 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3794 "s=-\r\n"
3795 "t=0 0\r\n"
3796 "m=audio 9 RTP/SAVPF 111\r\n"
3797 "c=IN IP4 0.0.0.0\r\n"
3798 "a=rtpmap:111 opus/48000/2\r\n"
3799 "a=msid: track_id\r\n";
3800
Steve Antona3a92c22017-12-07 10:27:41 -08003801 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003802 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
3803}
zhihuang38989e52017-03-21 11:04:53 -07003804
3805// Tests that if both session-level address and media-level address exist, use
3806// the media-level address.
3807TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 10:27:41 -08003808 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003809
3810 // Sesssion-level address.
3811 std::string sdp = kSdpFullString;
3812 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3813 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3814
3815 const auto& content1 = jsep_desc.description()->contents()[0];
3816 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 15:14:30 -08003817 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003818 const auto& content2 = jsep_desc.description()->contents()[1];
3819 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 15:14:30 -08003820 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003821}
3822
3823// Tests that the session-level connection address will be used if the media
3824// level-addresses are not specified.
3825TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 10:27:41 -08003826 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003827
3828 // Sesssion-level address.
3829 std::string sdp = kSdpString;
3830 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3831 // Remove the media level addresses.
3832 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3833 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3834 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3835
3836 const auto& content1 = jsep_desc.description()->contents()[0];
3837 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003838 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003839 const auto& content2 = jsep_desc.description()->contents()[1];
3840 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003841 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003842}
3843
3844TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 10:27:41 -08003845 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003846
3847 std::string sdp = kSdpString;
3848 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3849 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
3850 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
3851 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
3852 &sdp);
3853 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
3854 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
3855 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
3856 &sdp);
3857 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3858 const auto& content1 = jsep_desc.description()->contents()[0];
3859 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003860 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003861 const auto& content2 = jsep_desc.description()->contents()[1];
3862 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003863 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003864}
3865
3866// Test that the invalid or unsupprted connection data cannot be parsed.
3867TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 10:27:41 -08003868 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003869 std::string sdp = kSdpString;
3870 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3871
3872 // Unsupported multicast IPv4 address.
3873 sdp = kSdpFullString;
3874 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
3875 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3876
3877 // Unsupported multicast IPv6 address.
3878 sdp = kSdpFullString;
3879 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
3880 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3881
3882 // Mismatched address type.
3883 sdp = kSdpFullString;
3884 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
3885 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3886
3887 sdp = kSdpFullString;
3888 Replace("c=IN IP4 74.125.224.39\r\n",
3889 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
3890 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3891}
3892
3893TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 10:27:41 -08003894 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003895 MakeDescriptionWithoutCandidates(&expected_jsep);
3896 // Serialization.
Steve Antone831b8c2018-02-01 12:22:16 -08003897 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 11:04:53 -07003898 // Deserialization.
Steve Antona3a92c22017-12-07 10:27:41 -08003899 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003900 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 15:14:30 -08003901 auto audio_desc = jdesc.description()
3902 ->GetContentByName(kAudioContentName)
3903 ->media_description();
3904 auto video_desc = jdesc.description()
3905 ->GetContentByName(kVideoContentName)
3906 ->media_description();
zhihuang38989e52017-03-21 11:04:53 -07003907 EXPECT_EQ(audio_desc_->connection_address().ToString(),
3908 audio_desc->connection_address().ToString());
3909 EXPECT_EQ(video_desc_->connection_address().ToString(),
3910 video_desc->connection_address().ToString());
3911}
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07003912
3913// RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be
3914// used (i.e., a single space as the session name)." So we should accept that.
3915TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) {
3916 JsepSessionDescription jsep_desc(kDummyType);
3917 std::string sdp = kSdpString;
3918 Replace("s=-\r\n", "s= \r\n", &sdp);
3919 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3920}