blob: e7c5c77bb61ade2b5f948926610257b10965d07a [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2011 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
kwibergd1fe2812016-04-27 06:47:29 -070011#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000012#include <set>
13#include <string>
14#include <vector>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "api/jsepsessiondescription.h"
17#include "media/base/mediaconstants.h"
18#include "media/engine/webrtcvideoengine.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "p2p/base/p2pconstants.h"
Yves Gerey665174f2018-06-19 15:03:05 +020020#include "p2p/base/port.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "pc/mediasession.h"
22#include "rtc_base/checks.h"
23#include "rtc_base/gunit.h"
24#include "rtc_base/logging.h"
Yves Gerey2e00abc2018-10-05 15:39:24 +020025#include "rtc_base/messagedigest.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020026#include "rtc_base/stringencode.h"
27#include "rtc_base/stringutils.h"
Patrik Höglund563934e2017-09-15 09:04:28 +020028
ossu7bb87ee2017-01-23 04:56:25 -080029#ifdef WEBRTC_ANDROID
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020030#include "pc/test/androidtestinitializer.h"
ossu7bb87ee2017-01-23 04:56:25 -080031#endif
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020032#include "pc/webrtcsdp.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000033
34using cricket::AudioCodec;
35using cricket::AudioContentDescription;
36using cricket::Candidate;
37using cricket::ContentInfo;
38using cricket::CryptoParams;
39using cricket::ContentGroup;
40using cricket::DataCodec;
41using cricket::DataContentDescription;
42using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
43using cricket::ICE_CANDIDATE_COMPONENT_RTP;
44using cricket::kFecSsrcGroupSemantics;
45using cricket::LOCAL_PORT_TYPE;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000046using cricket::RELAY_PORT_TYPE;
47using cricket::SessionDescription;
Steve Anton5adfafd2017-12-20 16:34:00 -080048using cricket::MediaProtocolType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049using cricket::StreamParams;
50using cricket::STUN_PORT_TYPE;
51using cricket::TransportDescription;
52using cricket::TransportInfo;
53using cricket::VideoCodec;
54using cricket::VideoContentDescription;
55using webrtc::IceCandidateCollection;
56using webrtc::IceCandidateInterface;
57using webrtc::JsepIceCandidate;
58using webrtc::JsepSessionDescription;
isheriff6f8d6862016-05-26 11:24:55 -070059using webrtc::RtpExtension;
Steve Anton4e70a722017-11-28 14:57:10 -080060using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061using webrtc::SdpParseError;
Steve Antona3a92c22017-12-07 10:27:41 -080062using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063using webrtc::SessionDescriptionInterface;
64
65typedef std::vector<AudioCodec> AudioCodecs;
66typedef std::vector<Candidate> Candidates;
67
Peter Boström0c4e06b2015-10-07 12:23:21 +020068static const uint32_t kDefaultSctpPort = 5000;
zstein4b2e0822017-02-17 19:48:38 -080069static const char kDefaultSctpPortStr[] = "5000";
70static const uint16_t kUnusualSctpPort = 9556;
71static const char kUnusualSctpPortStr[] = "9556";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020073static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 15:17:14 -080074static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 15:17:14 -080076static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020078static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079static const char kCandidateFoundation1[] = "a0+B/1";
80static const char kCandidateFoundation2[] = "a0+B/2";
81static const char kCandidateFoundation3[] = "a0+B/3";
82static const char kCandidateFoundation4[] = "a0+B/4";
83static const char kAttributeCryptoVoice[] =
84 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
85 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
86 "dummy_session_params\r\n";
87static const char kAttributeCryptoVideo[] =
88 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
89 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
Yves Gerey665174f2018-06-19 15:03:05 +020090static const char kFingerprint[] =
91 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092 "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 +020093static const char kExtmapAllowMixed[] = "a=extmap-allow-mixed\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094static const int kExtmapId = 1;
95static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
96static const char kExtmap[] =
97 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
98static const char kExtmapWithDirectionAndAttribute[] =
99 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
jbauch5869f502017-06-29 12:31:36 -0700100static const char kExtmapWithDirectionAndAttributeEncrypted[] =
101 "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt "
102 "http://example.com/082005/ext.htm#ttime a1 a2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103
Peter Boström0c4e06b2015-10-07 12:23:21 +0200104static const uint8_t kIdentityDigest[] = {
105 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
106 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107
lally@webrtc.org34807282015-02-24 20:19:39 +0000108static const char kDtlsSctp[] = "DTLS/SCTP";
109static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
110static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +0000111
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000112struct CodecParams {
113 int max_ptime;
114 int ptime;
115 int min_ptime;
116 int sprop_stereo;
117 int stereo;
118 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000119 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120};
121
deadbeef9d3584c2016-02-16 17:54:10 -0800122// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
123// instead of "a=crypto", and have an explicit test for adding "a=crypto".
124// Currently it's the other way around.
125
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000126// Reference sdp string
127static const char kSdpFullString[] =
128 "v=0\r\n"
129 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
130 "s=-\r\n"
131 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800132 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000133 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
134 "c=IN IP4 74.125.127.126\r\n"
135 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
136 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
137 "generation 2\r\n"
138 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
139 "generation 2\r\n"
140 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
141 "generation 2\r\n"
142 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
143 "generation 2\r\n"
144 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
145 "raddr 192.168.1.5 rport 2346 "
146 "generation 2\r\n"
147 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
148 "raddr 192.168.1.5 rport 2348 "
149 "generation 2\r\n"
150 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
151 "a=mid:audio_content_name\r\n"
152 "a=sendrecv\r\n"
153 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800154 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000155 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
156 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
157 "dummy_session_params\r\n"
158 "a=rtpmap:111 opus/48000/2\r\n"
159 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000160 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000161 "a=ssrc:1 cname:stream_1_cname\r\n"
162 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
163 "a=ssrc:1 mslabel:local_stream_1\r\n"
164 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000165 "m=video 3457 RTP/SAVPF 120\r\n"
166 "c=IN IP4 74.125.224.39\r\n"
167 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
168 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
169 "generation 2\r\n"
170 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
171 "generation 2\r\n"
172 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
173 "generation 2\r\n"
174 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
175 "generation 2\r\n"
176 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
177 "generation 2\r\n"
178 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
179 "generation 2\r\n"
180 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
181 "a=mid:video_content_name\r\n"
182 "a=sendrecv\r\n"
183 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
184 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
185 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800186 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187 "a=ssrc:2 cname:stream_1_cname\r\n"
188 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
189 "a=ssrc:2 mslabel:local_stream_1\r\n"
190 "a=ssrc:2 label:video_track_id_1\r\n"
191 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800192 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000193 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800194 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000195
196// SDP reference string without the candidates.
197static const char kSdpString[] =
198 "v=0\r\n"
199 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
200 "s=-\r\n"
201 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800202 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000203 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000204 "c=IN IP4 0.0.0.0\r\n"
205 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000206 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
207 "a=mid:audio_content_name\r\n"
208 "a=sendrecv\r\n"
209 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800210 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
212 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
213 "dummy_session_params\r\n"
214 "a=rtpmap:111 opus/48000/2\r\n"
215 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000216 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000217 "a=ssrc:1 cname:stream_1_cname\r\n"
218 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
219 "a=ssrc:1 mslabel:local_stream_1\r\n"
220 "a=ssrc:1 label:audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000221 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000222 "c=IN IP4 0.0.0.0\r\n"
223 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000224 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
225 "a=mid:video_content_name\r\n"
226 "a=sendrecv\r\n"
227 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
228 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
229 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800230 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000231 "a=ssrc:2 cname:stream_1_cname\r\n"
232 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
233 "a=ssrc:2 mslabel:local_stream_1\r\n"
234 "a=ssrc:2 label:video_track_id_1\r\n"
235 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800236 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000237 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800238 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000239
240static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000241 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000242 "c=IN IP4 0.0.0.0\r\n"
243 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000244 "a=ice-ufrag:ufrag_data\r\n"
245 "a=ice-pwd:pwd_data\r\n"
246 "a=mid:data_content_name\r\n"
247 "a=sendrecv\r\n"
248 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
249 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
250 "a=rtpmap:101 google-data/90000\r\n"
251 "a=ssrc:10 cname:data_channel_cname\r\n"
252 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
253 "a=ssrc:10 mslabel:data_channel\r\n"
254 "a=ssrc:10 label:data_channeld0\r\n";
255
256static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000257 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000258 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000259 "a=ice-ufrag:ufrag_data\r\n"
260 "a=ice-pwd:pwd_data\r\n"
261 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000262 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000263
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000264// draft-ietf-mmusic-sctp-sdp-12
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000265static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000266 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
267 "a=max-message-size=100000\r\n"
268 "a=sctp-port 5000\r\n"
269 "c=IN IP4 0.0.0.0\r\n"
270 "a=ice-ufrag:ufrag_data\r\n"
271 "a=ice-pwd:pwd_data\r\n"
272 "a=mid:data_content_name\r\n";
273
lally69f57602015-10-08 10:15:04 -0700274static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
275 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
276 "a=max-message-size=100000\r\n"
277 "a=sctp-port:5000\r\n"
278 "c=IN IP4 0.0.0.0\r\n"
279 "a=ice-ufrag:ufrag_data\r\n"
280 "a=ice-pwd:pwd_data\r\n"
281 "a=mid:data_content_name\r\n";
282
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000283static const char kSdpSctpDataChannelWithCandidatesString[] =
284 "m=application 2345 DTLS/SCTP 5000\r\n"
285 "c=IN IP4 74.125.127.126\r\n"
286 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
287 "generation 2\r\n"
288 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
289 "generation 2\r\n"
290 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
291 "raddr 192.168.1.5 rport 2346 "
292 "generation 2\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"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000296 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000297
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000298static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000299 "v=0\r\n"
300 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
301 "s=-\r\n"
302 "t=0 0\r\n"
303 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000304 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000305 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000306 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000307 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000308 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000309 "a=x-google-flag:conference\r\n";
310
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000311static const char kSdpSessionString[] =
312 "v=0\r\n"
313 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
314 "s=-\r\n"
315 "t=0 0\r\n"
316 "a=msid-semantic: WMS local_stream\r\n";
317
318static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000319 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000320 "c=IN IP4 0.0.0.0\r\n"
321 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000322 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
323 "a=mid:audio_content_name\r\n"
324 "a=sendrecv\r\n"
325 "a=rtpmap:111 opus/48000/2\r\n"
326 "a=ssrc:1 cname:stream_1_cname\r\n"
327 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
328 "a=ssrc:1 mslabel:local_stream\r\n"
329 "a=ssrc:1 label:audio_track_id_1\r\n";
330
331static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000332 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000333 "c=IN IP4 0.0.0.0\r\n"
334 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000335 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
336 "a=mid:video_content_name\r\n"
337 "a=sendrecv\r\n"
338 "a=rtpmap:120 VP8/90000\r\n"
339 "a=ssrc:2 cname:stream_1_cname\r\n"
340 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
341 "a=ssrc:2 mslabel:local_stream\r\n"
342 "a=ssrc:2 label:video_track_id_1\r\n";
343
deadbeef25ed4352016-12-12 18:37:36 -0800344// Reference sdp string using bundle-only.
345static const char kBundleOnlySdpFullString[] =
346 "v=0\r\n"
347 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
348 "s=-\r\n"
349 "t=0 0\r\n"
350 "a=group:BUNDLE audio_content_name video_content_name\r\n"
351 "a=msid-semantic: WMS local_stream_1\r\n"
352 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
353 "c=IN IP4 74.125.127.126\r\n"
354 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
355 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
356 "generation 2\r\n"
357 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
358 "generation 2\r\n"
359 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
360 "generation 2\r\n"
361 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
362 "generation 2\r\n"
363 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
364 "raddr 192.168.1.5 rport 2346 "
365 "generation 2\r\n"
366 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
367 "raddr 192.168.1.5 rport 2348 "
368 "generation 2\r\n"
369 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
370 "a=mid:audio_content_name\r\n"
371 "a=sendrecv\r\n"
372 "a=rtcp-mux\r\n"
373 "a=rtcp-rsize\r\n"
374 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
375 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
376 "dummy_session_params\r\n"
377 "a=rtpmap:111 opus/48000/2\r\n"
378 "a=rtpmap:103 ISAC/16000\r\n"
379 "a=rtpmap:104 ISAC/32000\r\n"
380 "a=ssrc:1 cname:stream_1_cname\r\n"
381 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
382 "a=ssrc:1 mslabel:local_stream_1\r\n"
383 "a=ssrc:1 label:audio_track_id_1\r\n"
384 "m=video 0 RTP/SAVPF 120\r\n"
385 "c=IN IP4 0.0.0.0\r\n"
386 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
387 "a=bundle-only\r\n"
388 "a=mid:video_content_name\r\n"
389 "a=sendrecv\r\n"
390 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
391 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
392 "a=rtpmap:120 VP8/90000\r\n"
393 "a=ssrc-group:FEC 2 3\r\n"
394 "a=ssrc:2 cname:stream_1_cname\r\n"
395 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
396 "a=ssrc:2 mslabel:local_stream_1\r\n"
397 "a=ssrc:2 label:video_track_id_1\r\n"
398 "a=ssrc:3 cname:stream_1_cname\r\n"
399 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
400 "a=ssrc:3 mslabel:local_stream_1\r\n"
401 "a=ssrc:3 label:video_track_id_1\r\n";
402
deadbeef9d3584c2016-02-16 17:54:10 -0800403// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
404// tracks.
405static const char kPlanBSdpFullString[] =
406 "v=0\r\n"
407 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
408 "s=-\r\n"
409 "t=0 0\r\n"
410 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
411 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
412 "c=IN IP4 74.125.127.126\r\n"
413 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
414 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
415 "generation 2\r\n"
416 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
417 "generation 2\r\n"
418 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
419 "generation 2\r\n"
420 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
421 "generation 2\r\n"
422 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
423 "raddr 192.168.1.5 rport 2346 "
424 "generation 2\r\n"
425 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
426 "raddr 192.168.1.5 rport 2348 "
427 "generation 2\r\n"
428 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
429 "a=mid:audio_content_name\r\n"
430 "a=sendrecv\r\n"
431 "a=rtcp-mux\r\n"
432 "a=rtcp-rsize\r\n"
433 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
434 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
435 "dummy_session_params\r\n"
436 "a=rtpmap:111 opus/48000/2\r\n"
437 "a=rtpmap:103 ISAC/16000\r\n"
438 "a=rtpmap:104 ISAC/32000\r\n"
439 "a=ssrc:1 cname:stream_1_cname\r\n"
440 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
441 "a=ssrc:1 mslabel:local_stream_1\r\n"
442 "a=ssrc:1 label:audio_track_id_1\r\n"
443 "a=ssrc:4 cname:stream_2_cname\r\n"
444 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
445 "a=ssrc:4 mslabel:local_stream_2\r\n"
446 "a=ssrc:4 label:audio_track_id_2\r\n"
447 "m=video 3457 RTP/SAVPF 120\r\n"
448 "c=IN IP4 74.125.224.39\r\n"
449 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
450 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
451 "generation 2\r\n"
452 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
453 "generation 2\r\n"
454 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
455 "generation 2\r\n"
456 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
457 "generation 2\r\n"
458 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
459 "generation 2\r\n"
460 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
461 "generation 2\r\n"
462 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
463 "a=mid:video_content_name\r\n"
464 "a=sendrecv\r\n"
465 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
466 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
467 "a=rtpmap:120 VP8/90000\r\n"
468 "a=ssrc-group:FEC 2 3\r\n"
469 "a=ssrc:2 cname:stream_1_cname\r\n"
470 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
471 "a=ssrc:2 mslabel:local_stream_1\r\n"
472 "a=ssrc:2 label:video_track_id_1\r\n"
473 "a=ssrc:3 cname:stream_1_cname\r\n"
474 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
475 "a=ssrc:3 mslabel:local_stream_1\r\n"
476 "a=ssrc:3 label:video_track_id_1\r\n"
477 "a=ssrc:5 cname:stream_2_cname\r\n"
478 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
479 "a=ssrc:5 mslabel:local_stream_2\r\n"
480 "a=ssrc:5 label:video_track_id_2\r\n"
481 "a=ssrc:6 cname:stream_2_cname\r\n"
482 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
483 "a=ssrc:6 mslabel:local_stream_2\r\n"
484 "a=ssrc:6 label:video_track_id_3\r\n";
485
486// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
487// tracks.
488static const char kUnifiedPlanSdpFullString[] =
489 "v=0\r\n"
490 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
491 "s=-\r\n"
492 "t=0 0\r\n"
493 "a=msid-semantic: WMS local_stream_1\r\n"
494 // Audio track 1, stream 1 (with candidates).
495 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
496 "c=IN IP4 74.125.127.126\r\n"
497 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
498 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
499 "generation 2\r\n"
500 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
501 "generation 2\r\n"
502 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
503 "generation 2\r\n"
504 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
505 "generation 2\r\n"
506 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
507 "raddr 192.168.1.5 rport 2346 "
508 "generation 2\r\n"
509 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
510 "raddr 192.168.1.5 rport 2348 "
511 "generation 2\r\n"
512 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
513 "a=mid:audio_content_name\r\n"
514 "a=msid:local_stream_1 audio_track_id_1\r\n"
515 "a=sendrecv\r\n"
516 "a=rtcp-mux\r\n"
517 "a=rtcp-rsize\r\n"
518 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
519 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
520 "dummy_session_params\r\n"
521 "a=rtpmap:111 opus/48000/2\r\n"
522 "a=rtpmap:103 ISAC/16000\r\n"
523 "a=rtpmap:104 ISAC/32000\r\n"
524 "a=ssrc:1 cname:stream_1_cname\r\n"
525 // Video track 1, stream 1 (with candidates).
526 "m=video 3457 RTP/SAVPF 120\r\n"
527 "c=IN IP4 74.125.224.39\r\n"
528 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
529 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
530 "generation 2\r\n"
531 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
532 "generation 2\r\n"
533 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
534 "generation 2\r\n"
535 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
536 "generation 2\r\n"
537 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
538 "generation 2\r\n"
539 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
540 "generation 2\r\n"
541 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
542 "a=mid:video_content_name\r\n"
543 "a=msid:local_stream_1 video_track_id_1\r\n"
544 "a=sendrecv\r\n"
545 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
546 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
547 "a=rtpmap:120 VP8/90000\r\n"
548 "a=ssrc-group:FEC 2 3\r\n"
549 "a=ssrc:2 cname:stream_1_cname\r\n"
550 "a=ssrc:3 cname:stream_1_cname\r\n"
551 // Audio track 2, stream 2.
552 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
553 "c=IN IP4 0.0.0.0\r\n"
554 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
555 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
556 "a=mid:audio_content_name_2\r\n"
557 "a=msid:local_stream_2 audio_track_id_2\r\n"
558 "a=sendrecv\r\n"
559 "a=rtcp-mux\r\n"
560 "a=rtcp-rsize\r\n"
561 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
562 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
563 "dummy_session_params\r\n"
564 "a=rtpmap:111 opus/48000/2\r\n"
565 "a=rtpmap:103 ISAC/16000\r\n"
566 "a=rtpmap:104 ISAC/32000\r\n"
567 "a=ssrc:4 cname:stream_2_cname\r\n"
568 // Video track 2, stream 2.
569 "m=video 9 RTP/SAVPF 120\r\n"
570 "c=IN IP4 0.0.0.0\r\n"
571 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
572 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
573 "a=mid:video_content_name_2\r\n"
574 "a=msid:local_stream_2 video_track_id_2\r\n"
575 "a=sendrecv\r\n"
576 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
577 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
578 "a=rtpmap:120 VP8/90000\r\n"
579 "a=ssrc:5 cname:stream_2_cname\r\n"
580 // Video track 3, stream 2.
581 "m=video 9 RTP/SAVPF 120\r\n"
582 "c=IN IP4 0.0.0.0\r\n"
583 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
584 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
585 "a=mid:video_content_name_3\r\n"
586 "a=msid:local_stream_2 video_track_id_3\r\n"
587 "a=sendrecv\r\n"
588 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
589 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
590 "a=rtpmap:120 VP8/90000\r\n"
591 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000592
Seth Hampson5b4f0752018-04-02 16:31:36 -0700593// Unified Plan SDP reference string:
594// - audio track 1 has 1 a=msid lines
595// - audio track 2 has 2 a=msid lines
596// - audio track 3 has 1 a=msid line with the special "-" marker signifying that
597// there are 0 media stream ids.
598// This Unified Plan SDP represents a SDP that signals the msid using both
599// a=msid and a=ssrc msid semantics.
600static const char kUnifiedPlanSdpFullStringWithSpecialMsid[] =
601 "v=0\r\n"
602 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
603 "s=-\r\n"
604 "t=0 0\r\n"
605 "a=msid-semantic: WMS local_stream_1\r\n"
606 // Audio track 1, with 1 stream id.
607 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
608 "c=IN IP4 74.125.127.126\r\n"
609 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
610 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
611 "generation 2\r\n"
612 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
613 "generation 2\r\n"
614 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
615 "generation 2\r\n"
616 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
617 "generation 2\r\n"
618 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
619 "raddr 192.168.1.5 rport 2346 "
620 "generation 2\r\n"
621 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
622 "raddr 192.168.1.5 rport 2348 "
623 "generation 2\r\n"
624 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
625 "a=mid:audio_content_name\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700626 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700627 "a=msid:local_stream_1 audio_track_id_1\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700628 "a=rtcp-mux\r\n"
629 "a=rtcp-rsize\r\n"
630 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
631 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
632 "dummy_session_params\r\n"
633 "a=rtpmap:111 opus/48000/2\r\n"
634 "a=rtpmap:103 ISAC/16000\r\n"
635 "a=rtpmap:104 ISAC/32000\r\n"
636 "a=ssrc:1 cname:stream_1_cname\r\n"
637 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
638 "a=ssrc:1 mslabel:local_stream_1\r\n"
639 "a=ssrc:1 label:audio_track_id_1\r\n"
640 // Audio track 2, with two stream ids.
641 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
642 "c=IN IP4 0.0.0.0\r\n"
643 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
644 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
645 "a=mid:audio_content_name_2\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700646 "a=sendrecv\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700647 "a=msid:local_stream_1 audio_track_id_2\r\n"
648 "a=msid:local_stream_2 audio_track_id_2\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700649 "a=rtcp-mux\r\n"
650 "a=rtcp-rsize\r\n"
651 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
652 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
653 "dummy_session_params\r\n"
654 "a=rtpmap:111 opus/48000/2\r\n"
655 "a=rtpmap:103 ISAC/16000\r\n"
656 "a=rtpmap:104 ISAC/32000\r\n"
657 "a=ssrc:4 cname:stream_1_cname\r\n"
658 // The support for Plan B msid signaling only includes the
659 // first media stream id "local_stream_1."
660 "a=ssrc:4 msid:local_stream_1 audio_track_id_2\r\n"
661 "a=ssrc:4 mslabel:local_stream_1\r\n"
662 "a=ssrc:4 label:audio_track_id_2\r\n"
663 // Audio track 3, with no stream ids.
664 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
665 "c=IN IP4 0.0.0.0\r\n"
666 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
667 "a=ice-ufrag:ufrag_voice_3\r\na=ice-pwd:pwd_voice_3\r\n"
668 "a=mid:audio_content_name_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700669 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700670 "a=msid:- audio_track_id_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700671 "a=rtcp-mux\r\n"
672 "a=rtcp-rsize\r\n"
673 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
674 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
675 "dummy_session_params\r\n"
676 "a=rtpmap:111 opus/48000/2\r\n"
677 "a=rtpmap:103 ISAC/16000\r\n"
678 "a=rtpmap:104 ISAC/32000\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700679 "a=ssrc:7 cname:stream_2_cname\r\n"
680 "a=ssrc:7 msid:- audio_track_id_3\r\n"
681 "a=ssrc:7 mslabel:-\r\n"
682 "a=ssrc:7 label:audio_track_id_3\r\n";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700683
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000684// One candidate reference string as per W3c spec.
685// candidate:<blah> not a=candidate:<blah>CRLF
686static const char kRawCandidate[] =
687 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
688// One candidate reference string.
689static const char kSdpOneCandidate[] =
690 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
691 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000692
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000693static const char kSdpTcpActiveCandidate[] =
694 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
695 "tcptype active generation 2";
696static const char kSdpTcpPassiveCandidate[] =
697 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
698 "tcptype passive generation 2";
699static const char kSdpTcpSOCandidate[] =
700 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
701 "tcptype so generation 2";
702static const char kSdpTcpInvalidCandidate[] =
703 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
704 "tcptype invalid generation 2";
705
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000706// One candidate reference string with IPV6 address.
707static const char kRawIPV6Candidate[] =
708 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 12:04:36 -0700709 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000710
711// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800712static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000713 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800714 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000715
Zach Steinb336c272018-08-09 01:16:13 -0700716static const char kRawHostnameCandidate[] =
717 "candidate:a0+B/1 1 udp 2130706432 a.test 1234 typ host generation 2";
718
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000719// Session id and version
720static const char kSessionId[] = "18446744069414584320";
721static const char kSessionVersion[] = "18446462598732840960";
722
deadbeef9d3584c2016-02-16 17:54:10 -0800723// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000724static const char kIceOption1[] = "iceoption1";
725static const char kIceOption2[] = "iceoption2";
726static const char kIceOption3[] = "iceoption3";
727
deadbeef9d3584c2016-02-16 17:54:10 -0800728// ICE ufrags/passwords.
729static const char kUfragVoice[] = "ufrag_voice";
730static const char kPwdVoice[] = "pwd_voice";
731static const char kUfragVideo[] = "ufrag_video";
732static const char kPwdVideo[] = "pwd_video";
733static const char kUfragData[] = "ufrag_data";
734static const char kPwdData[] = "pwd_data";
735
736// Extra ufrags/passwords for extra unified plan m= sections.
737static const char kUfragVoice2[] = "ufrag_voice_2";
738static const char kPwdVoice2[] = "pwd_voice_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700739static const char kUfragVoice3[] = "ufrag_voice_3";
740static const char kPwdVoice3[] = "pwd_voice_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800741static const char kUfragVideo2[] = "ufrag_video_2";
742static const char kPwdVideo2[] = "pwd_video_2";
743static const char kUfragVideo3[] = "ufrag_video_3";
744static const char kPwdVideo3[] = "pwd_video_3";
745
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000746// Content name
747static const char kAudioContentName[] = "audio_content_name";
748static const char kVideoContentName[] = "video_content_name";
749static const char kDataContentName[] = "data_content_name";
750
deadbeef9d3584c2016-02-16 17:54:10 -0800751// Extra content names for extra unified plan m= sections.
752static const char kAudioContentName2[] = "audio_content_name_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700753static const char kAudioContentName3[] = "audio_content_name_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800754static const char kVideoContentName2[] = "video_content_name_2";
755static const char kVideoContentName3[] = "video_content_name_3";
756
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000757// MediaStream 1
Seth Hampson845e8782018-03-02 11:34:10 -0800758static const char kStreamId1[] = "local_stream_1";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000759static const char kStream1Cname[] = "stream_1_cname";
760static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200761static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000762static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800763static const uint32_t kVideoTrack1Ssrc1 = 2;
764static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000765
766// MediaStream 2
Seth Hampson845e8782018-03-02 11:34:10 -0800767static const char kStreamId2[] = "local_stream_2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000768static const char kStream2Cname[] = "stream_2_cname";
769static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200770static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800771static const char kVideoTrackId2[] = "video_track_id_2";
772static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000773static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800774static const uint32_t kVideoTrack3Ssrc = 6;
Seth Hampson5b4f0752018-04-02 16:31:36 -0700775static const char kAudioTrackId3[] = "audio_track_id_3";
776static const uint32_t kAudioTrack3Ssrc = 7;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000777
778// DataChannel
779static const char kDataChannelLabel[] = "data_channel";
780static const char kDataChannelMsid[] = "data_channeld0";
781static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200782static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000783
784// Candidate
785static const char kDummyMid[] = "dummy_mid";
786static const int kDummyIndex = 123;
787
788// Misc
Steve Antona3a92c22017-12-07 10:27:41 -0800789static SdpType kDummyType = SdpType::kOffer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000790
791// Helper functions
792
793static bool SdpDeserialize(const std::string& message,
794 JsepSessionDescription* jdesc) {
795 return webrtc::SdpDeserialize(message, jdesc, NULL);
796}
797
798static bool SdpDeserializeCandidate(const std::string& message,
799 JsepIceCandidate* candidate) {
800 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
801}
802
803// Add some extra |newlines| to the |message| after |line|.
804static void InjectAfter(const std::string& line,
805 const std::string& newlines,
806 std::string* message) {
807 const std::string tmp = line + newlines;
Yves Gerey665174f2018-06-19 15:03:05 +0200808 rtc::replace_substrs(line.c_str(), line.length(), tmp.c_str(), tmp.length(),
809 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000810}
811
812static void Replace(const std::string& line,
813 const std::string& newlines,
814 std::string* message) {
Yves Gerey665174f2018-06-19 15:03:05 +0200815 rtc::replace_substrs(line.c_str(), line.length(), newlines.c_str(),
816 newlines.length(), message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000817}
818
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000819// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
820// message.
821static void ExpectParseFailure(const std::string& bad_sdp,
822 const std::string& bad_part) {
Steve Antona3a92c22017-12-07 10:27:41 -0800823 JsepSessionDescription desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000824 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000825 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000826 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000827 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
828}
829
830// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
831static void ExpectParseFailure(const char* good_part, const char* bad_part) {
832 std::string bad_sdp = kSdpFullString;
833 Replace(good_part, bad_part, &bad_sdp);
834 ExpectParseFailure(bad_sdp, bad_part);
835}
836
837// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
838static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
839 const std::string& newlines,
840 const std::string& bad_part) {
841 std::string bad_sdp = kSdpFullString;
842 InjectAfter(injectpoint, newlines, &bad_sdp);
843 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844}
845
Steve Anton4e70a722017-11-28 14:57:10 -0800846static void ReplaceDirection(RtpTransceiverDirection direction,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000847 std::string* message) {
848 std::string new_direction;
849 switch (direction) {
Steve Anton4e70a722017-11-28 14:57:10 -0800850 case RtpTransceiverDirection::kInactive:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000851 new_direction = "a=inactive";
852 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800853 case RtpTransceiverDirection::kSendOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854 new_direction = "a=sendonly";
855 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800856 case RtpTransceiverDirection::kRecvOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000857 new_direction = "a=recvonly";
858 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800859 case RtpTransceiverDirection::kSendRecv:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000860 default:
861 new_direction = "a=sendrecv";
862 break;
863 }
864 Replace("a=sendrecv", new_direction, message);
865}
866
Yves Gerey665174f2018-06-19 15:03:05 +0200867static void ReplaceRejected(bool audio_rejected,
868 bool video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000869 std::string* message) {
870 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800871 Replace("m=audio 9", "m=audio 0", message);
872 Replace(kAttributeIceUfragVoice, "", message);
873 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000874 }
875 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800876 Replace("m=video 9", "m=video 0", message);
877 Replace(kAttributeIceUfragVideo, "", message);
878 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000879 }
880}
881
882// WebRtcSdpTest
883
884class WebRtcSdpTest : public testing::Test {
885 public:
Steve Antona3a92c22017-12-07 10:27:41 -0800886 WebRtcSdpTest() : jdesc_(kDummyType) {
phoglund37ebcf02016-01-08 05:04:57 -0800887#ifdef WEBRTC_ANDROID
888 webrtc::InitializeAndroidObjects();
889#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890 // AudioContentDescription
891 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -0800892 StreamParams audio_stream;
893 audio_stream.id = kAudioTrackId1;
894 audio_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -0800895 audio_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -0800896 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
897 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 11:04:53 -0700898 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
899 audio_desc_->set_connection_address(audio_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -0800900 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000901
902 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -0800903 video_desc_ = CreateVideoContentDescription();
904 StreamParams video_stream;
905 video_stream.id = kVideoTrackId1;
906 video_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -0800907 video_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -0800908 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
909 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
910 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
911 video_stream.ssrc_groups.push_back(ssrc_group);
912 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 11:04:53 -0700913 rtc::SocketAddress video_addr("74.125.224.39", 3457);
914 video_desc_->set_connection_address(video_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -0800915 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000916
917 // TransportInfo
deadbeef9d3584c2016-02-16 17:54:10 -0800918 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
919 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice))));
920 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
921 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000922
923 // v4 host
924 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000925 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000926 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000927 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
928 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000929 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000930 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000931 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
932 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000934 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000935 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
936 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000937 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000938 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000939 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
940 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000941
942 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000943 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000944 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
945 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000946 cricket::LOCAL_PORT_TYPE,
947 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000948 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000949 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
950 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000951 cricket::LOCAL_PORT_TYPE,
952 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000953 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000954 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
955 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000956 cricket::LOCAL_PORT_TYPE,
957 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000958 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000959 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
960 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000961 cricket::LOCAL_PORT_TYPE,
962 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000963
964 // stun
965 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000966 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
967 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000968 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
969 address_stun, kCandidatePriority, "", "",
970 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000971 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000972 candidate9.set_related_address(rel_address_stun);
973
974 address_stun.SetPort(port_stun++);
975 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000976 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
977 address_stun, kCandidatePriority, "", "",
978 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000979 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000980 candidate10.set_related_address(rel_address_stun);
981
982 // relay
983 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000984 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000985 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
986 address_relay, kCandidatePriority, "", "",
987 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000988 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000989 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000990 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
991 address_relay, kCandidatePriority, "", "",
992 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000993 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000994
995 // voice
996 candidates_.push_back(candidate1);
997 candidates_.push_back(candidate2);
998 candidates_.push_back(candidate5);
999 candidates_.push_back(candidate6);
1000 candidates_.push_back(candidate9);
1001 candidates_.push_back(candidate10);
1002
1003 // video
1004 candidates_.push_back(candidate3);
1005 candidates_.push_back(candidate4);
1006 candidates_.push_back(candidate7);
1007 candidates_.push_back(candidate8);
1008 candidates_.push_back(candidate11);
1009 candidates_.push_back(candidate12);
1010
Yves Gerey665174f2018-06-19 15:03:05 +02001011 jcandidate_.reset(
1012 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001013
1014 // Set up JsepSessionDescription.
1015 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
1016 std::string mline_id;
1017 int mline_index = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001018 for (size_t i = 0; i < candidates_.size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001019 // In this test, the audio m line index will be 0, and the video m line
1020 // will be 1.
1021 bool is_video = (i > 5);
1022 mline_id = is_video ? "video_content_name" : "audio_content_name";
1023 mline_index = is_video ? 1 : 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001024 JsepIceCandidate jice(mline_id, mline_index, candidates_.at(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001025 jdesc_.AddCandidate(&jice);
1026 }
1027 }
1028
Seth Hampson5b4f0752018-04-02 16:31:36 -07001029 void RemoveVideoCandidates() {
deadbeef25ed4352016-12-12 18:37:36 -08001030 const IceCandidateCollection* video_candidates_collection =
1031 jdesc_.candidates(1);
1032 ASSERT_NE(nullptr, video_candidates_collection);
1033 std::vector<cricket::Candidate> video_candidates;
1034 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1035 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1036 c.set_transport_name("video_content_name");
1037 video_candidates.push_back(c);
1038 }
1039 jdesc_.RemoveCandidates(video_candidates);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001040 }
1041
1042 // Turns the existing reference description into a description using
1043 // a=bundle-only. This means no transport attributes and a 0 port value on
1044 // the m= sections not associated with the BUNDLE-tag.
1045 void MakeBundleOnlyDescription() {
1046 RemoveVideoCandidates();
deadbeef25ed4352016-12-12 18:37:36 -08001047
1048 // And the rest of the transport attributes.
1049 desc_.transport_infos()[1].description.ice_ufrag.clear();
1050 desc_.transport_infos()[1].description.ice_pwd.clear();
1051 desc_.transport_infos()[1].description.connection_role =
1052 cricket::CONNECTIONROLE_NONE;
1053
1054 // Set bundle-only flag.
1055 desc_.contents()[1].bundle_only = true;
1056
1057 // Add BUNDLE group.
1058 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1059 group.AddContentName(kAudioContentName);
1060 group.AddContentName(kVideoContentName);
1061 desc_.AddGroup(group);
1062
1063 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1064 jdesc_.session_version()));
1065 }
1066
deadbeef9d3584c2016-02-16 17:54:10 -08001067 // Turns the existing reference description into a plan B description,
1068 // with 2 audio tracks and 3 video tracks.
1069 void MakePlanBDescription() {
Steve Antonb1c1de12017-12-21 15:14:30 -08001070 audio_desc_ = audio_desc_->Copy();
1071 video_desc_ = video_desc_->Copy();
deadbeef9d3584c2016-02-16 17:54:10 -08001072
1073 StreamParams audio_track_2;
1074 audio_track_2.id = kAudioTrackId2;
1075 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001076 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001077 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1078 audio_desc_->AddStream(audio_track_2);
1079
1080 StreamParams video_track_2;
1081 video_track_2.id = kVideoTrackId2;
1082 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001083 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001084 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1085 video_desc_->AddStream(video_track_2);
1086
1087 StreamParams video_track_3;
1088 video_track_3.id = kVideoTrackId3;
1089 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001090 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001091 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1092 video_desc_->AddStream(video_track_3);
1093
1094 desc_.RemoveContentByName(kAudioContentName);
1095 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001096 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1097 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001098
1099 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1100 jdesc_.session_version()));
1101 }
1102
1103 // Turns the existing reference description into a unified plan description,
1104 // with 2 audio tracks and 3 video tracks.
1105 void MakeUnifiedPlanDescription() {
1106 // Audio track 2.
1107 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1108 StreamParams audio_track_2;
1109 audio_track_2.id = kAudioTrackId2;
1110 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001111 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001112 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1113 audio_desc_2->AddStream(audio_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001114 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
deadbeef9d3584c2016-02-16 17:54:10 -08001115 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1116 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
deadbeef9d3584c2016-02-16 17:54:10 -08001117 // Video track 2, in stream 2.
1118 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1119 StreamParams video_track_2;
1120 video_track_2.id = kVideoTrackId2;
1121 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001122 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001123 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1124 video_desc_2->AddStream(video_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001125 desc_.AddContent(kVideoContentName2, MediaProtocolType::kRtp, video_desc_2);
deadbeef9d3584c2016-02-16 17:54:10 -08001126 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1127 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2))));
1128
1129 // Video track 3, in stream 2.
1130 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1131 StreamParams video_track_3;
1132 video_track_3.id = kVideoTrackId3;
1133 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001134 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001135 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1136 video_desc_3->AddStream(video_track_3);
Steve Anton5adfafd2017-12-20 16:34:00 -08001137 desc_.AddContent(kVideoContentName3, MediaProtocolType::kRtp, video_desc_3);
deadbeef9d3584c2016-02-16 17:54:10 -08001138 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1139 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3))));
Steve Antone831b8c2018-02-01 12:22:16 -08001140 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
deadbeef9d3584c2016-02-16 17:54:10 -08001141
1142 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1143 jdesc_.session_version()));
1144 }
1145
1146 // Creates an audio content description with no streams, and some default
1147 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001148 AudioContentDescription* CreateAudioContentDescription() {
1149 AudioContentDescription* audio = new AudioContentDescription();
1150 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -08001151 audio->set_rtcp_reduced_size(true);
Yves Gerey665174f2018-06-19 15:03:05 +02001152 audio->AddCrypto(CryptoParams(
1153 1, "AES_CM_128_HMAC_SHA1_32",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001154 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1155 "dummy_session_params"));
1156 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef67cf2c12016-04-13 10:07:16 -07001157 AudioCodec opus(111, "opus", 48000, 0, 2);
deadbeef9d3584c2016-02-16 17:54:10 -08001158 audio->AddCodec(opus);
ossue1405ad2017-01-23 08:55:48 -08001159 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1160 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001161 return audio;
1162 }
1163
Seth Hampson5b4f0752018-04-02 16:31:36 -07001164 // Turns the existing reference description into a unified plan description,
1165 // with 3 audio MediaContentDescriptions with special StreamParams that
1166 // contain 0 or multiple stream ids: - audio track 1 has 1 media stream id -
1167 // audio track 2 has 2 media stream ids - audio track 3 has 0 media stream ids
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001168 void MakeUnifiedPlanDescriptionMultipleStreamIds(const int msid_signaling) {
Seth Hampson5b4f0752018-04-02 16:31:36 -07001169 desc_.RemoveContentByName(kVideoContentName);
1170 desc_.RemoveTransportInfoByName(kVideoContentName);
1171 RemoveVideoCandidates();
1172
1173 // Audio track 2 has 2 media stream ids.
1174 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1175 StreamParams audio_track_2;
1176 audio_track_2.id = kAudioTrackId2;
1177 audio_track_2.cname = kStream1Cname;
1178 audio_track_2.set_stream_ids({kStreamId1, kStreamId2});
1179 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1180 audio_desc_2->AddStream(audio_track_2);
1181 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
1182 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1183 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
1184
1185 // Audio track 3 has no stream ids.
1186 AudioContentDescription* audio_desc_3 = CreateAudioContentDescription();
1187 StreamParams audio_track_3;
1188 audio_track_3.id = kAudioTrackId3;
1189 audio_track_3.cname = kStream2Cname;
1190 audio_track_3.set_stream_ids({});
1191 audio_track_3.ssrcs.push_back(kAudioTrack3Ssrc);
1192 audio_desc_3->AddStream(audio_track_3);
1193 desc_.AddContent(kAudioContentName3, MediaProtocolType::kRtp, audio_desc_3);
1194 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1195 kAudioContentName3, TransportDescription(kUfragVoice3, kPwdVoice3))));
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001196 desc_.set_msid_signaling(msid_signaling);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001197 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1198 jdesc_.session_version()));
1199 }
1200
Seth Hampson5897a6e2018-04-03 11:16:33 -07001201 // Turns the existing reference description into a unified plan description
1202 // with one audio MediaContentDescription that contains one StreamParams with
1203 // 0 ssrcs.
1204 void MakeUnifiedPlanDescriptionNoSsrcSignaling() {
1205 desc_.RemoveContentByName(kVideoContentName);
1206 desc_.RemoveContentByName(kAudioContentName);
1207 desc_.RemoveTransportInfoByName(kVideoContentName);
1208 RemoveVideoCandidates();
1209
1210 AudioContentDescription* audio_desc = CreateAudioContentDescription();
1211 StreamParams audio_track;
1212 audio_track.id = kAudioTrackId1;
1213 audio_track.set_stream_ids({kStreamId1});
1214 audio_desc->AddStream(audio_track);
1215 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc);
1216
1217 // Enable signaling a=msid lines.
1218 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
1219 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1220 jdesc_.session_version()));
1221 }
1222
deadbeef9d3584c2016-02-16 17:54:10 -08001223 // Creates a video content description with no streams, and some default
1224 // configuration.
1225 VideoContentDescription* CreateVideoContentDescription() {
1226 VideoContentDescription* video = new VideoContentDescription();
1227 video->AddCrypto(CryptoParams(
1228 1, "AES_CM_128_HMAC_SHA1_80",
1229 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1230 video->set_protocol(cricket::kMediaProtocolSavpf);
1231 video->AddCodec(
perkj26752742016-10-24 01:21:16 -07001232 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-16 17:54:10 -08001233 return video;
1234 }
1235
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001236 template <class MCD>
Yves Gerey665174f2018-06-19 15:03:05 +02001237 void CompareMediaContentDescription(const MCD* cd1, const MCD* cd2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001238 // type
1239 EXPECT_EQ(cd1->type(), cd1->type());
1240
1241 // content direction
1242 EXPECT_EQ(cd1->direction(), cd2->direction());
1243
1244 // rtcp_mux
1245 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1246
deadbeef13871492015-12-09 12:37:51 -08001247 // rtcp_reduced_size
1248 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1249
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001250 // cryptos
1251 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1252 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1253 ADD_FAILURE();
1254 return;
1255 }
Yves Gerey665174f2018-06-19 15:03:05 +02001256 for (size_t i = 0; i < cd1->cryptos().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001257 const CryptoParams c1 = cd1->cryptos().at(i);
1258 const CryptoParams c2 = cd2->cryptos().at(i);
1259 EXPECT_TRUE(c1.Matches(c2));
1260 EXPECT_EQ(c1.key_params, c2.key_params);
1261 EXPECT_EQ(c1.session_params, c2.session_params);
1262 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001263
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001264 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001265 // Use an equivalence class here, for old and new versions of the
1266 // protocol description.
Yves Gerey665174f2018-06-19 15:03:05 +02001267 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp ||
1268 cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1269 cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
lally@webrtc.org36300852015-02-24 20:19:35 +00001270 const bool cd2_is_also_dtls_sctp =
Yves Gerey665174f2018-06-19 15:03:05 +02001271 cd2->protocol() == cricket::kMediaProtocolDtlsSctp ||
1272 cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1273 cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
lally@webrtc.org36300852015-02-24 20:19:35 +00001274 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001275 } else {
1276 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1277 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001278
1279 // codecs
1280 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1281
1282 // bandwidth
1283 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1284
1285 // streams
1286 EXPECT_EQ(cd1->streams(), cd2->streams());
1287
Johannes Kron0854eb62018-10-10 22:33:20 +02001288 // extmap-allow-mixed
Johannes Kron9581bc42018-10-23 10:17:39 +02001289 EXPECT_EQ(cd1->extmap_allow_mixed_enum(), cd2->extmap_allow_mixed_enum());
Johannes Kron0854eb62018-10-10 22:33:20 +02001290
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001291 // extmap
1292 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1293 cd2->rtp_header_extensions().size());
Yves Gerey665174f2018-06-19 15:03:05 +02001294 for (size_t i = 0; i < cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 11:24:55 -07001295 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1296 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001297 EXPECT_EQ(ext1.uri, ext2.uri);
1298 EXPECT_EQ(ext1.id, ext2.id);
jbauch5869f502017-06-29 12:31:36 -07001299 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001300 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001301 }
1302
zstein4b2e0822017-02-17 19:48:38 -08001303 void CompareDataContentDescription(const DataContentDescription* dcd1,
1304 const DataContentDescription* dcd2) {
1305 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
1306 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
1307 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001308
1309 void CompareSessionDescription(const SessionDescription& desc1,
1310 const SessionDescription& desc2) {
1311 // Compare content descriptions.
1312 if (desc1.contents().size() != desc2.contents().size()) {
1313 ADD_FAILURE();
1314 return;
1315 }
Yves Gerey665174f2018-06-19 15:03:05 +02001316 for (size_t i = 0; i < desc1.contents().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001317 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1318 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-12 18:37:36 -08001319 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001320 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-12 18:37:36 -08001321 EXPECT_EQ(c1.type, c2.type);
1322 EXPECT_EQ(c1.rejected, c2.rejected);
1323 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001324
1325 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1326 if (IsAudioContent(&c1)) {
1327 const AudioContentDescription* acd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001328 c1.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001329 const AudioContentDescription* acd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001330 c2.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001331 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1332 }
1333
1334 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1335 if (IsVideoContent(&c1)) {
1336 const VideoContentDescription* vcd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001337 c1.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001338 const VideoContentDescription* vcd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001339 c2.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001340 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1341 }
1342
1343 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
1344 if (IsDataContent(&c1)) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001345 const DataContentDescription* dcd1 = c1.media_description()->as_data();
1346 const DataContentDescription* dcd2 = c2.media_description()->as_data();
zstein4b2e0822017-02-17 19:48:38 -08001347 CompareDataContentDescription(dcd1, dcd2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001348 }
1349 }
1350
1351 // group
1352 const cricket::ContentGroups groups1 = desc1.groups();
1353 const cricket::ContentGroups groups2 = desc2.groups();
1354 EXPECT_EQ(groups1.size(), groups1.size());
1355 if (groups1.size() != groups2.size()) {
1356 ADD_FAILURE();
1357 return;
1358 }
1359 for (size_t i = 0; i < groups1.size(); ++i) {
1360 const cricket::ContentGroup group1 = groups1.at(i);
1361 const cricket::ContentGroup group2 = groups2.at(i);
1362 EXPECT_EQ(group1.semantics(), group2.semantics());
1363 const cricket::ContentNames names1 = group1.content_names();
1364 const cricket::ContentNames names2 = group2.content_names();
1365 EXPECT_EQ(names1.size(), names2.size());
1366 if (names1.size() != names2.size()) {
1367 ADD_FAILURE();
1368 return;
1369 }
1370 cricket::ContentNames::const_iterator iter1 = names1.begin();
1371 cricket::ContentNames::const_iterator iter2 = names2.begin();
1372 while (iter1 != names1.end()) {
1373 EXPECT_EQ(*iter1++, *iter2++);
1374 }
1375 }
1376
1377 // transport info
1378 const cricket::TransportInfos transports1 = desc1.transport_infos();
1379 const cricket::TransportInfos transports2 = desc2.transport_infos();
1380 EXPECT_EQ(transports1.size(), transports2.size());
1381 if (transports1.size() != transports2.size()) {
1382 ADD_FAILURE();
1383 return;
1384 }
1385 for (size_t i = 0; i < transports1.size(); ++i) {
1386 const cricket::TransportInfo transport1 = transports1.at(i);
1387 const cricket::TransportInfo transport2 = transports2.at(i);
1388 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001389 EXPECT_EQ(transport1.description.ice_ufrag,
1390 transport2.description.ice_ufrag);
Yves Gerey665174f2018-06-19 15:03:05 +02001391 EXPECT_EQ(transport1.description.ice_pwd, transport2.description.ice_pwd);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07001392 EXPECT_EQ(transport1.description.ice_mode,
1393 transport2.description.ice_mode);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001394 if (transport1.description.identity_fingerprint) {
1395 EXPECT_EQ(*transport1.description.identity_fingerprint,
1396 *transport2.description.identity_fingerprint);
1397 } else {
1398 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1399 transport2.description.identity_fingerprint.get());
1400 }
1401 EXPECT_EQ(transport1.description.transport_options,
1402 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001403 }
deadbeefc80741f2015-10-22 13:14:45 -07001404
1405 // global attributes
1406 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
Johannes Kron9581bc42018-10-23 10:17:39 +02001407 EXPECT_EQ(desc1.extmap_allow_mixed(), desc2.extmap_allow_mixed());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001408 }
1409
Yves Gerey665174f2018-06-19 15:03:05 +02001410 bool CompareSessionDescription(const JsepSessionDescription& desc1,
1411 const JsepSessionDescription& desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001412 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1413 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1414 CompareSessionDescription(*desc1.description(), *desc2.description());
1415 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1416 return false;
1417 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1418 const IceCandidateCollection* cc1 = desc1.candidates(i);
1419 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-12 18:37:36 -08001420 if (cc1->count() != cc2->count()) {
1421 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001422 return false;
deadbeef25ed4352016-12-12 18:37:36 -08001423 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001424 for (size_t j = 0; j < cc1->count(); ++j) {
1425 const IceCandidateInterface* c1 = cc1->at(j);
1426 const IceCandidateInterface* c2 = cc2->at(j);
1427 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1428 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1429 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1430 }
1431 }
1432 return true;
1433 }
1434
1435 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1436 // them with invalid keywords so that the parser will just ignore them.
1437 bool RemoveCandidateUfragPwd(std::string* sdp) {
1438 const char ice_ufrag[] = "a=ice-ufrag";
1439 const char ice_ufragx[] = "a=xice-ufrag";
1440 const char ice_pwd[] = "a=ice-pwd";
1441 const char ice_pwdx[] = "a=xice-pwd";
Yves Gerey665174f2018-06-19 15:03:05 +02001442 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag), ice_ufragx,
1443 strlen(ice_ufragx), sdp);
1444 rtc::replace_substrs(ice_pwd, strlen(ice_pwd), ice_pwdx, strlen(ice_pwdx),
1445 sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001446 return true;
1447 }
1448
1449 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
Yves Gerey665174f2018-06-19 15:03:05 +02001450 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc,
1451 int mline_index,
1452 const std::string& ufrag,
1453 const std::string& pwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001454 std::string content_name;
1455 if (mline_index == 0) {
1456 content_name = kAudioContentName;
1457 } else if (mline_index == 1) {
1458 content_name = kVideoContentName;
1459 } else {
nissec80e7412017-01-11 05:56:46 -08001460 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001461 }
Yves Gerey665174f2018-06-19 15:03:05 +02001462 TransportInfo transport_info(content_name,
1463 TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001464 SessionDescription* desc =
1465 const_cast<SessionDescription*>(jdesc->description());
1466 desc->RemoveTransportInfoByName(content_name);
1467 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
1468 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1469 const IceCandidateCollection* cc = jdesc_.candidates(i);
1470 for (size_t j = 0; j < cc->count(); ++j) {
1471 if (cc->at(j)->sdp_mline_index() == mline_index) {
Yves Gerey665174f2018-06-19 15:03:05 +02001472 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(ufrag);
1473 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001474 }
1475 }
1476 }
1477 return true;
1478 }
1479
1480 void AddIceOptions(const std::string& content_name,
1481 const std::vector<std::string>& transport_options) {
1482 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1483 cricket::TransportInfo transport_info =
1484 *(desc_.GetTransportInfoByName(content_name));
1485 desc_.RemoveTransportInfoByName(content_name);
1486 transport_info.description.transport_options = transport_options;
1487 desc_.AddTransportInfo(transport_info);
1488 }
1489
deadbeef3f7219b2015-12-28 15:17:14 -08001490 void SetIceUfragPwd(const std::string& content_name,
1491 const std::string& ice_ufrag,
1492 const std::string& ice_pwd) {
1493 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1494 cricket::TransportInfo transport_info =
1495 *(desc_.GetTransportInfoByName(content_name));
1496 desc_.RemoveTransportInfoByName(content_name);
1497 transport_info.description.ice_ufrag = ice_ufrag;
1498 transport_info.description.ice_pwd = ice_pwd;
1499 desc_.AddTransportInfo(transport_info);
1500 }
1501
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001502 void AddFingerprint() {
1503 desc_.RemoveTransportInfoByName(kAudioContentName);
1504 desc_.RemoveTransportInfoByName(kVideoContentName);
Steve Anton4905edb2018-10-15 19:27:44 -07001505 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, kIdentityDigest);
deadbeef46eed762016-01-28 13:24:37 -08001506 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1507 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001508 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1509 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001510 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1511 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1512 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001513 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1514 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001515 cricket::CONNECTIONROLE_NONE, &fingerprint))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001516 }
1517
jbauch5869f502017-06-29 12:31:36 -07001518 void AddExtmap(bool encrypted) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001519 audio_desc_ = audio_desc_->Copy();
1520 video_desc_ = video_desc_->Copy();
jbauch5869f502017-06-29 12:31:36 -07001521 audio_desc_->AddRtpHeaderExtension(
1522 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1523 video_desc_->AddRtpHeaderExtension(
1524 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001525 desc_.RemoveContentByName(kAudioContentName);
1526 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001527 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1528 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001529 }
1530
1531 void RemoveCryptos() {
1532 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1533 video_desc_->set_cryptos(std::vector<CryptoParams>());
1534 }
1535
Seth Hampson5897a6e2018-04-03 11:16:33 -07001536 // Removes everything in StreamParams from the session description that is
1537 // used for a=ssrc lines.
1538 void RemoveSsrcSignalingFromStreamParams() {
1539 for (cricket::ContentInfo content_info : jdesc_.description()->contents()) {
1540 // With Unified Plan there should be one StreamParams per m= section.
1541 StreamParams& stream =
1542 content_info.media_description()->mutable_streams()[0];
1543 stream.ssrcs.clear();
1544 stream.ssrc_groups.clear();
1545 stream.cname.clear();
1546 }
1547 }
1548
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001549 // Removes all a=ssrc lines from the SDP string, except for the
1550 // "a=ssrc:... cname:..." lines.
1551 void RemoveSsrcMsidLinesFromSdpString(std::string* sdp_string) {
1552 const char kAttributeSsrc[] = "a=ssrc";
1553 const char kAttributeCname[] = "cname";
1554 size_t ssrc_line_pos = sdp_string->find(kAttributeSsrc);
1555 while (ssrc_line_pos != std::string::npos) {
1556 size_t beg_line_pos = sdp_string->rfind('\n', ssrc_line_pos);
1557 size_t end_line_pos = sdp_string->find('\n', ssrc_line_pos);
1558 size_t cname_pos = sdp_string->find(kAttributeCname, ssrc_line_pos);
1559 if (cname_pos == std::string::npos || cname_pos > end_line_pos) {
1560 // Only erase a=ssrc lines that don't contain "cname".
1561 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1562 ssrc_line_pos = sdp_string->find(kAttributeSsrc, beg_line_pos);
1563 } else {
1564 // Skip the "a=ssrc:... cname" line and find the next "a=ssrc" line.
1565 ssrc_line_pos = sdp_string->find(kAttributeSsrc, end_line_pos);
1566 }
1567 }
1568 }
1569
Seth Hampson5897a6e2018-04-03 11:16:33 -07001570 // Removes all a=ssrc lines from the SDP string.
1571 void RemoveSsrcLinesFromSdpString(std::string* sdp_string) {
1572 const char kAttributeSsrc[] = "a=ssrc";
1573 while (sdp_string->find(kAttributeSsrc) != std::string::npos) {
1574 size_t pos_ssrc_attribute = sdp_string->find(kAttributeSsrc);
1575 size_t beg_line_pos = sdp_string->rfind('\n', pos_ssrc_attribute);
1576 size_t end_line_pos = sdp_string->find('\n', pos_ssrc_attribute);
1577 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1578 }
1579 }
1580
Steve Anton4e70a722017-11-28 14:57:10 -08001581 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001582 audio_desc_->set_direction(direction);
1583 video_desc_->set_direction(direction);
1584 std::string new_sdp = kSdpFullString;
1585 ReplaceDirection(direction, &new_sdp);
1586
Yves Gerey665174f2018-06-19 15:03:05 +02001587 if (!jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001588 jdesc_.session_version())) {
1589 return false;
1590 }
Steve Antone831b8c2018-02-01 12:22:16 -08001591 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001592 EXPECT_EQ(new_sdp, message);
1593 return true;
1594 }
1595
1596 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001597 audio_desc_ = audio_desc_->Copy();
1598 video_desc_ = video_desc_->Copy();
zhihuang38989e52017-03-21 11:04:53 -07001599
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001600 desc_.RemoveContentByName(kAudioContentName);
1601 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001602 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001603 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001604 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001605 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001606 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1607 audio_rejected ? "" : kPwdVoice);
1608 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1609 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001610
1611 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001612 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1613
Steve Antona3a92c22017-12-07 10:27:41 -08001614 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001615 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001616 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001617 EXPECT_EQ(new_sdp, message);
1618 return true;
1619 }
1620
zstein4b2e0822017-02-17 19:48:38 -08001621 void AddSctpDataChannel(bool use_sctpmap) {
kwibergd1fe2812016-04-27 06:47:29 -07001622 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001623 data_desc_ = data.get();
zstein4b2e0822017-02-17 19:48:38 -08001624 data_desc_->set_use_sctpmap(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001625 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
solenberg9fa49752016-10-08 13:02:44 -07001626 DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07001627 cricket::kGoogleSctpDataCodecName);
wu@webrtc.org78187522013-10-07 23:32:02 +00001628 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1629 data_desc_->AddCodec(codec);
Steve Anton5adfafd2017-12-20 16:34:00 -08001630 desc_.AddContent(kDataContentName, MediaProtocolType::kSctp,
1631 data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001632 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1633 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001634 }
1635
1636 void AddRtpDataChannel() {
kwibergd1fe2812016-04-27 06:47:29 -07001637 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001638 data_desc_ = data.get();
1639
deadbeef67cf2c12016-04-13 10:07:16 -07001640 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001641 StreamParams data_stream;
1642 data_stream.id = kDataChannelMsid;
1643 data_stream.cname = kDataChannelCname;
Seth Hampson845e8782018-03-02 11:34:10 -08001644 data_stream.set_stream_ids({kDataChannelLabel});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001645 data_stream.ssrcs.push_back(kDataChannelSsrc);
1646 data_desc_->AddStream(data_stream);
Yves Gerey665174f2018-06-19 15:03:05 +02001647 data_desc_->AddCrypto(
1648 CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
1649 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001650 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
Steve Anton5adfafd2017-12-20 16:34:00 -08001651 desc_.AddContent(kDataContentName, MediaProtocolType::kRtp, data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001652 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1653 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001654 }
1655
Steve Anton4e70a722017-11-28 14:57:10 -08001656 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001657 std::string new_sdp = kSdpFullString;
1658 ReplaceDirection(direction, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001659 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001660
1661 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1662
1663 audio_desc_->set_direction(direction);
1664 video_desc_->set_direction(direction);
Yves Gerey665174f2018-06-19 15:03:05 +02001665 if (!jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001666 jdesc_.session_version())) {
1667 return false;
1668 }
1669 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1670 return true;
1671 }
1672
1673 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001674 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001675 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001676 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001677 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001678
Steve Antonb1c1de12017-12-21 15:14:30 -08001679 audio_desc_ = audio_desc_->Copy();
1680 video_desc_ = video_desc_->Copy();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001681 desc_.RemoveContentByName(kAudioContentName);
1682 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001683 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001684 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001685 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001686 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001687 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1688 audio_rejected ? "" : kPwdVoice);
1689 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1690 video_rejected ? "" : kPwdVideo);
Steve Antona3a92c22017-12-07 10:27:41 -08001691 JsepSessionDescription jdesc_no_candidates(kDummyType);
deadbeef3f7219b2015-12-28 15:17:14 -08001692 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1693 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001694 return false;
1695 }
deadbeef3f7219b2015-12-28 15:17:14 -08001696 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001697 return true;
1698 }
1699
Yves Gerey665174f2018-06-19 15:03:05 +02001700 void TestDeserializeExtmap(bool session_level,
1701 bool media_level,
1702 bool encrypted) {
jbauch5869f502017-06-29 12:31:36 -07001703 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08001704 JsepSessionDescription new_jdesc(SdpType::kOffer);
Yves Gerey665174f2018-06-19 15:03:05 +02001705 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001706 jdesc_.session_version()));
Steve Antona3a92c22017-12-07 10:27:41 -08001707 JsepSessionDescription jdesc_with_extmap(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001708 std::string sdp_with_extmap = kSdpString;
1709 if (session_level) {
jbauch5869f502017-06-29 12:31:36 -07001710 InjectAfter(kSessionTime,
1711 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1712 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001713 &sdp_with_extmap);
1714 }
1715 if (media_level) {
jbauch5869f502017-06-29 12:31:36 -07001716 InjectAfter(kAttributeIcePwdVoice,
1717 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1718 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001719 &sdp_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07001720 InjectAfter(kAttributeIcePwdVideo,
1721 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1722 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001723 &sdp_with_extmap);
1724 }
1725 // The extmap can't be present at the same time in both session level and
1726 // media level.
1727 if (session_level && media_level) {
1728 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02001729 EXPECT_FALSE(
1730 webrtc::SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001731 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1732 } else {
1733 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1734 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1735 }
1736 }
1737
1738 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
Yves Gerey665174f2018-06-19 15:03:05 +02001739 const std::string& name,
1740 int expected_value) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001741 cricket::CodecParameterMap::const_iterator found = params.find(name);
1742 ASSERT_TRUE(found != params.end());
Jonas Olsson6b1985d2018-07-05 11:59:48 +02001743 EXPECT_EQ(found->second, rtc::ToString(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001744 }
1745
1746 void TestDeserializeCodecParams(const CodecParams& params,
1747 JsepSessionDescription* jdesc_output) {
1748 std::string sdp =
1749 "v=0\r\n"
1750 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1751 "s=-\r\n"
1752 "t=0 0\r\n"
1753 // Include semantics for WebRTC Media Streams since it is supported by
1754 // this parser, and will be added to the SDP when serializing a session
1755 // description.
1756 "a=msid-semantic: WMS\r\n"
1757 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001758 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001759 // Pltype 111 listed before 103 and 104 in the map.
1760 "a=rtpmap:111 opus/48000/2\r\n"
1761 // Pltype 103 listed before 104.
1762 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001763 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001764 "a=fmtp:111 0-15,66,70\r\n"
1765 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001766 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001767 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001768 << "; sprop-stereo=" << params.sprop_stereo
1769 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001770 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001771 << "a=ptime:" << params.ptime << "\r\n"
1772 << "a=maxptime:" << params.max_ptime << "\r\n";
1773 sdp += os.str();
1774
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001775 os.clear();
1776 os.str("");
1777 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001778 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001779 << "a=rtpmap:99 VP8/90000\r\n"
1780 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001781 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001782 sdp += os.str();
1783
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001784 // Deserialize
1785 SdpParseError error;
1786 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1787
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001788 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001789 GetFirstAudioContentDescription(jdesc_output->description());
1790 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001791 ASSERT_FALSE(acd->codecs().empty());
1792 cricket::AudioCodec opus = acd->codecs()[0];
1793 EXPECT_EQ("opus", opus.name);
1794 EXPECT_EQ(111, opus.id);
1795 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1796 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1797 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1798 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001799 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1800 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001801 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1802 cricket::AudioCodec codec = acd->codecs()[i];
1803 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1804 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001805 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001806
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001807 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001808 GetFirstVideoContentDescription(jdesc_output->description());
1809 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001810 ASSERT_FALSE(vcd->codecs().empty());
1811 cricket::VideoCodec vp8 = vcd->codecs()[0];
1812 EXPECT_EQ("VP8", vp8.name);
1813 EXPECT_EQ(99, vp8.id);
1814 cricket::VideoCodec rtx = vcd->codecs()[1];
1815 EXPECT_EQ("RTX", rtx.name);
1816 EXPECT_EQ(95, rtx.id);
1817 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001818 }
1819
1820 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1821 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001822 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001823 "v=0\r\n"
1824 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1825 "s=-\r\n"
1826 "t=0 0\r\n"
1827 // Include semantics for WebRTC Media Streams since it is supported by
1828 // this parser, and will be added to the SDP when serializing a session
1829 // description.
1830 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001831 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001832 "a=rtpmap:111 opus/48000/2\r\n";
1833 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001834 "m=video 3457 RTP/SAVPF 101\r\n"
1835 "a=rtpmap:101 VP8/90000\r\n"
1836 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001837 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001838 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001839 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001840 os << sdp_session_and_audio;
Yves Gerey665174f2018-06-19 15:03:05 +02001841 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001842 os << sdp_video;
Yves Gerey665174f2018-06-19 15:03:05 +02001843 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001844 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001845 // Deserialize
1846 SdpParseError error;
1847 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001848 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001849 GetFirstAudioContentDescription(jdesc_output->description());
1850 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001851 ASSERT_FALSE(acd->codecs().empty());
1852 cricket::AudioCodec opus = acd->codecs()[0];
1853 EXPECT_EQ(111, opus.id);
Yves Gerey665174f2018-06-19 15:03:05 +02001854 EXPECT_TRUE(opus.HasFeedbackParam(cricket::FeedbackParam(
1855 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001856
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001857 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001858 GetFirstVideoContentDescription(jdesc_output->description());
1859 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001860 ASSERT_FALSE(vcd->codecs().empty());
1861 cricket::VideoCodec vp8 = vcd->codecs()[0];
1862 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1863 vp8.name.c_str());
1864 EXPECT_EQ(101, vp8.id);
Yves Gerey665174f2018-06-19 15:03:05 +02001865 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1866 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
1867 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1868 cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli)));
1869 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1870 cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty)));
1871 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1872 cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001873 }
1874
1875 // Two SDP messages can mean the same thing but be different strings, e.g.
1876 // some of the lines can be serialized in different order.
1877 // However, a deserialized description can be compared field by field and has
1878 // no order. If deserializer has already been tested, serializing then
1879 // deserializing and comparing JsepSessionDescription will test
1880 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 12:22:16 -08001881 void TestSerialize(const JsepSessionDescription& jdesc) {
1882 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 10:27:41 -08001883 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001884 SdpParseError error;
1885 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1886 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1887 }
1888
zhihuang38989e52017-03-21 11:04:53 -07001889 // Calling 'Initialize' with a copy of the inner SessionDescription will
1890 // create a copy of the JsepSessionDescription without candidates. The
1891 // 'connection address' field, previously set from the candidates, must also
1892 // be reset.
1893 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
1894 rtc::SocketAddress audio_addr("0.0.0.0", 9);
1895 rtc::SocketAddress video_addr("0.0.0.0", 9);
1896 audio_desc_->set_connection_address(audio_addr);
1897 video_desc_->set_connection_address(video_addr);
1898 ASSERT_TRUE(jdesc->Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1899 }
1900
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001901 protected:
1902 SessionDescription desc_;
1903 AudioContentDescription* audio_desc_;
1904 VideoContentDescription* video_desc_;
1905 DataContentDescription* data_desc_;
1906 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07001907 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001908 JsepSessionDescription jdesc_;
1909};
1910
1911void TestMismatch(const std::string& string1, const std::string& string2) {
1912 int position = 0;
1913 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1914 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001915 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001916 break;
1917 }
1918 }
1919 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1920 << " character\n"
1921 << " 1: " << string1.substr(position, 20) << "\n"
1922 << " 2: " << string2.substr(position, 20) << "\n";
1923}
1924
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001925TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1926 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 12:22:16 -08001927 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001928 TestMismatch(std::string(kSdpFullString), message);
1929}
1930
1931TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 10:27:41 -08001932 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 12:22:16 -08001933 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001934}
1935
1936// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1937// the case in a DTLS offer.
1938TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1939 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08001940 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001941 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08001942 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001943
1944 std::string sdp_with_fingerprint = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02001945 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1946 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001947
1948 EXPECT_EQ(sdp_with_fingerprint, message);
1949}
1950
1951// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1952// be the case in a DTLS answer.
1953TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1954 AddFingerprint();
1955 RemoveCryptos();
Steve Antona3a92c22017-12-07 10:27:41 -08001956 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001957 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08001958 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001959
1960 std::string sdp_with_fingerprint = kSdpString;
1961 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1962 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
Yves Gerey665174f2018-06-19 15:03:05 +02001963 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1964 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001965
1966 EXPECT_EQ(sdp_with_fingerprint, message);
1967}
1968
1969TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1970 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08001971 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001972 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001973 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001974 EXPECT_EQ(std::string(kSdpString), message);
1975}
1976
1977TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1978 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1979 group.AddContentName(kAudioContentName);
1980 group.AddContentName(kVideoContentName);
1981 desc_.AddGroup(group);
Yves Gerey665174f2018-06-19 15:03:05 +02001982 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001983 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08001984 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001985 std::string sdp_with_bundle = kSdpFullString;
1986 InjectAfter(kSessionTime,
1987 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1988 &sdp_with_bundle);
1989 EXPECT_EQ(sdp_with_bundle, message);
1990}
1991
1992TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001993 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001994 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08001995 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001996 acd->set_bandwidth(50 * 1000);
Yves Gerey665174f2018-06-19 15:03:05 +02001997 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001998 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08001999 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002000 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002001 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002002 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002003 InjectAfter("c=IN IP4 74.125.127.126\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002004 &sdp_with_bandwidth);
2005 EXPECT_EQ(sdp_with_bandwidth, message);
2006}
2007
2008TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
2009 std::vector<std::string> transport_options;
2010 transport_options.push_back(kIceOption1);
2011 transport_options.push_back(kIceOption3);
2012 AddIceOptions(kAudioContentName, transport_options);
2013 transport_options.clear();
2014 transport_options.push_back(kIceOption2);
2015 transport_options.push_back(kIceOption3);
2016 AddIceOptions(kVideoContentName, transport_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002017 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002018 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002019 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002020 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002021 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002022 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002023 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002024 &sdp_with_ice_options);
2025 EXPECT_EQ(sdp_with_ice_options, message);
2026}
2027
2028TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002029 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002030}
2031
2032TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002033 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002034}
2035
2036TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002037 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002038}
2039
2040TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2041 EXPECT_TRUE(TestSerializeRejected(true, false));
2042}
2043
2044TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2045 EXPECT_TRUE(TestSerializeRejected(false, true));
2046}
2047
2048TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2049 EXPECT_TRUE(TestSerializeRejected(true, true));
2050}
2051
2052TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
2053 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002054 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002055
zhihuang38989e52017-03-21 11:04:53 -07002056 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002057 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002058
2059 std::string expected_sdp = kSdpString;
2060 expected_sdp.append(kSdpRtpDataChannelString);
2061 EXPECT_EQ(expected_sdp, message);
2062}
2063
2064TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08002065 bool use_sctpmap = true;
2066 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002067 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002068
zhihuang38989e52017-03-21 11:04:53 -07002069 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002070 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002071
2072 std::string expected_sdp = kSdpString;
2073 expected_sdp.append(kSdpSctpDataChannelString);
2074 EXPECT_EQ(message, expected_sdp);
2075}
2076
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002077TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08002078 bool use_sctpmap = true;
2079 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002080 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002081 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antonb1c1de12017-12-21 15:14:30 -08002082 DataContentDescription* dcdesc =
2083 jsep_desc.description()
2084 ->GetContentDescriptionByName(kDataContentName)
2085 ->as_data();
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002086
2087 const int kNewPort = 1234;
solenberg9fa49752016-10-08 13:02:44 -07002088 cricket::DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07002089 cricket::kGoogleSctpDataCodecName);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002090 codec.SetParam(cricket::kCodecParamPort, kNewPort);
2091 dcdesc->AddOrReplaceCodec(codec);
2092
Steve Antone831b8c2018-02-01 12:22:16 -08002093 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002094
2095 std::string expected_sdp = kSdpString;
2096 expected_sdp.append(kSdpSctpDataChannelString);
2097
2098 char default_portstr[16];
2099 char new_portstr[16];
Niels Mölleraba06332018-10-16 15:14:15 +02002100 snprintf(default_portstr, sizeof(default_portstr), "%d", kDefaultSctpPort);
2101 snprintf(new_portstr, sizeof(new_portstr), "%d", kNewPort);
Yves Gerey665174f2018-06-19 15:03:05 +02002102 rtc::replace_substrs(default_portstr, strlen(default_portstr), new_portstr,
2103 strlen(new_portstr), &expected_sdp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002104
2105 EXPECT_EQ(expected_sdp, message);
2106}
2107
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002108TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002109 JsepSessionDescription jsep_desc(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002110 AddRtpDataChannel();
Yves Gerey665174f2018-06-19 15:03:05 +02002111 data_desc_->set_bandwidth(100 * 1000);
zhihuang38989e52017-03-21 11:04:53 -07002112 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002113 std::string message = webrtc::SdpSerialize(jsep_desc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002114
2115 std::string expected_sdp = kSdpString;
2116 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002117 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00002118 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02002119 "b=AS:100\r\n", &expected_sdp);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002120 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002121}
2122
Johannes Kron0854eb62018-10-10 22:33:20 +02002123TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002124 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002125 TestSerialize(jdesc_);
2126}
2127
2128TEST_F(WebRtcSdpTest, SerializeMediaContentDescriptionWithExtmapAllowMixed) {
2129 cricket::MediaContentDescription* video_desc =
2130 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2131 ASSERT_TRUE(video_desc);
2132 cricket::MediaContentDescription* audio_desc =
2133 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2134 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002135 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002136 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002137 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002138 cricket::MediaContentDescription::kMedia);
2139 TestSerialize(jdesc_);
2140}
2141
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002142TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002143 bool encrypted = false;
2144 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002145 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002146 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 12:22:16 -08002147 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002148
2149 std::string sdp_with_extmap = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002150 InjectAfter("a=mid:audio_content_name\r\n", kExtmap, &sdp_with_extmap);
2151 InjectAfter("a=mid:video_content_name\r\n", kExtmap, &sdp_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002152
2153 EXPECT_EQ(sdp_with_extmap, message);
2154}
2155
jbauch5869f502017-06-29 12:31:36 -07002156TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2157 bool encrypted = true;
2158 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002159 JsepSessionDescription desc_with_extmap(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002160 ASSERT_TRUE(
2161 desc_with_extmap.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 12:22:16 -08002162 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07002163}
2164
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002165TEST_F(WebRtcSdpTest, SerializeCandidates) {
2166 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002167 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002168
2169 Candidate candidate_with_ufrag(candidates_.front());
2170 candidate_with_ufrag.set_username("ABC");
2171 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2172 candidate_with_ufrag));
2173 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2174 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002175
2176 Candidate candidate_with_network_info(candidates_.front());
2177 candidate_with_network_info.set_network_id(1);
2178 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2179 candidate_with_network_info));
2180 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2181 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2182 candidate_with_network_info.set_network_cost(999);
2183 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2184 candidate_with_network_info));
2185 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2186 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2187 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002188}
2189
Zach Steinb336c272018-08-09 01:16:13 -07002190TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) {
2191 rtc::SocketAddress address("a.test", 1234);
2192 cricket::Candidate candidate(
2193 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
2194 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
2195 JsepIceCandidate jcandidate(std::string("audio_content_name"), 0, candidate);
2196 std::string message = webrtc::SdpSerializeCandidate(jcandidate);
2197 EXPECT_EQ(std::string(kRawHostnameCandidate), message);
2198}
2199
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002200// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2201// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002202TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002203 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002204 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2205 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2206 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002207 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002208 std::unique_ptr<IceCandidateInterface> jcandidate(
2209 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002210
2211 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2212 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2213}
2214
htaa6b99442016-04-12 10:29:17 -07002215TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002216 cricket::VideoCodec h264_codec("H264");
2217 h264_codec.SetParam("profile-level-id", "42e01f");
2218 h264_codec.SetParam("level-asymmetry-allowed", "1");
2219 h264_codec.SetParam("packetization-mode", "1");
2220 video_desc_->AddCodec(h264_codec);
2221
htaa6b99442016-04-12 10:29:17 -07002222 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
2223
Steve Antone831b8c2018-02-01 12:22:16 -08002224 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 10:29:17 -07002225 size_t after_pt = message.find(" H264/90000");
2226 ASSERT_NE(after_pt, std::string::npos);
2227 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2228 ASSERT_NE(before_pt, std::string::npos);
2229 before_pt += strlen("a=rtpmap:");
2230 std::string pt = message.substr(before_pt, after_pt - before_pt);
2231 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2232 std::string to_find = "a=fmtp:" + pt + " ";
2233 size_t fmtp_pos = message.find(to_find);
2234 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
2235 size_t fmtp_endpos = message.find("\n", fmtp_pos);
2236 ASSERT_NE(std::string::npos, fmtp_endpos);
2237 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2238 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2239 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2240 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002241 // Check that there are no spaces after semicolons.
2242 // https://bugs.webrtc.org/5793
2243 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002244}
2245
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002246TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 10:27:41 -08002247 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002248 // Deserialize
2249 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2250 // Verify
2251 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2252}
2253
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002254TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 10:27:41 -08002255 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002256 const char kSdpWithoutMline[] =
Yves Gerey665174f2018-06-19 15:03:05 +02002257 "v=0\r\n"
2258 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2259 "s=-\r\n"
2260 "t=0 0\r\n"
2261 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002262 // Deserialize
2263 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2264 EXPECT_EQ(0u, jdesc.description()->contents().size());
2265}
2266
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002267TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 10:27:41 -08002268 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002269 std::string sdp_without_carriage_return = kSdpFullString;
2270 Replace("\r\n", "\n", &sdp_without_carriage_return);
2271 // Deserialize
2272 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2273 // Verify
2274 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2275}
2276
2277TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2278 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002279 JsepSessionDescription jdesc_no_candidates(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002280 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
2281 kSessionVersion));
Steve Antona3a92c22017-12-07 10:27:41 -08002282 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002283 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2284 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2285}
2286
2287TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2288 static const char kSdpNoRtpmapString[] =
2289 "v=0\r\n"
2290 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2291 "s=-\r\n"
2292 "t=0 0\r\n"
2293 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2294 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002295 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002296 // The rtpmap line for static payload codec is optional.
2297 "a=rtpmap:18 G729/16000\r\n"
2298 "a=rtpmap:103 ISAC/16000\r\n";
2299
Steve Antona3a92c22017-12-07 10:27:41 -08002300 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002301 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2302 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002303 jdesc.description()
2304 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2305 ->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002306 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002307 // The codecs in the AudioContentDescription should be in the same order as
2308 // the payload types (<fmt>s) on the m= line.
2309 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2310 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002311 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002312 EXPECT_EQ(ref_codecs, audio->codecs());
2313}
2314
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002315TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2316 static const char kSdpNoRtpmapString[] =
2317 "v=0\r\n"
2318 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2319 "s=-\r\n"
2320 "t=0 0\r\n"
2321 "m=audio 49232 RTP/AVP 18 103\r\n"
2322 "a=fmtp:18 annexb=yes\r\n"
2323 "a=rtpmap:103 ISAC/16000\r\n";
2324
Steve Antona3a92c22017-12-07 10:27:41 -08002325 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002326 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2327 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002328 jdesc.description()
2329 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2330 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002331
2332 cricket::AudioCodec g729 = audio->codecs()[0];
2333 EXPECT_EQ("G729", g729.name);
2334 EXPECT_EQ(8000, g729.clockrate);
2335 EXPECT_EQ(18, g729.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002336 cricket::CodecParameterMap::iterator found = g729.params.find("annexb");
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002337 ASSERT_TRUE(found != g729.params.end());
2338 EXPECT_EQ(found->second, "yes");
2339
2340 cricket::AudioCodec isac = audio->codecs()[1];
2341 EXPECT_EQ("ISAC", isac.name);
2342 EXPECT_EQ(103, isac.id);
2343 EXPECT_EQ(16000, isac.clockrate);
2344}
2345
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002346// Ensure that we can deserialize SDP with a=fingerprint properly.
2347TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2348 // Add a DTLS a=fingerprint attribute to our session description.
2349 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002350 JsepSessionDescription new_jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002351 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002352 jdesc_.session_version()));
2353
Steve Antona3a92c22017-12-07 10:27:41 -08002354 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002355 std::string sdp_with_fingerprint = kSdpString;
2356 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2357 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2358 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2359 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2360}
2361
2362TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 10:27:41 -08002363 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002364 std::string sdp_with_bundle = kSdpFullString;
2365 InjectAfter(kSessionTime,
2366 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2367 &sdp_with_bundle);
2368 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2369 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2370 group.AddContentName(kAudioContentName);
2371 group.AddContentName(kVideoContentName);
2372 desc_.AddGroup(group);
Yves Gerey665174f2018-06-19 15:03:05 +02002373 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002374 jdesc_.session_version()));
2375 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2376}
2377
2378TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002379 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002380 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002381 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002382 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002383 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002384 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002385 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 15:14:30 -08002386 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002387 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002388 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002389 acd->set_bandwidth(50 * 1000);
Yves Gerey665174f2018-06-19 15:03:05 +02002390 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002391 jdesc_.session_version()));
2392 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2393}
2394
2395TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 10:27:41 -08002396 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002397 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002398 InjectAfter(kSessionTime, "a=ice-options:iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002399 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002400 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002401 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002402 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002403 &sdp_with_ice_options);
2404 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2405 std::vector<std::string> transport_options;
2406 transport_options.push_back(kIceOption3);
2407 transport_options.push_back(kIceOption1);
2408 AddIceOptions(kAudioContentName, transport_options);
2409 transport_options.clear();
2410 transport_options.push_back(kIceOption3);
2411 transport_options.push_back(kIceOption2);
2412 AddIceOptions(kVideoContentName, transport_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002413 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002414 jdesc_.session_version()));
2415 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2416}
2417
2418TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2419 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 10:27:41 -08002420 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002421 std::string sdp_with_ufrag_pwd = kSdpFullString;
2422 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2423 // Add session level ufrag and pwd
2424 InjectAfter(kSessionTime,
Yves Gerey665174f2018-06-19 15:03:05 +02002425 "a=ice-pwd:session+level+icepwd\r\n"
2426 "a=ice-ufrag:session+level+iceufrag\r\n",
2427 &sdp_with_ufrag_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002428 // Add media level ufrag and pwd for audio
Yves Gerey665174f2018-06-19 15:03:05 +02002429 InjectAfter(
2430 "a=mid:audio_content_name\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002431 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2432 &sdp_with_ufrag_pwd);
2433 // Update the candidate ufrag and pwd to the expected ones.
Yves Gerey665174f2018-06-19 15:03:05 +02002434 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, "media+level+iceufrag",
2435 "media+level+icepwd"));
2436 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, "session+level+iceufrag",
2437 "session+level+icepwd"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002438 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2439 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2440}
2441
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002442TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002443 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002444}
2445
2446TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002447 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002448}
2449
2450TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002451 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002452}
2453
2454TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2455 EXPECT_TRUE(TestDeserializeRejected(true, false));
2456}
2457
2458TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2459 EXPECT_TRUE(TestDeserializeRejected(false, true));
2460}
2461
2462TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2463 EXPECT_TRUE(TestDeserializeRejected(true, true));
2464}
2465
2466// Tests that we can still handle the sdp uses mslabel and label instead of
2467// msid for backward compatibility.
2468TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07002469 jdesc_.description()->set_msid_supported(false);
Steve Antona3a92c22017-12-07 10:27:41 -08002470 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002471 std::string sdp_without_msid = kSdpFullString;
2472 Replace("msid", "xmsid", &sdp_without_msid);
2473 // Deserialize
2474 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2475 // Verify
2476 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2477}
2478
Johannes Kron0854eb62018-10-10 22:33:20 +02002479TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002480 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002481 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2482 InjectAfter("t=0 0\r\n", kExtmapAllowMixed, &sdp_with_extmap_allow_mixed);
2483 // Deserialize
2484 JsepSessionDescription jdesc_deserialized(kDummyType);
2485 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2486 // Verify
2487 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2488}
2489
2490TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002491 jdesc_.description()->set_extmap_allow_mixed(false);
Johannes Kron0854eb62018-10-10 22:33:20 +02002492 std::string sdp_without_extmap_allow_mixed = kSdpFullString;
2493 // Deserialize
2494 JsepSessionDescription jdesc_deserialized(kDummyType);
2495 EXPECT_TRUE(
2496 SdpDeserialize(sdp_without_extmap_allow_mixed, &jdesc_deserialized));
2497 // Verify
2498 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2499}
2500
2501TEST_F(WebRtcSdpTest, DeserializeMediaContentDescriptionWithExtmapAllowMixed) {
2502 cricket::MediaContentDescription* video_desc =
2503 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2504 ASSERT_TRUE(video_desc);
2505 cricket::MediaContentDescription* audio_desc =
2506 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2507 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002508 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002509 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002510 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002511 cricket::MediaContentDescription::kMedia);
2512
2513 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2514 InjectAfter("a=mid:audio_content_name\r\n", kExtmapAllowMixed,
2515 &sdp_with_extmap_allow_mixed);
2516 InjectAfter("a=mid:video_content_name\r\n", kExtmapAllowMixed,
2517 &sdp_with_extmap_allow_mixed);
2518
2519 // Deserialize
2520 JsepSessionDescription jdesc_deserialized(kDummyType);
2521 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2522 // Verify
2523 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2524}
2525
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002526TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2527 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2528
2529 std::string sdp = kSdpOneCandidate;
2530 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2531 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2532 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2533 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002534 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002535
2536 // Candidate line without generation extension.
2537 sdp = kSdpOneCandidate;
2538 Replace(" generation 2", "", &sdp);
2539 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2540 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2541 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2542 Candidate expected = jcandidate_->candidate();
2543 expected.set_generation(0);
2544 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2545
honghaiza0c44ea2016-03-23 16:07:48 -07002546 // Candidate with network id and/or cost.
2547 sdp = kSdpOneCandidate;
2548 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2549 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2550 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2551 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2552 expected = jcandidate_->candidate();
2553 expected.set_network_id(2);
2554 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2555 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2556 // Add network cost
2557 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2558 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2559 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2560 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2561
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002562 sdp = kSdpTcpActiveCandidate;
2563 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2564 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002565 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002566 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2567 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2568 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002569 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2570 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
Yves Gerey665174f2018-06-19 15:03:05 +02002571 EXPECT_TRUE(
2572 jcandidate.candidate().IsEquivalent(jcandidate_template->candidate()));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002573 sdp = kSdpTcpPassiveCandidate;
2574 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2575 sdp = kSdpTcpSOCandidate;
2576 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002577}
2578
2579// This test verifies the deserialization of candidate-attribute
2580// as per RFC 5245. Candiate-attribute will be of the format
2581// candidate:<blah>. This format will be used when candidates
2582// are trickled.
2583TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2584 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2585
2586 std::string candidate_attribute = kRawCandidate;
2587 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2588 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2589 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2590 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2591 EXPECT_EQ(2u, jcandidate.candidate().generation());
2592
2593 // Candidate line without generation extension.
2594 candidate_attribute = kRawCandidate;
2595 Replace(" generation 2", "", &candidate_attribute);
2596 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2597 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2598 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2599 Candidate expected = jcandidate_->candidate();
2600 expected.set_generation(0);
2601 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2602
2603 // Candidate line without candidate:
2604 candidate_attribute = kRawCandidate;
2605 Replace("candidate:", "", &candidate_attribute);
2606 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2607
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002608 // Candidate line with IPV6 address.
2609 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
Zach Steinb336c272018-08-09 01:16:13 -07002610
2611 // Candidate line with hostname address.
2612 EXPECT_TRUE(SdpDeserializeCandidate(kRawHostnameCandidate, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002613}
2614
2615// This test verifies that the deserialization of an invalid candidate string
2616// fails.
2617TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
Yves Gerey665174f2018-06-19 15:03:05 +02002618 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002619
2620 std::string candidate_attribute = kRawCandidate;
2621 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002622 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002623
2624 candidate_attribute = kSdpOneCandidate;
2625 candidate_attribute.replace(0, 1, "x");
2626 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2627
2628 candidate_attribute = kRawCandidate;
2629 candidate_attribute.append("\r\n");
2630 candidate_attribute.append(kRawCandidate);
2631 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2632
2633 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002634}
2635
2636TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2637 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002638 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002639 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2640
2641 std::string sdp_with_data = kSdpString;
2642 sdp_with_data.append(kSdpRtpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002643 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002644
2645 // Deserialize
2646 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2647 // Verify
2648 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2649}
2650
2651TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002652 bool use_sctpmap = true;
2653 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002654 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002655 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2656
2657 std::string sdp_with_data = kSdpString;
2658 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002659 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002660
lally@webrtc.org36300852015-02-24 20:19:35 +00002661 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2662 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2663 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2664
2665 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002666 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2667 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002668 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2669 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2670
2671 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002672 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2673 kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002674 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2675 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2676}
2677
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002678TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002679 bool use_sctpmap = false;
2680 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002681 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002682 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2683
2684 std::string sdp_with_data = kSdpString;
2685 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002686 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002687
lally@webrtc.org36300852015-02-24 20:19:35 +00002688 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002689 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2690 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002691
lally@webrtc.org36300852015-02-24 20:19:35 +00002692 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002693 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2694 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002695 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2696 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002697
lally@webrtc.org36300852015-02-24 20:19:35 +00002698 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002699 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2700 kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002701 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2702 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2703}
2704
lally69f57602015-10-08 10:15:04 -07002705TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002706 bool use_sctpmap = false;
2707 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002708 JsepSessionDescription jdesc(kDummyType);
lally69f57602015-10-08 10:15:04 -07002709 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2710
2711 std::string sdp_with_data = kSdpString;
2712 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002713 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 10:15:04 -07002714
2715 // Verify with DTLS/SCTP.
2716 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2717 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2718
2719 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002720 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2721 kUdpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002722 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2723 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2724
2725 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002726 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2727 kTcpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002728 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2729 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2730}
2731
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002732// Test to check the behaviour if sctp-port is specified
2733// on the m= line and in a=sctp-port.
2734TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002735 bool use_sctpmap = true;
2736 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002737 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002738 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2739
2740 std::string sdp_with_data = kSdpString;
2741 // Append m= attributes
2742 sdp_with_data.append(kSdpSctpDataChannelString);
2743 // Append a=sctp-port attribute
2744 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 10:27:41 -08002745 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002746
2747 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2748}
2749
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002750// For crbug/344475.
2751TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2752 std::string sdp_with_data = kSdpString;
2753 sdp_with_data.append(kSdpSctpDataChannelString);
2754 // Remove the "\n" at the end.
2755 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 10:27:41 -08002756 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002757
2758 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2759 // No crash is a pass.
2760}
2761
Steve Anton36b29d12017-10-30 09:57:42 -07002762void MutateJsepSctpPort(JsepSessionDescription* jdesc,
zstein4b2e0822017-02-17 19:48:38 -08002763 const SessionDescription& desc) {
wu@webrtc.org78187522013-10-07 23:32:02 +00002764 // take our pre-built session description and change the SCTP port.
zstein4b2e0822017-02-17 19:48:38 -08002765 cricket::SessionDescription* mutant = desc.Copy();
Steve Antonb1c1de12017-12-21 15:14:30 -08002766 DataContentDescription* dcdesc =
2767 mutant->GetContentDescriptionByName(kDataContentName)->as_data();
wu@webrtc.org78187522013-10-07 23:32:02 +00002768 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002769 EXPECT_EQ(1U, codecs.size());
solenberg9fa49752016-10-08 13:02:44 -07002770 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002771 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002772 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002773
2774 // note: mutant's owned by jdesc now.
Steve Anton36b29d12017-10-30 09:57:42 -07002775 ASSERT_TRUE(jdesc->Initialize(mutant, kSessionId, kSessionVersion));
wu@webrtc.org78187522013-10-07 23:32:02 +00002776 mutant = NULL;
zstein4b2e0822017-02-17 19:48:38 -08002777}
2778
2779TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
2780 bool use_sctpmap = true;
2781 AddSctpDataChannel(use_sctpmap);
2782
2783 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 10:27:41 -08002784 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002785 MutateJsepSctpPort(&jdesc, desc_);
wu@webrtc.org78187522013-10-07 23:32:02 +00002786
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002787 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002788 std::string sdp_with_data = kSdpString;
2789 sdp_with_data.append(kSdpSctpDataChannelString);
zstein4b2e0822017-02-17 19:48:38 -08002790 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2791 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2792 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002793 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:02 +00002794
2795 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2796 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08002797}
2798
2799TEST_F(WebRtcSdpTest,
2800 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
2801 bool use_sctpmap = false;
2802 AddSctpDataChannel(use_sctpmap);
2803
Steve Antona3a92c22017-12-07 10:27:41 -08002804 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002805 MutateJsepSctpPort(&jdesc, desc_);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002806
2807 // We need to test the deserialized JsepSessionDescription from
2808 // kSdpSctpDataChannelStringWithSctpPort for
2809 // draft-ietf-mmusic-sctp-sdp-07
2810 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08002811 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002812 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
zstein4b2e0822017-02-17 19:48:38 -08002813 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2814 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2815 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002816 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002817
2818 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2819 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002820}
2821
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002822TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002823 // We want to test that deserializing data content limits bandwidth
2824 // settings (it should never be greater than the default).
2825 // This should prevent someone from using unlimited data bandwidth through
2826 // JS and "breaking the Internet".
2827 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002828 std::string sdp_with_bandwidth = kSdpString;
2829 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02002830 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002831 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002832 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002833
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002834 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2835}
2836
2837TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08002838 bool use_sctpmap = true;
2839 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002840 JsepSessionDescription jdesc(kDummyType);
Steve Antonb1c1de12017-12-21 15:14:30 -08002841 DataContentDescription* dcd = GetFirstDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002842 dcd->set_bandwidth(100 * 1000);
2843 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2844
2845 std::string sdp_with_bandwidth = kSdpString;
2846 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02002847 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002848 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002849 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002850
2851 // SCTP has congestion control, so we shouldn't limit the bandwidth
2852 // as we do for RTP.
2853 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002854 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2855}
2856
Yves Gerey665174f2018-06-19 15:03:05 +02002857class WebRtcSdpExtmapTest : public WebRtcSdpTest,
2858 public testing::WithParamInterface<bool> {};
jbauch5869f502017-06-29 12:31:36 -07002859
2860TEST_P(WebRtcSdpExtmapTest,
Yves Gerey665174f2018-06-19 15:03:05 +02002861 DeserializeSessionDescriptionWithSessionLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002862 bool encrypted = GetParam();
2863 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002864}
2865
Yves Gerey665174f2018-06-19 15:03:05 +02002866TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002867 bool encrypted = GetParam();
2868 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002869}
2870
Yves Gerey665174f2018-06-19 15:03:05 +02002871TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithInvalidExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002872 bool encrypted = GetParam();
2873 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002874}
2875
jbauch5869f502017-06-29 12:31:36 -07002876INSTANTIATE_TEST_CASE_P(Encrypted,
2877 WebRtcSdpExtmapTest,
2878 ::testing::Values(false, true));
2879
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002880TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 10:27:41 -08002881 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002882 std::string sdp = kSdpFullString;
2883 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2884 // Deserialize
2885 SdpParseError error;
2886 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-16 17:54:10 -08002887 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002888 EXPECT_EQ(lastline, error.line);
2889 EXPECT_EQ("Invalid SDP line.", error.description);
2890}
2891
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002892TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2893 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2894 std::string new_sdp = kSdpOneCandidate;
2895 Replace("udp", "unsupported_transport", &new_sdp);
2896 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2897 new_sdp = kSdpOneCandidate;
2898 Replace("udp", "uDP", &new_sdp);
2899 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2900 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2901 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2902 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2903}
2904
honghaiza54a0802015-12-16 18:37:23 -08002905TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002906 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08002907 EXPECT_TRUE(
2908 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002909 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2910 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2911 Candidate ref_candidate = jcandidate_->candidate();
2912 ref_candidate.set_username("user_rtp");
2913 ref_candidate.set_password("password_rtp");
2914 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2915}
2916
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002917TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08002918 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002919
2920 // Deserialize
2921 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2922
2923 // Verify
2924 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002925 jdesc.description()
2926 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2927 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002928 EXPECT_TRUE(audio->conference_mode());
2929
2930 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 15:14:30 -08002931 jdesc.description()
2932 ->GetContentDescriptionByName(cricket::CN_VIDEO)
2933 ->as_video();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002934 EXPECT_TRUE(video->conference_mode());
2935}
2936
deadbeefd45aea82017-09-16 01:24:29 -07002937TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08002938 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 01:24:29 -07002939
2940 // We tested deserialization already above, so just test that if we serialize
2941 // and deserialize the flag doesn't disappear.
2942 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 12:22:16 -08002943 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 01:24:29 -07002944 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
2945
2946 // Verify.
2947 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002948 jdesc.description()
2949 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2950 ->as_audio();
deadbeefd45aea82017-09-16 01:24:29 -07002951 EXPECT_TRUE(audio->conference_mode());
2952
2953 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 15:14:30 -08002954 jdesc.description()
2955 ->GetContentDescriptionByName(cricket::CN_VIDEO)
2956 ->as_video();
deadbeefd45aea82017-09-16 01:24:29 -07002957 EXPECT_TRUE(video->conference_mode());
2958}
2959
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002960TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2961 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002962 const char kSdpEmptyType[] = " =candidate";
2963 const char kSdpEqualAsPlus[] = "a+candidate";
2964 const char kSdpSpaceAfterEqual[] = "a= candidate";
2965 const char kSdpUpperType[] = "A=candidate";
2966 const char kSdpEmptyLine[] = "";
2967 const char kSdpMissingValue[] = "a=";
2968
Yves Gerey665174f2018-06-19 15:03:05 +02002969 const char kSdpBrokenFingerprint[] =
2970 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002971 "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 +02002972 const char kSdpExtraField[] =
2973 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002974 "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 +02002975 const char kSdpMissingSpace[] =
2976 "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002977 "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 +00002978 // MD5 is not allowed in fingerprints.
Yves Gerey665174f2018-06-19 15:03:05 +02002979 const char kSdpMd5[] =
2980 "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002981 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002982
2983 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002984 ExpectParseFailure("v=", kSdpDestroyer);
2985 ExpectParseFailure("o=", kSdpDestroyer);
2986 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002987 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002988 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002989
2990 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002991 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2992 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002993
2994 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002995 ExpectParseFailure("a=candidate", kSdpEmptyType);
2996 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2997 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
2998 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002999
3000 // Bogus fingerprint replacing a=sendrev. We selected this attribute
3001 // because it's orthogonal to what we are replacing and hence
3002 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003003 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
3004 ExpectParseFailure("a=sendrecv", kSdpExtraField);
3005 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
3006 ExpectParseFailure("a=sendrecv", kSdpMd5);
3007
3008 // Empty Line
3009 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
3010 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003011}
3012
3013TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
3014 // ssrc
3015 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08003016 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003017 // crypto
3018 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
3019 // rtpmap
3020 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
3021 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
3022 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
3023 // candidate
3024 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
3025 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
3026 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
3027 ExpectParseFailure("rport 2346", "rport badvalue");
3028 ExpectParseFailure("rport 2346 generation 2",
3029 "rport 2346 generation badvalue");
3030 // m line
3031 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
3032 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
3033
3034 // bandwidth
3035 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003036 "b=AS:badvalue\r\n", "b=AS:badvalue");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003037 // rtcp-fb
3038 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3039 "a=rtcp-fb:badvalue nack\r\n",
3040 "a=rtcp-fb:badvalue nack");
3041 // extmap
3042 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3043 "a=extmap:badvalue http://example.com\r\n",
3044 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003045}
3046
3047TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 10:27:41 -08003048 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003049
3050 const char kSdpWithReorderedPlTypesString[] =
3051 "v=0\r\n"
3052 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3053 "s=-\r\n"
3054 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00003055 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
Yves Gerey665174f2018-06-19 15:03:05 +02003056 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
3057 // in the map.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003058 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003059 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003060
3061 // Deserialize
3062 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
3063
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003064 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003065 GetFirstAudioContentDescription(jdesc_output.description());
3066 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003067 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003068 EXPECT_EQ("ISAC", acd->codecs()[0].name);
3069 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003070 EXPECT_EQ(104, acd->codecs()[0].id);
3071}
3072
3073TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 10:27:41 -08003074 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003075 CodecParams params;
3076 params.max_ptime = 40;
3077 params.ptime = 30;
3078 params.min_ptime = 10;
3079 params.sprop_stereo = 1;
3080 params.stereo = 1;
3081 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003082 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003083 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 12:22:16 -08003084 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003085}
3086
3087TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
3088 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 10:27:41 -08003089 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003090 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003091 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003092}
3093
3094TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
3095 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 10:27:41 -08003096 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003097 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003098 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003099}
3100
3101TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 10:27:41 -08003102 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003103
3104 const char kSdpWithFmtpString[] =
3105 "v=0\r\n"
3106 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3107 "s=-\r\n"
3108 "t=0 0\r\n"
3109 "m=video 3457 RTP/SAVPF 120\r\n"
3110 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07003111 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3112
3113 // Deserialize
3114 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07003115 EXPECT_TRUE(
3116 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07003117
Donald Curtis0e07f922015-05-15 09:21:23 -07003118 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003119 GetFirstVideoContentDescription(jdesc_output.description());
3120 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 09:21:23 -07003121 ASSERT_FALSE(vcd->codecs().empty());
3122 cricket::VideoCodec vp8 = vcd->codecs()[0];
3123 EXPECT_EQ("VP8", vp8.name);
3124 EXPECT_EQ(120, vp8.id);
3125 cricket::CodecParameterMap::iterator found =
3126 vp8.params.find("x-google-min-bitrate");
3127 ASSERT_TRUE(found != vp8.params.end());
3128 EXPECT_EQ(found->second, "10");
3129 found = vp8.params.find("x-google-max-quantization");
3130 ASSERT_TRUE(found != vp8.params.end());
3131 EXPECT_EQ(found->second, "40");
3132}
3133
johan2d8d23e2016-06-03 01:22:42 -07003134TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 10:27:41 -08003135 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 01:22:42 -07003136
3137 const char kSdpWithFmtpString[] =
3138 "v=0\r\n"
3139 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3140 "s=-\r\n"
3141 "t=0 0\r\n"
3142 "m=video 49170 RTP/AVP 98\r\n"
3143 "a=rtpmap:98 H264/90000\r\n"
3144 "a=fmtp:98 profile-level-id=42A01E; "
3145 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3146
3147 // Deserialize.
3148 SdpParseError error;
3149 EXPECT_TRUE(
3150 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3151
johan2d8d23e2016-06-03 01:22:42 -07003152 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003153 GetFirstVideoContentDescription(jdesc_output.description());
3154 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 01:22:42 -07003155 ASSERT_FALSE(vcd->codecs().empty());
3156 cricket::VideoCodec h264 = vcd->codecs()[0];
3157 EXPECT_EQ("H264", h264.name);
3158 EXPECT_EQ(98, h264.id);
3159 cricket::CodecParameterMap::const_iterator found =
3160 h264.params.find("profile-level-id");
3161 ASSERT_TRUE(found != h264.params.end());
3162 EXPECT_EQ(found->second, "42A01E");
3163 found = h264.params.find("sprop-parameter-sets");
3164 ASSERT_TRUE(found != h264.params.end());
3165 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3166}
3167
Donald Curtis0e07f922015-05-15 09:21:23 -07003168TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 10:27:41 -08003169 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 09:21:23 -07003170
3171 const char kSdpWithFmtpString[] =
3172 "v=0\r\n"
3173 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3174 "s=-\r\n"
3175 "t=0 0\r\n"
3176 "m=video 3457 RTP/SAVPF 120\r\n"
3177 "a=rtpmap:120 VP8/90000\r\n"
3178 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003179
3180 // Deserialize
3181 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02003182 EXPECT_TRUE(
3183 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003184
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003185 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003186 GetFirstVideoContentDescription(jdesc_output.description());
3187 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003188 ASSERT_FALSE(vcd->codecs().empty());
3189 cricket::VideoCodec vp8 = vcd->codecs()[0];
3190 EXPECT_EQ("VP8", vp8.name);
3191 EXPECT_EQ(120, vp8.id);
3192 cricket::CodecParameterMap::iterator found =
3193 vp8.params.find("x-google-min-bitrate");
3194 ASSERT_TRUE(found != vp8.params.end());
3195 EXPECT_EQ(found->second, "10");
3196 found = vp8.params.find("x-google-max-quantization");
3197 ASSERT_TRUE(found != vp8.params.end());
3198 EXPECT_EQ(found->second, "40");
3199}
3200
ossuaa4b0772017-01-30 07:41:18 -08003201TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003202 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003203
3204 cricket::AudioCodecs codecs = acd->codecs();
3205 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3206 acd->set_codecs(codecs);
3207
Yves Gerey665174f2018-06-19 15:03:05 +02003208 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003209 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003210 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003211 std::string sdp_with_fmtp = kSdpFullString;
3212 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3213 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3214 &sdp_with_fmtp);
3215 EXPECT_EQ(sdp_with_fmtp, message);
3216}
3217
3218TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003219 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003220
3221 cricket::AudioCodecs codecs = acd->codecs();
3222 codecs[0].params["stereo"] = "1";
3223 acd->set_codecs(codecs);
3224
Yves Gerey665174f2018-06-19 15:03:05 +02003225 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003226 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003227 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003228 std::string sdp_with_fmtp = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003229 InjectAfter("a=rtpmap:111 opus/48000/2\r\n", "a=fmtp:111 stereo=1\r\n",
ossuaa4b0772017-01-30 07:41:18 -08003230 &sdp_with_fmtp);
3231 EXPECT_EQ(sdp_with_fmtp, message);
3232}
3233
3234TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003235 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003236
3237 cricket::AudioCodecs codecs = acd->codecs();
3238 codecs[0].params["ptime"] = "20";
3239 codecs[0].params["maxptime"] = "120";
3240 acd->set_codecs(codecs);
3241
Yves Gerey665174f2018-06-19 15:03:05 +02003242 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003243 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003244 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003245 std::string sdp_with_fmtp = kSdpFullString;
3246 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3247 "a=maxptime:120\r\n" // No comma here. String merging!
3248 "a=ptime:20\r\n",
3249 &sdp_with_fmtp);
3250 EXPECT_EQ(sdp_with_fmtp, message);
3251}
3252
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003253TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003254 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003255
3256 cricket::VideoCodecs codecs = vcd->codecs();
3257 codecs[0].params["x-google-min-bitrate"] = "10";
3258 vcd->set_codecs(codecs);
3259
Yves Gerey665174f2018-06-19 15:03:05 +02003260 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003261 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003262 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003263 std::string sdp_with_fmtp = kSdpFullString;
3264 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003265 "a=fmtp:120 x-google-min-bitrate=10\r\n", &sdp_with_fmtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003266 EXPECT_EQ(sdp_with_fmtp, message);
3267}
3268
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003269TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) {
3270 // Deserialize the baseline description, making sure it's ICE full.
Steve Antona3a92c22017-12-07 10:27:41 -08003271 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003272 std::string sdp_with_icelite = kSdpFullString;
3273 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3274 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3275 const cricket::TransportInfo* tinfo1 =
3276 desc->GetTransportInfoByName("audio_content_name");
3277 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3278 const cricket::TransportInfo* tinfo2 =
3279 desc->GetTransportInfoByName("video_content_name");
3280 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003281
3282 // Add "a=ice-lite" and deserialize, making sure it's ICE lite.
Yves Gerey665174f2018-06-19 15:03:05 +02003283 InjectAfter(kSessionTime, "a=ice-lite\r\n", &sdp_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003284 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3285 desc = jdesc_with_icelite.description();
3286 const cricket::TransportInfo* atinfo =
3287 desc->GetTransportInfoByName("audio_content_name");
3288 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3289 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003290 desc->GetTransportInfoByName("video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003291 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003292
3293 // Now that we know deserialization works, we can use TestSerialize to test
3294 // serialization.
3295 TestSerialize(jdesc_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003296}
3297
3298// Verifies that the candidates in the input SDP are parsed and serialized
3299// correctly in the output SDP.
3300TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3301 std::string sdp_with_data = kSdpString;
3302 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 10:27:41 -08003303 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003304
3305 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 12:22:16 -08003306 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003307}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003308
3309TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3310 AddFingerprint();
3311 TransportInfo audio_transport_info =
3312 *(desc_.GetTransportInfoByName(kAudioContentName));
3313 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3314 audio_transport_info.description.connection_role);
3315 audio_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003316 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003317
3318 TransportInfo video_transport_info =
3319 *(desc_.GetTransportInfoByName(kVideoContentName));
3320 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3321 video_transport_info.description.connection_role);
3322 video_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003323 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003324
3325 desc_.RemoveTransportInfoByName(kAudioContentName);
3326 desc_.RemoveTransportInfoByName(kVideoContentName);
3327
3328 desc_.AddTransportInfo(audio_transport_info);
3329 desc_.AddTransportInfo(video_transport_info);
3330
Yves Gerey665174f2018-06-19 15:03:05 +02003331 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003332 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003333 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003334 std::string sdp_with_dtlssetup = kSdpFullString;
3335
3336 // Fingerprint attribute is necessary to add DTLS setup attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003337 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_dtlssetup);
3338 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003339 // Now adding |setup| attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003340 InjectAfter(kFingerprint, "a=setup:active\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003341 EXPECT_EQ(sdp_with_dtlssetup, message);
3342}
3343
3344TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
Steve Antona3a92c22017-12-07 10:27:41 -08003345 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003346 std::string sdp_with_dtlssetup = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003347 InjectAfter(kSessionTime, "a=setup:actpass\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003348 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3349 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3350 const cricket::TransportInfo* atinfo =
3351 desc->GetTransportInfoByName("audio_content_name");
3352 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3353 atinfo->description.connection_role);
3354 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003355 desc->GetTransportInfoByName("video_content_name");
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003356 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3357 vtinfo->description.connection_role);
3358}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003359
3360// Verifies that the order of the serialized m-lines follows the order of the
3361// ContentInfo in SessionDescription, and vise versa for deserialization.
3362TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 10:27:41 -08003363 JsepSessionDescription jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02003364 const std::string media_content_sdps[3] = {kSdpAudioString, kSdpVideoString,
3365 kSdpSctpDataChannelString};
3366 const cricket::MediaType media_types[3] = {cricket::MEDIA_TYPE_AUDIO,
3367 cricket::MEDIA_TYPE_VIDEO,
3368 cricket::MEDIA_TYPE_DATA};
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003369
3370 // Verifies all 6 permutations.
3371 for (size_t i = 0; i < 6; ++i) {
3372 size_t media_content_in_sdp[3];
3373 // The index of the first media content.
3374 media_content_in_sdp[0] = i / 2;
3375 // The index of the second media content.
3376 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3377 // The index of the third media content.
3378 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3379
3380 std::string sdp_string = kSdpSessionString;
3381 for (size_t i = 0; i < 3; ++i)
3382 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3383
3384 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3385 cricket::SessionDescription* desc = jdesc.description();
3386 EXPECT_EQ(3u, desc->contents().size());
3387
3388 for (size_t i = 0; i < 3; ++i) {
3389 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 15:14:30 -08003390 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003391 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3392 }
3393
Steve Antone831b8c2018-02-01 12:22:16 -08003394 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003395 EXPECT_EQ(sdp_string, serialized_sdp);
3396 }
3397}
deadbeef9d3584c2016-02-16 17:54:10 -08003398
deadbeef25ed4352016-12-12 18:37:36 -08003399TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3400 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 10:27:41 -08003401 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003402 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003403 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3404 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3405}
3406
deadbeef12771a12017-01-03 13:53:47 -08003407// The semantics of "a=bundle-only" are only defined when it's used in
3408// combination with a 0 port on the m= line. We should ignore it if used with a
3409// nonzero port.
3410TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3411 // Make the base bundle-only description but unset the bundle-only flag.
3412 MakeBundleOnlyDescription();
3413 jdesc_.description()->contents()[1].bundle_only = false;
3414
3415 std::string modified_sdp = kBundleOnlySdpFullString;
3416 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08003417 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003418 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3419 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003420}
3421
3422TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3423 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003424 TestSerialize(jdesc_);
deadbeef25ed4352016-12-12 18:37:36 -08003425}
3426
deadbeef9d3584c2016-02-16 17:54:10 -08003427TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3428 MakePlanBDescription();
3429
Steve Antona3a92c22017-12-07 10:27:41 -08003430 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003431 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3432
3433 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3434}
3435
3436TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3437 MakePlanBDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003438 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-16 17:54:10 -08003439}
3440
3441TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3442 MakeUnifiedPlanDescription();
3443
Steve Antona3a92c22017-12-07 10:27:41 -08003444 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003445 EXPECT_TRUE(
3446 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3447
3448 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3449}
3450
3451TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3452 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003453 TestSerialize(jdesc_);
3454}
3455
Seth Hampson5b4f0752018-04-02 16:31:36 -07003456// This tests deserializing a Unified Plan SDP that is compatible with both
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003457// Unified Plan and Plan B style SDP, meaning that it contains both "a=ssrc
3458// msid" lines and "a=msid " lines. It tests the case for audio/video tracks
Seth Hampson5b4f0752018-04-02 16:31:36 -07003459// with no stream ids and multiple stream ids. For parsing this, the Unified
3460// Plan a=msid lines should take priority, because the Plan B style a=ssrc msid
3461// lines do not support multiple stream ids and no stream ids.
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003462TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionSpecialMsid) {
3463 // Create both msid lines for Plan B and Unified Plan support.
3464 MakeUnifiedPlanDescriptionMultipleStreamIds(
3465 cricket::kMsidSignalingMediaSection |
3466 cricket::kMsidSignalingSsrcAttribute);
Seth Hampson5b4f0752018-04-02 16:31:36 -07003467
3468 JsepSessionDescription deserialized_description(kDummyType);
3469 EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid,
3470 &deserialized_description));
3471
3472 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3473}
3474
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003475// Tests the serialization of a Unified Plan SDP that is compatible for both
3476// Unified Plan and Plan B style SDPs, meaning that it contains both "a=ssrc
3477// msid" lines and "a=msid " lines. It tests the case for no stream ids and
3478// multiple stream ids.
3479TEST_F(WebRtcSdpTest, SerializeSessionDescriptionSpecialMsid) {
3480 // Create both msid lines for Plan B and Unified Plan support.
3481 MakeUnifiedPlanDescriptionMultipleStreamIds(
3482 cricket::kMsidSignalingMediaSection |
3483 cricket::kMsidSignalingSsrcAttribute);
3484 std::string serialized_sdp = webrtc::SdpSerialize(jdesc_);
3485 // We explicitly test that the serialized SDP string is equal to the hard
3486 // coded SDP string. This is necessary, because in the parser "a=msid" lines
3487 // take priority over "a=ssrc msid" lines. This means if we just used
3488 // TestSerialize(), it could serialize an SDP that omits "a=ssrc msid" lines,
3489 // and still pass, because the deserialized version would be the same.
3490 EXPECT_EQ(kUnifiedPlanSdpFullStringWithSpecialMsid, serialized_sdp);
3491}
3492
3493// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3494// that signal stream IDs) is deserialized appropriately. It tests the case for
3495// no stream ids and multiple stream ids.
3496TEST_F(WebRtcSdpTest, UnifiedPlanDeserializeSessionDescriptionSpecialMsid) {
3497 // Only create a=msid lines for strictly Unified Plan stream ID support.
3498 MakeUnifiedPlanDescriptionMultipleStreamIds(
3499 cricket::kMsidSignalingMediaSection);
3500
3501 JsepSessionDescription deserialized_description(kDummyType);
3502 std::string unified_plan_sdp_string =
3503 kUnifiedPlanSdpFullStringWithSpecialMsid;
3504 RemoveSsrcMsidLinesFromSdpString(&unified_plan_sdp_string);
3505 EXPECT_TRUE(
3506 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3507
3508 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3509}
3510
3511// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3512// that signal stream IDs) is serialized appropriately. It tests the case for no
3513// stream ids and multiple stream ids.
3514TEST_F(WebRtcSdpTest, UnifiedPlanSerializeSessionDescriptionSpecialMsid) {
3515 // Only create a=msid lines for strictly Unified Plan stream ID support.
3516 MakeUnifiedPlanDescriptionMultipleStreamIds(
3517 cricket::kMsidSignalingMediaSection);
3518
Seth Hampson5b4f0752018-04-02 16:31:36 -07003519 TestSerialize(jdesc_);
3520}
3521
Seth Hampson5897a6e2018-04-03 11:16:33 -07003522// This tests that a Unified Plan SDP with no a=ssrc lines is
3523// serialized/deserialized appropriately. In this case the
3524// MediaContentDescription will contain a StreamParams object that doesn't have
3525// any SSRCs. Vice versa, this will be created upon deserializing an SDP with no
3526// SSRC lines.
3527TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3528 MakeUnifiedPlanDescription();
3529 RemoveSsrcSignalingFromStreamParams();
3530 std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString;
3531 RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string);
3532
3533 JsepSessionDescription deserialized_description(kDummyType);
3534 EXPECT_TRUE(
3535 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3536 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3537}
3538
3539TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3540 MakeUnifiedPlanDescription();
3541 RemoveSsrcSignalingFromStreamParams();
3542
3543 TestSerialize(jdesc_);
3544}
3545
Steve Antone831b8c2018-02-01 12:22:16 -08003546TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
3547 JsepSessionDescription jsep_desc(kDummyType);
3548 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
3549 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3550}
3551
3552TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
3553 JsepSessionDescription jsep_desc(kDummyType);
3554 std::string sdp = kSdpSessionString;
3555 sdp += kSdpSctpDataChannelString;
3556 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3557 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3558}
3559
3560TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
3561 JsepSessionDescription jsep_desc(kDummyType);
3562 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
3563 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
3564 jsep_desc.description()->msid_signaling());
3565}
3566
3567TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
3568 JsepSessionDescription jsep_desc(kDummyType);
3569 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
3570 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
3571 jsep_desc.description()->msid_signaling());
3572}
3573
3574const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
3575const char kSsrcAttributeMsidLine[] =
3576 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
3577
3578TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
3579 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
3580 std::string sdp = webrtc::SdpSerialize(jdesc_);
3581
3582 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3583 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3584}
3585
3586TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
3587 jdesc_.description()->set_msid_signaling(
3588 cricket::kMsidSignalingSsrcAttribute);
3589 std::string sdp = webrtc::SdpSerialize(jdesc_);
3590
3591 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
3592 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3593}
3594
3595TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
3596 jdesc_.description()->set_msid_signaling(
3597 cricket::kMsidSignalingMediaSection |
3598 cricket::kMsidSignalingSsrcAttribute);
3599 std::string sdp = webrtc::SdpSerialize(jdesc_);
3600
3601 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3602 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-16 17:54:10 -08003603}
deadbeef7e146cb2016-09-28 10:04:34 -07003604
3605// Regression test for heap overflow bug:
3606// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3607TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 10:04:34 -07003608 // The issue occurs when the sctp-port attribute is found in a video
3609 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 12:43:58 -08003610 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 10:04:34 -07003611 "v=0\r\n"
3612 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3613 "s=-\r\n"
3614 "t=0 0\r\n"
3615 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3616 "a=sctp-port 5000\r\n"
3617 "a=fmtp:108 foo=10\r\n";
3618
3619 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3620 "sctp-port");
3621}
deadbeefb2362572016-12-13 16:37:06 -08003622
3623// Regression test for integer overflow bug:
3624// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3625TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003626 // Bandwidth attribute is the max signed 32-bit int, which will get
3627 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003628 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003629 "v=0\r\n"
3630 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3631 "s=-\r\n"
3632 "t=0 0\r\n"
3633 "m=video 3457 RTP/SAVPF 120\r\n"
3634 "b=AS:2147483647\r\n"
3635 "foo=fail\r\n";
3636
3637 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3638}
deadbeef7bcdb692017-01-20 12:43:58 -08003639
deadbeefbc88c6b2017-08-02 11:26:34 -07003640// Similar to the above, except that negative values are illegal, not just
3641// error-prone as large values are.
3642// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3643TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3644 static const char kSdpWithNegativeBandwidth[] =
3645 "v=0\r\n"
3646 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3647 "s=-\r\n"
3648 "t=0 0\r\n"
3649 "m=video 3457 RTP/SAVPF 120\r\n"
3650 "b=AS:-1000\r\n";
3651
3652 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3653}
3654
deadbeef3e8016e2017-08-03 17:49:30 -07003655// An exception to the above rule: a value of -1 for b=AS should just be
3656// ignored, resulting in "kAutoBandwidth" in the deserialized object.
3657// Applications historically may be using "b=AS:-1" to mean "no bandwidth
3658// limit", but this is now what ommitting the attribute entirely will do, so
3659// ignoring it will have the intended effect.
3660TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
3661 static const char kSdpWithBandwidthOfNegativeOne[] =
3662 "v=0\r\n"
3663 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3664 "s=-\r\n"
3665 "t=0 0\r\n"
3666 "m=video 3457 RTP/SAVPF 120\r\n"
3667 "b=AS:-1\r\n";
3668
Steve Antona3a92c22017-12-07 10:27:41 -08003669 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-03 17:49:30 -07003670 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-03 17:49:30 -07003671 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003672 GetFirstVideoContentDescription(jdesc_output.description());
3673 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-03 17:49:30 -07003674 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
3675}
3676
deadbeef7bcdb692017-01-20 12:43:58 -08003677// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3678// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3679// Regression test for:
3680// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3681TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3682 // Important piece is "ufrag foo pwd bar".
3683 static const char kSdpWithIceCredentialsInCandidateString[] =
3684 "v=0\r\n"
3685 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3686 "s=-\r\n"
3687 "t=0 0\r\n"
3688 "m=audio 9 RTP/SAVPF 111\r\n"
3689 "c=IN IP4 0.0.0.0\r\n"
3690 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3691 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3692 "a=rtpmap:111 opus/48000/2\r\n"
3693 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3694 "generation 2 ufrag foo pwd bar\r\n";
3695
Steve Antona3a92c22017-12-07 10:27:41 -08003696 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 12:43:58 -08003697 EXPECT_TRUE(
3698 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
3699 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3700 ASSERT_NE(nullptr, candidates);
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003701 ASSERT_EQ(1U, candidates->count());
deadbeef7bcdb692017-01-20 12:43:58 -08003702 cricket::Candidate c = candidates->at(0)->candidate();
3703 EXPECT_EQ("ufrag_voice", c.username());
3704 EXPECT_EQ("pwd_voice", c.password());
3705}
deadbeef90f1e1e2017-02-10 12:35:05 -08003706
Johannes Kron211856b2018-09-06 12:12:28 +02003707// Test that attribute lines "a=ice-ufrag-something"/"a=ice-pwd-something" are
3708// ignored, and only the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3709// Regression test for:
3710// https://bugs.chromium.org/p/webrtc/issues/detail?id=9712
3711TEST_F(WebRtcSdpTest, AttributeWithPartialMatchingNameIsIgnored) {
3712 static const char kSdpWithFooIceCredentials[] =
3713 "v=0\r\n"
3714 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3715 "s=-\r\n"
3716 "t=0 0\r\n"
3717 "m=audio 9 RTP/SAVPF 111\r\n"
3718 "c=IN IP4 0.0.0.0\r\n"
3719 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3720 "a=ice-ufrag-something:foo\r\na=ice-pwd-something:bar\r\n"
3721 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3722 "a=rtpmap:111 opus/48000/2\r\n"
3723 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3724 "generation 2\r\n";
3725
3726 JsepSessionDescription jdesc_output(kDummyType);
3727 EXPECT_TRUE(SdpDeserialize(kSdpWithFooIceCredentials, &jdesc_output));
3728 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3729 ASSERT_NE(nullptr, candidates);
3730 ASSERT_EQ(1U, candidates->count());
3731 cricket::Candidate c = candidates->at(0)->candidate();
3732 EXPECT_EQ("ufrag_voice", c.username());
3733 EXPECT_EQ("pwd_voice", c.password());
3734}
3735
deadbeef90f1e1e2017-02-10 12:35:05 -08003736// Test that SDP with an invalid port number in "a=candidate" lines is
3737// rejected, without crashing.
3738// Regression test for:
3739// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
3740TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
3741 static const char kSdpWithInvalidCandidatePort[] =
3742 "v=0\r\n"
3743 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3744 "s=-\r\n"
3745 "t=0 0\r\n"
3746 "m=audio 9 RTP/SAVPF 111\r\n"
3747 "c=IN IP4 0.0.0.0\r\n"
3748 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3749 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3750 "a=rtpmap:111 opus/48000/2\r\n"
3751 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
3752 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
3753
Steve Antona3a92c22017-12-07 10:27:41 -08003754 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 12:35:05 -08003755 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
3756}
deadbeefa4549d62017-02-10 17:26:22 -08003757
3758// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
3759// Regression test for:
3760// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
3761TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
3762 static const char kSdpWithMissingTrackId[] =
3763 "v=0\r\n"
3764 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3765 "s=-\r\n"
3766 "t=0 0\r\n"
3767 "m=audio 9 RTP/SAVPF 111\r\n"
3768 "c=IN IP4 0.0.0.0\r\n"
3769 "a=rtpmap:111 opus/48000/2\r\n"
3770 "a=msid:stream_id \r\n";
3771
Steve Antona3a92c22017-12-07 10:27:41 -08003772 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003773 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
3774}
3775
3776TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
3777 static const char kSdpWithMissingStreamId[] =
3778 "v=0\r\n"
3779 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3780 "s=-\r\n"
3781 "t=0 0\r\n"
3782 "m=audio 9 RTP/SAVPF 111\r\n"
3783 "c=IN IP4 0.0.0.0\r\n"
3784 "a=rtpmap:111 opus/48000/2\r\n"
3785 "a=msid: track_id\r\n";
3786
Steve Antona3a92c22017-12-07 10:27:41 -08003787 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003788 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
3789}
zhihuang38989e52017-03-21 11:04:53 -07003790
3791// Tests that if both session-level address and media-level address exist, use
3792// the media-level address.
3793TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 10:27:41 -08003794 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003795
3796 // Sesssion-level address.
3797 std::string sdp = kSdpFullString;
3798 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3799 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3800
3801 const auto& content1 = jsep_desc.description()->contents()[0];
3802 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 15:14:30 -08003803 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003804 const auto& content2 = jsep_desc.description()->contents()[1];
3805 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 15:14:30 -08003806 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003807}
3808
3809// Tests that the session-level connection address will be used if the media
3810// level-addresses are not specified.
3811TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 10:27:41 -08003812 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003813
3814 // Sesssion-level address.
3815 std::string sdp = kSdpString;
3816 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3817 // Remove the media level addresses.
3818 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3819 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3820 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3821
3822 const auto& content1 = jsep_desc.description()->contents()[0];
3823 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003824 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003825 const auto& content2 = jsep_desc.description()->contents()[1];
3826 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003827 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003828}
3829
3830TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 10:27:41 -08003831 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003832
3833 std::string sdp = kSdpString;
3834 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3835 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
3836 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
3837 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
3838 &sdp);
3839 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
3840 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
3841 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
3842 &sdp);
3843 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3844 const auto& content1 = jsep_desc.description()->contents()[0];
3845 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003846 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003847 const auto& content2 = jsep_desc.description()->contents()[1];
3848 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003849 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003850}
3851
3852// Test that the invalid or unsupprted connection data cannot be parsed.
3853TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 10:27:41 -08003854 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003855 std::string sdp = kSdpString;
3856 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3857
3858 // Unsupported multicast IPv4 address.
3859 sdp = kSdpFullString;
3860 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
3861 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3862
3863 // Unsupported multicast IPv6 address.
3864 sdp = kSdpFullString;
3865 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
3866 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3867
3868 // Mismatched address type.
3869 sdp = kSdpFullString;
3870 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
3871 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3872
3873 sdp = kSdpFullString;
3874 Replace("c=IN IP4 74.125.224.39\r\n",
3875 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
3876 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3877}
3878
3879TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 10:27:41 -08003880 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003881 MakeDescriptionWithoutCandidates(&expected_jsep);
3882 // Serialization.
Steve Antone831b8c2018-02-01 12:22:16 -08003883 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 11:04:53 -07003884 // Deserialization.
Steve Antona3a92c22017-12-07 10:27:41 -08003885 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003886 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 15:14:30 -08003887 auto audio_desc = jdesc.description()
3888 ->GetContentByName(kAudioContentName)
3889 ->media_description();
3890 auto video_desc = jdesc.description()
3891 ->GetContentByName(kVideoContentName)
3892 ->media_description();
zhihuang38989e52017-03-21 11:04:53 -07003893 EXPECT_EQ(audio_desc_->connection_address().ToString(),
3894 audio_desc->connection_address().ToString());
3895 EXPECT_EQ(video_desc_->connection_address().ToString(),
3896 video_desc->connection_address().ToString());
3897}
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07003898
3899// RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be
3900// used (i.e., a single space as the session name)." So we should accept that.
3901TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) {
3902 JsepSessionDescription jsep_desc(kDummyType);
3903 std::string sdp = kSdpString;
3904 Replace("s=-\r\n", "s= \r\n", &sdp);
3905 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3906}