blob: 3111724bfd80510f57376871f03721f3e063ce17 [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"
626 "a=msid:local_stream_1 audio_track_id_1\r\n"
627 "a=sendrecv\r\n"
628 "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"
646 "a=msid:local_stream_1 audio_track_id_2\r\n"
647 "a=msid:local_stream_2 audio_track_id_2\r\n"
648 "a=sendrecv\r\n"
649 "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"
669 "a=msid:- audio_track_id_3\r\n"
670 "a=sendrecv\r\n"
671 "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"
679 "a=ssrc:7 cname:stream_2_cname\r\n";
680
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000681// One candidate reference string as per W3c spec.
682// candidate:<blah> not a=candidate:<blah>CRLF
683static const char kRawCandidate[] =
684 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
685// One candidate reference string.
686static const char kSdpOneCandidate[] =
687 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
688 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000689
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000690static const char kSdpTcpActiveCandidate[] =
691 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
692 "tcptype active generation 2";
693static const char kSdpTcpPassiveCandidate[] =
694 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
695 "tcptype passive generation 2";
696static const char kSdpTcpSOCandidate[] =
697 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
698 "tcptype so generation 2";
699static const char kSdpTcpInvalidCandidate[] =
700 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
701 "tcptype invalid generation 2";
702
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000703// One candidate reference string with IPV6 address.
704static const char kRawIPV6Candidate[] =
705 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 12:04:36 -0700706 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000707
708// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800709static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000710 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800711 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712
Zach Steinb336c272018-08-09 01:16:13 -0700713static const char kRawHostnameCandidate[] =
714 "candidate:a0+B/1 1 udp 2130706432 a.test 1234 typ host generation 2";
715
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000716// Session id and version
717static const char kSessionId[] = "18446744069414584320";
718static const char kSessionVersion[] = "18446462598732840960";
719
deadbeef9d3584c2016-02-16 17:54:10 -0800720// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000721static const char kIceOption1[] = "iceoption1";
722static const char kIceOption2[] = "iceoption2";
723static const char kIceOption3[] = "iceoption3";
724
deadbeef9d3584c2016-02-16 17:54:10 -0800725// ICE ufrags/passwords.
726static const char kUfragVoice[] = "ufrag_voice";
727static const char kPwdVoice[] = "pwd_voice";
728static const char kUfragVideo[] = "ufrag_video";
729static const char kPwdVideo[] = "pwd_video";
730static const char kUfragData[] = "ufrag_data";
731static const char kPwdData[] = "pwd_data";
732
733// Extra ufrags/passwords for extra unified plan m= sections.
734static const char kUfragVoice2[] = "ufrag_voice_2";
735static const char kPwdVoice2[] = "pwd_voice_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700736static const char kUfragVoice3[] = "ufrag_voice_3";
737static const char kPwdVoice3[] = "pwd_voice_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800738static const char kUfragVideo2[] = "ufrag_video_2";
739static const char kPwdVideo2[] = "pwd_video_2";
740static const char kUfragVideo3[] = "ufrag_video_3";
741static const char kPwdVideo3[] = "pwd_video_3";
742
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000743// Content name
744static const char kAudioContentName[] = "audio_content_name";
745static const char kVideoContentName[] = "video_content_name";
746static const char kDataContentName[] = "data_content_name";
747
deadbeef9d3584c2016-02-16 17:54:10 -0800748// Extra content names for extra unified plan m= sections.
749static const char kAudioContentName2[] = "audio_content_name_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700750static const char kAudioContentName3[] = "audio_content_name_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800751static const char kVideoContentName2[] = "video_content_name_2";
752static const char kVideoContentName3[] = "video_content_name_3";
753
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000754// MediaStream 1
Seth Hampson845e8782018-03-02 11:34:10 -0800755static const char kStreamId1[] = "local_stream_1";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000756static const char kStream1Cname[] = "stream_1_cname";
757static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200758static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000759static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800760static const uint32_t kVideoTrack1Ssrc1 = 2;
761static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000762
763// MediaStream 2
Seth Hampson845e8782018-03-02 11:34:10 -0800764static const char kStreamId2[] = "local_stream_2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000765static const char kStream2Cname[] = "stream_2_cname";
766static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200767static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800768static const char kVideoTrackId2[] = "video_track_id_2";
769static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000770static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800771static const uint32_t kVideoTrack3Ssrc = 6;
Seth Hampson5b4f0752018-04-02 16:31:36 -0700772static const char kAudioTrackId3[] = "audio_track_id_3";
773static const uint32_t kAudioTrack3Ssrc = 7;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000774
775// DataChannel
776static const char kDataChannelLabel[] = "data_channel";
777static const char kDataChannelMsid[] = "data_channeld0";
778static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200779static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000780
781// Candidate
782static const char kDummyMid[] = "dummy_mid";
783static const int kDummyIndex = 123;
784
785// Misc
Steve Antona3a92c22017-12-07 10:27:41 -0800786static SdpType kDummyType = SdpType::kOffer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000787
788// Helper functions
789
790static bool SdpDeserialize(const std::string& message,
791 JsepSessionDescription* jdesc) {
792 return webrtc::SdpDeserialize(message, jdesc, NULL);
793}
794
795static bool SdpDeserializeCandidate(const std::string& message,
796 JsepIceCandidate* candidate) {
797 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
798}
799
800// Add some extra |newlines| to the |message| after |line|.
801static void InjectAfter(const std::string& line,
802 const std::string& newlines,
803 std::string* message) {
804 const std::string tmp = line + newlines;
Yves Gerey665174f2018-06-19 15:03:05 +0200805 rtc::replace_substrs(line.c_str(), line.length(), tmp.c_str(), tmp.length(),
806 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000807}
808
809static void Replace(const std::string& line,
810 const std::string& newlines,
811 std::string* message) {
Yves Gerey665174f2018-06-19 15:03:05 +0200812 rtc::replace_substrs(line.c_str(), line.length(), newlines.c_str(),
813 newlines.length(), message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000814}
815
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000816// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
817// message.
818static void ExpectParseFailure(const std::string& bad_sdp,
819 const std::string& bad_part) {
Steve Antona3a92c22017-12-07 10:27:41 -0800820 JsepSessionDescription desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000821 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000822 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000823 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000824 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
825}
826
827// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
828static void ExpectParseFailure(const char* good_part, const char* bad_part) {
829 std::string bad_sdp = kSdpFullString;
830 Replace(good_part, bad_part, &bad_sdp);
831 ExpectParseFailure(bad_sdp, bad_part);
832}
833
834// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
835static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
836 const std::string& newlines,
837 const std::string& bad_part) {
838 std::string bad_sdp = kSdpFullString;
839 InjectAfter(injectpoint, newlines, &bad_sdp);
840 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000841}
842
Steve Anton4e70a722017-11-28 14:57:10 -0800843static void ReplaceDirection(RtpTransceiverDirection direction,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844 std::string* message) {
845 std::string new_direction;
846 switch (direction) {
Steve Anton4e70a722017-11-28 14:57:10 -0800847 case RtpTransceiverDirection::kInactive:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000848 new_direction = "a=inactive";
849 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800850 case RtpTransceiverDirection::kSendOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000851 new_direction = "a=sendonly";
852 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800853 case RtpTransceiverDirection::kRecvOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854 new_direction = "a=recvonly";
855 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800856 case RtpTransceiverDirection::kSendRecv:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000857 default:
858 new_direction = "a=sendrecv";
859 break;
860 }
861 Replace("a=sendrecv", new_direction, message);
862}
863
Yves Gerey665174f2018-06-19 15:03:05 +0200864static void ReplaceRejected(bool audio_rejected,
865 bool video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000866 std::string* message) {
867 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800868 Replace("m=audio 9", "m=audio 0", message);
869 Replace(kAttributeIceUfragVoice, "", message);
870 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000871 }
872 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800873 Replace("m=video 9", "m=video 0", message);
874 Replace(kAttributeIceUfragVideo, "", message);
875 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876 }
877}
878
879// WebRtcSdpTest
880
881class WebRtcSdpTest : public testing::Test {
882 public:
Steve Antona3a92c22017-12-07 10:27:41 -0800883 WebRtcSdpTest() : jdesc_(kDummyType) {
phoglund37ebcf02016-01-08 05:04:57 -0800884#ifdef WEBRTC_ANDROID
885 webrtc::InitializeAndroidObjects();
886#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000887 // AudioContentDescription
888 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -0800889 StreamParams audio_stream;
890 audio_stream.id = kAudioTrackId1;
891 audio_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -0800892 audio_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -0800893 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
894 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 11:04:53 -0700895 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
896 audio_desc_->set_connection_address(audio_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -0800897 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000898
899 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -0800900 video_desc_ = CreateVideoContentDescription();
901 StreamParams video_stream;
902 video_stream.id = kVideoTrackId1;
903 video_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -0800904 video_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -0800905 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
906 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
907 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
908 video_stream.ssrc_groups.push_back(ssrc_group);
909 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 11:04:53 -0700910 rtc::SocketAddress video_addr("74.125.224.39", 3457);
911 video_desc_->set_connection_address(video_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -0800912 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000913
914 // TransportInfo
deadbeef9d3584c2016-02-16 17:54:10 -0800915 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
916 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice))));
917 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
918 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919
920 // v4 host
921 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000922 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000923 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000924 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
925 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000926 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000927 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000928 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
929 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000930 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000931 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000932 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
933 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000934 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000935 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000936 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
937 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000938
939 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000940 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000941 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
942 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000943 cricket::LOCAL_PORT_TYPE,
944 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000946 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
947 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000948 cricket::LOCAL_PORT_TYPE,
949 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000950 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000951 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
952 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000953 cricket::LOCAL_PORT_TYPE,
954 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000955 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000956 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
957 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000958 cricket::LOCAL_PORT_TYPE,
959 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000960
961 // stun
962 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000963 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
964 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000965 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
966 address_stun, kCandidatePriority, "", "",
967 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000968 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969 candidate9.set_related_address(rel_address_stun);
970
971 address_stun.SetPort(port_stun++);
972 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000973 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
974 address_stun, kCandidatePriority, "", "",
975 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000976 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000977 candidate10.set_related_address(rel_address_stun);
978
979 // relay
980 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000981 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000982 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
983 address_relay, kCandidatePriority, "", "",
984 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000985 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000986 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000987 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
988 address_relay, kCandidatePriority, "", "",
989 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000990 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000991
992 // voice
993 candidates_.push_back(candidate1);
994 candidates_.push_back(candidate2);
995 candidates_.push_back(candidate5);
996 candidates_.push_back(candidate6);
997 candidates_.push_back(candidate9);
998 candidates_.push_back(candidate10);
999
1000 // video
1001 candidates_.push_back(candidate3);
1002 candidates_.push_back(candidate4);
1003 candidates_.push_back(candidate7);
1004 candidates_.push_back(candidate8);
1005 candidates_.push_back(candidate11);
1006 candidates_.push_back(candidate12);
1007
Yves Gerey665174f2018-06-19 15:03:05 +02001008 jcandidate_.reset(
1009 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001010
1011 // Set up JsepSessionDescription.
1012 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
1013 std::string mline_id;
1014 int mline_index = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001015 for (size_t i = 0; i < candidates_.size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001016 // In this test, the audio m line index will be 0, and the video m line
1017 // will be 1.
1018 bool is_video = (i > 5);
1019 mline_id = is_video ? "video_content_name" : "audio_content_name";
1020 mline_index = is_video ? 1 : 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001021 JsepIceCandidate jice(mline_id, mline_index, candidates_.at(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001022 jdesc_.AddCandidate(&jice);
1023 }
1024 }
1025
Seth Hampson5b4f0752018-04-02 16:31:36 -07001026 void RemoveVideoCandidates() {
deadbeef25ed4352016-12-12 18:37:36 -08001027 const IceCandidateCollection* video_candidates_collection =
1028 jdesc_.candidates(1);
1029 ASSERT_NE(nullptr, video_candidates_collection);
1030 std::vector<cricket::Candidate> video_candidates;
1031 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1032 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1033 c.set_transport_name("video_content_name");
1034 video_candidates.push_back(c);
1035 }
1036 jdesc_.RemoveCandidates(video_candidates);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001037 }
1038
1039 // Turns the existing reference description into a description using
1040 // a=bundle-only. This means no transport attributes and a 0 port value on
1041 // the m= sections not associated with the BUNDLE-tag.
1042 void MakeBundleOnlyDescription() {
1043 RemoveVideoCandidates();
deadbeef25ed4352016-12-12 18:37:36 -08001044
1045 // And the rest of the transport attributes.
1046 desc_.transport_infos()[1].description.ice_ufrag.clear();
1047 desc_.transport_infos()[1].description.ice_pwd.clear();
1048 desc_.transport_infos()[1].description.connection_role =
1049 cricket::CONNECTIONROLE_NONE;
1050
1051 // Set bundle-only flag.
1052 desc_.contents()[1].bundle_only = true;
1053
1054 // Add BUNDLE group.
1055 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1056 group.AddContentName(kAudioContentName);
1057 group.AddContentName(kVideoContentName);
1058 desc_.AddGroup(group);
1059
1060 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1061 jdesc_.session_version()));
1062 }
1063
deadbeef9d3584c2016-02-16 17:54:10 -08001064 // Turns the existing reference description into a plan B description,
1065 // with 2 audio tracks and 3 video tracks.
1066 void MakePlanBDescription() {
Steve Antonb1c1de12017-12-21 15:14:30 -08001067 audio_desc_ = audio_desc_->Copy();
1068 video_desc_ = video_desc_->Copy();
deadbeef9d3584c2016-02-16 17:54:10 -08001069
1070 StreamParams audio_track_2;
1071 audio_track_2.id = kAudioTrackId2;
1072 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001073 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001074 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1075 audio_desc_->AddStream(audio_track_2);
1076
1077 StreamParams video_track_2;
1078 video_track_2.id = kVideoTrackId2;
1079 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001080 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001081 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1082 video_desc_->AddStream(video_track_2);
1083
1084 StreamParams video_track_3;
1085 video_track_3.id = kVideoTrackId3;
1086 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001087 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001088 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1089 video_desc_->AddStream(video_track_3);
1090
1091 desc_.RemoveContentByName(kAudioContentName);
1092 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001093 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1094 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001095
1096 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1097 jdesc_.session_version()));
1098 }
1099
1100 // Turns the existing reference description into a unified plan description,
1101 // with 2 audio tracks and 3 video tracks.
1102 void MakeUnifiedPlanDescription() {
1103 // Audio track 2.
1104 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1105 StreamParams audio_track_2;
1106 audio_track_2.id = kAudioTrackId2;
1107 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001108 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001109 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1110 audio_desc_2->AddStream(audio_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001111 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
deadbeef9d3584c2016-02-16 17:54:10 -08001112 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1113 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
deadbeef9d3584c2016-02-16 17:54:10 -08001114 // Video track 2, in stream 2.
1115 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1116 StreamParams video_track_2;
1117 video_track_2.id = kVideoTrackId2;
1118 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001119 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001120 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1121 video_desc_2->AddStream(video_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001122 desc_.AddContent(kVideoContentName2, MediaProtocolType::kRtp, video_desc_2);
deadbeef9d3584c2016-02-16 17:54:10 -08001123 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1124 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2))));
1125
1126 // Video track 3, in stream 2.
1127 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1128 StreamParams video_track_3;
1129 video_track_3.id = kVideoTrackId3;
1130 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001131 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001132 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1133 video_desc_3->AddStream(video_track_3);
Steve Anton5adfafd2017-12-20 16:34:00 -08001134 desc_.AddContent(kVideoContentName3, MediaProtocolType::kRtp, video_desc_3);
deadbeef9d3584c2016-02-16 17:54:10 -08001135 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1136 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3))));
Steve Antone831b8c2018-02-01 12:22:16 -08001137 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
deadbeef9d3584c2016-02-16 17:54:10 -08001138
1139 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1140 jdesc_.session_version()));
1141 }
1142
1143 // Creates an audio content description with no streams, and some default
1144 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001145 AudioContentDescription* CreateAudioContentDescription() {
1146 AudioContentDescription* audio = new AudioContentDescription();
1147 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -08001148 audio->set_rtcp_reduced_size(true);
Yves Gerey665174f2018-06-19 15:03:05 +02001149 audio->AddCrypto(CryptoParams(
1150 1, "AES_CM_128_HMAC_SHA1_32",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001151 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1152 "dummy_session_params"));
1153 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef67cf2c12016-04-13 10:07:16 -07001154 AudioCodec opus(111, "opus", 48000, 0, 2);
deadbeef9d3584c2016-02-16 17:54:10 -08001155 audio->AddCodec(opus);
ossue1405ad2017-01-23 08:55:48 -08001156 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1157 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001158 return audio;
1159 }
1160
Seth Hampson5b4f0752018-04-02 16:31:36 -07001161 // Turns the existing reference description into a unified plan description,
1162 // with 3 audio MediaContentDescriptions with special StreamParams that
1163 // contain 0 or multiple stream ids: - audio track 1 has 1 media stream id -
1164 // audio track 2 has 2 media stream ids - audio track 3 has 0 media stream ids
1165 void MakeUnifiedPlanDescriptionMultipleStreamIds() {
1166 desc_.RemoveContentByName(kVideoContentName);
1167 desc_.RemoveTransportInfoByName(kVideoContentName);
1168 RemoveVideoCandidates();
1169
1170 // Audio track 2 has 2 media stream ids.
1171 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1172 StreamParams audio_track_2;
1173 audio_track_2.id = kAudioTrackId2;
1174 audio_track_2.cname = kStream1Cname;
1175 audio_track_2.set_stream_ids({kStreamId1, kStreamId2});
1176 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1177 audio_desc_2->AddStream(audio_track_2);
1178 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
1179 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1180 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
1181
1182 // Audio track 3 has no stream ids.
1183 AudioContentDescription* audio_desc_3 = CreateAudioContentDescription();
1184 StreamParams audio_track_3;
1185 audio_track_3.id = kAudioTrackId3;
1186 audio_track_3.cname = kStream2Cname;
1187 audio_track_3.set_stream_ids({});
1188 audio_track_3.ssrcs.push_back(kAudioTrack3Ssrc);
1189 audio_desc_3->AddStream(audio_track_3);
1190 desc_.AddContent(kAudioContentName3, MediaProtocolType::kRtp, audio_desc_3);
1191 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1192 kAudioContentName3, TransportDescription(kUfragVoice3, kPwdVoice3))));
1193 // Make sure to create both a=msid lines.
1194 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection |
1195 cricket::kMsidSignalingSsrcAttribute);
1196 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1197 jdesc_.session_version()));
1198 }
1199
Seth Hampson5897a6e2018-04-03 11:16:33 -07001200 // Turns the existing reference description into a unified plan description
1201 // with one audio MediaContentDescription that contains one StreamParams with
1202 // 0 ssrcs.
1203 void MakeUnifiedPlanDescriptionNoSsrcSignaling() {
1204 desc_.RemoveContentByName(kVideoContentName);
1205 desc_.RemoveContentByName(kAudioContentName);
1206 desc_.RemoveTransportInfoByName(kVideoContentName);
1207 RemoveVideoCandidates();
1208
1209 AudioContentDescription* audio_desc = CreateAudioContentDescription();
1210 StreamParams audio_track;
1211 audio_track.id = kAudioTrackId1;
1212 audio_track.set_stream_ids({kStreamId1});
1213 audio_desc->AddStream(audio_track);
1214 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc);
1215
1216 // Enable signaling a=msid lines.
1217 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
1218 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1219 jdesc_.session_version()));
1220 }
1221
deadbeef9d3584c2016-02-16 17:54:10 -08001222 // Creates a video content description with no streams, and some default
1223 // configuration.
1224 VideoContentDescription* CreateVideoContentDescription() {
1225 VideoContentDescription* video = new VideoContentDescription();
1226 video->AddCrypto(CryptoParams(
1227 1, "AES_CM_128_HMAC_SHA1_80",
1228 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1229 video->set_protocol(cricket::kMediaProtocolSavpf);
1230 video->AddCodec(
perkj26752742016-10-24 01:21:16 -07001231 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-16 17:54:10 -08001232 return video;
1233 }
1234
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001235 template <class MCD>
Yves Gerey665174f2018-06-19 15:03:05 +02001236 void CompareMediaContentDescription(const MCD* cd1, const MCD* cd2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001237 // type
1238 EXPECT_EQ(cd1->type(), cd1->type());
1239
1240 // content direction
1241 EXPECT_EQ(cd1->direction(), cd2->direction());
1242
1243 // rtcp_mux
1244 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1245
deadbeef13871492015-12-09 12:37:51 -08001246 // rtcp_reduced_size
1247 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1248
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001249 // cryptos
1250 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1251 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1252 ADD_FAILURE();
1253 return;
1254 }
Yves Gerey665174f2018-06-19 15:03:05 +02001255 for (size_t i = 0; i < cd1->cryptos().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001256 const CryptoParams c1 = cd1->cryptos().at(i);
1257 const CryptoParams c2 = cd2->cryptos().at(i);
1258 EXPECT_TRUE(c1.Matches(c2));
1259 EXPECT_EQ(c1.key_params, c2.key_params);
1260 EXPECT_EQ(c1.session_params, c2.session_params);
1261 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001262
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001263 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001264 // Use an equivalence class here, for old and new versions of the
1265 // protocol description.
Yves Gerey665174f2018-06-19 15:03:05 +02001266 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp ||
1267 cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1268 cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
lally@webrtc.org36300852015-02-24 20:19:35 +00001269 const bool cd2_is_also_dtls_sctp =
Yves Gerey665174f2018-06-19 15:03:05 +02001270 cd2->protocol() == cricket::kMediaProtocolDtlsSctp ||
1271 cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1272 cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
lally@webrtc.org36300852015-02-24 20:19:35 +00001273 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001274 } else {
1275 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1276 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001277
1278 // codecs
1279 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1280
1281 // bandwidth
1282 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1283
1284 // streams
1285 EXPECT_EQ(cd1->streams(), cd2->streams());
1286
Johannes Kron0854eb62018-10-10 22:33:20 +02001287 // extmap-allow-mixed
1288 EXPECT_EQ(cd1->mixed_one_two_byte_header_extensions_supported(),
1289 cd2->mixed_one_two_byte_header_extensions_supported());
1290
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 Kron0854eb62018-10-10 22:33:20 +02001407 EXPECT_EQ(desc1.mixed_one_two_byte_header_extensions_supported(),
1408 desc2.mixed_one_two_byte_header_extensions_supported());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001409 }
1410
Yves Gerey665174f2018-06-19 15:03:05 +02001411 bool CompareSessionDescription(const JsepSessionDescription& desc1,
1412 const JsepSessionDescription& desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001413 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1414 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1415 CompareSessionDescription(*desc1.description(), *desc2.description());
1416 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1417 return false;
1418 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1419 const IceCandidateCollection* cc1 = desc1.candidates(i);
1420 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-12 18:37:36 -08001421 if (cc1->count() != cc2->count()) {
1422 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001423 return false;
deadbeef25ed4352016-12-12 18:37:36 -08001424 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001425 for (size_t j = 0; j < cc1->count(); ++j) {
1426 const IceCandidateInterface* c1 = cc1->at(j);
1427 const IceCandidateInterface* c2 = cc2->at(j);
1428 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1429 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1430 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1431 }
1432 }
1433 return true;
1434 }
1435
1436 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1437 // them with invalid keywords so that the parser will just ignore them.
1438 bool RemoveCandidateUfragPwd(std::string* sdp) {
1439 const char ice_ufrag[] = "a=ice-ufrag";
1440 const char ice_ufragx[] = "a=xice-ufrag";
1441 const char ice_pwd[] = "a=ice-pwd";
1442 const char ice_pwdx[] = "a=xice-pwd";
Yves Gerey665174f2018-06-19 15:03:05 +02001443 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag), ice_ufragx,
1444 strlen(ice_ufragx), sdp);
1445 rtc::replace_substrs(ice_pwd, strlen(ice_pwd), ice_pwdx, strlen(ice_pwdx),
1446 sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001447 return true;
1448 }
1449
1450 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
Yves Gerey665174f2018-06-19 15:03:05 +02001451 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc,
1452 int mline_index,
1453 const std::string& ufrag,
1454 const std::string& pwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001455 std::string content_name;
1456 if (mline_index == 0) {
1457 content_name = kAudioContentName;
1458 } else if (mline_index == 1) {
1459 content_name = kVideoContentName;
1460 } else {
nissec80e7412017-01-11 05:56:46 -08001461 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001462 }
Yves Gerey665174f2018-06-19 15:03:05 +02001463 TransportInfo transport_info(content_name,
1464 TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001465 SessionDescription* desc =
1466 const_cast<SessionDescription*>(jdesc->description());
1467 desc->RemoveTransportInfoByName(content_name);
1468 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
1469 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1470 const IceCandidateCollection* cc = jdesc_.candidates(i);
1471 for (size_t j = 0; j < cc->count(); ++j) {
1472 if (cc->at(j)->sdp_mline_index() == mline_index) {
Yves Gerey665174f2018-06-19 15:03:05 +02001473 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(ufrag);
1474 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001475 }
1476 }
1477 }
1478 return true;
1479 }
1480
1481 void AddIceOptions(const std::string& content_name,
1482 const std::vector<std::string>& transport_options) {
1483 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1484 cricket::TransportInfo transport_info =
1485 *(desc_.GetTransportInfoByName(content_name));
1486 desc_.RemoveTransportInfoByName(content_name);
1487 transport_info.description.transport_options = transport_options;
1488 desc_.AddTransportInfo(transport_info);
1489 }
1490
deadbeef3f7219b2015-12-28 15:17:14 -08001491 void SetIceUfragPwd(const std::string& content_name,
1492 const std::string& ice_ufrag,
1493 const std::string& ice_pwd) {
1494 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1495 cricket::TransportInfo transport_info =
1496 *(desc_.GetTransportInfoByName(content_name));
1497 desc_.RemoveTransportInfoByName(content_name);
1498 transport_info.description.ice_ufrag = ice_ufrag;
1499 transport_info.description.ice_pwd = ice_pwd;
1500 desc_.AddTransportInfo(transport_info);
1501 }
1502
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001503 void AddFingerprint() {
1504 desc_.RemoveTransportInfoByName(kAudioContentName);
1505 desc_.RemoveTransportInfoByName(kVideoContentName);
Steve Anton47f32402018-10-11 13:22:38 -07001506 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, kIdentityDigest);
deadbeef46eed762016-01-28 13:24:37 -08001507 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1508 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001509 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1510 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001511 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1512 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1513 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001514 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1515 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001516 cricket::CONNECTIONROLE_NONE, &fingerprint))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001517 }
1518
jbauch5869f502017-06-29 12:31:36 -07001519 void AddExtmap(bool encrypted) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001520 audio_desc_ = audio_desc_->Copy();
1521 video_desc_ = video_desc_->Copy();
jbauch5869f502017-06-29 12:31:36 -07001522 audio_desc_->AddRtpHeaderExtension(
1523 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1524 video_desc_->AddRtpHeaderExtension(
1525 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001526 desc_.RemoveContentByName(kAudioContentName);
1527 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001528 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1529 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001530 }
1531
1532 void RemoveCryptos() {
1533 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1534 video_desc_->set_cryptos(std::vector<CryptoParams>());
1535 }
1536
Seth Hampson5897a6e2018-04-03 11:16:33 -07001537 // Removes everything in StreamParams from the session description that is
1538 // used for a=ssrc lines.
1539 void RemoveSsrcSignalingFromStreamParams() {
1540 for (cricket::ContentInfo content_info : jdesc_.description()->contents()) {
1541 // With Unified Plan there should be one StreamParams per m= section.
1542 StreamParams& stream =
1543 content_info.media_description()->mutable_streams()[0];
1544 stream.ssrcs.clear();
1545 stream.ssrc_groups.clear();
1546 stream.cname.clear();
1547 }
1548 }
1549
1550 // Removes all a=ssrc lines from the SDP string.
1551 void RemoveSsrcLinesFromSdpString(std::string* sdp_string) {
1552 const char kAttributeSsrc[] = "a=ssrc";
1553 while (sdp_string->find(kAttributeSsrc) != std::string::npos) {
1554 size_t pos_ssrc_attribute = sdp_string->find(kAttributeSsrc);
1555 size_t beg_line_pos = sdp_string->rfind('\n', pos_ssrc_attribute);
1556 size_t end_line_pos = sdp_string->find('\n', pos_ssrc_attribute);
1557 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1558 }
1559 }
1560
Steve Anton4e70a722017-11-28 14:57:10 -08001561 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001562 audio_desc_->set_direction(direction);
1563 video_desc_->set_direction(direction);
1564 std::string new_sdp = kSdpFullString;
1565 ReplaceDirection(direction, &new_sdp);
1566
Yves Gerey665174f2018-06-19 15:03:05 +02001567 if (!jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001568 jdesc_.session_version())) {
1569 return false;
1570 }
Steve Antone831b8c2018-02-01 12:22:16 -08001571 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001572 EXPECT_EQ(new_sdp, message);
1573 return true;
1574 }
1575
1576 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001577 audio_desc_ = audio_desc_->Copy();
1578 video_desc_ = video_desc_->Copy();
zhihuang38989e52017-03-21 11:04:53 -07001579
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001580 desc_.RemoveContentByName(kAudioContentName);
1581 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001582 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001583 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001584 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001585 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001586 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1587 audio_rejected ? "" : kPwdVoice);
1588 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1589 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001590
1591 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001592 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1593
Steve Antona3a92c22017-12-07 10:27:41 -08001594 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001595 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001596 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001597 EXPECT_EQ(new_sdp, message);
1598 return true;
1599 }
1600
zstein4b2e0822017-02-17 19:48:38 -08001601 void AddSctpDataChannel(bool use_sctpmap) {
kwibergd1fe2812016-04-27 06:47:29 -07001602 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001603 data_desc_ = data.get();
zstein4b2e0822017-02-17 19:48:38 -08001604 data_desc_->set_use_sctpmap(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001605 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
solenberg9fa49752016-10-08 13:02:44 -07001606 DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07001607 cricket::kGoogleSctpDataCodecName);
wu@webrtc.org78187522013-10-07 23:32:02 +00001608 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1609 data_desc_->AddCodec(codec);
Steve Anton5adfafd2017-12-20 16:34:00 -08001610 desc_.AddContent(kDataContentName, MediaProtocolType::kSctp,
1611 data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001612 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1613 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001614 }
1615
1616 void AddRtpDataChannel() {
kwibergd1fe2812016-04-27 06:47:29 -07001617 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001618 data_desc_ = data.get();
1619
deadbeef67cf2c12016-04-13 10:07:16 -07001620 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001621 StreamParams data_stream;
1622 data_stream.id = kDataChannelMsid;
1623 data_stream.cname = kDataChannelCname;
Seth Hampson845e8782018-03-02 11:34:10 -08001624 data_stream.set_stream_ids({kDataChannelLabel});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001625 data_stream.ssrcs.push_back(kDataChannelSsrc);
1626 data_desc_->AddStream(data_stream);
Yves Gerey665174f2018-06-19 15:03:05 +02001627 data_desc_->AddCrypto(
1628 CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
1629 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001630 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
Steve Anton5adfafd2017-12-20 16:34:00 -08001631 desc_.AddContent(kDataContentName, MediaProtocolType::kRtp, 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
Steve Anton4e70a722017-11-28 14:57:10 -08001636 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001637 std::string new_sdp = kSdpFullString;
1638 ReplaceDirection(direction, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001639 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001640
1641 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1642
1643 audio_desc_->set_direction(direction);
1644 video_desc_->set_direction(direction);
Yves Gerey665174f2018-06-19 15:03:05 +02001645 if (!jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001646 jdesc_.session_version())) {
1647 return false;
1648 }
1649 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1650 return true;
1651 }
1652
1653 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001654 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001655 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001656 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001657 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001658
Steve Antonb1c1de12017-12-21 15:14:30 -08001659 audio_desc_ = audio_desc_->Copy();
1660 video_desc_ = video_desc_->Copy();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001661 desc_.RemoveContentByName(kAudioContentName);
1662 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001663 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001664 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001665 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001666 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001667 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1668 audio_rejected ? "" : kPwdVoice);
1669 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1670 video_rejected ? "" : kPwdVideo);
Steve Antona3a92c22017-12-07 10:27:41 -08001671 JsepSessionDescription jdesc_no_candidates(kDummyType);
deadbeef3f7219b2015-12-28 15:17:14 -08001672 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1673 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001674 return false;
1675 }
deadbeef3f7219b2015-12-28 15:17:14 -08001676 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001677 return true;
1678 }
1679
Yves Gerey665174f2018-06-19 15:03:05 +02001680 void TestDeserializeExtmap(bool session_level,
1681 bool media_level,
1682 bool encrypted) {
jbauch5869f502017-06-29 12:31:36 -07001683 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08001684 JsepSessionDescription new_jdesc(SdpType::kOffer);
Yves Gerey665174f2018-06-19 15:03:05 +02001685 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001686 jdesc_.session_version()));
Steve Antona3a92c22017-12-07 10:27:41 -08001687 JsepSessionDescription jdesc_with_extmap(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001688 std::string sdp_with_extmap = kSdpString;
1689 if (session_level) {
jbauch5869f502017-06-29 12:31:36 -07001690 InjectAfter(kSessionTime,
1691 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1692 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001693 &sdp_with_extmap);
1694 }
1695 if (media_level) {
jbauch5869f502017-06-29 12:31:36 -07001696 InjectAfter(kAttributeIcePwdVoice,
1697 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1698 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001699 &sdp_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07001700 InjectAfter(kAttributeIcePwdVideo,
1701 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1702 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001703 &sdp_with_extmap);
1704 }
1705 // The extmap can't be present at the same time in both session level and
1706 // media level.
1707 if (session_level && media_level) {
1708 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02001709 EXPECT_FALSE(
1710 webrtc::SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001711 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1712 } else {
1713 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1714 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1715 }
1716 }
1717
1718 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
Yves Gerey665174f2018-06-19 15:03:05 +02001719 const std::string& name,
1720 int expected_value) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001721 cricket::CodecParameterMap::const_iterator found = params.find(name);
1722 ASSERT_TRUE(found != params.end());
Jonas Olsson6b1985d2018-07-05 11:59:48 +02001723 EXPECT_EQ(found->second, rtc::ToString(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001724 }
1725
1726 void TestDeserializeCodecParams(const CodecParams& params,
1727 JsepSessionDescription* jdesc_output) {
1728 std::string sdp =
1729 "v=0\r\n"
1730 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1731 "s=-\r\n"
1732 "t=0 0\r\n"
1733 // Include semantics for WebRTC Media Streams since it is supported by
1734 // this parser, and will be added to the SDP when serializing a session
1735 // description.
1736 "a=msid-semantic: WMS\r\n"
1737 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001738 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001739 // Pltype 111 listed before 103 and 104 in the map.
1740 "a=rtpmap:111 opus/48000/2\r\n"
1741 // Pltype 103 listed before 104.
1742 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001743 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001744 "a=fmtp:111 0-15,66,70\r\n"
1745 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001746 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001747 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001748 << "; sprop-stereo=" << params.sprop_stereo
1749 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001750 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001751 << "a=ptime:" << params.ptime << "\r\n"
1752 << "a=maxptime:" << params.max_ptime << "\r\n";
1753 sdp += os.str();
1754
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001755 os.clear();
1756 os.str("");
1757 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001758 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001759 << "a=rtpmap:99 VP8/90000\r\n"
1760 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001761 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001762 sdp += os.str();
1763
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001764 // Deserialize
1765 SdpParseError error;
1766 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1767
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001768 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001769 GetFirstAudioContentDescription(jdesc_output->description());
1770 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001771 ASSERT_FALSE(acd->codecs().empty());
1772 cricket::AudioCodec opus = acd->codecs()[0];
1773 EXPECT_EQ("opus", opus.name);
1774 EXPECT_EQ(111, opus.id);
1775 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1776 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1777 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1778 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001779 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1780 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001781 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1782 cricket::AudioCodec codec = acd->codecs()[i];
1783 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1784 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001785 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001786
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001787 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001788 GetFirstVideoContentDescription(jdesc_output->description());
1789 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001790 ASSERT_FALSE(vcd->codecs().empty());
1791 cricket::VideoCodec vp8 = vcd->codecs()[0];
1792 EXPECT_EQ("VP8", vp8.name);
1793 EXPECT_EQ(99, vp8.id);
1794 cricket::VideoCodec rtx = vcd->codecs()[1];
1795 EXPECT_EQ("RTX", rtx.name);
1796 EXPECT_EQ(95, rtx.id);
1797 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001798 }
1799
1800 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1801 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001802 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001803 "v=0\r\n"
1804 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1805 "s=-\r\n"
1806 "t=0 0\r\n"
1807 // Include semantics for WebRTC Media Streams since it is supported by
1808 // this parser, and will be added to the SDP when serializing a session
1809 // description.
1810 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001811 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001812 "a=rtpmap:111 opus/48000/2\r\n";
1813 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001814 "m=video 3457 RTP/SAVPF 101\r\n"
1815 "a=rtpmap:101 VP8/90000\r\n"
1816 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001817 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001818 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001819 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001820 os << sdp_session_and_audio;
Yves Gerey665174f2018-06-19 15:03:05 +02001821 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001822 os << sdp_video;
Yves Gerey665174f2018-06-19 15:03:05 +02001823 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001824 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001825 // Deserialize
1826 SdpParseError error;
1827 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001828 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001829 GetFirstAudioContentDescription(jdesc_output->description());
1830 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001831 ASSERT_FALSE(acd->codecs().empty());
1832 cricket::AudioCodec opus = acd->codecs()[0];
1833 EXPECT_EQ(111, opus.id);
Yves Gerey665174f2018-06-19 15:03:05 +02001834 EXPECT_TRUE(opus.HasFeedbackParam(cricket::FeedbackParam(
1835 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001836
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001837 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001838 GetFirstVideoContentDescription(jdesc_output->description());
1839 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001840 ASSERT_FALSE(vcd->codecs().empty());
1841 cricket::VideoCodec vp8 = vcd->codecs()[0];
1842 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1843 vp8.name.c_str());
1844 EXPECT_EQ(101, vp8.id);
Yves Gerey665174f2018-06-19 15:03:05 +02001845 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1846 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
1847 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1848 cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli)));
1849 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1850 cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty)));
1851 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1852 cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001853 }
1854
1855 // Two SDP messages can mean the same thing but be different strings, e.g.
1856 // some of the lines can be serialized in different order.
1857 // However, a deserialized description can be compared field by field and has
1858 // no order. If deserializer has already been tested, serializing then
1859 // deserializing and comparing JsepSessionDescription will test
1860 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 12:22:16 -08001861 void TestSerialize(const JsepSessionDescription& jdesc) {
1862 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 10:27:41 -08001863 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001864 SdpParseError error;
1865 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1866 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1867 }
1868
zhihuang38989e52017-03-21 11:04:53 -07001869 // Calling 'Initialize' with a copy of the inner SessionDescription will
1870 // create a copy of the JsepSessionDescription without candidates. The
1871 // 'connection address' field, previously set from the candidates, must also
1872 // be reset.
1873 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
1874 rtc::SocketAddress audio_addr("0.0.0.0", 9);
1875 rtc::SocketAddress video_addr("0.0.0.0", 9);
1876 audio_desc_->set_connection_address(audio_addr);
1877 video_desc_->set_connection_address(video_addr);
1878 ASSERT_TRUE(jdesc->Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1879 }
1880
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001881 protected:
1882 SessionDescription desc_;
1883 AudioContentDescription* audio_desc_;
1884 VideoContentDescription* video_desc_;
1885 DataContentDescription* data_desc_;
1886 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07001887 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001888 JsepSessionDescription jdesc_;
1889};
1890
1891void TestMismatch(const std::string& string1, const std::string& string2) {
1892 int position = 0;
1893 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1894 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001895 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001896 break;
1897 }
1898 }
1899 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1900 << " character\n"
1901 << " 1: " << string1.substr(position, 20) << "\n"
1902 << " 2: " << string2.substr(position, 20) << "\n";
1903}
1904
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001905TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1906 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 12:22:16 -08001907 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001908 TestMismatch(std::string(kSdpFullString), message);
1909}
1910
1911TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 10:27:41 -08001912 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 12:22:16 -08001913 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001914}
1915
1916// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1917// the case in a DTLS offer.
1918TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1919 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08001920 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001921 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08001922 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001923
1924 std::string sdp_with_fingerprint = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02001925 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1926 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001927
1928 EXPECT_EQ(sdp_with_fingerprint, message);
1929}
1930
1931// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1932// be the case in a DTLS answer.
1933TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1934 AddFingerprint();
1935 RemoveCryptos();
Steve Antona3a92c22017-12-07 10:27:41 -08001936 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001937 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08001938 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001939
1940 std::string sdp_with_fingerprint = kSdpString;
1941 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1942 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
Yves Gerey665174f2018-06-19 15:03:05 +02001943 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1944 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001945
1946 EXPECT_EQ(sdp_with_fingerprint, message);
1947}
1948
1949TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1950 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08001951 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001952 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001953 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001954 EXPECT_EQ(std::string(kSdpString), message);
1955}
1956
1957TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1958 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1959 group.AddContentName(kAudioContentName);
1960 group.AddContentName(kVideoContentName);
1961 desc_.AddGroup(group);
Yves Gerey665174f2018-06-19 15:03:05 +02001962 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001963 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08001964 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001965 std::string sdp_with_bundle = kSdpFullString;
1966 InjectAfter(kSessionTime,
1967 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1968 &sdp_with_bundle);
1969 EXPECT_EQ(sdp_with_bundle, message);
1970}
1971
1972TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001973 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001974 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08001975 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001976 acd->set_bandwidth(50 * 1000);
Yves Gerey665174f2018-06-19 15:03:05 +02001977 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001978 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08001979 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001980 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02001981 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001982 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02001983 InjectAfter("c=IN IP4 74.125.127.126\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001984 &sdp_with_bandwidth);
1985 EXPECT_EQ(sdp_with_bandwidth, message);
1986}
1987
1988TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1989 std::vector<std::string> transport_options;
1990 transport_options.push_back(kIceOption1);
1991 transport_options.push_back(kIceOption3);
1992 AddIceOptions(kAudioContentName, transport_options);
1993 transport_options.clear();
1994 transport_options.push_back(kIceOption2);
1995 transport_options.push_back(kIceOption3);
1996 AddIceOptions(kVideoContentName, transport_options);
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_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002001 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002002 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002003 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002004 &sdp_with_ice_options);
2005 EXPECT_EQ(sdp_with_ice_options, message);
2006}
2007
2008TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002009 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002010}
2011
2012TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002013 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002014}
2015
2016TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002017 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002018}
2019
2020TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2021 EXPECT_TRUE(TestSerializeRejected(true, false));
2022}
2023
2024TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2025 EXPECT_TRUE(TestSerializeRejected(false, true));
2026}
2027
2028TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2029 EXPECT_TRUE(TestSerializeRejected(true, true));
2030}
2031
2032TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
2033 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002034 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002035
zhihuang38989e52017-03-21 11:04:53 -07002036 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002037 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002038
2039 std::string expected_sdp = kSdpString;
2040 expected_sdp.append(kSdpRtpDataChannelString);
2041 EXPECT_EQ(expected_sdp, message);
2042}
2043
2044TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08002045 bool use_sctpmap = true;
2046 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002047 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002048
zhihuang38989e52017-03-21 11:04:53 -07002049 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002050 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002051
2052 std::string expected_sdp = kSdpString;
2053 expected_sdp.append(kSdpSctpDataChannelString);
2054 EXPECT_EQ(message, expected_sdp);
2055}
2056
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002057TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08002058 bool use_sctpmap = true;
2059 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002060 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002061 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antonb1c1de12017-12-21 15:14:30 -08002062 DataContentDescription* dcdesc =
2063 jsep_desc.description()
2064 ->GetContentDescriptionByName(kDataContentName)
2065 ->as_data();
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002066
2067 const int kNewPort = 1234;
solenberg9fa49752016-10-08 13:02:44 -07002068 cricket::DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07002069 cricket::kGoogleSctpDataCodecName);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002070 codec.SetParam(cricket::kCodecParamPort, kNewPort);
2071 dcdesc->AddOrReplaceCodec(codec);
2072
Steve Antone831b8c2018-02-01 12:22:16 -08002073 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002074
2075 std::string expected_sdp = kSdpString;
2076 expected_sdp.append(kSdpSctpDataChannelString);
2077
2078 char default_portstr[16];
2079 char new_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002080 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
Yves Gerey665174f2018-06-19 15:03:05 +02002081 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002082 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
Yves Gerey665174f2018-06-19 15:03:05 +02002083 rtc::replace_substrs(default_portstr, strlen(default_portstr), new_portstr,
2084 strlen(new_portstr), &expected_sdp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002085
2086 EXPECT_EQ(expected_sdp, message);
2087}
2088
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002089TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002090 JsepSessionDescription jsep_desc(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002091 AddRtpDataChannel();
Yves Gerey665174f2018-06-19 15:03:05 +02002092 data_desc_->set_bandwidth(100 * 1000);
zhihuang38989e52017-03-21 11:04:53 -07002093 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002094 std::string message = webrtc::SdpSerialize(jsep_desc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002095
2096 std::string expected_sdp = kSdpString;
2097 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002098 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00002099 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02002100 "b=AS:100\r\n", &expected_sdp);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002101 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002102}
2103
Johannes Kron0854eb62018-10-10 22:33:20 +02002104TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapAllowMixed) {
2105 jdesc_.description()->set_mixed_one_two_byte_header_extensions_supported(
2106 true);
2107 TestSerialize(jdesc_);
2108}
2109
2110TEST_F(WebRtcSdpTest, SerializeMediaContentDescriptionWithExtmapAllowMixed) {
2111 cricket::MediaContentDescription* video_desc =
2112 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2113 ASSERT_TRUE(video_desc);
2114 cricket::MediaContentDescription* audio_desc =
2115 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2116 ASSERT_TRUE(audio_desc);
2117 video_desc->set_mixed_one_two_byte_header_extensions_supported(
2118 cricket::MediaContentDescription::kMedia);
2119 audio_desc->set_mixed_one_two_byte_header_extensions_supported(
2120 cricket::MediaContentDescription::kMedia);
2121 TestSerialize(jdesc_);
2122}
2123
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002124TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002125 bool encrypted = false;
2126 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002127 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002128 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 12:22:16 -08002129 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002130
2131 std::string sdp_with_extmap = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002132 InjectAfter("a=mid:audio_content_name\r\n", kExtmap, &sdp_with_extmap);
2133 InjectAfter("a=mid:video_content_name\r\n", kExtmap, &sdp_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002134
2135 EXPECT_EQ(sdp_with_extmap, message);
2136}
2137
jbauch5869f502017-06-29 12:31:36 -07002138TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2139 bool encrypted = true;
2140 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002141 JsepSessionDescription desc_with_extmap(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002142 ASSERT_TRUE(
2143 desc_with_extmap.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 12:22:16 -08002144 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07002145}
2146
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002147TEST_F(WebRtcSdpTest, SerializeCandidates) {
2148 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002149 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002150
2151 Candidate candidate_with_ufrag(candidates_.front());
2152 candidate_with_ufrag.set_username("ABC");
2153 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2154 candidate_with_ufrag));
2155 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2156 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002157
2158 Candidate candidate_with_network_info(candidates_.front());
2159 candidate_with_network_info.set_network_id(1);
2160 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2161 candidate_with_network_info));
2162 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2163 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2164 candidate_with_network_info.set_network_cost(999);
2165 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2166 candidate_with_network_info));
2167 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2168 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2169 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002170}
2171
Zach Steinb336c272018-08-09 01:16:13 -07002172TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) {
2173 rtc::SocketAddress address("a.test", 1234);
2174 cricket::Candidate candidate(
2175 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
2176 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
2177 JsepIceCandidate jcandidate(std::string("audio_content_name"), 0, candidate);
2178 std::string message = webrtc::SdpSerializeCandidate(jcandidate);
2179 EXPECT_EQ(std::string(kRawHostnameCandidate), message);
2180}
2181
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002182// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2183// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002184TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002185 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002186 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2187 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2188 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002189 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002190 std::unique_ptr<IceCandidateInterface> jcandidate(
2191 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002192
2193 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2194 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2195}
2196
htaa6b99442016-04-12 10:29:17 -07002197TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002198 cricket::VideoCodec h264_codec("H264");
2199 h264_codec.SetParam("profile-level-id", "42e01f");
2200 h264_codec.SetParam("level-asymmetry-allowed", "1");
2201 h264_codec.SetParam("packetization-mode", "1");
2202 video_desc_->AddCodec(h264_codec);
2203
htaa6b99442016-04-12 10:29:17 -07002204 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
2205
Steve Antone831b8c2018-02-01 12:22:16 -08002206 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 10:29:17 -07002207 size_t after_pt = message.find(" H264/90000");
2208 ASSERT_NE(after_pt, std::string::npos);
2209 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2210 ASSERT_NE(before_pt, std::string::npos);
2211 before_pt += strlen("a=rtpmap:");
2212 std::string pt = message.substr(before_pt, after_pt - before_pt);
2213 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2214 std::string to_find = "a=fmtp:" + pt + " ";
2215 size_t fmtp_pos = message.find(to_find);
2216 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
2217 size_t fmtp_endpos = message.find("\n", fmtp_pos);
2218 ASSERT_NE(std::string::npos, fmtp_endpos);
2219 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2220 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2221 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2222 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002223 // Check that there are no spaces after semicolons.
2224 // https://bugs.webrtc.org/5793
2225 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002226}
2227
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002228TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 10:27:41 -08002229 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002230 // Deserialize
2231 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2232 // Verify
2233 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2234}
2235
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002236TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 10:27:41 -08002237 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002238 const char kSdpWithoutMline[] =
Yves Gerey665174f2018-06-19 15:03:05 +02002239 "v=0\r\n"
2240 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2241 "s=-\r\n"
2242 "t=0 0\r\n"
2243 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002244 // Deserialize
2245 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2246 EXPECT_EQ(0u, jdesc.description()->contents().size());
2247}
2248
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002249TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 10:27:41 -08002250 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002251 std::string sdp_without_carriage_return = kSdpFullString;
2252 Replace("\r\n", "\n", &sdp_without_carriage_return);
2253 // Deserialize
2254 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2255 // Verify
2256 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2257}
2258
2259TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2260 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002261 JsepSessionDescription jdesc_no_candidates(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002262 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
2263 kSessionVersion));
Steve Antona3a92c22017-12-07 10:27:41 -08002264 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002265 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2266 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2267}
2268
2269TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2270 static const char kSdpNoRtpmapString[] =
2271 "v=0\r\n"
2272 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2273 "s=-\r\n"
2274 "t=0 0\r\n"
2275 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2276 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002277 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002278 // The rtpmap line for static payload codec is optional.
2279 "a=rtpmap:18 G729/16000\r\n"
2280 "a=rtpmap:103 ISAC/16000\r\n";
2281
Steve Antona3a92c22017-12-07 10:27:41 -08002282 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002283 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2284 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002285 jdesc.description()
2286 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2287 ->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002288 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002289 // The codecs in the AudioContentDescription should be in the same order as
2290 // the payload types (<fmt>s) on the m= line.
2291 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2292 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002293 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002294 EXPECT_EQ(ref_codecs, audio->codecs());
2295}
2296
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002297TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2298 static const char kSdpNoRtpmapString[] =
2299 "v=0\r\n"
2300 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2301 "s=-\r\n"
2302 "t=0 0\r\n"
2303 "m=audio 49232 RTP/AVP 18 103\r\n"
2304 "a=fmtp:18 annexb=yes\r\n"
2305 "a=rtpmap:103 ISAC/16000\r\n";
2306
Steve Antona3a92c22017-12-07 10:27:41 -08002307 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002308 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2309 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002310 jdesc.description()
2311 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2312 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002313
2314 cricket::AudioCodec g729 = audio->codecs()[0];
2315 EXPECT_EQ("G729", g729.name);
2316 EXPECT_EQ(8000, g729.clockrate);
2317 EXPECT_EQ(18, g729.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002318 cricket::CodecParameterMap::iterator found = g729.params.find("annexb");
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002319 ASSERT_TRUE(found != g729.params.end());
2320 EXPECT_EQ(found->second, "yes");
2321
2322 cricket::AudioCodec isac = audio->codecs()[1];
2323 EXPECT_EQ("ISAC", isac.name);
2324 EXPECT_EQ(103, isac.id);
2325 EXPECT_EQ(16000, isac.clockrate);
2326}
2327
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002328// Ensure that we can deserialize SDP with a=fingerprint properly.
2329TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2330 // Add a DTLS a=fingerprint attribute to our session description.
2331 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002332 JsepSessionDescription new_jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002333 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002334 jdesc_.session_version()));
2335
Steve Antona3a92c22017-12-07 10:27:41 -08002336 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002337 std::string sdp_with_fingerprint = kSdpString;
2338 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2339 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2340 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2341 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2342}
2343
2344TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 10:27:41 -08002345 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002346 std::string sdp_with_bundle = kSdpFullString;
2347 InjectAfter(kSessionTime,
2348 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2349 &sdp_with_bundle);
2350 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2351 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2352 group.AddContentName(kAudioContentName);
2353 group.AddContentName(kVideoContentName);
2354 desc_.AddGroup(group);
Yves Gerey665174f2018-06-19 15:03:05 +02002355 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002356 jdesc_.session_version()));
2357 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2358}
2359
2360TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002361 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002362 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002363 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002364 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002365 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002366 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002367 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 15:14:30 -08002368 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002369 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002370 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002371 acd->set_bandwidth(50 * 1000);
Yves Gerey665174f2018-06-19 15:03:05 +02002372 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002373 jdesc_.session_version()));
2374 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2375}
2376
2377TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 10:27:41 -08002378 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002379 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002380 InjectAfter(kSessionTime, "a=ice-options:iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002381 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002382 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002383 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002384 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002385 &sdp_with_ice_options);
2386 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2387 std::vector<std::string> transport_options;
2388 transport_options.push_back(kIceOption3);
2389 transport_options.push_back(kIceOption1);
2390 AddIceOptions(kAudioContentName, transport_options);
2391 transport_options.clear();
2392 transport_options.push_back(kIceOption3);
2393 transport_options.push_back(kIceOption2);
2394 AddIceOptions(kVideoContentName, transport_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002395 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002396 jdesc_.session_version()));
2397 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2398}
2399
2400TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2401 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 10:27:41 -08002402 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002403 std::string sdp_with_ufrag_pwd = kSdpFullString;
2404 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2405 // Add session level ufrag and pwd
2406 InjectAfter(kSessionTime,
Yves Gerey665174f2018-06-19 15:03:05 +02002407 "a=ice-pwd:session+level+icepwd\r\n"
2408 "a=ice-ufrag:session+level+iceufrag\r\n",
2409 &sdp_with_ufrag_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002410 // Add media level ufrag and pwd for audio
Yves Gerey665174f2018-06-19 15:03:05 +02002411 InjectAfter(
2412 "a=mid:audio_content_name\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002413 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2414 &sdp_with_ufrag_pwd);
2415 // Update the candidate ufrag and pwd to the expected ones.
Yves Gerey665174f2018-06-19 15:03:05 +02002416 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, "media+level+iceufrag",
2417 "media+level+icepwd"));
2418 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, "session+level+iceufrag",
2419 "session+level+icepwd"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002420 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2421 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2422}
2423
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002424TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002425 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002426}
2427
2428TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002429 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002430}
2431
2432TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002433 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002434}
2435
2436TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2437 EXPECT_TRUE(TestDeserializeRejected(true, false));
2438}
2439
2440TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2441 EXPECT_TRUE(TestDeserializeRejected(false, true));
2442}
2443
2444TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2445 EXPECT_TRUE(TestDeserializeRejected(true, true));
2446}
2447
2448// Tests that we can still handle the sdp uses mslabel and label instead of
2449// msid for backward compatibility.
2450TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07002451 jdesc_.description()->set_msid_supported(false);
Steve Antona3a92c22017-12-07 10:27:41 -08002452 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002453 std::string sdp_without_msid = kSdpFullString;
2454 Replace("msid", "xmsid", &sdp_without_msid);
2455 // Deserialize
2456 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2457 // Verify
2458 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2459}
2460
Johannes Kron0854eb62018-10-10 22:33:20 +02002461TEST_F(WebRtcSdpTest, SessionLevelMixedHeaderExtensionsAlsoSetsMediaSetting) {
2462 cricket::MediaContentDescription* video_desc =
2463 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2464 ASSERT_TRUE(video_desc);
2465 cricket::MediaContentDescription* audio_desc =
2466 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2467 ASSERT_TRUE(audio_desc);
2468
2469 // Setting true on session level propagates to media level.
2470 jdesc_.description()->set_mixed_one_two_byte_header_extensions_supported(
2471 true);
2472 EXPECT_EQ(cricket::MediaContentDescription::kSession,
2473 video_desc->mixed_one_two_byte_header_extensions_supported());
2474 EXPECT_EQ(cricket::MediaContentDescription::kSession,
2475 audio_desc->mixed_one_two_byte_header_extensions_supported());
2476
2477 // Don't downgrade from session level to media level
2478 video_desc->set_mixed_one_two_byte_header_extensions_supported(
2479 cricket::MediaContentDescription::kMedia);
2480 EXPECT_EQ(cricket::MediaContentDescription::kSession,
2481 video_desc->mixed_one_two_byte_header_extensions_supported());
2482
2483 // Setting false on session level propagates to media level.
2484 jdesc_.description()->set_mixed_one_two_byte_header_extensions_supported(
2485 false);
2486 EXPECT_EQ(cricket::MediaContentDescription::kNo,
2487 video_desc->mixed_one_two_byte_header_extensions_supported());
2488 EXPECT_EQ(cricket::MediaContentDescription::kNo,
2489 audio_desc->mixed_one_two_byte_header_extensions_supported());
2490
2491 // Now possible to set at media level.
2492 video_desc->set_mixed_one_two_byte_header_extensions_supported(
2493 cricket::MediaContentDescription::kMedia);
2494 EXPECT_EQ(cricket::MediaContentDescription::kMedia,
2495 video_desc->mixed_one_two_byte_header_extensions_supported());
2496}
2497
2498TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithExtmapAllowMixed) {
2499 jdesc_.description()->set_mixed_one_two_byte_header_extensions_supported(
2500 true);
2501 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2502 InjectAfter("t=0 0\r\n", kExtmapAllowMixed, &sdp_with_extmap_allow_mixed);
2503 // Deserialize
2504 JsepSessionDescription jdesc_deserialized(kDummyType);
2505 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2506 // Verify
2507 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2508}
2509
2510TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutExtmapAllowMixed) {
2511 jdesc_.description()->set_mixed_one_two_byte_header_extensions_supported(
2512 false);
2513 std::string sdp_without_extmap_allow_mixed = kSdpFullString;
2514 // Deserialize
2515 JsepSessionDescription jdesc_deserialized(kDummyType);
2516 EXPECT_TRUE(
2517 SdpDeserialize(sdp_without_extmap_allow_mixed, &jdesc_deserialized));
2518 // Verify
2519 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2520}
2521
2522TEST_F(WebRtcSdpTest, DeserializeMediaContentDescriptionWithExtmapAllowMixed) {
2523 cricket::MediaContentDescription* video_desc =
2524 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2525 ASSERT_TRUE(video_desc);
2526 cricket::MediaContentDescription* audio_desc =
2527 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2528 ASSERT_TRUE(audio_desc);
2529 video_desc->set_mixed_one_two_byte_header_extensions_supported(
2530 cricket::MediaContentDescription::kMedia);
2531 audio_desc->set_mixed_one_two_byte_header_extensions_supported(
2532 cricket::MediaContentDescription::kMedia);
2533
2534 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2535 InjectAfter("a=mid:audio_content_name\r\n", kExtmapAllowMixed,
2536 &sdp_with_extmap_allow_mixed);
2537 InjectAfter("a=mid:video_content_name\r\n", kExtmapAllowMixed,
2538 &sdp_with_extmap_allow_mixed);
2539
2540 // Deserialize
2541 JsepSessionDescription jdesc_deserialized(kDummyType);
2542 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2543 // Verify
2544 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2545}
2546
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002547TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2548 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2549
2550 std::string sdp = kSdpOneCandidate;
2551 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2552 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2553 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2554 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002555 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002556
2557 // Candidate line without generation extension.
2558 sdp = kSdpOneCandidate;
2559 Replace(" generation 2", "", &sdp);
2560 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2561 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2562 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2563 Candidate expected = jcandidate_->candidate();
2564 expected.set_generation(0);
2565 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2566
honghaiza0c44ea2016-03-23 16:07:48 -07002567 // Candidate with network id and/or cost.
2568 sdp = kSdpOneCandidate;
2569 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2570 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2571 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2572 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2573 expected = jcandidate_->candidate();
2574 expected.set_network_id(2);
2575 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2576 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2577 // Add network cost
2578 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2579 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2580 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2581 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2582
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002583 sdp = kSdpTcpActiveCandidate;
2584 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2585 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002586 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002587 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2588 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2589 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002590 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2591 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
Yves Gerey665174f2018-06-19 15:03:05 +02002592 EXPECT_TRUE(
2593 jcandidate.candidate().IsEquivalent(jcandidate_template->candidate()));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002594 sdp = kSdpTcpPassiveCandidate;
2595 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2596 sdp = kSdpTcpSOCandidate;
2597 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002598}
2599
2600// This test verifies the deserialization of candidate-attribute
2601// as per RFC 5245. Candiate-attribute will be of the format
2602// candidate:<blah>. This format will be used when candidates
2603// are trickled.
2604TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2605 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2606
2607 std::string candidate_attribute = kRawCandidate;
2608 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2609 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2610 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2611 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2612 EXPECT_EQ(2u, jcandidate.candidate().generation());
2613
2614 // Candidate line without generation extension.
2615 candidate_attribute = kRawCandidate;
2616 Replace(" generation 2", "", &candidate_attribute);
2617 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2618 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2619 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2620 Candidate expected = jcandidate_->candidate();
2621 expected.set_generation(0);
2622 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2623
2624 // Candidate line without candidate:
2625 candidate_attribute = kRawCandidate;
2626 Replace("candidate:", "", &candidate_attribute);
2627 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2628
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002629 // Candidate line with IPV6 address.
2630 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
Zach Steinb336c272018-08-09 01:16:13 -07002631
2632 // Candidate line with hostname address.
2633 EXPECT_TRUE(SdpDeserializeCandidate(kRawHostnameCandidate, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002634}
2635
2636// This test verifies that the deserialization of an invalid candidate string
2637// fails.
2638TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
Yves Gerey665174f2018-06-19 15:03:05 +02002639 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002640
2641 std::string candidate_attribute = kRawCandidate;
2642 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002643 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002644
2645 candidate_attribute = kSdpOneCandidate;
2646 candidate_attribute.replace(0, 1, "x");
2647 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2648
2649 candidate_attribute = kRawCandidate;
2650 candidate_attribute.append("\r\n");
2651 candidate_attribute.append(kRawCandidate);
2652 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2653
2654 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002655}
2656
2657TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2658 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002659 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002660 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2661
2662 std::string sdp_with_data = kSdpString;
2663 sdp_with_data.append(kSdpRtpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002664 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002665
2666 // Deserialize
2667 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2668 // Verify
2669 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2670}
2671
2672TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002673 bool use_sctpmap = true;
2674 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002675 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002676 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2677
2678 std::string sdp_with_data = kSdpString;
2679 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002680 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002681
lally@webrtc.org36300852015-02-24 20:19:35 +00002682 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2683 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2684 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2685
2686 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002687 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2688 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002689 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2690 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2691
2692 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002693 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2694 kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002695 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2696 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2697}
2698
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002699TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002700 bool use_sctpmap = false;
2701 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002702 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002703 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2704
2705 std::string sdp_with_data = kSdpString;
2706 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002707 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002708
lally@webrtc.org36300852015-02-24 20:19:35 +00002709 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002710 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2711 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002712
lally@webrtc.org36300852015-02-24 20:19:35 +00002713 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002714 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2715 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002716 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2717 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002718
lally@webrtc.org36300852015-02-24 20:19:35 +00002719 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002720 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2721 kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002722 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2723 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2724}
2725
lally69f57602015-10-08 10:15:04 -07002726TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002727 bool use_sctpmap = false;
2728 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002729 JsepSessionDescription jdesc(kDummyType);
lally69f57602015-10-08 10:15:04 -07002730 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2731
2732 std::string sdp_with_data = kSdpString;
2733 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002734 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 10:15:04 -07002735
2736 // Verify with DTLS/SCTP.
2737 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2738 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2739
2740 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002741 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2742 kUdpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002743 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2744 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2745
2746 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002747 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2748 kTcpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002749 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2750 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2751}
2752
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002753// Test to check the behaviour if sctp-port is specified
2754// on the m= line and in a=sctp-port.
2755TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002756 bool use_sctpmap = true;
2757 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002758 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002759 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2760
2761 std::string sdp_with_data = kSdpString;
2762 // Append m= attributes
2763 sdp_with_data.append(kSdpSctpDataChannelString);
2764 // Append a=sctp-port attribute
2765 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 10:27:41 -08002766 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002767
2768 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2769}
2770
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002771// For crbug/344475.
2772TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2773 std::string sdp_with_data = kSdpString;
2774 sdp_with_data.append(kSdpSctpDataChannelString);
2775 // Remove the "\n" at the end.
2776 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 10:27:41 -08002777 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002778
2779 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2780 // No crash is a pass.
2781}
2782
Steve Anton36b29d12017-10-30 09:57:42 -07002783void MutateJsepSctpPort(JsepSessionDescription* jdesc,
zstein4b2e0822017-02-17 19:48:38 -08002784 const SessionDescription& desc) {
wu@webrtc.org78187522013-10-07 23:32:02 +00002785 // take our pre-built session description and change the SCTP port.
zstein4b2e0822017-02-17 19:48:38 -08002786 cricket::SessionDescription* mutant = desc.Copy();
Steve Antonb1c1de12017-12-21 15:14:30 -08002787 DataContentDescription* dcdesc =
2788 mutant->GetContentDescriptionByName(kDataContentName)->as_data();
wu@webrtc.org78187522013-10-07 23:32:02 +00002789 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002790 EXPECT_EQ(1U, codecs.size());
solenberg9fa49752016-10-08 13:02:44 -07002791 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002792 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002793 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002794
2795 // note: mutant's owned by jdesc now.
Steve Anton36b29d12017-10-30 09:57:42 -07002796 ASSERT_TRUE(jdesc->Initialize(mutant, kSessionId, kSessionVersion));
wu@webrtc.org78187522013-10-07 23:32:02 +00002797 mutant = NULL;
zstein4b2e0822017-02-17 19:48:38 -08002798}
2799
2800TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
2801 bool use_sctpmap = true;
2802 AddSctpDataChannel(use_sctpmap);
2803
2804 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 10:27:41 -08002805 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002806 MutateJsepSctpPort(&jdesc, desc_);
wu@webrtc.org78187522013-10-07 23:32:02 +00002807
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002808 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002809 std::string sdp_with_data = kSdpString;
2810 sdp_with_data.append(kSdpSctpDataChannelString);
zstein4b2e0822017-02-17 19:48:38 -08002811 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2812 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2813 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002814 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:02 +00002815
2816 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2817 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08002818}
2819
2820TEST_F(WebRtcSdpTest,
2821 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
2822 bool use_sctpmap = false;
2823 AddSctpDataChannel(use_sctpmap);
2824
Steve Antona3a92c22017-12-07 10:27:41 -08002825 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002826 MutateJsepSctpPort(&jdesc, desc_);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002827
2828 // We need to test the deserialized JsepSessionDescription from
2829 // kSdpSctpDataChannelStringWithSctpPort for
2830 // draft-ietf-mmusic-sctp-sdp-07
2831 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08002832 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002833 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
zstein4b2e0822017-02-17 19:48:38 -08002834 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2835 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2836 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002837 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002838
2839 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2840 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002841}
2842
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002843TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002844 // We want to test that deserializing data content limits bandwidth
2845 // settings (it should never be greater than the default).
2846 // This should prevent someone from using unlimited data bandwidth through
2847 // JS and "breaking the Internet".
2848 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002849 std::string sdp_with_bandwidth = kSdpString;
2850 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02002851 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002852 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002853 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002854
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002855 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2856}
2857
2858TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08002859 bool use_sctpmap = true;
2860 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002861 JsepSessionDescription jdesc(kDummyType);
Steve Antonb1c1de12017-12-21 15:14:30 -08002862 DataContentDescription* dcd = GetFirstDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002863 dcd->set_bandwidth(100 * 1000);
2864 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2865
2866 std::string sdp_with_bandwidth = kSdpString;
2867 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02002868 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002869 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002870 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002871
2872 // SCTP has congestion control, so we shouldn't limit the bandwidth
2873 // as we do for RTP.
2874 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002875 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2876}
2877
Yves Gerey665174f2018-06-19 15:03:05 +02002878class WebRtcSdpExtmapTest : public WebRtcSdpTest,
2879 public testing::WithParamInterface<bool> {};
jbauch5869f502017-06-29 12:31:36 -07002880
2881TEST_P(WebRtcSdpExtmapTest,
Yves Gerey665174f2018-06-19 15:03:05 +02002882 DeserializeSessionDescriptionWithSessionLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002883 bool encrypted = GetParam();
2884 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002885}
2886
Yves Gerey665174f2018-06-19 15:03:05 +02002887TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002888 bool encrypted = GetParam();
2889 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002890}
2891
Yves Gerey665174f2018-06-19 15:03:05 +02002892TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithInvalidExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002893 bool encrypted = GetParam();
2894 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002895}
2896
jbauch5869f502017-06-29 12:31:36 -07002897INSTANTIATE_TEST_CASE_P(Encrypted,
2898 WebRtcSdpExtmapTest,
2899 ::testing::Values(false, true));
2900
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002901TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 10:27:41 -08002902 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002903 std::string sdp = kSdpFullString;
2904 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2905 // Deserialize
2906 SdpParseError error;
2907 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-16 17:54:10 -08002908 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002909 EXPECT_EQ(lastline, error.line);
2910 EXPECT_EQ("Invalid SDP line.", error.description);
2911}
2912
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002913TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2914 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2915 std::string new_sdp = kSdpOneCandidate;
2916 Replace("udp", "unsupported_transport", &new_sdp);
2917 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2918 new_sdp = kSdpOneCandidate;
2919 Replace("udp", "uDP", &new_sdp);
2920 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2921 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2922 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2923 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2924}
2925
honghaiza54a0802015-12-16 18:37:23 -08002926TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002927 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08002928 EXPECT_TRUE(
2929 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002930 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2931 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2932 Candidate ref_candidate = jcandidate_->candidate();
2933 ref_candidate.set_username("user_rtp");
2934 ref_candidate.set_password("password_rtp");
2935 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2936}
2937
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002938TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08002939 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002940
2941 // Deserialize
2942 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2943
2944 // Verify
2945 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002946 jdesc.description()
2947 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2948 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002949 EXPECT_TRUE(audio->conference_mode());
2950
2951 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 15:14:30 -08002952 jdesc.description()
2953 ->GetContentDescriptionByName(cricket::CN_VIDEO)
2954 ->as_video();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002955 EXPECT_TRUE(video->conference_mode());
2956}
2957
deadbeefd45aea82017-09-16 01:24:29 -07002958TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08002959 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 01:24:29 -07002960
2961 // We tested deserialization already above, so just test that if we serialize
2962 // and deserialize the flag doesn't disappear.
2963 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 12:22:16 -08002964 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 01:24:29 -07002965 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
2966
2967 // Verify.
2968 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002969 jdesc.description()
2970 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2971 ->as_audio();
deadbeefd45aea82017-09-16 01:24:29 -07002972 EXPECT_TRUE(audio->conference_mode());
2973
2974 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 15:14:30 -08002975 jdesc.description()
2976 ->GetContentDescriptionByName(cricket::CN_VIDEO)
2977 ->as_video();
deadbeefd45aea82017-09-16 01:24:29 -07002978 EXPECT_TRUE(video->conference_mode());
2979}
2980
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002981TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2982 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002983 const char kSdpEmptyType[] = " =candidate";
2984 const char kSdpEqualAsPlus[] = "a+candidate";
2985 const char kSdpSpaceAfterEqual[] = "a= candidate";
2986 const char kSdpUpperType[] = "A=candidate";
2987 const char kSdpEmptyLine[] = "";
2988 const char kSdpMissingValue[] = "a=";
2989
Yves Gerey665174f2018-06-19 15:03:05 +02002990 const char kSdpBrokenFingerprint[] =
2991 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002992 "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 +02002993 const char kSdpExtraField[] =
2994 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002995 "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 +02002996 const char kSdpMissingSpace[] =
2997 "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002998 "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 +00002999 // MD5 is not allowed in fingerprints.
Yves Gerey665174f2018-06-19 15:03:05 +02003000 const char kSdpMd5[] =
3001 "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003002 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003003
3004 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003005 ExpectParseFailure("v=", kSdpDestroyer);
3006 ExpectParseFailure("o=", kSdpDestroyer);
3007 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003008 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003009 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003010
3011 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003012 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
3013 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003014
3015 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003016 ExpectParseFailure("a=candidate", kSdpEmptyType);
3017 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
3018 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
3019 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003020
3021 // Bogus fingerprint replacing a=sendrev. We selected this attribute
3022 // because it's orthogonal to what we are replacing and hence
3023 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003024 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
3025 ExpectParseFailure("a=sendrecv", kSdpExtraField);
3026 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
3027 ExpectParseFailure("a=sendrecv", kSdpMd5);
3028
3029 // Empty Line
3030 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
3031 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003032}
3033
3034TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
3035 // ssrc
3036 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08003037 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003038 // crypto
3039 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
3040 // rtpmap
3041 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
3042 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
3043 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
3044 // candidate
3045 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
3046 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
3047 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
3048 ExpectParseFailure("rport 2346", "rport badvalue");
3049 ExpectParseFailure("rport 2346 generation 2",
3050 "rport 2346 generation badvalue");
3051 // m line
3052 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
3053 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
3054
3055 // bandwidth
3056 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003057 "b=AS:badvalue\r\n", "b=AS:badvalue");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003058 // rtcp-fb
3059 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3060 "a=rtcp-fb:badvalue nack\r\n",
3061 "a=rtcp-fb:badvalue nack");
3062 // extmap
3063 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3064 "a=extmap:badvalue http://example.com\r\n",
3065 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003066}
3067
3068TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 10:27:41 -08003069 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003070
3071 const char kSdpWithReorderedPlTypesString[] =
3072 "v=0\r\n"
3073 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3074 "s=-\r\n"
3075 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00003076 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
Yves Gerey665174f2018-06-19 15:03:05 +02003077 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
3078 // in the map.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003079 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003080 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003081
3082 // Deserialize
3083 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
3084
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003085 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003086 GetFirstAudioContentDescription(jdesc_output.description());
3087 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003088 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003089 EXPECT_EQ("ISAC", acd->codecs()[0].name);
3090 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003091 EXPECT_EQ(104, acd->codecs()[0].id);
3092}
3093
3094TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 10:27:41 -08003095 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003096 CodecParams params;
3097 params.max_ptime = 40;
3098 params.ptime = 30;
3099 params.min_ptime = 10;
3100 params.sprop_stereo = 1;
3101 params.stereo = 1;
3102 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003103 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003104 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 12:22:16 -08003105 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003106}
3107
3108TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
3109 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 10:27:41 -08003110 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003111 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003112 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003113}
3114
3115TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
3116 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 10:27:41 -08003117 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003118 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003119 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003120}
3121
3122TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 10:27:41 -08003123 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003124
3125 const char kSdpWithFmtpString[] =
3126 "v=0\r\n"
3127 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3128 "s=-\r\n"
3129 "t=0 0\r\n"
3130 "m=video 3457 RTP/SAVPF 120\r\n"
3131 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07003132 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3133
3134 // Deserialize
3135 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07003136 EXPECT_TRUE(
3137 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07003138
Donald Curtis0e07f922015-05-15 09:21:23 -07003139 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003140 GetFirstVideoContentDescription(jdesc_output.description());
3141 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 09:21:23 -07003142 ASSERT_FALSE(vcd->codecs().empty());
3143 cricket::VideoCodec vp8 = vcd->codecs()[0];
3144 EXPECT_EQ("VP8", vp8.name);
3145 EXPECT_EQ(120, vp8.id);
3146 cricket::CodecParameterMap::iterator found =
3147 vp8.params.find("x-google-min-bitrate");
3148 ASSERT_TRUE(found != vp8.params.end());
3149 EXPECT_EQ(found->second, "10");
3150 found = vp8.params.find("x-google-max-quantization");
3151 ASSERT_TRUE(found != vp8.params.end());
3152 EXPECT_EQ(found->second, "40");
3153}
3154
johan2d8d23e2016-06-03 01:22:42 -07003155TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 10:27:41 -08003156 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 01:22:42 -07003157
3158 const char kSdpWithFmtpString[] =
3159 "v=0\r\n"
3160 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3161 "s=-\r\n"
3162 "t=0 0\r\n"
3163 "m=video 49170 RTP/AVP 98\r\n"
3164 "a=rtpmap:98 H264/90000\r\n"
3165 "a=fmtp:98 profile-level-id=42A01E; "
3166 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3167
3168 // Deserialize.
3169 SdpParseError error;
3170 EXPECT_TRUE(
3171 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3172
johan2d8d23e2016-06-03 01:22:42 -07003173 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003174 GetFirstVideoContentDescription(jdesc_output.description());
3175 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 01:22:42 -07003176 ASSERT_FALSE(vcd->codecs().empty());
3177 cricket::VideoCodec h264 = vcd->codecs()[0];
3178 EXPECT_EQ("H264", h264.name);
3179 EXPECT_EQ(98, h264.id);
3180 cricket::CodecParameterMap::const_iterator found =
3181 h264.params.find("profile-level-id");
3182 ASSERT_TRUE(found != h264.params.end());
3183 EXPECT_EQ(found->second, "42A01E");
3184 found = h264.params.find("sprop-parameter-sets");
3185 ASSERT_TRUE(found != h264.params.end());
3186 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3187}
3188
Donald Curtis0e07f922015-05-15 09:21:23 -07003189TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 10:27:41 -08003190 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 09:21:23 -07003191
3192 const char kSdpWithFmtpString[] =
3193 "v=0\r\n"
3194 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3195 "s=-\r\n"
3196 "t=0 0\r\n"
3197 "m=video 3457 RTP/SAVPF 120\r\n"
3198 "a=rtpmap:120 VP8/90000\r\n"
3199 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003200
3201 // Deserialize
3202 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02003203 EXPECT_TRUE(
3204 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003205
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003206 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003207 GetFirstVideoContentDescription(jdesc_output.description());
3208 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003209 ASSERT_FALSE(vcd->codecs().empty());
3210 cricket::VideoCodec vp8 = vcd->codecs()[0];
3211 EXPECT_EQ("VP8", vp8.name);
3212 EXPECT_EQ(120, vp8.id);
3213 cricket::CodecParameterMap::iterator found =
3214 vp8.params.find("x-google-min-bitrate");
3215 ASSERT_TRUE(found != vp8.params.end());
3216 EXPECT_EQ(found->second, "10");
3217 found = vp8.params.find("x-google-max-quantization");
3218 ASSERT_TRUE(found != vp8.params.end());
3219 EXPECT_EQ(found->second, "40");
3220}
3221
ossuaa4b0772017-01-30 07:41:18 -08003222TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003223 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003224
3225 cricket::AudioCodecs codecs = acd->codecs();
3226 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3227 acd->set_codecs(codecs);
3228
Yves Gerey665174f2018-06-19 15:03:05 +02003229 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003230 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003231 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003232 std::string sdp_with_fmtp = kSdpFullString;
3233 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3234 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3235 &sdp_with_fmtp);
3236 EXPECT_EQ(sdp_with_fmtp, message);
3237}
3238
3239TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003240 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003241
3242 cricket::AudioCodecs codecs = acd->codecs();
3243 codecs[0].params["stereo"] = "1";
3244 acd->set_codecs(codecs);
3245
Yves Gerey665174f2018-06-19 15:03:05 +02003246 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003247 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003248 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003249 std::string sdp_with_fmtp = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003250 InjectAfter("a=rtpmap:111 opus/48000/2\r\n", "a=fmtp:111 stereo=1\r\n",
ossuaa4b0772017-01-30 07:41:18 -08003251 &sdp_with_fmtp);
3252 EXPECT_EQ(sdp_with_fmtp, message);
3253}
3254
3255TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003256 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003257
3258 cricket::AudioCodecs codecs = acd->codecs();
3259 codecs[0].params["ptime"] = "20";
3260 codecs[0].params["maxptime"] = "120";
3261 acd->set_codecs(codecs);
3262
Yves Gerey665174f2018-06-19 15:03:05 +02003263 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003264 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003265 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003266 std::string sdp_with_fmtp = kSdpFullString;
3267 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3268 "a=maxptime:120\r\n" // No comma here. String merging!
3269 "a=ptime:20\r\n",
3270 &sdp_with_fmtp);
3271 EXPECT_EQ(sdp_with_fmtp, message);
3272}
3273
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003274TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003275 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003276
3277 cricket::VideoCodecs codecs = vcd->codecs();
3278 codecs[0].params["x-google-min-bitrate"] = "10";
3279 vcd->set_codecs(codecs);
3280
Yves Gerey665174f2018-06-19 15:03:05 +02003281 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003282 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003283 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003284 std::string sdp_with_fmtp = kSdpFullString;
3285 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003286 "a=fmtp:120 x-google-min-bitrate=10\r\n", &sdp_with_fmtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003287 EXPECT_EQ(sdp_with_fmtp, message);
3288}
3289
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003290TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) {
3291 // Deserialize the baseline description, making sure it's ICE full.
Steve Antona3a92c22017-12-07 10:27:41 -08003292 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003293 std::string sdp_with_icelite = kSdpFullString;
3294 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3295 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3296 const cricket::TransportInfo* tinfo1 =
3297 desc->GetTransportInfoByName("audio_content_name");
3298 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3299 const cricket::TransportInfo* tinfo2 =
3300 desc->GetTransportInfoByName("video_content_name");
3301 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003302
3303 // Add "a=ice-lite" and deserialize, making sure it's ICE lite.
Yves Gerey665174f2018-06-19 15:03:05 +02003304 InjectAfter(kSessionTime, "a=ice-lite\r\n", &sdp_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003305 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3306 desc = jdesc_with_icelite.description();
3307 const cricket::TransportInfo* atinfo =
3308 desc->GetTransportInfoByName("audio_content_name");
3309 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3310 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003311 desc->GetTransportInfoByName("video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003312 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003313
3314 // Now that we know deserialization works, we can use TestSerialize to test
3315 // serialization.
3316 TestSerialize(jdesc_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003317}
3318
3319// Verifies that the candidates in the input SDP are parsed and serialized
3320// correctly in the output SDP.
3321TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3322 std::string sdp_with_data = kSdpString;
3323 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 10:27:41 -08003324 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003325
3326 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 12:22:16 -08003327 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003328}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003329
3330TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3331 AddFingerprint();
3332 TransportInfo audio_transport_info =
3333 *(desc_.GetTransportInfoByName(kAudioContentName));
3334 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3335 audio_transport_info.description.connection_role);
3336 audio_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003337 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003338
3339 TransportInfo video_transport_info =
3340 *(desc_.GetTransportInfoByName(kVideoContentName));
3341 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3342 video_transport_info.description.connection_role);
3343 video_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003344 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003345
3346 desc_.RemoveTransportInfoByName(kAudioContentName);
3347 desc_.RemoveTransportInfoByName(kVideoContentName);
3348
3349 desc_.AddTransportInfo(audio_transport_info);
3350 desc_.AddTransportInfo(video_transport_info);
3351
Yves Gerey665174f2018-06-19 15:03:05 +02003352 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003353 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003354 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003355 std::string sdp_with_dtlssetup = kSdpFullString;
3356
3357 // Fingerprint attribute is necessary to add DTLS setup attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003358 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_dtlssetup);
3359 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003360 // Now adding |setup| attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003361 InjectAfter(kFingerprint, "a=setup:active\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003362 EXPECT_EQ(sdp_with_dtlssetup, message);
3363}
3364
3365TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
Steve Antona3a92c22017-12-07 10:27:41 -08003366 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003367 std::string sdp_with_dtlssetup = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003368 InjectAfter(kSessionTime, "a=setup:actpass\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003369 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3370 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3371 const cricket::TransportInfo* atinfo =
3372 desc->GetTransportInfoByName("audio_content_name");
3373 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3374 atinfo->description.connection_role);
3375 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003376 desc->GetTransportInfoByName("video_content_name");
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003377 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3378 vtinfo->description.connection_role);
3379}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003380
3381// Verifies that the order of the serialized m-lines follows the order of the
3382// ContentInfo in SessionDescription, and vise versa for deserialization.
3383TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 10:27:41 -08003384 JsepSessionDescription jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02003385 const std::string media_content_sdps[3] = {kSdpAudioString, kSdpVideoString,
3386 kSdpSctpDataChannelString};
3387 const cricket::MediaType media_types[3] = {cricket::MEDIA_TYPE_AUDIO,
3388 cricket::MEDIA_TYPE_VIDEO,
3389 cricket::MEDIA_TYPE_DATA};
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003390
3391 // Verifies all 6 permutations.
3392 for (size_t i = 0; i < 6; ++i) {
3393 size_t media_content_in_sdp[3];
3394 // The index of the first media content.
3395 media_content_in_sdp[0] = i / 2;
3396 // The index of the second media content.
3397 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3398 // The index of the third media content.
3399 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3400
3401 std::string sdp_string = kSdpSessionString;
3402 for (size_t i = 0; i < 3; ++i)
3403 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3404
3405 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3406 cricket::SessionDescription* desc = jdesc.description();
3407 EXPECT_EQ(3u, desc->contents().size());
3408
3409 for (size_t i = 0; i < 3; ++i) {
3410 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 15:14:30 -08003411 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003412 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3413 }
3414
Steve Antone831b8c2018-02-01 12:22:16 -08003415 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003416 EXPECT_EQ(sdp_string, serialized_sdp);
3417 }
3418}
deadbeef9d3584c2016-02-16 17:54:10 -08003419
deadbeef25ed4352016-12-12 18:37:36 -08003420TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3421 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 10:27:41 -08003422 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003423 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003424 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3425 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3426}
3427
deadbeef12771a12017-01-03 13:53:47 -08003428// The semantics of "a=bundle-only" are only defined when it's used in
3429// combination with a 0 port on the m= line. We should ignore it if used with a
3430// nonzero port.
3431TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3432 // Make the base bundle-only description but unset the bundle-only flag.
3433 MakeBundleOnlyDescription();
3434 jdesc_.description()->contents()[1].bundle_only = false;
3435
3436 std::string modified_sdp = kBundleOnlySdpFullString;
3437 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08003438 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003439 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3440 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003441}
3442
3443TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3444 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003445 TestSerialize(jdesc_);
deadbeef25ed4352016-12-12 18:37:36 -08003446}
3447
deadbeef9d3584c2016-02-16 17:54:10 -08003448TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3449 MakePlanBDescription();
3450
Steve Antona3a92c22017-12-07 10:27:41 -08003451 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003452 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3453
3454 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3455}
3456
3457TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3458 MakePlanBDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003459 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-16 17:54:10 -08003460}
3461
3462TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3463 MakeUnifiedPlanDescription();
3464
Steve Antona3a92c22017-12-07 10:27:41 -08003465 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003466 EXPECT_TRUE(
3467 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3468
3469 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3470}
3471
3472TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3473 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003474 TestSerialize(jdesc_);
3475}
3476
Seth Hampson5b4f0752018-04-02 16:31:36 -07003477// This tests deserializing a Unified Plan SDP that is compatible with both
3478// Unified Plan and Plan B style SDP. It tests the case for audio/video tracks
3479// with no stream ids and multiple stream ids. For parsing this, the Unified
3480// Plan a=msid lines should take priority, because the Plan B style a=ssrc msid
3481// lines do not support multiple stream ids and no stream ids.
3482TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionSpecialMsid) {
3483 MakeUnifiedPlanDescriptionMultipleStreamIds();
3484
3485 JsepSessionDescription deserialized_description(kDummyType);
3486 EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid,
3487 &deserialized_description));
3488
3489 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3490}
3491
3492TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionSpecialMsid) {
3493 MakeUnifiedPlanDescriptionMultipleStreamIds();
3494 TestSerialize(jdesc_);
3495}
3496
Seth Hampson5897a6e2018-04-03 11:16:33 -07003497// This tests that a Unified Plan SDP with no a=ssrc lines is
3498// serialized/deserialized appropriately. In this case the
3499// MediaContentDescription will contain a StreamParams object that doesn't have
3500// any SSRCs. Vice versa, this will be created upon deserializing an SDP with no
3501// SSRC lines.
3502TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3503 MakeUnifiedPlanDescription();
3504 RemoveSsrcSignalingFromStreamParams();
3505 std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString;
3506 RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string);
3507
3508 JsepSessionDescription deserialized_description(kDummyType);
3509 EXPECT_TRUE(
3510 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3511 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3512}
3513
3514TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3515 MakeUnifiedPlanDescription();
3516 RemoveSsrcSignalingFromStreamParams();
3517
3518 TestSerialize(jdesc_);
3519}
3520
Steve Antone831b8c2018-02-01 12:22:16 -08003521TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
3522 JsepSessionDescription jsep_desc(kDummyType);
3523 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
3524 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3525}
3526
3527TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
3528 JsepSessionDescription jsep_desc(kDummyType);
3529 std::string sdp = kSdpSessionString;
3530 sdp += kSdpSctpDataChannelString;
3531 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3532 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3533}
3534
3535TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
3536 JsepSessionDescription jsep_desc(kDummyType);
3537 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
3538 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
3539 jsep_desc.description()->msid_signaling());
3540}
3541
3542TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
3543 JsepSessionDescription jsep_desc(kDummyType);
3544 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
3545 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
3546 jsep_desc.description()->msid_signaling());
3547}
3548
3549const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
3550const char kSsrcAttributeMsidLine[] =
3551 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
3552
3553TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
3554 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
3555 std::string sdp = webrtc::SdpSerialize(jdesc_);
3556
3557 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3558 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3559}
3560
3561TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
3562 jdesc_.description()->set_msid_signaling(
3563 cricket::kMsidSignalingSsrcAttribute);
3564 std::string sdp = webrtc::SdpSerialize(jdesc_);
3565
3566 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
3567 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3568}
3569
3570TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
3571 jdesc_.description()->set_msid_signaling(
3572 cricket::kMsidSignalingMediaSection |
3573 cricket::kMsidSignalingSsrcAttribute);
3574 std::string sdp = webrtc::SdpSerialize(jdesc_);
3575
3576 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3577 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-16 17:54:10 -08003578}
deadbeef7e146cb2016-09-28 10:04:34 -07003579
3580// Regression test for heap overflow bug:
3581// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3582TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 10:04:34 -07003583 // The issue occurs when the sctp-port attribute is found in a video
3584 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 12:43:58 -08003585 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 10:04:34 -07003586 "v=0\r\n"
3587 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3588 "s=-\r\n"
3589 "t=0 0\r\n"
3590 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3591 "a=sctp-port 5000\r\n"
3592 "a=fmtp:108 foo=10\r\n";
3593
3594 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3595 "sctp-port");
3596}
deadbeefb2362572016-12-13 16:37:06 -08003597
3598// Regression test for integer overflow bug:
3599// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3600TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003601 // Bandwidth attribute is the max signed 32-bit int, which will get
3602 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003603 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003604 "v=0\r\n"
3605 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3606 "s=-\r\n"
3607 "t=0 0\r\n"
3608 "m=video 3457 RTP/SAVPF 120\r\n"
3609 "b=AS:2147483647\r\n"
3610 "foo=fail\r\n";
3611
3612 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3613}
deadbeef7bcdb692017-01-20 12:43:58 -08003614
deadbeefbc88c6b2017-08-02 11:26:34 -07003615// Similar to the above, except that negative values are illegal, not just
3616// error-prone as large values are.
3617// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3618TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3619 static const char kSdpWithNegativeBandwidth[] =
3620 "v=0\r\n"
3621 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3622 "s=-\r\n"
3623 "t=0 0\r\n"
3624 "m=video 3457 RTP/SAVPF 120\r\n"
3625 "b=AS:-1000\r\n";
3626
3627 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3628}
3629
deadbeef3e8016e2017-08-03 17:49:30 -07003630// An exception to the above rule: a value of -1 for b=AS should just be
3631// ignored, resulting in "kAutoBandwidth" in the deserialized object.
3632// Applications historically may be using "b=AS:-1" to mean "no bandwidth
3633// limit", but this is now what ommitting the attribute entirely will do, so
3634// ignoring it will have the intended effect.
3635TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
3636 static const char kSdpWithBandwidthOfNegativeOne[] =
3637 "v=0\r\n"
3638 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3639 "s=-\r\n"
3640 "t=0 0\r\n"
3641 "m=video 3457 RTP/SAVPF 120\r\n"
3642 "b=AS:-1\r\n";
3643
Steve Antona3a92c22017-12-07 10:27:41 -08003644 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-03 17:49:30 -07003645 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-03 17:49:30 -07003646 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003647 GetFirstVideoContentDescription(jdesc_output.description());
3648 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-03 17:49:30 -07003649 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
3650}
3651
deadbeef7bcdb692017-01-20 12:43:58 -08003652// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3653// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3654// Regression test for:
3655// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3656TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3657 // Important piece is "ufrag foo pwd bar".
3658 static const char kSdpWithIceCredentialsInCandidateString[] =
3659 "v=0\r\n"
3660 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3661 "s=-\r\n"
3662 "t=0 0\r\n"
3663 "m=audio 9 RTP/SAVPF 111\r\n"
3664 "c=IN IP4 0.0.0.0\r\n"
3665 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3666 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3667 "a=rtpmap:111 opus/48000/2\r\n"
3668 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3669 "generation 2 ufrag foo pwd bar\r\n";
3670
Steve Antona3a92c22017-12-07 10:27:41 -08003671 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 12:43:58 -08003672 EXPECT_TRUE(
3673 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
3674 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3675 ASSERT_NE(nullptr, candidates);
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003676 ASSERT_EQ(1U, candidates->count());
deadbeef7bcdb692017-01-20 12:43:58 -08003677 cricket::Candidate c = candidates->at(0)->candidate();
3678 EXPECT_EQ("ufrag_voice", c.username());
3679 EXPECT_EQ("pwd_voice", c.password());
3680}
deadbeef90f1e1e2017-02-10 12:35:05 -08003681
Johannes Kron211856b2018-09-06 12:12:28 +02003682// Test that attribute lines "a=ice-ufrag-something"/"a=ice-pwd-something" are
3683// ignored, and only the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3684// Regression test for:
3685// https://bugs.chromium.org/p/webrtc/issues/detail?id=9712
3686TEST_F(WebRtcSdpTest, AttributeWithPartialMatchingNameIsIgnored) {
3687 static const char kSdpWithFooIceCredentials[] =
3688 "v=0\r\n"
3689 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3690 "s=-\r\n"
3691 "t=0 0\r\n"
3692 "m=audio 9 RTP/SAVPF 111\r\n"
3693 "c=IN IP4 0.0.0.0\r\n"
3694 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3695 "a=ice-ufrag-something:foo\r\na=ice-pwd-something:bar\r\n"
3696 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3697 "a=rtpmap:111 opus/48000/2\r\n"
3698 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3699 "generation 2\r\n";
3700
3701 JsepSessionDescription jdesc_output(kDummyType);
3702 EXPECT_TRUE(SdpDeserialize(kSdpWithFooIceCredentials, &jdesc_output));
3703 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3704 ASSERT_NE(nullptr, candidates);
3705 ASSERT_EQ(1U, candidates->count());
3706 cricket::Candidate c = candidates->at(0)->candidate();
3707 EXPECT_EQ("ufrag_voice", c.username());
3708 EXPECT_EQ("pwd_voice", c.password());
3709}
3710
deadbeef90f1e1e2017-02-10 12:35:05 -08003711// Test that SDP with an invalid port number in "a=candidate" lines is
3712// rejected, without crashing.
3713// Regression test for:
3714// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
3715TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
3716 static const char kSdpWithInvalidCandidatePort[] =
3717 "v=0\r\n"
3718 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3719 "s=-\r\n"
3720 "t=0 0\r\n"
3721 "m=audio 9 RTP/SAVPF 111\r\n"
3722 "c=IN IP4 0.0.0.0\r\n"
3723 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3724 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3725 "a=rtpmap:111 opus/48000/2\r\n"
3726 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
3727 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
3728
Steve Antona3a92c22017-12-07 10:27:41 -08003729 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 12:35:05 -08003730 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
3731}
deadbeefa4549d62017-02-10 17:26:22 -08003732
3733// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
3734// Regression test for:
3735// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
3736TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
3737 static const char kSdpWithMissingTrackId[] =
3738 "v=0\r\n"
3739 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3740 "s=-\r\n"
3741 "t=0 0\r\n"
3742 "m=audio 9 RTP/SAVPF 111\r\n"
3743 "c=IN IP4 0.0.0.0\r\n"
3744 "a=rtpmap:111 opus/48000/2\r\n"
3745 "a=msid:stream_id \r\n";
3746
Steve Antona3a92c22017-12-07 10:27:41 -08003747 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003748 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
3749}
3750
3751TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
3752 static const char kSdpWithMissingStreamId[] =
3753 "v=0\r\n"
3754 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3755 "s=-\r\n"
3756 "t=0 0\r\n"
3757 "m=audio 9 RTP/SAVPF 111\r\n"
3758 "c=IN IP4 0.0.0.0\r\n"
3759 "a=rtpmap:111 opus/48000/2\r\n"
3760 "a=msid: track_id\r\n";
3761
Steve Antona3a92c22017-12-07 10:27:41 -08003762 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003763 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
3764}
zhihuang38989e52017-03-21 11:04:53 -07003765
3766// Tests that if both session-level address and media-level address exist, use
3767// the media-level address.
3768TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 10:27:41 -08003769 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003770
3771 // Sesssion-level address.
3772 std::string sdp = kSdpFullString;
3773 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3774 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3775
3776 const auto& content1 = jsep_desc.description()->contents()[0];
3777 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 15:14:30 -08003778 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003779 const auto& content2 = jsep_desc.description()->contents()[1];
3780 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 15:14:30 -08003781 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003782}
3783
3784// Tests that the session-level connection address will be used if the media
3785// level-addresses are not specified.
3786TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 10:27:41 -08003787 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003788
3789 // Sesssion-level address.
3790 std::string sdp = kSdpString;
3791 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3792 // Remove the media level addresses.
3793 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3794 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3795 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3796
3797 const auto& content1 = jsep_desc.description()->contents()[0];
3798 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003799 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003800 const auto& content2 = jsep_desc.description()->contents()[1];
3801 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003802 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003803}
3804
3805TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 10:27:41 -08003806 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003807
3808 std::string sdp = kSdpString;
3809 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3810 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
3811 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
3812 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
3813 &sdp);
3814 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
3815 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
3816 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
3817 &sdp);
3818 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3819 const auto& content1 = jsep_desc.description()->contents()[0];
3820 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003821 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003822 const auto& content2 = jsep_desc.description()->contents()[1];
3823 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003824 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003825}
3826
3827// Test that the invalid or unsupprted connection data cannot be parsed.
3828TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 10:27:41 -08003829 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003830 std::string sdp = kSdpString;
3831 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3832
3833 // Unsupported multicast IPv4 address.
3834 sdp = kSdpFullString;
3835 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
3836 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3837
3838 // Unsupported multicast IPv6 address.
3839 sdp = kSdpFullString;
3840 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
3841 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3842
3843 // Mismatched address type.
3844 sdp = kSdpFullString;
3845 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
3846 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3847
3848 sdp = kSdpFullString;
3849 Replace("c=IN IP4 74.125.224.39\r\n",
3850 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
3851 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3852}
3853
3854TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 10:27:41 -08003855 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003856 MakeDescriptionWithoutCandidates(&expected_jsep);
3857 // Serialization.
Steve Antone831b8c2018-02-01 12:22:16 -08003858 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 11:04:53 -07003859 // Deserialization.
Steve Antona3a92c22017-12-07 10:27:41 -08003860 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003861 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 15:14:30 -08003862 auto audio_desc = jdesc.description()
3863 ->GetContentByName(kAudioContentName)
3864 ->media_description();
3865 auto video_desc = jdesc.description()
3866 ->GetContentByName(kVideoContentName)
3867 ->media_description();
zhihuang38989e52017-03-21 11:04:53 -07003868 EXPECT_EQ(audio_desc_->connection_address().ToString(),
3869 audio_desc->connection_address().ToString());
3870 EXPECT_EQ(video_desc_->connection_address().ToString(),
3871 video_desc->connection_address().ToString());
3872}
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07003873
3874// RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be
3875// used (i.e., a single space as the session name)." So we should accept that.
3876TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) {
3877 JsepSessionDescription jsep_desc(kDummyType);
3878 std::string sdp = kSdpString;
3879 Replace("s=-\r\n", "s= \r\n", &sdp);
3880 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3881}