blob: bba10f205425b9834ef6f4c2e9b78d8a5784b8f7 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2011 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
kwibergd1fe2812016-04-27 06:47:29 -070011#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000012#include <set>
13#include <string>
14#include <vector>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "api/jsepsessiondescription.h"
17#include "media/base/mediaconstants.h"
18#include "media/engine/webrtcvideoengine.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "p2p/base/p2pconstants.h"
Yves Gerey665174f2018-06-19 15:03:05 +020020#include "p2p/base/port.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "pc/mediasession.h"
22#include "rtc_base/checks.h"
23#include "rtc_base/gunit.h"
24#include "rtc_base/logging.h"
Yves Gerey2e00abc2018-10-05 15:39:24 +020025#include "rtc_base/messagedigest.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020026#include "rtc_base/stringencode.h"
27#include "rtc_base/stringutils.h"
Patrik Höglund563934e2017-09-15 09:04:28 +020028
ossu7bb87ee2017-01-23 04:56:25 -080029#ifdef WEBRTC_ANDROID
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020030#include "pc/test/androidtestinitializer.h"
ossu7bb87ee2017-01-23 04:56:25 -080031#endif
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020032#include "pc/webrtcsdp.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000033
34using cricket::AudioCodec;
35using cricket::AudioContentDescription;
36using cricket::Candidate;
37using cricket::ContentInfo;
38using cricket::CryptoParams;
39using cricket::ContentGroup;
40using cricket::DataCodec;
41using cricket::DataContentDescription;
42using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
43using cricket::ICE_CANDIDATE_COMPONENT_RTP;
44using cricket::kFecSsrcGroupSemantics;
45using cricket::LOCAL_PORT_TYPE;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000046using cricket::RELAY_PORT_TYPE;
47using cricket::SessionDescription;
Steve Anton5adfafd2017-12-20 16:34:00 -080048using cricket::MediaProtocolType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049using cricket::StreamParams;
50using cricket::STUN_PORT_TYPE;
51using cricket::TransportDescription;
52using cricket::TransportInfo;
53using cricket::VideoCodec;
54using cricket::VideoContentDescription;
55using webrtc::IceCandidateCollection;
56using webrtc::IceCandidateInterface;
57using webrtc::JsepIceCandidate;
58using webrtc::JsepSessionDescription;
isheriff6f8d6862016-05-26 11:24:55 -070059using webrtc::RtpExtension;
Steve Anton4e70a722017-11-28 14:57:10 -080060using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061using webrtc::SdpParseError;
Steve Antona3a92c22017-12-07 10:27:41 -080062using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063using webrtc::SessionDescriptionInterface;
64
65typedef std::vector<AudioCodec> AudioCodecs;
66typedef std::vector<Candidate> Candidates;
67
Peter Boström0c4e06b2015-10-07 12:23:21 +020068static const uint32_t kDefaultSctpPort = 5000;
zstein4b2e0822017-02-17 19:48:38 -080069static const char kDefaultSctpPortStr[] = "5000";
70static const uint16_t kUnusualSctpPort = 9556;
71static const char kUnusualSctpPortStr[] = "9556";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020073static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 15:17:14 -080074static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 15:17:14 -080076static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020078static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079static const char kCandidateFoundation1[] = "a0+B/1";
80static const char kCandidateFoundation2[] = "a0+B/2";
81static const char kCandidateFoundation3[] = "a0+B/3";
82static const char kCandidateFoundation4[] = "a0+B/4";
83static const char kAttributeCryptoVoice[] =
84 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
85 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
86 "dummy_session_params\r\n";
87static const char kAttributeCryptoVideo[] =
88 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
89 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
Yves Gerey665174f2018-06-19 15:03:05 +020090static const char kFingerprint[] =
91 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n";
Johannes Kron0854eb62018-10-10 22:33:20 +020093static const char kExtmapAllowMixed[] = "a=extmap-allow-mixed\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094static const int kExtmapId = 1;
95static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
96static const char kExtmap[] =
97 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
98static const char kExtmapWithDirectionAndAttribute[] =
99 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
jbauch5869f502017-06-29 12:31:36 -0700100static const char kExtmapWithDirectionAndAttributeEncrypted[] =
101 "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt "
102 "http://example.com/082005/ext.htm#ttime a1 a2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103
Peter Boström0c4e06b2015-10-07 12:23:21 +0200104static const uint8_t kIdentityDigest[] = {
105 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
106 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107
lally@webrtc.org34807282015-02-24 20:19:39 +0000108static const char kDtlsSctp[] = "DTLS/SCTP";
109static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
110static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +0000111
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000112struct CodecParams {
113 int max_ptime;
114 int ptime;
115 int min_ptime;
116 int sprop_stereo;
117 int stereo;
118 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000119 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120};
121
deadbeef9d3584c2016-02-16 17:54:10 -0800122// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
123// instead of "a=crypto", and have an explicit test for adding "a=crypto".
124// Currently it's the other way around.
125
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000126// Reference sdp string
127static const char kSdpFullString[] =
128 "v=0\r\n"
129 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
130 "s=-\r\n"
131 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800132 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000133 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
134 "c=IN IP4 74.125.127.126\r\n"
135 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
136 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
137 "generation 2\r\n"
138 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
139 "generation 2\r\n"
140 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
141 "generation 2\r\n"
142 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
143 "generation 2\r\n"
144 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
145 "raddr 192.168.1.5 rport 2346 "
146 "generation 2\r\n"
147 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
148 "raddr 192.168.1.5 rport 2348 "
149 "generation 2\r\n"
150 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
151 "a=mid:audio_content_name\r\n"
152 "a=sendrecv\r\n"
153 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800154 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000155 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
156 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
157 "dummy_session_params\r\n"
158 "a=rtpmap:111 opus/48000/2\r\n"
159 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000160 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000161 "a=ssrc:1 cname:stream_1_cname\r\n"
162 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
163 "a=ssrc:1 mslabel:local_stream_1\r\n"
164 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000165 "m=video 3457 RTP/SAVPF 120\r\n"
166 "c=IN IP4 74.125.224.39\r\n"
167 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
168 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
169 "generation 2\r\n"
170 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
171 "generation 2\r\n"
172 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
173 "generation 2\r\n"
174 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
175 "generation 2\r\n"
176 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
177 "generation 2\r\n"
178 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
179 "generation 2\r\n"
180 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
181 "a=mid:video_content_name\r\n"
182 "a=sendrecv\r\n"
183 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
184 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
185 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800186 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187 "a=ssrc:2 cname:stream_1_cname\r\n"
188 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
189 "a=ssrc:2 mslabel:local_stream_1\r\n"
190 "a=ssrc:2 label:video_track_id_1\r\n"
191 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800192 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000193 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800194 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000195
196// SDP reference string without the candidates.
197static const char kSdpString[] =
198 "v=0\r\n"
199 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
200 "s=-\r\n"
201 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800202 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000203 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000204 "c=IN IP4 0.0.0.0\r\n"
205 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000206 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
207 "a=mid:audio_content_name\r\n"
208 "a=sendrecv\r\n"
209 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800210 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
212 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
213 "dummy_session_params\r\n"
214 "a=rtpmap:111 opus/48000/2\r\n"
215 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000216 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000217 "a=ssrc:1 cname:stream_1_cname\r\n"
218 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
219 "a=ssrc:1 mslabel:local_stream_1\r\n"
220 "a=ssrc:1 label:audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000221 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000222 "c=IN IP4 0.0.0.0\r\n"
223 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000224 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
225 "a=mid:video_content_name\r\n"
226 "a=sendrecv\r\n"
227 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
228 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
229 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800230 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000231 "a=ssrc:2 cname:stream_1_cname\r\n"
232 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
233 "a=ssrc:2 mslabel:local_stream_1\r\n"
234 "a=ssrc:2 label:video_track_id_1\r\n"
235 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800236 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000237 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800238 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000239
240static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000241 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000242 "c=IN IP4 0.0.0.0\r\n"
243 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000244 "a=ice-ufrag:ufrag_data\r\n"
245 "a=ice-pwd:pwd_data\r\n"
246 "a=mid:data_content_name\r\n"
247 "a=sendrecv\r\n"
248 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
249 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
250 "a=rtpmap:101 google-data/90000\r\n"
251 "a=ssrc:10 cname:data_channel_cname\r\n"
252 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
253 "a=ssrc:10 mslabel:data_channel\r\n"
254 "a=ssrc:10 label:data_channeld0\r\n";
255
256static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000257 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000258 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000259 "a=ice-ufrag:ufrag_data\r\n"
260 "a=ice-pwd:pwd_data\r\n"
261 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000262 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000263
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000264// draft-ietf-mmusic-sctp-sdp-12
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000265static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000266 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
267 "a=max-message-size=100000\r\n"
268 "a=sctp-port 5000\r\n"
269 "c=IN IP4 0.0.0.0\r\n"
270 "a=ice-ufrag:ufrag_data\r\n"
271 "a=ice-pwd:pwd_data\r\n"
272 "a=mid:data_content_name\r\n";
273
lally69f57602015-10-08 10:15:04 -0700274static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
275 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
276 "a=max-message-size=100000\r\n"
277 "a=sctp-port:5000\r\n"
278 "c=IN IP4 0.0.0.0\r\n"
279 "a=ice-ufrag:ufrag_data\r\n"
280 "a=ice-pwd:pwd_data\r\n"
281 "a=mid:data_content_name\r\n";
282
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000283static const char kSdpSctpDataChannelWithCandidatesString[] =
284 "m=application 2345 DTLS/SCTP 5000\r\n"
285 "c=IN IP4 74.125.127.126\r\n"
286 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
287 "generation 2\r\n"
288 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
289 "generation 2\r\n"
290 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
291 "raddr 192.168.1.5 rport 2346 "
292 "generation 2\r\n"
293 "a=ice-ufrag:ufrag_data\r\n"
294 "a=ice-pwd:pwd_data\r\n"
295 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000296 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000297
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000298static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000299 "v=0\r\n"
300 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
301 "s=-\r\n"
302 "t=0 0\r\n"
303 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000304 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000305 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000306 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000307 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000308 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000309 "a=x-google-flag:conference\r\n";
310
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000311static const char kSdpSessionString[] =
312 "v=0\r\n"
313 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
314 "s=-\r\n"
315 "t=0 0\r\n"
316 "a=msid-semantic: WMS local_stream\r\n";
317
318static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000319 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000320 "c=IN IP4 0.0.0.0\r\n"
321 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000322 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
323 "a=mid:audio_content_name\r\n"
324 "a=sendrecv\r\n"
325 "a=rtpmap:111 opus/48000/2\r\n"
326 "a=ssrc:1 cname:stream_1_cname\r\n"
327 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
328 "a=ssrc:1 mslabel:local_stream\r\n"
329 "a=ssrc:1 label:audio_track_id_1\r\n";
330
331static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000332 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000333 "c=IN IP4 0.0.0.0\r\n"
334 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000335 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
336 "a=mid:video_content_name\r\n"
337 "a=sendrecv\r\n"
338 "a=rtpmap:120 VP8/90000\r\n"
339 "a=ssrc:2 cname:stream_1_cname\r\n"
340 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
341 "a=ssrc:2 mslabel:local_stream\r\n"
342 "a=ssrc:2 label:video_track_id_1\r\n";
343
deadbeef25ed4352016-12-12 18:37:36 -0800344// Reference sdp string using bundle-only.
345static const char kBundleOnlySdpFullString[] =
346 "v=0\r\n"
347 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
348 "s=-\r\n"
349 "t=0 0\r\n"
350 "a=group:BUNDLE audio_content_name video_content_name\r\n"
351 "a=msid-semantic: WMS local_stream_1\r\n"
352 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
353 "c=IN IP4 74.125.127.126\r\n"
354 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
355 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
356 "generation 2\r\n"
357 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
358 "generation 2\r\n"
359 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
360 "generation 2\r\n"
361 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
362 "generation 2\r\n"
363 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
364 "raddr 192.168.1.5 rport 2346 "
365 "generation 2\r\n"
366 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
367 "raddr 192.168.1.5 rport 2348 "
368 "generation 2\r\n"
369 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
370 "a=mid:audio_content_name\r\n"
371 "a=sendrecv\r\n"
372 "a=rtcp-mux\r\n"
373 "a=rtcp-rsize\r\n"
374 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
375 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
376 "dummy_session_params\r\n"
377 "a=rtpmap:111 opus/48000/2\r\n"
378 "a=rtpmap:103 ISAC/16000\r\n"
379 "a=rtpmap:104 ISAC/32000\r\n"
380 "a=ssrc:1 cname:stream_1_cname\r\n"
381 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
382 "a=ssrc:1 mslabel:local_stream_1\r\n"
383 "a=ssrc:1 label:audio_track_id_1\r\n"
384 "m=video 0 RTP/SAVPF 120\r\n"
385 "c=IN IP4 0.0.0.0\r\n"
386 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
387 "a=bundle-only\r\n"
388 "a=mid:video_content_name\r\n"
389 "a=sendrecv\r\n"
390 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
391 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
392 "a=rtpmap:120 VP8/90000\r\n"
393 "a=ssrc-group:FEC 2 3\r\n"
394 "a=ssrc:2 cname:stream_1_cname\r\n"
395 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
396 "a=ssrc:2 mslabel:local_stream_1\r\n"
397 "a=ssrc:2 label:video_track_id_1\r\n"
398 "a=ssrc:3 cname:stream_1_cname\r\n"
399 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
400 "a=ssrc:3 mslabel:local_stream_1\r\n"
401 "a=ssrc:3 label:video_track_id_1\r\n";
402
deadbeef9d3584c2016-02-16 17:54:10 -0800403// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
404// tracks.
405static const char kPlanBSdpFullString[] =
406 "v=0\r\n"
407 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
408 "s=-\r\n"
409 "t=0 0\r\n"
410 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
411 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
412 "c=IN IP4 74.125.127.126\r\n"
413 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
414 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
415 "generation 2\r\n"
416 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
417 "generation 2\r\n"
418 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
419 "generation 2\r\n"
420 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
421 "generation 2\r\n"
422 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
423 "raddr 192.168.1.5 rport 2346 "
424 "generation 2\r\n"
425 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
426 "raddr 192.168.1.5 rport 2348 "
427 "generation 2\r\n"
428 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
429 "a=mid:audio_content_name\r\n"
430 "a=sendrecv\r\n"
431 "a=rtcp-mux\r\n"
432 "a=rtcp-rsize\r\n"
433 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
434 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
435 "dummy_session_params\r\n"
436 "a=rtpmap:111 opus/48000/2\r\n"
437 "a=rtpmap:103 ISAC/16000\r\n"
438 "a=rtpmap:104 ISAC/32000\r\n"
439 "a=ssrc:1 cname:stream_1_cname\r\n"
440 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
441 "a=ssrc:1 mslabel:local_stream_1\r\n"
442 "a=ssrc:1 label:audio_track_id_1\r\n"
443 "a=ssrc:4 cname:stream_2_cname\r\n"
444 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
445 "a=ssrc:4 mslabel:local_stream_2\r\n"
446 "a=ssrc:4 label:audio_track_id_2\r\n"
447 "m=video 3457 RTP/SAVPF 120\r\n"
448 "c=IN IP4 74.125.224.39\r\n"
449 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
450 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
451 "generation 2\r\n"
452 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
453 "generation 2\r\n"
454 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
455 "generation 2\r\n"
456 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
457 "generation 2\r\n"
458 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
459 "generation 2\r\n"
460 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
461 "generation 2\r\n"
462 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
463 "a=mid:video_content_name\r\n"
464 "a=sendrecv\r\n"
465 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
466 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
467 "a=rtpmap:120 VP8/90000\r\n"
468 "a=ssrc-group:FEC 2 3\r\n"
469 "a=ssrc:2 cname:stream_1_cname\r\n"
470 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
471 "a=ssrc:2 mslabel:local_stream_1\r\n"
472 "a=ssrc:2 label:video_track_id_1\r\n"
473 "a=ssrc:3 cname:stream_1_cname\r\n"
474 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
475 "a=ssrc:3 mslabel:local_stream_1\r\n"
476 "a=ssrc:3 label:video_track_id_1\r\n"
477 "a=ssrc:5 cname:stream_2_cname\r\n"
478 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
479 "a=ssrc:5 mslabel:local_stream_2\r\n"
480 "a=ssrc:5 label:video_track_id_2\r\n"
481 "a=ssrc:6 cname:stream_2_cname\r\n"
482 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
483 "a=ssrc:6 mslabel:local_stream_2\r\n"
484 "a=ssrc:6 label:video_track_id_3\r\n";
485
486// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
487// tracks.
488static const char kUnifiedPlanSdpFullString[] =
489 "v=0\r\n"
490 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
491 "s=-\r\n"
492 "t=0 0\r\n"
493 "a=msid-semantic: WMS local_stream_1\r\n"
494 // Audio track 1, stream 1 (with candidates).
495 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
496 "c=IN IP4 74.125.127.126\r\n"
497 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
498 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
499 "generation 2\r\n"
500 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
501 "generation 2\r\n"
502 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
503 "generation 2\r\n"
504 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
505 "generation 2\r\n"
506 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
507 "raddr 192.168.1.5 rport 2346 "
508 "generation 2\r\n"
509 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
510 "raddr 192.168.1.5 rport 2348 "
511 "generation 2\r\n"
512 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
513 "a=mid:audio_content_name\r\n"
514 "a=msid:local_stream_1 audio_track_id_1\r\n"
515 "a=sendrecv\r\n"
516 "a=rtcp-mux\r\n"
517 "a=rtcp-rsize\r\n"
518 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
519 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
520 "dummy_session_params\r\n"
521 "a=rtpmap:111 opus/48000/2\r\n"
522 "a=rtpmap:103 ISAC/16000\r\n"
523 "a=rtpmap:104 ISAC/32000\r\n"
524 "a=ssrc:1 cname:stream_1_cname\r\n"
525 // Video track 1, stream 1 (with candidates).
526 "m=video 3457 RTP/SAVPF 120\r\n"
527 "c=IN IP4 74.125.224.39\r\n"
528 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
529 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
530 "generation 2\r\n"
531 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
532 "generation 2\r\n"
533 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
534 "generation 2\r\n"
535 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
536 "generation 2\r\n"
537 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
538 "generation 2\r\n"
539 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
540 "generation 2\r\n"
541 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
542 "a=mid:video_content_name\r\n"
543 "a=msid:local_stream_1 video_track_id_1\r\n"
544 "a=sendrecv\r\n"
545 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
546 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
547 "a=rtpmap:120 VP8/90000\r\n"
548 "a=ssrc-group:FEC 2 3\r\n"
549 "a=ssrc:2 cname:stream_1_cname\r\n"
550 "a=ssrc:3 cname:stream_1_cname\r\n"
551 // Audio track 2, stream 2.
552 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
553 "c=IN IP4 0.0.0.0\r\n"
554 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
555 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
556 "a=mid:audio_content_name_2\r\n"
557 "a=msid:local_stream_2 audio_track_id_2\r\n"
558 "a=sendrecv\r\n"
559 "a=rtcp-mux\r\n"
560 "a=rtcp-rsize\r\n"
561 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
562 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
563 "dummy_session_params\r\n"
564 "a=rtpmap:111 opus/48000/2\r\n"
565 "a=rtpmap:103 ISAC/16000\r\n"
566 "a=rtpmap:104 ISAC/32000\r\n"
567 "a=ssrc:4 cname:stream_2_cname\r\n"
568 // Video track 2, stream 2.
569 "m=video 9 RTP/SAVPF 120\r\n"
570 "c=IN IP4 0.0.0.0\r\n"
571 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
572 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
573 "a=mid:video_content_name_2\r\n"
574 "a=msid:local_stream_2 video_track_id_2\r\n"
575 "a=sendrecv\r\n"
576 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
577 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
578 "a=rtpmap:120 VP8/90000\r\n"
579 "a=ssrc:5 cname:stream_2_cname\r\n"
580 // Video track 3, stream 2.
581 "m=video 9 RTP/SAVPF 120\r\n"
582 "c=IN IP4 0.0.0.0\r\n"
583 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
584 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
585 "a=mid:video_content_name_3\r\n"
586 "a=msid:local_stream_2 video_track_id_3\r\n"
587 "a=sendrecv\r\n"
588 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
589 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
590 "a=rtpmap:120 VP8/90000\r\n"
591 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000592
Seth Hampson5b4f0752018-04-02 16:31:36 -0700593// Unified Plan SDP reference string:
594// - audio track 1 has 1 a=msid lines
595// - audio track 2 has 2 a=msid lines
596// - audio track 3 has 1 a=msid line with the special "-" marker signifying that
597// there are 0 media stream ids.
598// This Unified Plan SDP represents a SDP that signals the msid using both
599// a=msid and a=ssrc msid semantics.
600static const char kUnifiedPlanSdpFullStringWithSpecialMsid[] =
601 "v=0\r\n"
602 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
603 "s=-\r\n"
604 "t=0 0\r\n"
605 "a=msid-semantic: WMS local_stream_1\r\n"
606 // Audio track 1, with 1 stream id.
607 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
608 "c=IN IP4 74.125.127.126\r\n"
609 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
610 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
611 "generation 2\r\n"
612 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
613 "generation 2\r\n"
614 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
615 "generation 2\r\n"
616 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
617 "generation 2\r\n"
618 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
619 "raddr 192.168.1.5 rport 2346 "
620 "generation 2\r\n"
621 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
622 "raddr 192.168.1.5 rport 2348 "
623 "generation 2\r\n"
624 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
625 "a=mid:audio_content_name\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700626 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700627 "a=msid:local_stream_1 audio_track_id_1\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700628 "a=rtcp-mux\r\n"
629 "a=rtcp-rsize\r\n"
630 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
631 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
632 "dummy_session_params\r\n"
633 "a=rtpmap:111 opus/48000/2\r\n"
634 "a=rtpmap:103 ISAC/16000\r\n"
635 "a=rtpmap:104 ISAC/32000\r\n"
636 "a=ssrc:1 cname:stream_1_cname\r\n"
637 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
638 "a=ssrc:1 mslabel:local_stream_1\r\n"
639 "a=ssrc:1 label:audio_track_id_1\r\n"
640 // Audio track 2, with two stream ids.
641 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
642 "c=IN IP4 0.0.0.0\r\n"
643 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
644 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
645 "a=mid:audio_content_name_2\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700646 "a=sendrecv\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700647 "a=msid:local_stream_1 audio_track_id_2\r\n"
648 "a=msid:local_stream_2 audio_track_id_2\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700649 "a=rtcp-mux\r\n"
650 "a=rtcp-rsize\r\n"
651 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
652 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
653 "dummy_session_params\r\n"
654 "a=rtpmap:111 opus/48000/2\r\n"
655 "a=rtpmap:103 ISAC/16000\r\n"
656 "a=rtpmap:104 ISAC/32000\r\n"
657 "a=ssrc:4 cname:stream_1_cname\r\n"
658 // The support for Plan B msid signaling only includes the
659 // first media stream id "local_stream_1."
660 "a=ssrc:4 msid:local_stream_1 audio_track_id_2\r\n"
661 "a=ssrc:4 mslabel:local_stream_1\r\n"
662 "a=ssrc:4 label:audio_track_id_2\r\n"
663 // Audio track 3, with no stream ids.
664 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
665 "c=IN IP4 0.0.0.0\r\n"
666 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
667 "a=ice-ufrag:ufrag_voice_3\r\na=ice-pwd:pwd_voice_3\r\n"
668 "a=mid:audio_content_name_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700669 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700670 "a=msid:- audio_track_id_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700671 "a=rtcp-mux\r\n"
672 "a=rtcp-rsize\r\n"
673 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
674 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
675 "dummy_session_params\r\n"
676 "a=rtpmap:111 opus/48000/2\r\n"
677 "a=rtpmap:103 ISAC/16000\r\n"
678 "a=rtpmap:104 ISAC/32000\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700679 "a=ssrc:7 cname:stream_2_cname\r\n"
680 "a=ssrc:7 msid:- audio_track_id_3\r\n"
681 "a=ssrc:7 mslabel:-\r\n"
682 "a=ssrc:7 label:audio_track_id_3\r\n";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700683
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000684// One candidate reference string as per W3c spec.
685// candidate:<blah> not a=candidate:<blah>CRLF
686static const char kRawCandidate[] =
687 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
688// One candidate reference string.
689static const char kSdpOneCandidate[] =
690 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
691 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000692
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000693static const char kSdpTcpActiveCandidate[] =
694 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
695 "tcptype active generation 2";
696static const char kSdpTcpPassiveCandidate[] =
697 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
698 "tcptype passive generation 2";
699static const char kSdpTcpSOCandidate[] =
700 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
701 "tcptype so generation 2";
702static const char kSdpTcpInvalidCandidate[] =
703 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
704 "tcptype invalid generation 2";
705
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000706// One candidate reference string with IPV6 address.
707static const char kRawIPV6Candidate[] =
708 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 12:04:36 -0700709 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000710
711// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800712static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000713 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800714 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000715
Zach Steinb336c272018-08-09 01:16:13 -0700716static const char kRawHostnameCandidate[] =
717 "candidate:a0+B/1 1 udp 2130706432 a.test 1234 typ host generation 2";
718
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000719// Session id and version
720static const char kSessionId[] = "18446744069414584320";
721static const char kSessionVersion[] = "18446462598732840960";
722
deadbeef9d3584c2016-02-16 17:54:10 -0800723// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000724static const char kIceOption1[] = "iceoption1";
725static const char kIceOption2[] = "iceoption2";
726static const char kIceOption3[] = "iceoption3";
727
deadbeef9d3584c2016-02-16 17:54:10 -0800728// ICE ufrags/passwords.
729static const char kUfragVoice[] = "ufrag_voice";
730static const char kPwdVoice[] = "pwd_voice";
731static const char kUfragVideo[] = "ufrag_video";
732static const char kPwdVideo[] = "pwd_video";
733static const char kUfragData[] = "ufrag_data";
734static const char kPwdData[] = "pwd_data";
735
736// Extra ufrags/passwords for extra unified plan m= sections.
737static const char kUfragVoice2[] = "ufrag_voice_2";
738static const char kPwdVoice2[] = "pwd_voice_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700739static const char kUfragVoice3[] = "ufrag_voice_3";
740static const char kPwdVoice3[] = "pwd_voice_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800741static const char kUfragVideo2[] = "ufrag_video_2";
742static const char kPwdVideo2[] = "pwd_video_2";
743static const char kUfragVideo3[] = "ufrag_video_3";
744static const char kPwdVideo3[] = "pwd_video_3";
745
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000746// Content name
747static const char kAudioContentName[] = "audio_content_name";
748static const char kVideoContentName[] = "video_content_name";
749static const char kDataContentName[] = "data_content_name";
750
deadbeef9d3584c2016-02-16 17:54:10 -0800751// Extra content names for extra unified plan m= sections.
752static const char kAudioContentName2[] = "audio_content_name_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700753static const char kAudioContentName3[] = "audio_content_name_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800754static const char kVideoContentName2[] = "video_content_name_2";
755static const char kVideoContentName3[] = "video_content_name_3";
756
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000757// MediaStream 1
Seth Hampson845e8782018-03-02 11:34:10 -0800758static const char kStreamId1[] = "local_stream_1";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000759static const char kStream1Cname[] = "stream_1_cname";
760static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200761static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000762static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800763static const uint32_t kVideoTrack1Ssrc1 = 2;
764static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000765
766// MediaStream 2
Seth Hampson845e8782018-03-02 11:34:10 -0800767static const char kStreamId2[] = "local_stream_2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000768static const char kStream2Cname[] = "stream_2_cname";
769static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200770static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800771static const char kVideoTrackId2[] = "video_track_id_2";
772static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000773static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800774static const uint32_t kVideoTrack3Ssrc = 6;
Seth Hampson5b4f0752018-04-02 16:31:36 -0700775static const char kAudioTrackId3[] = "audio_track_id_3";
776static const uint32_t kAudioTrack3Ssrc = 7;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000777
778// DataChannel
779static const char kDataChannelLabel[] = "data_channel";
780static const char kDataChannelMsid[] = "data_channeld0";
781static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200782static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000783
784// Candidate
785static const char kDummyMid[] = "dummy_mid";
786static const int kDummyIndex = 123;
787
788// Misc
Steve Antona3a92c22017-12-07 10:27:41 -0800789static SdpType kDummyType = SdpType::kOffer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000790
791// Helper functions
792
793static bool SdpDeserialize(const std::string& message,
794 JsepSessionDescription* jdesc) {
795 return webrtc::SdpDeserialize(message, jdesc, NULL);
796}
797
798static bool SdpDeserializeCandidate(const std::string& message,
799 JsepIceCandidate* candidate) {
800 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
801}
802
803// Add some extra |newlines| to the |message| after |line|.
804static void InjectAfter(const std::string& line,
805 const std::string& newlines,
806 std::string* message) {
807 const std::string tmp = line + newlines;
Yves Gerey665174f2018-06-19 15:03:05 +0200808 rtc::replace_substrs(line.c_str(), line.length(), tmp.c_str(), tmp.length(),
809 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000810}
811
812static void Replace(const std::string& line,
813 const std::string& newlines,
814 std::string* message) {
Yves Gerey665174f2018-06-19 15:03:05 +0200815 rtc::replace_substrs(line.c_str(), line.length(), newlines.c_str(),
816 newlines.length(), message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000817}
818
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000819// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
820// message.
821static void ExpectParseFailure(const std::string& bad_sdp,
822 const std::string& bad_part) {
Steve Antona3a92c22017-12-07 10:27:41 -0800823 JsepSessionDescription desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000824 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000825 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000826 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000827 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
828}
829
830// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
831static void ExpectParseFailure(const char* good_part, const char* bad_part) {
832 std::string bad_sdp = kSdpFullString;
833 Replace(good_part, bad_part, &bad_sdp);
834 ExpectParseFailure(bad_sdp, bad_part);
835}
836
837// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
838static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
839 const std::string& newlines,
840 const std::string& bad_part) {
841 std::string bad_sdp = kSdpFullString;
842 InjectAfter(injectpoint, newlines, &bad_sdp);
843 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844}
845
Steve Anton4e70a722017-11-28 14:57:10 -0800846static void ReplaceDirection(RtpTransceiverDirection direction,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000847 std::string* message) {
848 std::string new_direction;
849 switch (direction) {
Steve Anton4e70a722017-11-28 14:57:10 -0800850 case RtpTransceiverDirection::kInactive:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000851 new_direction = "a=inactive";
852 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800853 case RtpTransceiverDirection::kSendOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854 new_direction = "a=sendonly";
855 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800856 case RtpTransceiverDirection::kRecvOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000857 new_direction = "a=recvonly";
858 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800859 case RtpTransceiverDirection::kSendRecv:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000860 default:
861 new_direction = "a=sendrecv";
862 break;
863 }
864 Replace("a=sendrecv", new_direction, message);
865}
866
Yves Gerey665174f2018-06-19 15:03:05 +0200867static void ReplaceRejected(bool audio_rejected,
868 bool video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000869 std::string* message) {
870 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800871 Replace("m=audio 9", "m=audio 0", message);
872 Replace(kAttributeIceUfragVoice, "", message);
873 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000874 }
875 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800876 Replace("m=video 9", "m=video 0", message);
877 Replace(kAttributeIceUfragVideo, "", message);
878 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000879 }
880}
881
882// WebRtcSdpTest
883
884class WebRtcSdpTest : public testing::Test {
885 public:
Steve Antona3a92c22017-12-07 10:27:41 -0800886 WebRtcSdpTest() : jdesc_(kDummyType) {
phoglund37ebcf02016-01-08 05:04:57 -0800887#ifdef WEBRTC_ANDROID
888 webrtc::InitializeAndroidObjects();
889#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890 // AudioContentDescription
891 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -0800892 StreamParams audio_stream;
893 audio_stream.id = kAudioTrackId1;
894 audio_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -0800895 audio_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -0800896 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
897 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 11:04:53 -0700898 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
899 audio_desc_->set_connection_address(audio_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -0800900 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000901
902 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -0800903 video_desc_ = CreateVideoContentDescription();
904 StreamParams video_stream;
905 video_stream.id = kVideoTrackId1;
906 video_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -0800907 video_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -0800908 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
909 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
910 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
911 video_stream.ssrc_groups.push_back(ssrc_group);
912 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 11:04:53 -0700913 rtc::SocketAddress video_addr("74.125.224.39", 3457);
914 video_desc_->set_connection_address(video_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -0800915 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000916
917 // TransportInfo
deadbeef9d3584c2016-02-16 17:54:10 -0800918 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
919 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice))));
920 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
921 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000922
923 // v4 host
924 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000925 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000926 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000927 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
928 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000929 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000930 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000931 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
932 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000934 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000935 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
936 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000937 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000938 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000939 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
940 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000941
942 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000943 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000944 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
945 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000946 cricket::LOCAL_PORT_TYPE,
947 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000948 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000949 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
950 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000951 cricket::LOCAL_PORT_TYPE,
952 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000953 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000954 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
955 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000956 cricket::LOCAL_PORT_TYPE,
957 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000958 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000959 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
960 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000961 cricket::LOCAL_PORT_TYPE,
962 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000963
964 // stun
965 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000966 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
967 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000968 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
969 address_stun, kCandidatePriority, "", "",
970 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000971 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000972 candidate9.set_related_address(rel_address_stun);
973
974 address_stun.SetPort(port_stun++);
975 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000976 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
977 address_stun, kCandidatePriority, "", "",
978 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000979 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000980 candidate10.set_related_address(rel_address_stun);
981
982 // relay
983 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000984 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000985 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
986 address_relay, kCandidatePriority, "", "",
987 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000988 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000989 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000990 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
991 address_relay, kCandidatePriority, "", "",
992 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000993 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000994
995 // voice
996 candidates_.push_back(candidate1);
997 candidates_.push_back(candidate2);
998 candidates_.push_back(candidate5);
999 candidates_.push_back(candidate6);
1000 candidates_.push_back(candidate9);
1001 candidates_.push_back(candidate10);
1002
1003 // video
1004 candidates_.push_back(candidate3);
1005 candidates_.push_back(candidate4);
1006 candidates_.push_back(candidate7);
1007 candidates_.push_back(candidate8);
1008 candidates_.push_back(candidate11);
1009 candidates_.push_back(candidate12);
1010
Yves Gerey665174f2018-06-19 15:03:05 +02001011 jcandidate_.reset(
1012 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001013
1014 // Set up JsepSessionDescription.
1015 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
1016 std::string mline_id;
1017 int mline_index = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001018 for (size_t i = 0; i < candidates_.size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001019 // In this test, the audio m line index will be 0, and the video m line
1020 // will be 1.
1021 bool is_video = (i > 5);
1022 mline_id = is_video ? "video_content_name" : "audio_content_name";
1023 mline_index = is_video ? 1 : 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001024 JsepIceCandidate jice(mline_id, mline_index, candidates_.at(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001025 jdesc_.AddCandidate(&jice);
1026 }
1027 }
1028
Seth Hampson5b4f0752018-04-02 16:31:36 -07001029 void RemoveVideoCandidates() {
deadbeef25ed4352016-12-12 18:37:36 -08001030 const IceCandidateCollection* video_candidates_collection =
1031 jdesc_.candidates(1);
1032 ASSERT_NE(nullptr, video_candidates_collection);
1033 std::vector<cricket::Candidate> video_candidates;
1034 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1035 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1036 c.set_transport_name("video_content_name");
1037 video_candidates.push_back(c);
1038 }
1039 jdesc_.RemoveCandidates(video_candidates);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001040 }
1041
1042 // Turns the existing reference description into a description using
1043 // a=bundle-only. This means no transport attributes and a 0 port value on
1044 // the m= sections not associated with the BUNDLE-tag.
1045 void MakeBundleOnlyDescription() {
1046 RemoveVideoCandidates();
deadbeef25ed4352016-12-12 18:37:36 -08001047
1048 // And the rest of the transport attributes.
1049 desc_.transport_infos()[1].description.ice_ufrag.clear();
1050 desc_.transport_infos()[1].description.ice_pwd.clear();
1051 desc_.transport_infos()[1].description.connection_role =
1052 cricket::CONNECTIONROLE_NONE;
1053
1054 // Set bundle-only flag.
1055 desc_.contents()[1].bundle_only = true;
1056
1057 // Add BUNDLE group.
1058 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1059 group.AddContentName(kAudioContentName);
1060 group.AddContentName(kVideoContentName);
1061 desc_.AddGroup(group);
1062
1063 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1064 jdesc_.session_version()));
1065 }
1066
deadbeef9d3584c2016-02-16 17:54:10 -08001067 // Turns the existing reference description into a plan B description,
1068 // with 2 audio tracks and 3 video tracks.
1069 void MakePlanBDescription() {
Steve Antonb1c1de12017-12-21 15:14:30 -08001070 audio_desc_ = audio_desc_->Copy();
1071 video_desc_ = video_desc_->Copy();
deadbeef9d3584c2016-02-16 17:54:10 -08001072
1073 StreamParams audio_track_2;
1074 audio_track_2.id = kAudioTrackId2;
1075 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001076 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001077 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1078 audio_desc_->AddStream(audio_track_2);
1079
1080 StreamParams video_track_2;
1081 video_track_2.id = kVideoTrackId2;
1082 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001083 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001084 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1085 video_desc_->AddStream(video_track_2);
1086
1087 StreamParams video_track_3;
1088 video_track_3.id = kVideoTrackId3;
1089 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001090 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001091 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1092 video_desc_->AddStream(video_track_3);
1093
1094 desc_.RemoveContentByName(kAudioContentName);
1095 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001096 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1097 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001098
1099 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1100 jdesc_.session_version()));
1101 }
1102
1103 // Turns the existing reference description into a unified plan description,
1104 // with 2 audio tracks and 3 video tracks.
1105 void MakeUnifiedPlanDescription() {
1106 // Audio track 2.
1107 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1108 StreamParams audio_track_2;
1109 audio_track_2.id = kAudioTrackId2;
1110 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001111 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001112 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1113 audio_desc_2->AddStream(audio_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001114 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
deadbeef9d3584c2016-02-16 17:54:10 -08001115 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1116 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
deadbeef9d3584c2016-02-16 17:54:10 -08001117 // Video track 2, in stream 2.
1118 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1119 StreamParams video_track_2;
1120 video_track_2.id = kVideoTrackId2;
1121 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001122 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001123 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1124 video_desc_2->AddStream(video_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001125 desc_.AddContent(kVideoContentName2, MediaProtocolType::kRtp, video_desc_2);
deadbeef9d3584c2016-02-16 17:54:10 -08001126 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1127 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2))));
1128
1129 // Video track 3, in stream 2.
1130 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1131 StreamParams video_track_3;
1132 video_track_3.id = kVideoTrackId3;
1133 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001134 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001135 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1136 video_desc_3->AddStream(video_track_3);
Steve Anton5adfafd2017-12-20 16:34:00 -08001137 desc_.AddContent(kVideoContentName3, MediaProtocolType::kRtp, video_desc_3);
deadbeef9d3584c2016-02-16 17:54:10 -08001138 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1139 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3))));
Steve Antone831b8c2018-02-01 12:22:16 -08001140 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
deadbeef9d3584c2016-02-16 17:54:10 -08001141
1142 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1143 jdesc_.session_version()));
1144 }
1145
1146 // Creates an audio content description with no streams, and some default
1147 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001148 AudioContentDescription* CreateAudioContentDescription() {
1149 AudioContentDescription* audio = new AudioContentDescription();
1150 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -08001151 audio->set_rtcp_reduced_size(true);
Yves Gerey665174f2018-06-19 15:03:05 +02001152 audio->AddCrypto(CryptoParams(
1153 1, "AES_CM_128_HMAC_SHA1_32",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001154 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1155 "dummy_session_params"));
1156 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef67cf2c12016-04-13 10:07:16 -07001157 AudioCodec opus(111, "opus", 48000, 0, 2);
deadbeef9d3584c2016-02-16 17:54:10 -08001158 audio->AddCodec(opus);
ossue1405ad2017-01-23 08:55:48 -08001159 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1160 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001161 return audio;
1162 }
1163
Seth Hampson5b4f0752018-04-02 16:31:36 -07001164 // Turns the existing reference description into a unified plan description,
1165 // with 3 audio MediaContentDescriptions with special StreamParams that
1166 // contain 0 or multiple stream ids: - audio track 1 has 1 media stream id -
1167 // audio track 2 has 2 media stream ids - audio track 3 has 0 media stream ids
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001168 void MakeUnifiedPlanDescriptionMultipleStreamIds(const int msid_signaling) {
Seth Hampson5b4f0752018-04-02 16:31:36 -07001169 desc_.RemoveContentByName(kVideoContentName);
1170 desc_.RemoveTransportInfoByName(kVideoContentName);
1171 RemoveVideoCandidates();
1172
1173 // Audio track 2 has 2 media stream ids.
1174 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1175 StreamParams audio_track_2;
1176 audio_track_2.id = kAudioTrackId2;
1177 audio_track_2.cname = kStream1Cname;
1178 audio_track_2.set_stream_ids({kStreamId1, kStreamId2});
1179 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1180 audio_desc_2->AddStream(audio_track_2);
1181 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
1182 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1183 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
1184
1185 // Audio track 3 has no stream ids.
1186 AudioContentDescription* audio_desc_3 = CreateAudioContentDescription();
1187 StreamParams audio_track_3;
1188 audio_track_3.id = kAudioTrackId3;
1189 audio_track_3.cname = kStream2Cname;
1190 audio_track_3.set_stream_ids({});
1191 audio_track_3.ssrcs.push_back(kAudioTrack3Ssrc);
1192 audio_desc_3->AddStream(audio_track_3);
1193 desc_.AddContent(kAudioContentName3, MediaProtocolType::kRtp, audio_desc_3);
1194 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1195 kAudioContentName3, TransportDescription(kUfragVoice3, kPwdVoice3))));
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001196 desc_.set_msid_signaling(msid_signaling);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001197 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1198 jdesc_.session_version()));
1199 }
1200
Seth Hampson5897a6e2018-04-03 11:16:33 -07001201 // Turns the existing reference description into a unified plan description
1202 // with one audio MediaContentDescription that contains one StreamParams with
1203 // 0 ssrcs.
1204 void MakeUnifiedPlanDescriptionNoSsrcSignaling() {
1205 desc_.RemoveContentByName(kVideoContentName);
1206 desc_.RemoveContentByName(kAudioContentName);
1207 desc_.RemoveTransportInfoByName(kVideoContentName);
1208 RemoveVideoCandidates();
1209
1210 AudioContentDescription* audio_desc = CreateAudioContentDescription();
1211 StreamParams audio_track;
1212 audio_track.id = kAudioTrackId1;
1213 audio_track.set_stream_ids({kStreamId1});
1214 audio_desc->AddStream(audio_track);
1215 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc);
1216
1217 // Enable signaling a=msid lines.
1218 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
1219 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1220 jdesc_.session_version()));
1221 }
1222
deadbeef9d3584c2016-02-16 17:54:10 -08001223 // Creates a video content description with no streams, and some default
1224 // configuration.
1225 VideoContentDescription* CreateVideoContentDescription() {
1226 VideoContentDescription* video = new VideoContentDescription();
1227 video->AddCrypto(CryptoParams(
1228 1, "AES_CM_128_HMAC_SHA1_80",
1229 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1230 video->set_protocol(cricket::kMediaProtocolSavpf);
1231 video->AddCodec(
perkj26752742016-10-24 01:21:16 -07001232 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-16 17:54:10 -08001233 return video;
1234 }
1235
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001236 template <class MCD>
Yves Gerey665174f2018-06-19 15:03:05 +02001237 void CompareMediaContentDescription(const MCD* cd1, const MCD* cd2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001238 // type
1239 EXPECT_EQ(cd1->type(), cd1->type());
1240
1241 // content direction
1242 EXPECT_EQ(cd1->direction(), cd2->direction());
1243
1244 // rtcp_mux
1245 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1246
deadbeef13871492015-12-09 12:37:51 -08001247 // rtcp_reduced_size
1248 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1249
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001250 // cryptos
1251 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1252 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1253 ADD_FAILURE();
1254 return;
1255 }
Yves Gerey665174f2018-06-19 15:03:05 +02001256 for (size_t i = 0; i < cd1->cryptos().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001257 const CryptoParams c1 = cd1->cryptos().at(i);
1258 const CryptoParams c2 = cd2->cryptos().at(i);
1259 EXPECT_TRUE(c1.Matches(c2));
1260 EXPECT_EQ(c1.key_params, c2.key_params);
1261 EXPECT_EQ(c1.session_params, c2.session_params);
1262 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001263
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001264 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001265 // Use an equivalence class here, for old and new versions of the
1266 // protocol description.
Yves Gerey665174f2018-06-19 15:03:05 +02001267 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp ||
1268 cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1269 cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
lally@webrtc.org36300852015-02-24 20:19:35 +00001270 const bool cd2_is_also_dtls_sctp =
Yves Gerey665174f2018-06-19 15:03:05 +02001271 cd2->protocol() == cricket::kMediaProtocolDtlsSctp ||
1272 cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1273 cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
lally@webrtc.org36300852015-02-24 20:19:35 +00001274 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001275 } else {
1276 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1277 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001278
1279 // codecs
1280 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1281
1282 // bandwidth
1283 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1284
1285 // streams
1286 EXPECT_EQ(cd1->streams(), cd2->streams());
1287
Johannes Kron0854eb62018-10-10 22:33:20 +02001288 // extmap-allow-mixed
Johannes Kron9ac3c912018-10-12 10:54:26 +02001289 EXPECT_EQ(cd1->extmap_allow_mixed_headers(),
1290 cd2->extmap_allow_mixed_headers());
Johannes Kron0854eb62018-10-10 22:33:20 +02001291
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001292 // extmap
1293 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1294 cd2->rtp_header_extensions().size());
Yves Gerey665174f2018-06-19 15:03:05 +02001295 for (size_t i = 0; i < cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 11:24:55 -07001296 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1297 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001298 EXPECT_EQ(ext1.uri, ext2.uri);
1299 EXPECT_EQ(ext1.id, ext2.id);
jbauch5869f502017-06-29 12:31:36 -07001300 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001301 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001302 }
1303
zstein4b2e0822017-02-17 19:48:38 -08001304 void CompareDataContentDescription(const DataContentDescription* dcd1,
1305 const DataContentDescription* dcd2) {
1306 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
1307 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
1308 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001309
1310 void CompareSessionDescription(const SessionDescription& desc1,
1311 const SessionDescription& desc2) {
1312 // Compare content descriptions.
1313 if (desc1.contents().size() != desc2.contents().size()) {
1314 ADD_FAILURE();
1315 return;
1316 }
Yves Gerey665174f2018-06-19 15:03:05 +02001317 for (size_t i = 0; i < desc1.contents().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001318 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1319 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-12 18:37:36 -08001320 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001321 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-12 18:37:36 -08001322 EXPECT_EQ(c1.type, c2.type);
1323 EXPECT_EQ(c1.rejected, c2.rejected);
1324 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001325
1326 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1327 if (IsAudioContent(&c1)) {
1328 const AudioContentDescription* acd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001329 c1.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001330 const AudioContentDescription* acd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001331 c2.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001332 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1333 }
1334
1335 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1336 if (IsVideoContent(&c1)) {
1337 const VideoContentDescription* vcd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001338 c1.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001339 const VideoContentDescription* vcd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001340 c2.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001341 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1342 }
1343
1344 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
1345 if (IsDataContent(&c1)) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001346 const DataContentDescription* dcd1 = c1.media_description()->as_data();
1347 const DataContentDescription* dcd2 = c2.media_description()->as_data();
zstein4b2e0822017-02-17 19:48:38 -08001348 CompareDataContentDescription(dcd1, dcd2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001349 }
1350 }
1351
1352 // group
1353 const cricket::ContentGroups groups1 = desc1.groups();
1354 const cricket::ContentGroups groups2 = desc2.groups();
1355 EXPECT_EQ(groups1.size(), groups1.size());
1356 if (groups1.size() != groups2.size()) {
1357 ADD_FAILURE();
1358 return;
1359 }
1360 for (size_t i = 0; i < groups1.size(); ++i) {
1361 const cricket::ContentGroup group1 = groups1.at(i);
1362 const cricket::ContentGroup group2 = groups2.at(i);
1363 EXPECT_EQ(group1.semantics(), group2.semantics());
1364 const cricket::ContentNames names1 = group1.content_names();
1365 const cricket::ContentNames names2 = group2.content_names();
1366 EXPECT_EQ(names1.size(), names2.size());
1367 if (names1.size() != names2.size()) {
1368 ADD_FAILURE();
1369 return;
1370 }
1371 cricket::ContentNames::const_iterator iter1 = names1.begin();
1372 cricket::ContentNames::const_iterator iter2 = names2.begin();
1373 while (iter1 != names1.end()) {
1374 EXPECT_EQ(*iter1++, *iter2++);
1375 }
1376 }
1377
1378 // transport info
1379 const cricket::TransportInfos transports1 = desc1.transport_infos();
1380 const cricket::TransportInfos transports2 = desc2.transport_infos();
1381 EXPECT_EQ(transports1.size(), transports2.size());
1382 if (transports1.size() != transports2.size()) {
1383 ADD_FAILURE();
1384 return;
1385 }
1386 for (size_t i = 0; i < transports1.size(); ++i) {
1387 const cricket::TransportInfo transport1 = transports1.at(i);
1388 const cricket::TransportInfo transport2 = transports2.at(i);
1389 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001390 EXPECT_EQ(transport1.description.ice_ufrag,
1391 transport2.description.ice_ufrag);
Yves Gerey665174f2018-06-19 15:03:05 +02001392 EXPECT_EQ(transport1.description.ice_pwd, transport2.description.ice_pwd);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07001393 EXPECT_EQ(transport1.description.ice_mode,
1394 transport2.description.ice_mode);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001395 if (transport1.description.identity_fingerprint) {
1396 EXPECT_EQ(*transport1.description.identity_fingerprint,
1397 *transport2.description.identity_fingerprint);
1398 } else {
1399 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1400 transport2.description.identity_fingerprint.get());
1401 }
1402 EXPECT_EQ(transport1.description.transport_options,
1403 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001404 }
deadbeefc80741f2015-10-22 13:14:45 -07001405
1406 // global attributes
1407 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
Johannes Kron9ac3c912018-10-12 10:54:26 +02001408 EXPECT_EQ(desc1.extmap_allow_mixed_headers(),
1409 desc2.extmap_allow_mixed_headers());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001410 }
1411
Yves Gerey665174f2018-06-19 15:03:05 +02001412 bool CompareSessionDescription(const JsepSessionDescription& desc1,
1413 const JsepSessionDescription& desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001414 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1415 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1416 CompareSessionDescription(*desc1.description(), *desc2.description());
1417 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1418 return false;
1419 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1420 const IceCandidateCollection* cc1 = desc1.candidates(i);
1421 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-12 18:37:36 -08001422 if (cc1->count() != cc2->count()) {
1423 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001424 return false;
deadbeef25ed4352016-12-12 18:37:36 -08001425 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001426 for (size_t j = 0; j < cc1->count(); ++j) {
1427 const IceCandidateInterface* c1 = cc1->at(j);
1428 const IceCandidateInterface* c2 = cc2->at(j);
1429 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1430 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1431 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1432 }
1433 }
1434 return true;
1435 }
1436
1437 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1438 // them with invalid keywords so that the parser will just ignore them.
1439 bool RemoveCandidateUfragPwd(std::string* sdp) {
1440 const char ice_ufrag[] = "a=ice-ufrag";
1441 const char ice_ufragx[] = "a=xice-ufrag";
1442 const char ice_pwd[] = "a=ice-pwd";
1443 const char ice_pwdx[] = "a=xice-pwd";
Yves Gerey665174f2018-06-19 15:03:05 +02001444 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag), ice_ufragx,
1445 strlen(ice_ufragx), sdp);
1446 rtc::replace_substrs(ice_pwd, strlen(ice_pwd), ice_pwdx, strlen(ice_pwdx),
1447 sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001448 return true;
1449 }
1450
1451 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
Yves Gerey665174f2018-06-19 15:03:05 +02001452 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc,
1453 int mline_index,
1454 const std::string& ufrag,
1455 const std::string& pwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001456 std::string content_name;
1457 if (mline_index == 0) {
1458 content_name = kAudioContentName;
1459 } else if (mline_index == 1) {
1460 content_name = kVideoContentName;
1461 } else {
nissec80e7412017-01-11 05:56:46 -08001462 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001463 }
Yves Gerey665174f2018-06-19 15:03:05 +02001464 TransportInfo transport_info(content_name,
1465 TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001466 SessionDescription* desc =
1467 const_cast<SessionDescription*>(jdesc->description());
1468 desc->RemoveTransportInfoByName(content_name);
1469 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
1470 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1471 const IceCandidateCollection* cc = jdesc_.candidates(i);
1472 for (size_t j = 0; j < cc->count(); ++j) {
1473 if (cc->at(j)->sdp_mline_index() == mline_index) {
Yves Gerey665174f2018-06-19 15:03:05 +02001474 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(ufrag);
1475 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001476 }
1477 }
1478 }
1479 return true;
1480 }
1481
1482 void AddIceOptions(const std::string& content_name,
1483 const std::vector<std::string>& transport_options) {
1484 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1485 cricket::TransportInfo transport_info =
1486 *(desc_.GetTransportInfoByName(content_name));
1487 desc_.RemoveTransportInfoByName(content_name);
1488 transport_info.description.transport_options = transport_options;
1489 desc_.AddTransportInfo(transport_info);
1490 }
1491
deadbeef3f7219b2015-12-28 15:17:14 -08001492 void SetIceUfragPwd(const std::string& content_name,
1493 const std::string& ice_ufrag,
1494 const std::string& ice_pwd) {
1495 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1496 cricket::TransportInfo transport_info =
1497 *(desc_.GetTransportInfoByName(content_name));
1498 desc_.RemoveTransportInfoByName(content_name);
1499 transport_info.description.ice_ufrag = ice_ufrag;
1500 transport_info.description.ice_pwd = ice_pwd;
1501 desc_.AddTransportInfo(transport_info);
1502 }
1503
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001504 void AddFingerprint() {
1505 desc_.RemoveTransportInfoByName(kAudioContentName);
1506 desc_.RemoveTransportInfoByName(kVideoContentName);
Steve Anton4905edb2018-10-15 19:27:44 -07001507 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, kIdentityDigest);
deadbeef46eed762016-01-28 13:24:37 -08001508 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1509 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001510 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1511 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001512 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1513 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1514 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001515 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1516 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001517 cricket::CONNECTIONROLE_NONE, &fingerprint))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001518 }
1519
jbauch5869f502017-06-29 12:31:36 -07001520 void AddExtmap(bool encrypted) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001521 audio_desc_ = audio_desc_->Copy();
1522 video_desc_ = video_desc_->Copy();
jbauch5869f502017-06-29 12:31:36 -07001523 audio_desc_->AddRtpHeaderExtension(
1524 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1525 video_desc_->AddRtpHeaderExtension(
1526 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001527 desc_.RemoveContentByName(kAudioContentName);
1528 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001529 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1530 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001531 }
1532
1533 void RemoveCryptos() {
1534 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1535 video_desc_->set_cryptos(std::vector<CryptoParams>());
1536 }
1537
Seth Hampson5897a6e2018-04-03 11:16:33 -07001538 // Removes everything in StreamParams from the session description that is
1539 // used for a=ssrc lines.
1540 void RemoveSsrcSignalingFromStreamParams() {
1541 for (cricket::ContentInfo content_info : jdesc_.description()->contents()) {
1542 // With Unified Plan there should be one StreamParams per m= section.
1543 StreamParams& stream =
1544 content_info.media_description()->mutable_streams()[0];
1545 stream.ssrcs.clear();
1546 stream.ssrc_groups.clear();
1547 stream.cname.clear();
1548 }
1549 }
1550
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001551 // Removes all a=ssrc lines from the SDP string, except for the
1552 // "a=ssrc:... cname:..." lines.
1553 void RemoveSsrcMsidLinesFromSdpString(std::string* sdp_string) {
1554 const char kAttributeSsrc[] = "a=ssrc";
1555 const char kAttributeCname[] = "cname";
1556 size_t ssrc_line_pos = sdp_string->find(kAttributeSsrc);
1557 while (ssrc_line_pos != std::string::npos) {
1558 size_t beg_line_pos = sdp_string->rfind('\n', ssrc_line_pos);
1559 size_t end_line_pos = sdp_string->find('\n', ssrc_line_pos);
1560 size_t cname_pos = sdp_string->find(kAttributeCname, ssrc_line_pos);
1561 if (cname_pos == std::string::npos || cname_pos > end_line_pos) {
1562 // Only erase a=ssrc lines that don't contain "cname".
1563 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1564 ssrc_line_pos = sdp_string->find(kAttributeSsrc, beg_line_pos);
1565 } else {
1566 // Skip the "a=ssrc:... cname" line and find the next "a=ssrc" line.
1567 ssrc_line_pos = sdp_string->find(kAttributeSsrc, end_line_pos);
1568 }
1569 }
1570 }
1571
Seth Hampson5897a6e2018-04-03 11:16:33 -07001572 // Removes all a=ssrc lines from the SDP string.
1573 void RemoveSsrcLinesFromSdpString(std::string* sdp_string) {
1574 const char kAttributeSsrc[] = "a=ssrc";
1575 while (sdp_string->find(kAttributeSsrc) != std::string::npos) {
1576 size_t pos_ssrc_attribute = sdp_string->find(kAttributeSsrc);
1577 size_t beg_line_pos = sdp_string->rfind('\n', pos_ssrc_attribute);
1578 size_t end_line_pos = sdp_string->find('\n', pos_ssrc_attribute);
1579 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1580 }
1581 }
1582
Steve Anton4e70a722017-11-28 14:57:10 -08001583 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001584 audio_desc_->set_direction(direction);
1585 video_desc_->set_direction(direction);
1586 std::string new_sdp = kSdpFullString;
1587 ReplaceDirection(direction, &new_sdp);
1588
Yves Gerey665174f2018-06-19 15:03:05 +02001589 if (!jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001590 jdesc_.session_version())) {
1591 return false;
1592 }
Steve Antone831b8c2018-02-01 12:22:16 -08001593 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001594 EXPECT_EQ(new_sdp, message);
1595 return true;
1596 }
1597
1598 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001599 audio_desc_ = audio_desc_->Copy();
1600 video_desc_ = video_desc_->Copy();
zhihuang38989e52017-03-21 11:04:53 -07001601
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001602 desc_.RemoveContentByName(kAudioContentName);
1603 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001604 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001605 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001606 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001607 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001608 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1609 audio_rejected ? "" : kPwdVoice);
1610 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1611 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001612
1613 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001614 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1615
Steve Antona3a92c22017-12-07 10:27:41 -08001616 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001617 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001618 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001619 EXPECT_EQ(new_sdp, message);
1620 return true;
1621 }
1622
zstein4b2e0822017-02-17 19:48:38 -08001623 void AddSctpDataChannel(bool use_sctpmap) {
kwibergd1fe2812016-04-27 06:47:29 -07001624 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001625 data_desc_ = data.get();
zstein4b2e0822017-02-17 19:48:38 -08001626 data_desc_->set_use_sctpmap(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001627 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
solenberg9fa49752016-10-08 13:02:44 -07001628 DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07001629 cricket::kGoogleSctpDataCodecName);
wu@webrtc.org78187522013-10-07 23:32:02 +00001630 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1631 data_desc_->AddCodec(codec);
Steve Anton5adfafd2017-12-20 16:34:00 -08001632 desc_.AddContent(kDataContentName, MediaProtocolType::kSctp,
1633 data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001634 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1635 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001636 }
1637
1638 void AddRtpDataChannel() {
kwibergd1fe2812016-04-27 06:47:29 -07001639 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001640 data_desc_ = data.get();
1641
deadbeef67cf2c12016-04-13 10:07:16 -07001642 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001643 StreamParams data_stream;
1644 data_stream.id = kDataChannelMsid;
1645 data_stream.cname = kDataChannelCname;
Seth Hampson845e8782018-03-02 11:34:10 -08001646 data_stream.set_stream_ids({kDataChannelLabel});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001647 data_stream.ssrcs.push_back(kDataChannelSsrc);
1648 data_desc_->AddStream(data_stream);
Yves Gerey665174f2018-06-19 15:03:05 +02001649 data_desc_->AddCrypto(
1650 CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
1651 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001652 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
Steve Anton5adfafd2017-12-20 16:34:00 -08001653 desc_.AddContent(kDataContentName, MediaProtocolType::kRtp, data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001654 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1655 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001656 }
1657
Steve Anton4e70a722017-11-28 14:57:10 -08001658 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001659 std::string new_sdp = kSdpFullString;
1660 ReplaceDirection(direction, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001661 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001662
1663 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1664
1665 audio_desc_->set_direction(direction);
1666 video_desc_->set_direction(direction);
Yves Gerey665174f2018-06-19 15:03:05 +02001667 if (!jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001668 jdesc_.session_version())) {
1669 return false;
1670 }
1671 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1672 return true;
1673 }
1674
1675 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001676 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001677 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001678 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001679 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001680
Steve Antonb1c1de12017-12-21 15:14:30 -08001681 audio_desc_ = audio_desc_->Copy();
1682 video_desc_ = video_desc_->Copy();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001683 desc_.RemoveContentByName(kAudioContentName);
1684 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001685 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001686 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001687 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001688 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001689 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1690 audio_rejected ? "" : kPwdVoice);
1691 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1692 video_rejected ? "" : kPwdVideo);
Steve Antona3a92c22017-12-07 10:27:41 -08001693 JsepSessionDescription jdesc_no_candidates(kDummyType);
deadbeef3f7219b2015-12-28 15:17:14 -08001694 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1695 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001696 return false;
1697 }
deadbeef3f7219b2015-12-28 15:17:14 -08001698 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001699 return true;
1700 }
1701
Yves Gerey665174f2018-06-19 15:03:05 +02001702 void TestDeserializeExtmap(bool session_level,
1703 bool media_level,
1704 bool encrypted) {
jbauch5869f502017-06-29 12:31:36 -07001705 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08001706 JsepSessionDescription new_jdesc(SdpType::kOffer);
Yves Gerey665174f2018-06-19 15:03:05 +02001707 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001708 jdesc_.session_version()));
Steve Antona3a92c22017-12-07 10:27:41 -08001709 JsepSessionDescription jdesc_with_extmap(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001710 std::string sdp_with_extmap = kSdpString;
1711 if (session_level) {
jbauch5869f502017-06-29 12:31:36 -07001712 InjectAfter(kSessionTime,
1713 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1714 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001715 &sdp_with_extmap);
1716 }
1717 if (media_level) {
jbauch5869f502017-06-29 12:31:36 -07001718 InjectAfter(kAttributeIcePwdVoice,
1719 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1720 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001721 &sdp_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07001722 InjectAfter(kAttributeIcePwdVideo,
1723 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1724 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001725 &sdp_with_extmap);
1726 }
1727 // The extmap can't be present at the same time in both session level and
1728 // media level.
1729 if (session_level && media_level) {
1730 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02001731 EXPECT_FALSE(
1732 webrtc::SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001733 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1734 } else {
1735 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1736 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1737 }
1738 }
1739
1740 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
Yves Gerey665174f2018-06-19 15:03:05 +02001741 const std::string& name,
1742 int expected_value) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001743 cricket::CodecParameterMap::const_iterator found = params.find(name);
1744 ASSERT_TRUE(found != params.end());
Jonas Olsson6b1985d2018-07-05 11:59:48 +02001745 EXPECT_EQ(found->second, rtc::ToString(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001746 }
1747
1748 void TestDeserializeCodecParams(const CodecParams& params,
1749 JsepSessionDescription* jdesc_output) {
1750 std::string sdp =
1751 "v=0\r\n"
1752 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1753 "s=-\r\n"
1754 "t=0 0\r\n"
1755 // Include semantics for WebRTC Media Streams since it is supported by
1756 // this parser, and will be added to the SDP when serializing a session
1757 // description.
1758 "a=msid-semantic: WMS\r\n"
1759 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001760 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761 // Pltype 111 listed before 103 and 104 in the map.
1762 "a=rtpmap:111 opus/48000/2\r\n"
1763 // Pltype 103 listed before 104.
1764 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001765 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001766 "a=fmtp:111 0-15,66,70\r\n"
1767 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001768 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001769 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001770 << "; sprop-stereo=" << params.sprop_stereo
1771 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001772 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001773 << "a=ptime:" << params.ptime << "\r\n"
1774 << "a=maxptime:" << params.max_ptime << "\r\n";
1775 sdp += os.str();
1776
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001777 os.clear();
1778 os.str("");
1779 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001780 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001781 << "a=rtpmap:99 VP8/90000\r\n"
1782 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001783 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001784 sdp += os.str();
1785
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001786 // Deserialize
1787 SdpParseError error;
1788 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1789
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001790 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001791 GetFirstAudioContentDescription(jdesc_output->description());
1792 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001793 ASSERT_FALSE(acd->codecs().empty());
1794 cricket::AudioCodec opus = acd->codecs()[0];
1795 EXPECT_EQ("opus", opus.name);
1796 EXPECT_EQ(111, opus.id);
1797 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1798 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1799 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1800 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001801 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1802 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001803 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1804 cricket::AudioCodec codec = acd->codecs()[i];
1805 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1806 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001807 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001808
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001809 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001810 GetFirstVideoContentDescription(jdesc_output->description());
1811 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001812 ASSERT_FALSE(vcd->codecs().empty());
1813 cricket::VideoCodec vp8 = vcd->codecs()[0];
1814 EXPECT_EQ("VP8", vp8.name);
1815 EXPECT_EQ(99, vp8.id);
1816 cricket::VideoCodec rtx = vcd->codecs()[1];
1817 EXPECT_EQ("RTX", rtx.name);
1818 EXPECT_EQ(95, rtx.id);
1819 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001820 }
1821
1822 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1823 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001824 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001825 "v=0\r\n"
1826 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1827 "s=-\r\n"
1828 "t=0 0\r\n"
1829 // Include semantics for WebRTC Media Streams since it is supported by
1830 // this parser, and will be added to the SDP when serializing a session
1831 // description.
1832 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001833 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001834 "a=rtpmap:111 opus/48000/2\r\n";
1835 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001836 "m=video 3457 RTP/SAVPF 101\r\n"
1837 "a=rtpmap:101 VP8/90000\r\n"
1838 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001839 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001840 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001841 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001842 os << sdp_session_and_audio;
Yves Gerey665174f2018-06-19 15:03:05 +02001843 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001844 os << sdp_video;
Yves Gerey665174f2018-06-19 15:03:05 +02001845 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001846 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001847 // Deserialize
1848 SdpParseError error;
1849 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001850 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001851 GetFirstAudioContentDescription(jdesc_output->description());
1852 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001853 ASSERT_FALSE(acd->codecs().empty());
1854 cricket::AudioCodec opus = acd->codecs()[0];
1855 EXPECT_EQ(111, opus.id);
Yves Gerey665174f2018-06-19 15:03:05 +02001856 EXPECT_TRUE(opus.HasFeedbackParam(cricket::FeedbackParam(
1857 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001858
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001859 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001860 GetFirstVideoContentDescription(jdesc_output->description());
1861 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001862 ASSERT_FALSE(vcd->codecs().empty());
1863 cricket::VideoCodec vp8 = vcd->codecs()[0];
1864 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1865 vp8.name.c_str());
1866 EXPECT_EQ(101, vp8.id);
Yves Gerey665174f2018-06-19 15:03:05 +02001867 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1868 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
1869 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1870 cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli)));
1871 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1872 cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty)));
1873 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1874 cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001875 }
1876
1877 // Two SDP messages can mean the same thing but be different strings, e.g.
1878 // some of the lines can be serialized in different order.
1879 // However, a deserialized description can be compared field by field and has
1880 // no order. If deserializer has already been tested, serializing then
1881 // deserializing and comparing JsepSessionDescription will test
1882 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 12:22:16 -08001883 void TestSerialize(const JsepSessionDescription& jdesc) {
1884 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 10:27:41 -08001885 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001886 SdpParseError error;
1887 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1888 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1889 }
1890
zhihuang38989e52017-03-21 11:04:53 -07001891 // Calling 'Initialize' with a copy of the inner SessionDescription will
1892 // create a copy of the JsepSessionDescription without candidates. The
1893 // 'connection address' field, previously set from the candidates, must also
1894 // be reset.
1895 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
1896 rtc::SocketAddress audio_addr("0.0.0.0", 9);
1897 rtc::SocketAddress video_addr("0.0.0.0", 9);
1898 audio_desc_->set_connection_address(audio_addr);
1899 video_desc_->set_connection_address(video_addr);
1900 ASSERT_TRUE(jdesc->Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1901 }
1902
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001903 protected:
1904 SessionDescription desc_;
1905 AudioContentDescription* audio_desc_;
1906 VideoContentDescription* video_desc_;
1907 DataContentDescription* data_desc_;
1908 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07001909 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001910 JsepSessionDescription jdesc_;
1911};
1912
1913void TestMismatch(const std::string& string1, const std::string& string2) {
1914 int position = 0;
1915 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1916 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001917 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001918 break;
1919 }
1920 }
1921 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1922 << " character\n"
1923 << " 1: " << string1.substr(position, 20) << "\n"
1924 << " 2: " << string2.substr(position, 20) << "\n";
1925}
1926
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001927TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1928 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 12:22:16 -08001929 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001930 TestMismatch(std::string(kSdpFullString), message);
1931}
1932
1933TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 10:27:41 -08001934 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 12:22:16 -08001935 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001936}
1937
1938// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1939// the case in a DTLS offer.
1940TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1941 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08001942 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001943 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08001944 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001945
1946 std::string sdp_with_fingerprint = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02001947 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1948 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001949
1950 EXPECT_EQ(sdp_with_fingerprint, message);
1951}
1952
1953// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1954// be the case in a DTLS answer.
1955TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1956 AddFingerprint();
1957 RemoveCryptos();
Steve Antona3a92c22017-12-07 10:27:41 -08001958 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001959 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08001960 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001961
1962 std::string sdp_with_fingerprint = kSdpString;
1963 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1964 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
Yves Gerey665174f2018-06-19 15:03:05 +02001965 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1966 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001967
1968 EXPECT_EQ(sdp_with_fingerprint, message);
1969}
1970
1971TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1972 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08001973 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001974 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001975 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001976 EXPECT_EQ(std::string(kSdpString), message);
1977}
1978
1979TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1980 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1981 group.AddContentName(kAudioContentName);
1982 group.AddContentName(kVideoContentName);
1983 desc_.AddGroup(group);
Yves Gerey665174f2018-06-19 15:03:05 +02001984 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001985 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08001986 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001987 std::string sdp_with_bundle = kSdpFullString;
1988 InjectAfter(kSessionTime,
1989 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1990 &sdp_with_bundle);
1991 EXPECT_EQ(sdp_with_bundle, message);
1992}
1993
1994TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001995 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001996 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08001997 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001998 acd->set_bandwidth(50 * 1000);
Yves Gerey665174f2018-06-19 15:03:05 +02001999 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002000 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002001 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002002 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002003 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002004 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002005 InjectAfter("c=IN IP4 74.125.127.126\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002006 &sdp_with_bandwidth);
2007 EXPECT_EQ(sdp_with_bandwidth, message);
2008}
2009
2010TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
2011 std::vector<std::string> transport_options;
2012 transport_options.push_back(kIceOption1);
2013 transport_options.push_back(kIceOption3);
2014 AddIceOptions(kAudioContentName, transport_options);
2015 transport_options.clear();
2016 transport_options.push_back(kIceOption2);
2017 transport_options.push_back(kIceOption3);
2018 AddIceOptions(kVideoContentName, transport_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002019 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002020 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002021 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002022 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002023 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002024 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002025 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002026 &sdp_with_ice_options);
2027 EXPECT_EQ(sdp_with_ice_options, message);
2028}
2029
2030TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002031 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002032}
2033
2034TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002035 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002036}
2037
2038TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002039 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002040}
2041
2042TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2043 EXPECT_TRUE(TestSerializeRejected(true, false));
2044}
2045
2046TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2047 EXPECT_TRUE(TestSerializeRejected(false, true));
2048}
2049
2050TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2051 EXPECT_TRUE(TestSerializeRejected(true, true));
2052}
2053
2054TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
2055 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002056 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002057
zhihuang38989e52017-03-21 11:04:53 -07002058 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002059 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002060
2061 std::string expected_sdp = kSdpString;
2062 expected_sdp.append(kSdpRtpDataChannelString);
2063 EXPECT_EQ(expected_sdp, message);
2064}
2065
2066TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08002067 bool use_sctpmap = true;
2068 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002069 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002070
zhihuang38989e52017-03-21 11:04:53 -07002071 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002072 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002073
2074 std::string expected_sdp = kSdpString;
2075 expected_sdp.append(kSdpSctpDataChannelString);
2076 EXPECT_EQ(message, expected_sdp);
2077}
2078
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002079TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08002080 bool use_sctpmap = true;
2081 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002082 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002083 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antonb1c1de12017-12-21 15:14:30 -08002084 DataContentDescription* dcdesc =
2085 jsep_desc.description()
2086 ->GetContentDescriptionByName(kDataContentName)
2087 ->as_data();
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002088
2089 const int kNewPort = 1234;
solenberg9fa49752016-10-08 13:02:44 -07002090 cricket::DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07002091 cricket::kGoogleSctpDataCodecName);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002092 codec.SetParam(cricket::kCodecParamPort, kNewPort);
2093 dcdesc->AddOrReplaceCodec(codec);
2094
Steve Antone831b8c2018-02-01 12:22:16 -08002095 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002096
2097 std::string expected_sdp = kSdpString;
2098 expected_sdp.append(kSdpSctpDataChannelString);
2099
2100 char default_portstr[16];
2101 char new_portstr[16];
Niels Mölleraba06332018-10-16 15:14:15 +02002102 snprintf(default_portstr, sizeof(default_portstr), "%d", kDefaultSctpPort);
2103 snprintf(new_portstr, sizeof(new_portstr), "%d", kNewPort);
Yves Gerey665174f2018-06-19 15:03:05 +02002104 rtc::replace_substrs(default_portstr, strlen(default_portstr), new_portstr,
2105 strlen(new_portstr), &expected_sdp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002106
2107 EXPECT_EQ(expected_sdp, message);
2108}
2109
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002110TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002111 JsepSessionDescription jsep_desc(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002112 AddRtpDataChannel();
Yves Gerey665174f2018-06-19 15:03:05 +02002113 data_desc_->set_bandwidth(100 * 1000);
zhihuang38989e52017-03-21 11:04:53 -07002114 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002115 std::string message = webrtc::SdpSerialize(jsep_desc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002116
2117 std::string expected_sdp = kSdpString;
2118 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002119 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00002120 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02002121 "b=AS:100\r\n", &expected_sdp);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002122 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002123}
2124
Johannes Kron0854eb62018-10-10 22:33:20 +02002125TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9ac3c912018-10-12 10:54:26 +02002126 jdesc_.description()->set_extmap_allow_mixed_headers(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002127 TestSerialize(jdesc_);
2128}
2129
2130TEST_F(WebRtcSdpTest, SerializeMediaContentDescriptionWithExtmapAllowMixed) {
2131 cricket::MediaContentDescription* video_desc =
2132 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2133 ASSERT_TRUE(video_desc);
2134 cricket::MediaContentDescription* audio_desc =
2135 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2136 ASSERT_TRUE(audio_desc);
Johannes Kron9ac3c912018-10-12 10:54:26 +02002137 video_desc->set_extmap_allow_mixed_headers(
Johannes Kron0854eb62018-10-10 22:33:20 +02002138 cricket::MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 10:54:26 +02002139 audio_desc->set_extmap_allow_mixed_headers(
Johannes Kron0854eb62018-10-10 22:33:20 +02002140 cricket::MediaContentDescription::kMedia);
2141 TestSerialize(jdesc_);
2142}
2143
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002144TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002145 bool encrypted = false;
2146 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002147 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002148 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 12:22:16 -08002149 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002150
2151 std::string sdp_with_extmap = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002152 InjectAfter("a=mid:audio_content_name\r\n", kExtmap, &sdp_with_extmap);
2153 InjectAfter("a=mid:video_content_name\r\n", kExtmap, &sdp_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002154
2155 EXPECT_EQ(sdp_with_extmap, message);
2156}
2157
jbauch5869f502017-06-29 12:31:36 -07002158TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2159 bool encrypted = true;
2160 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002161 JsepSessionDescription desc_with_extmap(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002162 ASSERT_TRUE(
2163 desc_with_extmap.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 12:22:16 -08002164 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07002165}
2166
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002167TEST_F(WebRtcSdpTest, SerializeCandidates) {
2168 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002169 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002170
2171 Candidate candidate_with_ufrag(candidates_.front());
2172 candidate_with_ufrag.set_username("ABC");
2173 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2174 candidate_with_ufrag));
2175 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2176 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002177
2178 Candidate candidate_with_network_info(candidates_.front());
2179 candidate_with_network_info.set_network_id(1);
2180 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2181 candidate_with_network_info));
2182 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2183 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2184 candidate_with_network_info.set_network_cost(999);
2185 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2186 candidate_with_network_info));
2187 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2188 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2189 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002190}
2191
Zach Steinb336c272018-08-09 01:16:13 -07002192TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) {
2193 rtc::SocketAddress address("a.test", 1234);
2194 cricket::Candidate candidate(
2195 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
2196 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
2197 JsepIceCandidate jcandidate(std::string("audio_content_name"), 0, candidate);
2198 std::string message = webrtc::SdpSerializeCandidate(jcandidate);
2199 EXPECT_EQ(std::string(kRawHostnameCandidate), message);
2200}
2201
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002202// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2203// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002204TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002205 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002206 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2207 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2208 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002209 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002210 std::unique_ptr<IceCandidateInterface> jcandidate(
2211 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002212
2213 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2214 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2215}
2216
htaa6b99442016-04-12 10:29:17 -07002217TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002218 cricket::VideoCodec h264_codec("H264");
2219 h264_codec.SetParam("profile-level-id", "42e01f");
2220 h264_codec.SetParam("level-asymmetry-allowed", "1");
2221 h264_codec.SetParam("packetization-mode", "1");
2222 video_desc_->AddCodec(h264_codec);
2223
htaa6b99442016-04-12 10:29:17 -07002224 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
2225
Steve Antone831b8c2018-02-01 12:22:16 -08002226 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 10:29:17 -07002227 size_t after_pt = message.find(" H264/90000");
2228 ASSERT_NE(after_pt, std::string::npos);
2229 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2230 ASSERT_NE(before_pt, std::string::npos);
2231 before_pt += strlen("a=rtpmap:");
2232 std::string pt = message.substr(before_pt, after_pt - before_pt);
2233 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2234 std::string to_find = "a=fmtp:" + pt + " ";
2235 size_t fmtp_pos = message.find(to_find);
2236 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
2237 size_t fmtp_endpos = message.find("\n", fmtp_pos);
2238 ASSERT_NE(std::string::npos, fmtp_endpos);
2239 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2240 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2241 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2242 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002243 // Check that there are no spaces after semicolons.
2244 // https://bugs.webrtc.org/5793
2245 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002246}
2247
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002248TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 10:27:41 -08002249 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002250 // Deserialize
2251 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2252 // Verify
2253 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2254}
2255
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002256TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 10:27:41 -08002257 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002258 const char kSdpWithoutMline[] =
Yves Gerey665174f2018-06-19 15:03:05 +02002259 "v=0\r\n"
2260 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2261 "s=-\r\n"
2262 "t=0 0\r\n"
2263 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002264 // Deserialize
2265 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2266 EXPECT_EQ(0u, jdesc.description()->contents().size());
2267}
2268
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002269TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 10:27:41 -08002270 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002271 std::string sdp_without_carriage_return = kSdpFullString;
2272 Replace("\r\n", "\n", &sdp_without_carriage_return);
2273 // Deserialize
2274 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2275 // Verify
2276 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2277}
2278
2279TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2280 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002281 JsepSessionDescription jdesc_no_candidates(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002282 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
2283 kSessionVersion));
Steve Antona3a92c22017-12-07 10:27:41 -08002284 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002285 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2286 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2287}
2288
2289TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2290 static const char kSdpNoRtpmapString[] =
2291 "v=0\r\n"
2292 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2293 "s=-\r\n"
2294 "t=0 0\r\n"
2295 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2296 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002297 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002298 // The rtpmap line for static payload codec is optional.
2299 "a=rtpmap:18 G729/16000\r\n"
2300 "a=rtpmap:103 ISAC/16000\r\n";
2301
Steve Antona3a92c22017-12-07 10:27:41 -08002302 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002303 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2304 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002305 jdesc.description()
2306 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2307 ->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002308 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002309 // The codecs in the AudioContentDescription should be in the same order as
2310 // the payload types (<fmt>s) on the m= line.
2311 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2312 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002313 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002314 EXPECT_EQ(ref_codecs, audio->codecs());
2315}
2316
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002317TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2318 static const char kSdpNoRtpmapString[] =
2319 "v=0\r\n"
2320 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2321 "s=-\r\n"
2322 "t=0 0\r\n"
2323 "m=audio 49232 RTP/AVP 18 103\r\n"
2324 "a=fmtp:18 annexb=yes\r\n"
2325 "a=rtpmap:103 ISAC/16000\r\n";
2326
Steve Antona3a92c22017-12-07 10:27:41 -08002327 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002328 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2329 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002330 jdesc.description()
2331 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2332 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002333
2334 cricket::AudioCodec g729 = audio->codecs()[0];
2335 EXPECT_EQ("G729", g729.name);
2336 EXPECT_EQ(8000, g729.clockrate);
2337 EXPECT_EQ(18, g729.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002338 cricket::CodecParameterMap::iterator found = g729.params.find("annexb");
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002339 ASSERT_TRUE(found != g729.params.end());
2340 EXPECT_EQ(found->second, "yes");
2341
2342 cricket::AudioCodec isac = audio->codecs()[1];
2343 EXPECT_EQ("ISAC", isac.name);
2344 EXPECT_EQ(103, isac.id);
2345 EXPECT_EQ(16000, isac.clockrate);
2346}
2347
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002348// Ensure that we can deserialize SDP with a=fingerprint properly.
2349TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2350 // Add a DTLS a=fingerprint attribute to our session description.
2351 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002352 JsepSessionDescription new_jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002353 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002354 jdesc_.session_version()));
2355
Steve Antona3a92c22017-12-07 10:27:41 -08002356 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002357 std::string sdp_with_fingerprint = kSdpString;
2358 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2359 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2360 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2361 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2362}
2363
2364TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 10:27:41 -08002365 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002366 std::string sdp_with_bundle = kSdpFullString;
2367 InjectAfter(kSessionTime,
2368 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2369 &sdp_with_bundle);
2370 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2371 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2372 group.AddContentName(kAudioContentName);
2373 group.AddContentName(kVideoContentName);
2374 desc_.AddGroup(group);
Yves Gerey665174f2018-06-19 15:03:05 +02002375 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002376 jdesc_.session_version()));
2377 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2378}
2379
2380TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002381 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002382 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002383 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002384 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002385 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002386 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002387 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 15:14:30 -08002388 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002389 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002390 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002391 acd->set_bandwidth(50 * 1000);
Yves Gerey665174f2018-06-19 15:03:05 +02002392 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002393 jdesc_.session_version()));
2394 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2395}
2396
2397TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 10:27:41 -08002398 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002399 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002400 InjectAfter(kSessionTime, "a=ice-options:iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002401 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002402 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002403 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002404 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002405 &sdp_with_ice_options);
2406 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2407 std::vector<std::string> transport_options;
2408 transport_options.push_back(kIceOption3);
2409 transport_options.push_back(kIceOption1);
2410 AddIceOptions(kAudioContentName, transport_options);
2411 transport_options.clear();
2412 transport_options.push_back(kIceOption3);
2413 transport_options.push_back(kIceOption2);
2414 AddIceOptions(kVideoContentName, transport_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002415 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002416 jdesc_.session_version()));
2417 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2418}
2419
2420TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2421 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 10:27:41 -08002422 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002423 std::string sdp_with_ufrag_pwd = kSdpFullString;
2424 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2425 // Add session level ufrag and pwd
2426 InjectAfter(kSessionTime,
Yves Gerey665174f2018-06-19 15:03:05 +02002427 "a=ice-pwd:session+level+icepwd\r\n"
2428 "a=ice-ufrag:session+level+iceufrag\r\n",
2429 &sdp_with_ufrag_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002430 // Add media level ufrag and pwd for audio
Yves Gerey665174f2018-06-19 15:03:05 +02002431 InjectAfter(
2432 "a=mid:audio_content_name\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002433 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2434 &sdp_with_ufrag_pwd);
2435 // Update the candidate ufrag and pwd to the expected ones.
Yves Gerey665174f2018-06-19 15:03:05 +02002436 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, "media+level+iceufrag",
2437 "media+level+icepwd"));
2438 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, "session+level+iceufrag",
2439 "session+level+icepwd"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002440 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2441 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2442}
2443
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002444TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002445 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002446}
2447
2448TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002449 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002450}
2451
2452TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002453 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002454}
2455
2456TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2457 EXPECT_TRUE(TestDeserializeRejected(true, false));
2458}
2459
2460TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2461 EXPECT_TRUE(TestDeserializeRejected(false, true));
2462}
2463
2464TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2465 EXPECT_TRUE(TestDeserializeRejected(true, true));
2466}
2467
2468// Tests that we can still handle the sdp uses mslabel and label instead of
2469// msid for backward compatibility.
2470TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07002471 jdesc_.description()->set_msid_supported(false);
Steve Antona3a92c22017-12-07 10:27:41 -08002472 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002473 std::string sdp_without_msid = kSdpFullString;
2474 Replace("msid", "xmsid", &sdp_without_msid);
2475 // Deserialize
2476 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2477 // Verify
2478 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2479}
2480
Johannes Kron0854eb62018-10-10 22:33:20 +02002481TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9ac3c912018-10-12 10:54:26 +02002482 jdesc_.description()->set_extmap_allow_mixed_headers(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002483 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2484 InjectAfter("t=0 0\r\n", kExtmapAllowMixed, &sdp_with_extmap_allow_mixed);
2485 // Deserialize
2486 JsepSessionDescription jdesc_deserialized(kDummyType);
2487 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2488 // Verify
2489 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2490}
2491
2492TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutExtmapAllowMixed) {
Johannes Kron9ac3c912018-10-12 10:54:26 +02002493 jdesc_.description()->set_extmap_allow_mixed_headers(false);
Johannes Kron0854eb62018-10-10 22:33:20 +02002494 std::string sdp_without_extmap_allow_mixed = kSdpFullString;
2495 // Deserialize
2496 JsepSessionDescription jdesc_deserialized(kDummyType);
2497 EXPECT_TRUE(
2498 SdpDeserialize(sdp_without_extmap_allow_mixed, &jdesc_deserialized));
2499 // Verify
2500 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2501}
2502
2503TEST_F(WebRtcSdpTest, DeserializeMediaContentDescriptionWithExtmapAllowMixed) {
2504 cricket::MediaContentDescription* video_desc =
2505 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2506 ASSERT_TRUE(video_desc);
2507 cricket::MediaContentDescription* audio_desc =
2508 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2509 ASSERT_TRUE(audio_desc);
Johannes Kron9ac3c912018-10-12 10:54:26 +02002510 video_desc->set_extmap_allow_mixed_headers(
Johannes Kron0854eb62018-10-10 22:33:20 +02002511 cricket::MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 10:54:26 +02002512 audio_desc->set_extmap_allow_mixed_headers(
Johannes Kron0854eb62018-10-10 22:33:20 +02002513 cricket::MediaContentDescription::kMedia);
2514
2515 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2516 InjectAfter("a=mid:audio_content_name\r\n", kExtmapAllowMixed,
2517 &sdp_with_extmap_allow_mixed);
2518 InjectAfter("a=mid:video_content_name\r\n", kExtmapAllowMixed,
2519 &sdp_with_extmap_allow_mixed);
2520
2521 // Deserialize
2522 JsepSessionDescription jdesc_deserialized(kDummyType);
2523 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2524 // Verify
2525 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2526}
2527
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002528TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2529 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2530
2531 std::string sdp = kSdpOneCandidate;
2532 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2533 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2534 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2535 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002536 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002537
2538 // Candidate line without generation extension.
2539 sdp = kSdpOneCandidate;
2540 Replace(" generation 2", "", &sdp);
2541 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2542 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2543 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2544 Candidate expected = jcandidate_->candidate();
2545 expected.set_generation(0);
2546 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2547
honghaiza0c44ea2016-03-23 16:07:48 -07002548 // Candidate with network id and/or cost.
2549 sdp = kSdpOneCandidate;
2550 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2551 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2552 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2553 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2554 expected = jcandidate_->candidate();
2555 expected.set_network_id(2);
2556 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2557 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2558 // Add network cost
2559 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2560 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2561 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2562 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2563
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002564 sdp = kSdpTcpActiveCandidate;
2565 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2566 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002567 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002568 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2569 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2570 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002571 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2572 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
Yves Gerey665174f2018-06-19 15:03:05 +02002573 EXPECT_TRUE(
2574 jcandidate.candidate().IsEquivalent(jcandidate_template->candidate()));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002575 sdp = kSdpTcpPassiveCandidate;
2576 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2577 sdp = kSdpTcpSOCandidate;
2578 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002579}
2580
2581// This test verifies the deserialization of candidate-attribute
2582// as per RFC 5245. Candiate-attribute will be of the format
2583// candidate:<blah>. This format will be used when candidates
2584// are trickled.
2585TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2586 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2587
2588 std::string candidate_attribute = kRawCandidate;
2589 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2590 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2591 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2592 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2593 EXPECT_EQ(2u, jcandidate.candidate().generation());
2594
2595 // Candidate line without generation extension.
2596 candidate_attribute = kRawCandidate;
2597 Replace(" generation 2", "", &candidate_attribute);
2598 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2599 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2600 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2601 Candidate expected = jcandidate_->candidate();
2602 expected.set_generation(0);
2603 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2604
2605 // Candidate line without candidate:
2606 candidate_attribute = kRawCandidate;
2607 Replace("candidate:", "", &candidate_attribute);
2608 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2609
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002610 // Candidate line with IPV6 address.
2611 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
Zach Steinb336c272018-08-09 01:16:13 -07002612
2613 // Candidate line with hostname address.
2614 EXPECT_TRUE(SdpDeserializeCandidate(kRawHostnameCandidate, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002615}
2616
2617// This test verifies that the deserialization of an invalid candidate string
2618// fails.
2619TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
Yves Gerey665174f2018-06-19 15:03:05 +02002620 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002621
2622 std::string candidate_attribute = kRawCandidate;
2623 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002624 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002625
2626 candidate_attribute = kSdpOneCandidate;
2627 candidate_attribute.replace(0, 1, "x");
2628 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2629
2630 candidate_attribute = kRawCandidate;
2631 candidate_attribute.append("\r\n");
2632 candidate_attribute.append(kRawCandidate);
2633 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2634
2635 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002636}
2637
2638TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2639 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002640 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002641 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2642
2643 std::string sdp_with_data = kSdpString;
2644 sdp_with_data.append(kSdpRtpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002645 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002646
2647 // Deserialize
2648 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2649 // Verify
2650 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2651}
2652
2653TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002654 bool use_sctpmap = true;
2655 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002656 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002657 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2658
2659 std::string sdp_with_data = kSdpString;
2660 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002661 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002662
lally@webrtc.org36300852015-02-24 20:19:35 +00002663 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2664 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2665 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2666
2667 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002668 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2669 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002670 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2671 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2672
2673 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002674 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2675 kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002676 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2677 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2678}
2679
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002680TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002681 bool use_sctpmap = false;
2682 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002683 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002684 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2685
2686 std::string sdp_with_data = kSdpString;
2687 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002688 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002689
lally@webrtc.org36300852015-02-24 20:19:35 +00002690 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002691 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2692 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002693
lally@webrtc.org36300852015-02-24 20:19:35 +00002694 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002695 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2696 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002697 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2698 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002699
lally@webrtc.org36300852015-02-24 20:19:35 +00002700 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002701 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2702 kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002703 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2704 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2705}
2706
lally69f57602015-10-08 10:15:04 -07002707TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002708 bool use_sctpmap = false;
2709 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002710 JsepSessionDescription jdesc(kDummyType);
lally69f57602015-10-08 10:15:04 -07002711 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2712
2713 std::string sdp_with_data = kSdpString;
2714 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002715 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 10:15:04 -07002716
2717 // Verify with DTLS/SCTP.
2718 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2719 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2720
2721 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002722 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2723 kUdpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002724 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2725 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2726
2727 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002728 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2729 kTcpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002730 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2731 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2732}
2733
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002734// Test to check the behaviour if sctp-port is specified
2735// on the m= line and in a=sctp-port.
2736TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002737 bool use_sctpmap = true;
2738 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002739 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002740 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2741
2742 std::string sdp_with_data = kSdpString;
2743 // Append m= attributes
2744 sdp_with_data.append(kSdpSctpDataChannelString);
2745 // Append a=sctp-port attribute
2746 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 10:27:41 -08002747 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002748
2749 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2750}
2751
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002752// For crbug/344475.
2753TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2754 std::string sdp_with_data = kSdpString;
2755 sdp_with_data.append(kSdpSctpDataChannelString);
2756 // Remove the "\n" at the end.
2757 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 10:27:41 -08002758 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002759
2760 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2761 // No crash is a pass.
2762}
2763
Steve Anton36b29d12017-10-30 09:57:42 -07002764void MutateJsepSctpPort(JsepSessionDescription* jdesc,
zstein4b2e0822017-02-17 19:48:38 -08002765 const SessionDescription& desc) {
wu@webrtc.org78187522013-10-07 23:32:02 +00002766 // take our pre-built session description and change the SCTP port.
zstein4b2e0822017-02-17 19:48:38 -08002767 cricket::SessionDescription* mutant = desc.Copy();
Steve Antonb1c1de12017-12-21 15:14:30 -08002768 DataContentDescription* dcdesc =
2769 mutant->GetContentDescriptionByName(kDataContentName)->as_data();
wu@webrtc.org78187522013-10-07 23:32:02 +00002770 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002771 EXPECT_EQ(1U, codecs.size());
solenberg9fa49752016-10-08 13:02:44 -07002772 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002773 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002774 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002775
2776 // note: mutant's owned by jdesc now.
Steve Anton36b29d12017-10-30 09:57:42 -07002777 ASSERT_TRUE(jdesc->Initialize(mutant, kSessionId, kSessionVersion));
wu@webrtc.org78187522013-10-07 23:32:02 +00002778 mutant = NULL;
zstein4b2e0822017-02-17 19:48:38 -08002779}
2780
2781TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
2782 bool use_sctpmap = true;
2783 AddSctpDataChannel(use_sctpmap);
2784
2785 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 10:27:41 -08002786 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002787 MutateJsepSctpPort(&jdesc, desc_);
wu@webrtc.org78187522013-10-07 23:32:02 +00002788
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002789 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002790 std::string sdp_with_data = kSdpString;
2791 sdp_with_data.append(kSdpSctpDataChannelString);
zstein4b2e0822017-02-17 19:48:38 -08002792 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2793 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2794 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002795 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:02 +00002796
2797 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2798 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08002799}
2800
2801TEST_F(WebRtcSdpTest,
2802 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
2803 bool use_sctpmap = false;
2804 AddSctpDataChannel(use_sctpmap);
2805
Steve Antona3a92c22017-12-07 10:27:41 -08002806 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002807 MutateJsepSctpPort(&jdesc, desc_);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002808
2809 // We need to test the deserialized JsepSessionDescription from
2810 // kSdpSctpDataChannelStringWithSctpPort for
2811 // draft-ietf-mmusic-sctp-sdp-07
2812 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08002813 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002814 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
zstein4b2e0822017-02-17 19:48:38 -08002815 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2816 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2817 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002818 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002819
2820 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2821 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002822}
2823
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002824TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002825 // We want to test that deserializing data content limits bandwidth
2826 // settings (it should never be greater than the default).
2827 // This should prevent someone from using unlimited data bandwidth through
2828 // JS and "breaking the Internet".
2829 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002830 std::string sdp_with_bandwidth = kSdpString;
2831 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02002832 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002833 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002834 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002835
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002836 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2837}
2838
2839TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08002840 bool use_sctpmap = true;
2841 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002842 JsepSessionDescription jdesc(kDummyType);
Steve Antonb1c1de12017-12-21 15:14:30 -08002843 DataContentDescription* dcd = GetFirstDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002844 dcd->set_bandwidth(100 * 1000);
2845 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2846
2847 std::string sdp_with_bandwidth = kSdpString;
2848 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02002849 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002850 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002851 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002852
2853 // SCTP has congestion control, so we shouldn't limit the bandwidth
2854 // as we do for RTP.
2855 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002856 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2857}
2858
Yves Gerey665174f2018-06-19 15:03:05 +02002859class WebRtcSdpExtmapTest : public WebRtcSdpTest,
2860 public testing::WithParamInterface<bool> {};
jbauch5869f502017-06-29 12:31:36 -07002861
2862TEST_P(WebRtcSdpExtmapTest,
Yves Gerey665174f2018-06-19 15:03:05 +02002863 DeserializeSessionDescriptionWithSessionLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002864 bool encrypted = GetParam();
2865 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002866}
2867
Yves Gerey665174f2018-06-19 15:03:05 +02002868TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002869 bool encrypted = GetParam();
2870 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002871}
2872
Yves Gerey665174f2018-06-19 15:03:05 +02002873TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithInvalidExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002874 bool encrypted = GetParam();
2875 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002876}
2877
jbauch5869f502017-06-29 12:31:36 -07002878INSTANTIATE_TEST_CASE_P(Encrypted,
2879 WebRtcSdpExtmapTest,
2880 ::testing::Values(false, true));
2881
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002882TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 10:27:41 -08002883 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002884 std::string sdp = kSdpFullString;
2885 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2886 // Deserialize
2887 SdpParseError error;
2888 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-16 17:54:10 -08002889 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002890 EXPECT_EQ(lastline, error.line);
2891 EXPECT_EQ("Invalid SDP line.", error.description);
2892}
2893
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002894TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2895 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2896 std::string new_sdp = kSdpOneCandidate;
2897 Replace("udp", "unsupported_transport", &new_sdp);
2898 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2899 new_sdp = kSdpOneCandidate;
2900 Replace("udp", "uDP", &new_sdp);
2901 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2902 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2903 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2904 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2905}
2906
honghaiza54a0802015-12-16 18:37:23 -08002907TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002908 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08002909 EXPECT_TRUE(
2910 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002911 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2912 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2913 Candidate ref_candidate = jcandidate_->candidate();
2914 ref_candidate.set_username("user_rtp");
2915 ref_candidate.set_password("password_rtp");
2916 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2917}
2918
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002919TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08002920 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002921
2922 // Deserialize
2923 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2924
2925 // Verify
2926 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002927 jdesc.description()
2928 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2929 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002930 EXPECT_TRUE(audio->conference_mode());
2931
2932 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 15:14:30 -08002933 jdesc.description()
2934 ->GetContentDescriptionByName(cricket::CN_VIDEO)
2935 ->as_video();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002936 EXPECT_TRUE(video->conference_mode());
2937}
2938
deadbeefd45aea82017-09-16 01:24:29 -07002939TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08002940 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 01:24:29 -07002941
2942 // We tested deserialization already above, so just test that if we serialize
2943 // and deserialize the flag doesn't disappear.
2944 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 12:22:16 -08002945 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 01:24:29 -07002946 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
2947
2948 // Verify.
2949 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002950 jdesc.description()
2951 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2952 ->as_audio();
deadbeefd45aea82017-09-16 01:24:29 -07002953 EXPECT_TRUE(audio->conference_mode());
2954
2955 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 15:14:30 -08002956 jdesc.description()
2957 ->GetContentDescriptionByName(cricket::CN_VIDEO)
2958 ->as_video();
deadbeefd45aea82017-09-16 01:24:29 -07002959 EXPECT_TRUE(video->conference_mode());
2960}
2961
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002962TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2963 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002964 const char kSdpEmptyType[] = " =candidate";
2965 const char kSdpEqualAsPlus[] = "a+candidate";
2966 const char kSdpSpaceAfterEqual[] = "a= candidate";
2967 const char kSdpUpperType[] = "A=candidate";
2968 const char kSdpEmptyLine[] = "";
2969 const char kSdpMissingValue[] = "a=";
2970
Yves Gerey665174f2018-06-19 15:03:05 +02002971 const char kSdpBrokenFingerprint[] =
2972 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002973 "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 +02002974 const char kSdpExtraField[] =
2975 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002976 "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 +02002977 const char kSdpMissingSpace[] =
2978 "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002979 "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 +00002980 // MD5 is not allowed in fingerprints.
Yves Gerey665174f2018-06-19 15:03:05 +02002981 const char kSdpMd5[] =
2982 "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002983 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002984
2985 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002986 ExpectParseFailure("v=", kSdpDestroyer);
2987 ExpectParseFailure("o=", kSdpDestroyer);
2988 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002989 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002990 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002991
2992 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002993 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2994 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002995
2996 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002997 ExpectParseFailure("a=candidate", kSdpEmptyType);
2998 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2999 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
3000 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003001
3002 // Bogus fingerprint replacing a=sendrev. We selected this attribute
3003 // because it's orthogonal to what we are replacing and hence
3004 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003005 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
3006 ExpectParseFailure("a=sendrecv", kSdpExtraField);
3007 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
3008 ExpectParseFailure("a=sendrecv", kSdpMd5);
3009
3010 // Empty Line
3011 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
3012 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003013}
3014
3015TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
3016 // ssrc
3017 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08003018 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003019 // crypto
3020 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
3021 // rtpmap
3022 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
3023 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
3024 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
3025 // candidate
3026 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
3027 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
3028 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
3029 ExpectParseFailure("rport 2346", "rport badvalue");
3030 ExpectParseFailure("rport 2346 generation 2",
3031 "rport 2346 generation badvalue");
3032 // m line
3033 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
3034 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
3035
3036 // bandwidth
3037 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003038 "b=AS:badvalue\r\n", "b=AS:badvalue");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003039 // rtcp-fb
3040 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3041 "a=rtcp-fb:badvalue nack\r\n",
3042 "a=rtcp-fb:badvalue nack");
3043 // extmap
3044 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3045 "a=extmap:badvalue http://example.com\r\n",
3046 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003047}
3048
3049TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 10:27:41 -08003050 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003051
3052 const char kSdpWithReorderedPlTypesString[] =
3053 "v=0\r\n"
3054 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3055 "s=-\r\n"
3056 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00003057 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
Yves Gerey665174f2018-06-19 15:03:05 +02003058 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
3059 // in the map.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003060 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003061 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003062
3063 // Deserialize
3064 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
3065
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003066 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003067 GetFirstAudioContentDescription(jdesc_output.description());
3068 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003069 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003070 EXPECT_EQ("ISAC", acd->codecs()[0].name);
3071 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003072 EXPECT_EQ(104, acd->codecs()[0].id);
3073}
3074
3075TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 10:27:41 -08003076 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003077 CodecParams params;
3078 params.max_ptime = 40;
3079 params.ptime = 30;
3080 params.min_ptime = 10;
3081 params.sprop_stereo = 1;
3082 params.stereo = 1;
3083 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003084 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003085 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 12:22:16 -08003086 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003087}
3088
3089TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
3090 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 10:27:41 -08003091 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003092 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003093 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003094}
3095
3096TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
3097 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 10:27:41 -08003098 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003099 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003100 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003101}
3102
3103TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 10:27:41 -08003104 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003105
3106 const char kSdpWithFmtpString[] =
3107 "v=0\r\n"
3108 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3109 "s=-\r\n"
3110 "t=0 0\r\n"
3111 "m=video 3457 RTP/SAVPF 120\r\n"
3112 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07003113 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3114
3115 // Deserialize
3116 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07003117 EXPECT_TRUE(
3118 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07003119
Donald Curtis0e07f922015-05-15 09:21:23 -07003120 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003121 GetFirstVideoContentDescription(jdesc_output.description());
3122 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 09:21:23 -07003123 ASSERT_FALSE(vcd->codecs().empty());
3124 cricket::VideoCodec vp8 = vcd->codecs()[0];
3125 EXPECT_EQ("VP8", vp8.name);
3126 EXPECT_EQ(120, vp8.id);
3127 cricket::CodecParameterMap::iterator found =
3128 vp8.params.find("x-google-min-bitrate");
3129 ASSERT_TRUE(found != vp8.params.end());
3130 EXPECT_EQ(found->second, "10");
3131 found = vp8.params.find("x-google-max-quantization");
3132 ASSERT_TRUE(found != vp8.params.end());
3133 EXPECT_EQ(found->second, "40");
3134}
3135
johan2d8d23e2016-06-03 01:22:42 -07003136TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 10:27:41 -08003137 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 01:22:42 -07003138
3139 const char kSdpWithFmtpString[] =
3140 "v=0\r\n"
3141 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3142 "s=-\r\n"
3143 "t=0 0\r\n"
3144 "m=video 49170 RTP/AVP 98\r\n"
3145 "a=rtpmap:98 H264/90000\r\n"
3146 "a=fmtp:98 profile-level-id=42A01E; "
3147 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3148
3149 // Deserialize.
3150 SdpParseError error;
3151 EXPECT_TRUE(
3152 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3153
johan2d8d23e2016-06-03 01:22:42 -07003154 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003155 GetFirstVideoContentDescription(jdesc_output.description());
3156 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 01:22:42 -07003157 ASSERT_FALSE(vcd->codecs().empty());
3158 cricket::VideoCodec h264 = vcd->codecs()[0];
3159 EXPECT_EQ("H264", h264.name);
3160 EXPECT_EQ(98, h264.id);
3161 cricket::CodecParameterMap::const_iterator found =
3162 h264.params.find("profile-level-id");
3163 ASSERT_TRUE(found != h264.params.end());
3164 EXPECT_EQ(found->second, "42A01E");
3165 found = h264.params.find("sprop-parameter-sets");
3166 ASSERT_TRUE(found != h264.params.end());
3167 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3168}
3169
Donald Curtis0e07f922015-05-15 09:21:23 -07003170TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 10:27:41 -08003171 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 09:21:23 -07003172
3173 const char kSdpWithFmtpString[] =
3174 "v=0\r\n"
3175 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3176 "s=-\r\n"
3177 "t=0 0\r\n"
3178 "m=video 3457 RTP/SAVPF 120\r\n"
3179 "a=rtpmap:120 VP8/90000\r\n"
3180 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003181
3182 // Deserialize
3183 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02003184 EXPECT_TRUE(
3185 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003186
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003187 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003188 GetFirstVideoContentDescription(jdesc_output.description());
3189 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003190 ASSERT_FALSE(vcd->codecs().empty());
3191 cricket::VideoCodec vp8 = vcd->codecs()[0];
3192 EXPECT_EQ("VP8", vp8.name);
3193 EXPECT_EQ(120, vp8.id);
3194 cricket::CodecParameterMap::iterator found =
3195 vp8.params.find("x-google-min-bitrate");
3196 ASSERT_TRUE(found != vp8.params.end());
3197 EXPECT_EQ(found->second, "10");
3198 found = vp8.params.find("x-google-max-quantization");
3199 ASSERT_TRUE(found != vp8.params.end());
3200 EXPECT_EQ(found->second, "40");
3201}
3202
ossuaa4b0772017-01-30 07:41:18 -08003203TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003204 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003205
3206 cricket::AudioCodecs codecs = acd->codecs();
3207 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3208 acd->set_codecs(codecs);
3209
Yves Gerey665174f2018-06-19 15:03:05 +02003210 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003211 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003212 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003213 std::string sdp_with_fmtp = kSdpFullString;
3214 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3215 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3216 &sdp_with_fmtp);
3217 EXPECT_EQ(sdp_with_fmtp, message);
3218}
3219
3220TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003221 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003222
3223 cricket::AudioCodecs codecs = acd->codecs();
3224 codecs[0].params["stereo"] = "1";
3225 acd->set_codecs(codecs);
3226
Yves Gerey665174f2018-06-19 15:03:05 +02003227 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003228 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003229 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003230 std::string sdp_with_fmtp = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003231 InjectAfter("a=rtpmap:111 opus/48000/2\r\n", "a=fmtp:111 stereo=1\r\n",
ossuaa4b0772017-01-30 07:41:18 -08003232 &sdp_with_fmtp);
3233 EXPECT_EQ(sdp_with_fmtp, message);
3234}
3235
3236TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003237 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003238
3239 cricket::AudioCodecs codecs = acd->codecs();
3240 codecs[0].params["ptime"] = "20";
3241 codecs[0].params["maxptime"] = "120";
3242 acd->set_codecs(codecs);
3243
Yves Gerey665174f2018-06-19 15:03:05 +02003244 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003245 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003246 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003247 std::string sdp_with_fmtp = kSdpFullString;
3248 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3249 "a=maxptime:120\r\n" // No comma here. String merging!
3250 "a=ptime:20\r\n",
3251 &sdp_with_fmtp);
3252 EXPECT_EQ(sdp_with_fmtp, message);
3253}
3254
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003255TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003256 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003257
3258 cricket::VideoCodecs codecs = vcd->codecs();
3259 codecs[0].params["x-google-min-bitrate"] = "10";
3260 vcd->set_codecs(codecs);
3261
Yves Gerey665174f2018-06-19 15:03:05 +02003262 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003263 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003264 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003265 std::string sdp_with_fmtp = kSdpFullString;
3266 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003267 "a=fmtp:120 x-google-min-bitrate=10\r\n", &sdp_with_fmtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003268 EXPECT_EQ(sdp_with_fmtp, message);
3269}
3270
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003271TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) {
3272 // Deserialize the baseline description, making sure it's ICE full.
Steve Antona3a92c22017-12-07 10:27:41 -08003273 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003274 std::string sdp_with_icelite = kSdpFullString;
3275 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3276 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3277 const cricket::TransportInfo* tinfo1 =
3278 desc->GetTransportInfoByName("audio_content_name");
3279 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3280 const cricket::TransportInfo* tinfo2 =
3281 desc->GetTransportInfoByName("video_content_name");
3282 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003283
3284 // Add "a=ice-lite" and deserialize, making sure it's ICE lite.
Yves Gerey665174f2018-06-19 15:03:05 +02003285 InjectAfter(kSessionTime, "a=ice-lite\r\n", &sdp_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003286 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3287 desc = jdesc_with_icelite.description();
3288 const cricket::TransportInfo* atinfo =
3289 desc->GetTransportInfoByName("audio_content_name");
3290 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3291 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003292 desc->GetTransportInfoByName("video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003293 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003294
3295 // Now that we know deserialization works, we can use TestSerialize to test
3296 // serialization.
3297 TestSerialize(jdesc_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003298}
3299
3300// Verifies that the candidates in the input SDP are parsed and serialized
3301// correctly in the output SDP.
3302TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3303 std::string sdp_with_data = kSdpString;
3304 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 10:27:41 -08003305 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003306
3307 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 12:22:16 -08003308 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003309}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003310
3311TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3312 AddFingerprint();
3313 TransportInfo audio_transport_info =
3314 *(desc_.GetTransportInfoByName(kAudioContentName));
3315 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3316 audio_transport_info.description.connection_role);
3317 audio_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003318 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003319
3320 TransportInfo video_transport_info =
3321 *(desc_.GetTransportInfoByName(kVideoContentName));
3322 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3323 video_transport_info.description.connection_role);
3324 video_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003325 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003326
3327 desc_.RemoveTransportInfoByName(kAudioContentName);
3328 desc_.RemoveTransportInfoByName(kVideoContentName);
3329
3330 desc_.AddTransportInfo(audio_transport_info);
3331 desc_.AddTransportInfo(video_transport_info);
3332
Yves Gerey665174f2018-06-19 15:03:05 +02003333 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003334 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003335 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003336 std::string sdp_with_dtlssetup = kSdpFullString;
3337
3338 // Fingerprint attribute is necessary to add DTLS setup attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003339 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_dtlssetup);
3340 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003341 // Now adding |setup| attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003342 InjectAfter(kFingerprint, "a=setup:active\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003343 EXPECT_EQ(sdp_with_dtlssetup, message);
3344}
3345
3346TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
Steve Antona3a92c22017-12-07 10:27:41 -08003347 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003348 std::string sdp_with_dtlssetup = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003349 InjectAfter(kSessionTime, "a=setup:actpass\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003350 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3351 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3352 const cricket::TransportInfo* atinfo =
3353 desc->GetTransportInfoByName("audio_content_name");
3354 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3355 atinfo->description.connection_role);
3356 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003357 desc->GetTransportInfoByName("video_content_name");
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003358 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3359 vtinfo->description.connection_role);
3360}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003361
3362// Verifies that the order of the serialized m-lines follows the order of the
3363// ContentInfo in SessionDescription, and vise versa for deserialization.
3364TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 10:27:41 -08003365 JsepSessionDescription jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02003366 const std::string media_content_sdps[3] = {kSdpAudioString, kSdpVideoString,
3367 kSdpSctpDataChannelString};
3368 const cricket::MediaType media_types[3] = {cricket::MEDIA_TYPE_AUDIO,
3369 cricket::MEDIA_TYPE_VIDEO,
3370 cricket::MEDIA_TYPE_DATA};
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003371
3372 // Verifies all 6 permutations.
3373 for (size_t i = 0; i < 6; ++i) {
3374 size_t media_content_in_sdp[3];
3375 // The index of the first media content.
3376 media_content_in_sdp[0] = i / 2;
3377 // The index of the second media content.
3378 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3379 // The index of the third media content.
3380 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3381
3382 std::string sdp_string = kSdpSessionString;
3383 for (size_t i = 0; i < 3; ++i)
3384 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3385
3386 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3387 cricket::SessionDescription* desc = jdesc.description();
3388 EXPECT_EQ(3u, desc->contents().size());
3389
3390 for (size_t i = 0; i < 3; ++i) {
3391 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 15:14:30 -08003392 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003393 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3394 }
3395
Steve Antone831b8c2018-02-01 12:22:16 -08003396 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003397 EXPECT_EQ(sdp_string, serialized_sdp);
3398 }
3399}
deadbeef9d3584c2016-02-16 17:54:10 -08003400
deadbeef25ed4352016-12-12 18:37:36 -08003401TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3402 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 10:27:41 -08003403 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003404 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003405 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3406 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3407}
3408
deadbeef12771a12017-01-03 13:53:47 -08003409// The semantics of "a=bundle-only" are only defined when it's used in
3410// combination with a 0 port on the m= line. We should ignore it if used with a
3411// nonzero port.
3412TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3413 // Make the base bundle-only description but unset the bundle-only flag.
3414 MakeBundleOnlyDescription();
3415 jdesc_.description()->contents()[1].bundle_only = false;
3416
3417 std::string modified_sdp = kBundleOnlySdpFullString;
3418 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08003419 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003420 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3421 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003422}
3423
3424TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3425 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003426 TestSerialize(jdesc_);
deadbeef25ed4352016-12-12 18:37:36 -08003427}
3428
deadbeef9d3584c2016-02-16 17:54:10 -08003429TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3430 MakePlanBDescription();
3431
Steve Antona3a92c22017-12-07 10:27:41 -08003432 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003433 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3434
3435 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3436}
3437
3438TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3439 MakePlanBDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003440 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-16 17:54:10 -08003441}
3442
3443TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3444 MakeUnifiedPlanDescription();
3445
Steve Antona3a92c22017-12-07 10:27:41 -08003446 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003447 EXPECT_TRUE(
3448 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3449
3450 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3451}
3452
3453TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3454 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003455 TestSerialize(jdesc_);
3456}
3457
Seth Hampson5b4f0752018-04-02 16:31:36 -07003458// This tests deserializing a Unified Plan SDP that is compatible with both
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003459// Unified Plan and Plan B style SDP, meaning that it contains both "a=ssrc
3460// msid" lines and "a=msid " lines. It tests the case for audio/video tracks
Seth Hampson5b4f0752018-04-02 16:31:36 -07003461// with no stream ids and multiple stream ids. For parsing this, the Unified
3462// Plan a=msid lines should take priority, because the Plan B style a=ssrc msid
3463// lines do not support multiple stream ids and no stream ids.
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003464TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionSpecialMsid) {
3465 // Create both msid lines for Plan B and Unified Plan support.
3466 MakeUnifiedPlanDescriptionMultipleStreamIds(
3467 cricket::kMsidSignalingMediaSection |
3468 cricket::kMsidSignalingSsrcAttribute);
Seth Hampson5b4f0752018-04-02 16:31:36 -07003469
3470 JsepSessionDescription deserialized_description(kDummyType);
3471 EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid,
3472 &deserialized_description));
3473
3474 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3475}
3476
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003477// Tests the serialization of a Unified Plan SDP that is compatible for both
3478// Unified Plan and Plan B style SDPs, meaning that it contains both "a=ssrc
3479// msid" lines and "a=msid " lines. It tests the case for no stream ids and
3480// multiple stream ids.
3481TEST_F(WebRtcSdpTest, SerializeSessionDescriptionSpecialMsid) {
3482 // Create both msid lines for Plan B and Unified Plan support.
3483 MakeUnifiedPlanDescriptionMultipleStreamIds(
3484 cricket::kMsidSignalingMediaSection |
3485 cricket::kMsidSignalingSsrcAttribute);
3486 std::string serialized_sdp = webrtc::SdpSerialize(jdesc_);
3487 // We explicitly test that the serialized SDP string is equal to the hard
3488 // coded SDP string. This is necessary, because in the parser "a=msid" lines
3489 // take priority over "a=ssrc msid" lines. This means if we just used
3490 // TestSerialize(), it could serialize an SDP that omits "a=ssrc msid" lines,
3491 // and still pass, because the deserialized version would be the same.
3492 EXPECT_EQ(kUnifiedPlanSdpFullStringWithSpecialMsid, serialized_sdp);
3493}
3494
3495// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3496// that signal stream IDs) is deserialized appropriately. It tests the case for
3497// no stream ids and multiple stream ids.
3498TEST_F(WebRtcSdpTest, UnifiedPlanDeserializeSessionDescriptionSpecialMsid) {
3499 // Only create a=msid lines for strictly Unified Plan stream ID support.
3500 MakeUnifiedPlanDescriptionMultipleStreamIds(
3501 cricket::kMsidSignalingMediaSection);
3502
3503 JsepSessionDescription deserialized_description(kDummyType);
3504 std::string unified_plan_sdp_string =
3505 kUnifiedPlanSdpFullStringWithSpecialMsid;
3506 RemoveSsrcMsidLinesFromSdpString(&unified_plan_sdp_string);
3507 EXPECT_TRUE(
3508 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3509
3510 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3511}
3512
3513// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3514// that signal stream IDs) is serialized appropriately. It tests the case for no
3515// stream ids and multiple stream ids.
3516TEST_F(WebRtcSdpTest, UnifiedPlanSerializeSessionDescriptionSpecialMsid) {
3517 // Only create a=msid lines for strictly Unified Plan stream ID support.
3518 MakeUnifiedPlanDescriptionMultipleStreamIds(
3519 cricket::kMsidSignalingMediaSection);
3520
Seth Hampson5b4f0752018-04-02 16:31:36 -07003521 TestSerialize(jdesc_);
3522}
3523
Seth Hampson5897a6e2018-04-03 11:16:33 -07003524// This tests that a Unified Plan SDP with no a=ssrc lines is
3525// serialized/deserialized appropriately. In this case the
3526// MediaContentDescription will contain a StreamParams object that doesn't have
3527// any SSRCs. Vice versa, this will be created upon deserializing an SDP with no
3528// SSRC lines.
3529TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3530 MakeUnifiedPlanDescription();
3531 RemoveSsrcSignalingFromStreamParams();
3532 std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString;
3533 RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string);
3534
3535 JsepSessionDescription deserialized_description(kDummyType);
3536 EXPECT_TRUE(
3537 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3538 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3539}
3540
3541TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3542 MakeUnifiedPlanDescription();
3543 RemoveSsrcSignalingFromStreamParams();
3544
3545 TestSerialize(jdesc_);
3546}
3547
Steve Antone831b8c2018-02-01 12:22:16 -08003548TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
3549 JsepSessionDescription jsep_desc(kDummyType);
3550 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
3551 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3552}
3553
3554TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
3555 JsepSessionDescription jsep_desc(kDummyType);
3556 std::string sdp = kSdpSessionString;
3557 sdp += kSdpSctpDataChannelString;
3558 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3559 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3560}
3561
3562TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
3563 JsepSessionDescription jsep_desc(kDummyType);
3564 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
3565 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
3566 jsep_desc.description()->msid_signaling());
3567}
3568
3569TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
3570 JsepSessionDescription jsep_desc(kDummyType);
3571 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
3572 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
3573 jsep_desc.description()->msid_signaling());
3574}
3575
3576const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
3577const char kSsrcAttributeMsidLine[] =
3578 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
3579
3580TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
3581 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
3582 std::string sdp = webrtc::SdpSerialize(jdesc_);
3583
3584 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3585 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3586}
3587
3588TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
3589 jdesc_.description()->set_msid_signaling(
3590 cricket::kMsidSignalingSsrcAttribute);
3591 std::string sdp = webrtc::SdpSerialize(jdesc_);
3592
3593 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
3594 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3595}
3596
3597TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
3598 jdesc_.description()->set_msid_signaling(
3599 cricket::kMsidSignalingMediaSection |
3600 cricket::kMsidSignalingSsrcAttribute);
3601 std::string sdp = webrtc::SdpSerialize(jdesc_);
3602
3603 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3604 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-16 17:54:10 -08003605}
deadbeef7e146cb2016-09-28 10:04:34 -07003606
3607// Regression test for heap overflow bug:
3608// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3609TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 10:04:34 -07003610 // The issue occurs when the sctp-port attribute is found in a video
3611 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 12:43:58 -08003612 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 10:04:34 -07003613 "v=0\r\n"
3614 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3615 "s=-\r\n"
3616 "t=0 0\r\n"
3617 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3618 "a=sctp-port 5000\r\n"
3619 "a=fmtp:108 foo=10\r\n";
3620
3621 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3622 "sctp-port");
3623}
deadbeefb2362572016-12-13 16:37:06 -08003624
3625// Regression test for integer overflow bug:
3626// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3627TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003628 // Bandwidth attribute is the max signed 32-bit int, which will get
3629 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003630 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003631 "v=0\r\n"
3632 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3633 "s=-\r\n"
3634 "t=0 0\r\n"
3635 "m=video 3457 RTP/SAVPF 120\r\n"
3636 "b=AS:2147483647\r\n"
3637 "foo=fail\r\n";
3638
3639 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3640}
deadbeef7bcdb692017-01-20 12:43:58 -08003641
deadbeefbc88c6b2017-08-02 11:26:34 -07003642// Similar to the above, except that negative values are illegal, not just
3643// error-prone as large values are.
3644// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3645TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3646 static const char kSdpWithNegativeBandwidth[] =
3647 "v=0\r\n"
3648 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3649 "s=-\r\n"
3650 "t=0 0\r\n"
3651 "m=video 3457 RTP/SAVPF 120\r\n"
3652 "b=AS:-1000\r\n";
3653
3654 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3655}
3656
deadbeef3e8016e2017-08-03 17:49:30 -07003657// An exception to the above rule: a value of -1 for b=AS should just be
3658// ignored, resulting in "kAutoBandwidth" in the deserialized object.
3659// Applications historically may be using "b=AS:-1" to mean "no bandwidth
3660// limit", but this is now what ommitting the attribute entirely will do, so
3661// ignoring it will have the intended effect.
3662TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
3663 static const char kSdpWithBandwidthOfNegativeOne[] =
3664 "v=0\r\n"
3665 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3666 "s=-\r\n"
3667 "t=0 0\r\n"
3668 "m=video 3457 RTP/SAVPF 120\r\n"
3669 "b=AS:-1\r\n";
3670
Steve Antona3a92c22017-12-07 10:27:41 -08003671 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-03 17:49:30 -07003672 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-03 17:49:30 -07003673 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003674 GetFirstVideoContentDescription(jdesc_output.description());
3675 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-03 17:49:30 -07003676 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
3677}
3678
deadbeef7bcdb692017-01-20 12:43:58 -08003679// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3680// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3681// Regression test for:
3682// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3683TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3684 // Important piece is "ufrag foo pwd bar".
3685 static const char kSdpWithIceCredentialsInCandidateString[] =
3686 "v=0\r\n"
3687 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3688 "s=-\r\n"
3689 "t=0 0\r\n"
3690 "m=audio 9 RTP/SAVPF 111\r\n"
3691 "c=IN IP4 0.0.0.0\r\n"
3692 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3693 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3694 "a=rtpmap:111 opus/48000/2\r\n"
3695 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3696 "generation 2 ufrag foo pwd bar\r\n";
3697
Steve Antona3a92c22017-12-07 10:27:41 -08003698 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 12:43:58 -08003699 EXPECT_TRUE(
3700 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
3701 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3702 ASSERT_NE(nullptr, candidates);
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003703 ASSERT_EQ(1U, candidates->count());
deadbeef7bcdb692017-01-20 12:43:58 -08003704 cricket::Candidate c = candidates->at(0)->candidate();
3705 EXPECT_EQ("ufrag_voice", c.username());
3706 EXPECT_EQ("pwd_voice", c.password());
3707}
deadbeef90f1e1e2017-02-10 12:35:05 -08003708
Johannes Kron211856b2018-09-06 12:12:28 +02003709// Test that attribute lines "a=ice-ufrag-something"/"a=ice-pwd-something" are
3710// ignored, and only the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3711// Regression test for:
3712// https://bugs.chromium.org/p/webrtc/issues/detail?id=9712
3713TEST_F(WebRtcSdpTest, AttributeWithPartialMatchingNameIsIgnored) {
3714 static const char kSdpWithFooIceCredentials[] =
3715 "v=0\r\n"
3716 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3717 "s=-\r\n"
3718 "t=0 0\r\n"
3719 "m=audio 9 RTP/SAVPF 111\r\n"
3720 "c=IN IP4 0.0.0.0\r\n"
3721 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3722 "a=ice-ufrag-something:foo\r\na=ice-pwd-something:bar\r\n"
3723 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3724 "a=rtpmap:111 opus/48000/2\r\n"
3725 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3726 "generation 2\r\n";
3727
3728 JsepSessionDescription jdesc_output(kDummyType);
3729 EXPECT_TRUE(SdpDeserialize(kSdpWithFooIceCredentials, &jdesc_output));
3730 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3731 ASSERT_NE(nullptr, candidates);
3732 ASSERT_EQ(1U, candidates->count());
3733 cricket::Candidate c = candidates->at(0)->candidate();
3734 EXPECT_EQ("ufrag_voice", c.username());
3735 EXPECT_EQ("pwd_voice", c.password());
3736}
3737
deadbeef90f1e1e2017-02-10 12:35:05 -08003738// Test that SDP with an invalid port number in "a=candidate" lines is
3739// rejected, without crashing.
3740// Regression test for:
3741// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
3742TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
3743 static const char kSdpWithInvalidCandidatePort[] =
3744 "v=0\r\n"
3745 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3746 "s=-\r\n"
3747 "t=0 0\r\n"
3748 "m=audio 9 RTP/SAVPF 111\r\n"
3749 "c=IN IP4 0.0.0.0\r\n"
3750 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3751 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3752 "a=rtpmap:111 opus/48000/2\r\n"
3753 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
3754 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
3755
Steve Antona3a92c22017-12-07 10:27:41 -08003756 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 12:35:05 -08003757 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
3758}
deadbeefa4549d62017-02-10 17:26:22 -08003759
3760// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
3761// Regression test for:
3762// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
3763TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
3764 static const char kSdpWithMissingTrackId[] =
3765 "v=0\r\n"
3766 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3767 "s=-\r\n"
3768 "t=0 0\r\n"
3769 "m=audio 9 RTP/SAVPF 111\r\n"
3770 "c=IN IP4 0.0.0.0\r\n"
3771 "a=rtpmap:111 opus/48000/2\r\n"
3772 "a=msid:stream_id \r\n";
3773
Steve Antona3a92c22017-12-07 10:27:41 -08003774 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003775 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
3776}
3777
3778TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
3779 static const char kSdpWithMissingStreamId[] =
3780 "v=0\r\n"
3781 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3782 "s=-\r\n"
3783 "t=0 0\r\n"
3784 "m=audio 9 RTP/SAVPF 111\r\n"
3785 "c=IN IP4 0.0.0.0\r\n"
3786 "a=rtpmap:111 opus/48000/2\r\n"
3787 "a=msid: track_id\r\n";
3788
Steve Antona3a92c22017-12-07 10:27:41 -08003789 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003790 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
3791}
zhihuang38989e52017-03-21 11:04:53 -07003792
3793// Tests that if both session-level address and media-level address exist, use
3794// the media-level address.
3795TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 10:27:41 -08003796 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003797
3798 // Sesssion-level address.
3799 std::string sdp = kSdpFullString;
3800 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3801 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3802
3803 const auto& content1 = jsep_desc.description()->contents()[0];
3804 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 15:14:30 -08003805 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003806 const auto& content2 = jsep_desc.description()->contents()[1];
3807 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 15:14:30 -08003808 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003809}
3810
3811// Tests that the session-level connection address will be used if the media
3812// level-addresses are not specified.
3813TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 10:27:41 -08003814 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003815
3816 // Sesssion-level address.
3817 std::string sdp = kSdpString;
3818 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3819 // Remove the media level addresses.
3820 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3821 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3822 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3823
3824 const auto& content1 = jsep_desc.description()->contents()[0];
3825 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003826 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003827 const auto& content2 = jsep_desc.description()->contents()[1];
3828 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003829 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003830}
3831
3832TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 10:27:41 -08003833 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003834
3835 std::string sdp = kSdpString;
3836 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3837 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
3838 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
3839 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
3840 &sdp);
3841 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
3842 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
3843 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
3844 &sdp);
3845 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3846 const auto& content1 = jsep_desc.description()->contents()[0];
3847 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003848 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003849 const auto& content2 = jsep_desc.description()->contents()[1];
3850 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003851 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003852}
3853
3854// Test that the invalid or unsupprted connection data cannot be parsed.
3855TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 10:27:41 -08003856 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003857 std::string sdp = kSdpString;
3858 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3859
3860 // Unsupported multicast IPv4 address.
3861 sdp = kSdpFullString;
3862 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
3863 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3864
3865 // Unsupported multicast IPv6 address.
3866 sdp = kSdpFullString;
3867 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
3868 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3869
3870 // Mismatched address type.
3871 sdp = kSdpFullString;
3872 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
3873 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3874
3875 sdp = kSdpFullString;
3876 Replace("c=IN IP4 74.125.224.39\r\n",
3877 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
3878 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3879}
3880
3881TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 10:27:41 -08003882 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003883 MakeDescriptionWithoutCandidates(&expected_jsep);
3884 // Serialization.
Steve Antone831b8c2018-02-01 12:22:16 -08003885 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 11:04:53 -07003886 // Deserialization.
Steve Antona3a92c22017-12-07 10:27:41 -08003887 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003888 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 15:14:30 -08003889 auto audio_desc = jdesc.description()
3890 ->GetContentByName(kAudioContentName)
3891 ->media_description();
3892 auto video_desc = jdesc.description()
3893 ->GetContentByName(kVideoContentName)
3894 ->media_description();
zhihuang38989e52017-03-21 11:04:53 -07003895 EXPECT_EQ(audio_desc_->connection_address().ToString(),
3896 audio_desc->connection_address().ToString());
3897 EXPECT_EQ(video_desc_->connection_address().ToString(),
3898 video_desc->connection_address().ToString());
3899}
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07003900
3901// RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be
3902// used (i.e., a single space as the session name)." So we should accept that.
3903TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) {
3904 JsepSessionDescription jsep_desc(kDummyType);
3905 std::string sdp = kSdpString;
3906 Replace("s=-\r\n", "s= \r\n", &sdp);
3907 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3908}