blob: 8eeeeabb77f7a0befa1177378a4412c88c5d392c [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2011 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
kwibergd1fe2812016-04-27 06:47:29 -070011#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000012#include <set>
13#include <string>
14#include <vector>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "api/jsepsessiondescription.h"
17#include "media/base/mediaconstants.h"
18#include "media/engine/webrtcvideoengine.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "p2p/base/p2pconstants.h"
Yves Gerey665174f2018-06-19 15:03:05 +020020#include "p2p/base/port.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "pc/mediasession.h"
22#include "rtc_base/checks.h"
23#include "rtc_base/gunit.h"
24#include "rtc_base/logging.h"
Yves Gerey2e00abc2018-10-05 15:39:24 +020025#include "rtc_base/messagedigest.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020026#include "rtc_base/stringencode.h"
27#include "rtc_base/stringutils.h"
Patrik Höglund563934e2017-09-15 09:04:28 +020028
ossu7bb87ee2017-01-23 04:56:25 -080029#ifdef WEBRTC_ANDROID
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020030#include "pc/test/androidtestinitializer.h"
ossu7bb87ee2017-01-23 04:56:25 -080031#endif
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020032#include "pc/webrtcsdp.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000033
34using cricket::AudioCodec;
35using cricket::AudioContentDescription;
36using cricket::Candidate;
37using cricket::ContentInfo;
38using cricket::CryptoParams;
39using cricket::ContentGroup;
40using cricket::DataCodec;
41using cricket::DataContentDescription;
42using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
43using cricket::ICE_CANDIDATE_COMPONENT_RTP;
44using cricket::kFecSsrcGroupSemantics;
45using cricket::LOCAL_PORT_TYPE;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000046using cricket::RELAY_PORT_TYPE;
47using cricket::SessionDescription;
Steve Anton5adfafd2017-12-20 16:34:00 -080048using cricket::MediaProtocolType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049using cricket::StreamParams;
50using cricket::STUN_PORT_TYPE;
51using cricket::TransportDescription;
52using cricket::TransportInfo;
53using cricket::VideoCodec;
54using cricket::VideoContentDescription;
55using webrtc::IceCandidateCollection;
56using webrtc::IceCandidateInterface;
57using webrtc::JsepIceCandidate;
58using webrtc::JsepSessionDescription;
isheriff6f8d6862016-05-26 11:24:55 -070059using webrtc::RtpExtension;
Steve Anton4e70a722017-11-28 14:57:10 -080060using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061using webrtc::SdpParseError;
Steve Antona3a92c22017-12-07 10:27:41 -080062using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063using webrtc::SessionDescriptionInterface;
64
65typedef std::vector<AudioCodec> AudioCodecs;
66typedef std::vector<Candidate> Candidates;
67
Peter Boström0c4e06b2015-10-07 12:23:21 +020068static const uint32_t kDefaultSctpPort = 5000;
zstein4b2e0822017-02-17 19:48:38 -080069static const char kDefaultSctpPortStr[] = "5000";
70static const uint16_t kUnusualSctpPort = 9556;
71static const char kUnusualSctpPortStr[] = "9556";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020073static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 15:17:14 -080074static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 15:17:14 -080076static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020078static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079static const char kCandidateFoundation1[] = "a0+B/1";
80static const char kCandidateFoundation2[] = "a0+B/2";
81static const char kCandidateFoundation3[] = "a0+B/3";
82static const char kCandidateFoundation4[] = "a0+B/4";
83static const char kAttributeCryptoVoice[] =
84 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
85 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
86 "dummy_session_params\r\n";
87static const char kAttributeCryptoVideo[] =
88 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
89 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
Yves Gerey665174f2018-06-19 15:03:05 +020090static const char kFingerprint[] =
91 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n";
Johannes Kron0854eb62018-10-10 22:33:20 +020093static const char kExtmapAllowMixed[] = "a=extmap-allow-mixed\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094static const int kExtmapId = 1;
95static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
96static const char kExtmap[] =
97 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
98static const char kExtmapWithDirectionAndAttribute[] =
99 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
jbauch5869f502017-06-29 12:31:36 -0700100static const char kExtmapWithDirectionAndAttributeEncrypted[] =
101 "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt "
102 "http://example.com/082005/ext.htm#ttime a1 a2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103
Peter Boström0c4e06b2015-10-07 12:23:21 +0200104static const uint8_t kIdentityDigest[] = {
105 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
106 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107
lally@webrtc.org34807282015-02-24 20:19:39 +0000108static const char kDtlsSctp[] = "DTLS/SCTP";
109static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
110static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +0000111
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000112struct CodecParams {
113 int max_ptime;
114 int ptime;
115 int min_ptime;
116 int sprop_stereo;
117 int stereo;
118 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000119 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120};
121
deadbeef9d3584c2016-02-16 17:54:10 -0800122// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
123// instead of "a=crypto", and have an explicit test for adding "a=crypto".
124// Currently it's the other way around.
125
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000126// Reference sdp string
127static const char kSdpFullString[] =
128 "v=0\r\n"
129 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
130 "s=-\r\n"
131 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800132 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000133 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
134 "c=IN IP4 74.125.127.126\r\n"
135 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
136 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
137 "generation 2\r\n"
138 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
139 "generation 2\r\n"
140 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
141 "generation 2\r\n"
142 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
143 "generation 2\r\n"
144 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
145 "raddr 192.168.1.5 rport 2346 "
146 "generation 2\r\n"
147 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
148 "raddr 192.168.1.5 rport 2348 "
149 "generation 2\r\n"
150 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
151 "a=mid:audio_content_name\r\n"
152 "a=sendrecv\r\n"
153 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800154 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000155 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
156 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
157 "dummy_session_params\r\n"
158 "a=rtpmap:111 opus/48000/2\r\n"
159 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000160 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000161 "a=ssrc:1 cname:stream_1_cname\r\n"
162 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
163 "a=ssrc:1 mslabel:local_stream_1\r\n"
164 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000165 "m=video 3457 RTP/SAVPF 120\r\n"
166 "c=IN IP4 74.125.224.39\r\n"
167 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
168 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
169 "generation 2\r\n"
170 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
171 "generation 2\r\n"
172 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
173 "generation 2\r\n"
174 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
175 "generation 2\r\n"
176 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
177 "generation 2\r\n"
178 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
179 "generation 2\r\n"
180 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
181 "a=mid:video_content_name\r\n"
182 "a=sendrecv\r\n"
183 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
184 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
185 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800186 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187 "a=ssrc:2 cname:stream_1_cname\r\n"
188 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
189 "a=ssrc:2 mslabel:local_stream_1\r\n"
190 "a=ssrc:2 label:video_track_id_1\r\n"
191 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800192 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000193 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800194 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000195
196// SDP reference string without the candidates.
197static const char kSdpString[] =
198 "v=0\r\n"
199 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
200 "s=-\r\n"
201 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800202 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000203 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000204 "c=IN IP4 0.0.0.0\r\n"
205 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000206 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
207 "a=mid:audio_content_name\r\n"
208 "a=sendrecv\r\n"
209 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800210 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
212 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
213 "dummy_session_params\r\n"
214 "a=rtpmap:111 opus/48000/2\r\n"
215 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000216 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000217 "a=ssrc:1 cname:stream_1_cname\r\n"
218 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
219 "a=ssrc:1 mslabel:local_stream_1\r\n"
220 "a=ssrc:1 label:audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000221 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000222 "c=IN IP4 0.0.0.0\r\n"
223 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000224 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
225 "a=mid:video_content_name\r\n"
226 "a=sendrecv\r\n"
227 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
228 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
229 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800230 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000231 "a=ssrc:2 cname:stream_1_cname\r\n"
232 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
233 "a=ssrc:2 mslabel:local_stream_1\r\n"
234 "a=ssrc:2 label:video_track_id_1\r\n"
235 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800236 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000237 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800238 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000239
240static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000241 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000242 "c=IN IP4 0.0.0.0\r\n"
243 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000244 "a=ice-ufrag:ufrag_data\r\n"
245 "a=ice-pwd:pwd_data\r\n"
246 "a=mid:data_content_name\r\n"
247 "a=sendrecv\r\n"
248 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
249 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
250 "a=rtpmap:101 google-data/90000\r\n"
251 "a=ssrc:10 cname:data_channel_cname\r\n"
252 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
253 "a=ssrc:10 mslabel:data_channel\r\n"
254 "a=ssrc:10 label:data_channeld0\r\n";
255
256static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000257 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000258 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000259 "a=ice-ufrag:ufrag_data\r\n"
260 "a=ice-pwd:pwd_data\r\n"
261 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000262 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000263
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000264// draft-ietf-mmusic-sctp-sdp-12
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000265static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000266 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
267 "a=max-message-size=100000\r\n"
268 "a=sctp-port 5000\r\n"
269 "c=IN IP4 0.0.0.0\r\n"
270 "a=ice-ufrag:ufrag_data\r\n"
271 "a=ice-pwd:pwd_data\r\n"
272 "a=mid:data_content_name\r\n";
273
lally69f57602015-10-08 10:15:04 -0700274static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
275 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
276 "a=max-message-size=100000\r\n"
277 "a=sctp-port:5000\r\n"
278 "c=IN IP4 0.0.0.0\r\n"
279 "a=ice-ufrag:ufrag_data\r\n"
280 "a=ice-pwd:pwd_data\r\n"
281 "a=mid:data_content_name\r\n";
282
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000283static const char kSdpSctpDataChannelWithCandidatesString[] =
284 "m=application 2345 DTLS/SCTP 5000\r\n"
285 "c=IN IP4 74.125.127.126\r\n"
286 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
287 "generation 2\r\n"
288 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
289 "generation 2\r\n"
290 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
291 "raddr 192.168.1.5 rport 2346 "
292 "generation 2\r\n"
293 "a=ice-ufrag:ufrag_data\r\n"
294 "a=ice-pwd:pwd_data\r\n"
295 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000296 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000297
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000298static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000299 "v=0\r\n"
300 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
301 "s=-\r\n"
302 "t=0 0\r\n"
303 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000304 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000305 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000306 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000307 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000308 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000309 "a=x-google-flag:conference\r\n";
310
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000311static const char kSdpSessionString[] =
312 "v=0\r\n"
313 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
314 "s=-\r\n"
315 "t=0 0\r\n"
316 "a=msid-semantic: WMS local_stream\r\n";
317
318static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000319 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000320 "c=IN IP4 0.0.0.0\r\n"
321 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000322 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
323 "a=mid:audio_content_name\r\n"
324 "a=sendrecv\r\n"
325 "a=rtpmap:111 opus/48000/2\r\n"
326 "a=ssrc:1 cname:stream_1_cname\r\n"
327 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
328 "a=ssrc:1 mslabel:local_stream\r\n"
329 "a=ssrc:1 label:audio_track_id_1\r\n";
330
331static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000332 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000333 "c=IN IP4 0.0.0.0\r\n"
334 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000335 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
336 "a=mid:video_content_name\r\n"
337 "a=sendrecv\r\n"
338 "a=rtpmap:120 VP8/90000\r\n"
339 "a=ssrc:2 cname:stream_1_cname\r\n"
340 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
341 "a=ssrc:2 mslabel:local_stream\r\n"
342 "a=ssrc:2 label:video_track_id_1\r\n";
343
deadbeef25ed4352016-12-12 18:37:36 -0800344// Reference sdp string using bundle-only.
345static const char kBundleOnlySdpFullString[] =
346 "v=0\r\n"
347 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
348 "s=-\r\n"
349 "t=0 0\r\n"
350 "a=group:BUNDLE audio_content_name video_content_name\r\n"
351 "a=msid-semantic: WMS local_stream_1\r\n"
352 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
353 "c=IN IP4 74.125.127.126\r\n"
354 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
355 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
356 "generation 2\r\n"
357 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
358 "generation 2\r\n"
359 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
360 "generation 2\r\n"
361 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
362 "generation 2\r\n"
363 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
364 "raddr 192.168.1.5 rport 2346 "
365 "generation 2\r\n"
366 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
367 "raddr 192.168.1.5 rport 2348 "
368 "generation 2\r\n"
369 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
370 "a=mid:audio_content_name\r\n"
371 "a=sendrecv\r\n"
372 "a=rtcp-mux\r\n"
373 "a=rtcp-rsize\r\n"
374 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
375 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
376 "dummy_session_params\r\n"
377 "a=rtpmap:111 opus/48000/2\r\n"
378 "a=rtpmap:103 ISAC/16000\r\n"
379 "a=rtpmap:104 ISAC/32000\r\n"
380 "a=ssrc:1 cname:stream_1_cname\r\n"
381 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
382 "a=ssrc:1 mslabel:local_stream_1\r\n"
383 "a=ssrc:1 label:audio_track_id_1\r\n"
384 "m=video 0 RTP/SAVPF 120\r\n"
385 "c=IN IP4 0.0.0.0\r\n"
386 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
387 "a=bundle-only\r\n"
388 "a=mid:video_content_name\r\n"
389 "a=sendrecv\r\n"
390 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
391 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
392 "a=rtpmap:120 VP8/90000\r\n"
393 "a=ssrc-group:FEC 2 3\r\n"
394 "a=ssrc:2 cname:stream_1_cname\r\n"
395 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
396 "a=ssrc:2 mslabel:local_stream_1\r\n"
397 "a=ssrc:2 label:video_track_id_1\r\n"
398 "a=ssrc:3 cname:stream_1_cname\r\n"
399 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
400 "a=ssrc:3 mslabel:local_stream_1\r\n"
401 "a=ssrc:3 label:video_track_id_1\r\n";
402
deadbeef9d3584c2016-02-16 17:54:10 -0800403// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
404// tracks.
405static const char kPlanBSdpFullString[] =
406 "v=0\r\n"
407 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
408 "s=-\r\n"
409 "t=0 0\r\n"
410 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
411 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
412 "c=IN IP4 74.125.127.126\r\n"
413 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
414 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
415 "generation 2\r\n"
416 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
417 "generation 2\r\n"
418 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
419 "generation 2\r\n"
420 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
421 "generation 2\r\n"
422 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
423 "raddr 192.168.1.5 rport 2346 "
424 "generation 2\r\n"
425 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
426 "raddr 192.168.1.5 rport 2348 "
427 "generation 2\r\n"
428 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
429 "a=mid:audio_content_name\r\n"
430 "a=sendrecv\r\n"
431 "a=rtcp-mux\r\n"
432 "a=rtcp-rsize\r\n"
433 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
434 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
435 "dummy_session_params\r\n"
436 "a=rtpmap:111 opus/48000/2\r\n"
437 "a=rtpmap:103 ISAC/16000\r\n"
438 "a=rtpmap:104 ISAC/32000\r\n"
439 "a=ssrc:1 cname:stream_1_cname\r\n"
440 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
441 "a=ssrc:1 mslabel:local_stream_1\r\n"
442 "a=ssrc:1 label:audio_track_id_1\r\n"
443 "a=ssrc:4 cname:stream_2_cname\r\n"
444 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
445 "a=ssrc:4 mslabel:local_stream_2\r\n"
446 "a=ssrc:4 label:audio_track_id_2\r\n"
447 "m=video 3457 RTP/SAVPF 120\r\n"
448 "c=IN IP4 74.125.224.39\r\n"
449 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
450 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
451 "generation 2\r\n"
452 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
453 "generation 2\r\n"
454 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
455 "generation 2\r\n"
456 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
457 "generation 2\r\n"
458 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
459 "generation 2\r\n"
460 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
461 "generation 2\r\n"
462 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
463 "a=mid:video_content_name\r\n"
464 "a=sendrecv\r\n"
465 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
466 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
467 "a=rtpmap:120 VP8/90000\r\n"
468 "a=ssrc-group:FEC 2 3\r\n"
469 "a=ssrc:2 cname:stream_1_cname\r\n"
470 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
471 "a=ssrc:2 mslabel:local_stream_1\r\n"
472 "a=ssrc:2 label:video_track_id_1\r\n"
473 "a=ssrc:3 cname:stream_1_cname\r\n"
474 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
475 "a=ssrc:3 mslabel:local_stream_1\r\n"
476 "a=ssrc:3 label:video_track_id_1\r\n"
477 "a=ssrc:5 cname:stream_2_cname\r\n"
478 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
479 "a=ssrc:5 mslabel:local_stream_2\r\n"
480 "a=ssrc:5 label:video_track_id_2\r\n"
481 "a=ssrc:6 cname:stream_2_cname\r\n"
482 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
483 "a=ssrc:6 mslabel:local_stream_2\r\n"
484 "a=ssrc:6 label:video_track_id_3\r\n";
485
486// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
487// tracks.
488static const char kUnifiedPlanSdpFullString[] =
489 "v=0\r\n"
490 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
491 "s=-\r\n"
492 "t=0 0\r\n"
493 "a=msid-semantic: WMS local_stream_1\r\n"
494 // Audio track 1, stream 1 (with candidates).
495 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
496 "c=IN IP4 74.125.127.126\r\n"
497 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
498 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
499 "generation 2\r\n"
500 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
501 "generation 2\r\n"
502 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
503 "generation 2\r\n"
504 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
505 "generation 2\r\n"
506 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
507 "raddr 192.168.1.5 rport 2346 "
508 "generation 2\r\n"
509 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
510 "raddr 192.168.1.5 rport 2348 "
511 "generation 2\r\n"
512 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
513 "a=mid:audio_content_name\r\n"
514 "a=msid:local_stream_1 audio_track_id_1\r\n"
515 "a=sendrecv\r\n"
516 "a=rtcp-mux\r\n"
517 "a=rtcp-rsize\r\n"
518 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
519 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
520 "dummy_session_params\r\n"
521 "a=rtpmap:111 opus/48000/2\r\n"
522 "a=rtpmap:103 ISAC/16000\r\n"
523 "a=rtpmap:104 ISAC/32000\r\n"
524 "a=ssrc:1 cname:stream_1_cname\r\n"
525 // Video track 1, stream 1 (with candidates).
526 "m=video 3457 RTP/SAVPF 120\r\n"
527 "c=IN IP4 74.125.224.39\r\n"
528 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
529 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
530 "generation 2\r\n"
531 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
532 "generation 2\r\n"
533 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
534 "generation 2\r\n"
535 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
536 "generation 2\r\n"
537 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
538 "generation 2\r\n"
539 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
540 "generation 2\r\n"
541 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
542 "a=mid:video_content_name\r\n"
543 "a=msid:local_stream_1 video_track_id_1\r\n"
544 "a=sendrecv\r\n"
545 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
546 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
547 "a=rtpmap:120 VP8/90000\r\n"
548 "a=ssrc-group:FEC 2 3\r\n"
549 "a=ssrc:2 cname:stream_1_cname\r\n"
550 "a=ssrc:3 cname:stream_1_cname\r\n"
551 // Audio track 2, stream 2.
552 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
553 "c=IN IP4 0.0.0.0\r\n"
554 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
555 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
556 "a=mid:audio_content_name_2\r\n"
557 "a=msid:local_stream_2 audio_track_id_2\r\n"
558 "a=sendrecv\r\n"
559 "a=rtcp-mux\r\n"
560 "a=rtcp-rsize\r\n"
561 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
562 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
563 "dummy_session_params\r\n"
564 "a=rtpmap:111 opus/48000/2\r\n"
565 "a=rtpmap:103 ISAC/16000\r\n"
566 "a=rtpmap:104 ISAC/32000\r\n"
567 "a=ssrc:4 cname:stream_2_cname\r\n"
568 // Video track 2, stream 2.
569 "m=video 9 RTP/SAVPF 120\r\n"
570 "c=IN IP4 0.0.0.0\r\n"
571 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
572 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
573 "a=mid:video_content_name_2\r\n"
574 "a=msid:local_stream_2 video_track_id_2\r\n"
575 "a=sendrecv\r\n"
576 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
577 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
578 "a=rtpmap:120 VP8/90000\r\n"
579 "a=ssrc:5 cname:stream_2_cname\r\n"
580 // Video track 3, stream 2.
581 "m=video 9 RTP/SAVPF 120\r\n"
582 "c=IN IP4 0.0.0.0\r\n"
583 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
584 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
585 "a=mid:video_content_name_3\r\n"
586 "a=msid:local_stream_2 video_track_id_3\r\n"
587 "a=sendrecv\r\n"
588 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
589 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
590 "a=rtpmap:120 VP8/90000\r\n"
591 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000592
Seth Hampson5b4f0752018-04-02 16:31:36 -0700593// Unified Plan SDP reference string:
594// - audio track 1 has 1 a=msid lines
595// - audio track 2 has 2 a=msid lines
596// - audio track 3 has 1 a=msid line with the special "-" marker signifying that
597// there are 0 media stream ids.
598// This Unified Plan SDP represents a SDP that signals the msid using both
599// a=msid and a=ssrc msid semantics.
600static const char kUnifiedPlanSdpFullStringWithSpecialMsid[] =
601 "v=0\r\n"
602 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
603 "s=-\r\n"
604 "t=0 0\r\n"
605 "a=msid-semantic: WMS local_stream_1\r\n"
606 // Audio track 1, with 1 stream id.
607 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
608 "c=IN IP4 74.125.127.126\r\n"
609 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
610 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
611 "generation 2\r\n"
612 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
613 "generation 2\r\n"
614 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
615 "generation 2\r\n"
616 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
617 "generation 2\r\n"
618 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
619 "raddr 192.168.1.5 rport 2346 "
620 "generation 2\r\n"
621 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
622 "raddr 192.168.1.5 rport 2348 "
623 "generation 2\r\n"
624 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
625 "a=mid:audio_content_name\r\n"
626 "a=msid:local_stream_1 audio_track_id_1\r\n"
627 "a=sendrecv\r\n"
628 "a=rtcp-mux\r\n"
629 "a=rtcp-rsize\r\n"
630 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
631 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
632 "dummy_session_params\r\n"
633 "a=rtpmap:111 opus/48000/2\r\n"
634 "a=rtpmap:103 ISAC/16000\r\n"
635 "a=rtpmap:104 ISAC/32000\r\n"
636 "a=ssrc:1 cname:stream_1_cname\r\n"
637 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
638 "a=ssrc:1 mslabel:local_stream_1\r\n"
639 "a=ssrc:1 label:audio_track_id_1\r\n"
640 // Audio track 2, with two stream ids.
641 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
642 "c=IN IP4 0.0.0.0\r\n"
643 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
644 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
645 "a=mid:audio_content_name_2\r\n"
646 "a=msid:local_stream_1 audio_track_id_2\r\n"
647 "a=msid:local_stream_2 audio_track_id_2\r\n"
648 "a=sendrecv\r\n"
649 "a=rtcp-mux\r\n"
650 "a=rtcp-rsize\r\n"
651 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
652 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
653 "dummy_session_params\r\n"
654 "a=rtpmap:111 opus/48000/2\r\n"
655 "a=rtpmap:103 ISAC/16000\r\n"
656 "a=rtpmap:104 ISAC/32000\r\n"
657 "a=ssrc:4 cname:stream_1_cname\r\n"
658 // The support for Plan B msid signaling only includes the
659 // first media stream id "local_stream_1."
660 "a=ssrc:4 msid:local_stream_1 audio_track_id_2\r\n"
661 "a=ssrc:4 mslabel:local_stream_1\r\n"
662 "a=ssrc:4 label:audio_track_id_2\r\n"
663 // Audio track 3, with no stream ids.
664 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
665 "c=IN IP4 0.0.0.0\r\n"
666 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
667 "a=ice-ufrag:ufrag_voice_3\r\na=ice-pwd:pwd_voice_3\r\n"
668 "a=mid:audio_content_name_3\r\n"
669 "a=msid:- audio_track_id_3\r\n"
670 "a=sendrecv\r\n"
671 "a=rtcp-mux\r\n"
672 "a=rtcp-rsize\r\n"
673 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
674 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
675 "dummy_session_params\r\n"
676 "a=rtpmap:111 opus/48000/2\r\n"
677 "a=rtpmap:103 ISAC/16000\r\n"
678 "a=rtpmap:104 ISAC/32000\r\n"
679 "a=ssrc:7 cname:stream_2_cname\r\n";
680
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000681// One candidate reference string as per W3c spec.
682// candidate:<blah> not a=candidate:<blah>CRLF
683static const char kRawCandidate[] =
684 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
685// One candidate reference string.
686static const char kSdpOneCandidate[] =
687 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
688 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000689
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000690static const char kSdpTcpActiveCandidate[] =
691 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
692 "tcptype active generation 2";
693static const char kSdpTcpPassiveCandidate[] =
694 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
695 "tcptype passive generation 2";
696static const char kSdpTcpSOCandidate[] =
697 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
698 "tcptype so generation 2";
699static const char kSdpTcpInvalidCandidate[] =
700 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
701 "tcptype invalid generation 2";
702
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000703// One candidate reference string with IPV6 address.
704static const char kRawIPV6Candidate[] =
705 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 12:04:36 -0700706 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000707
708// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800709static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000710 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800711 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712
Zach Steinb336c272018-08-09 01:16:13 -0700713static const char kRawHostnameCandidate[] =
714 "candidate:a0+B/1 1 udp 2130706432 a.test 1234 typ host generation 2";
715
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000716// Session id and version
717static const char kSessionId[] = "18446744069414584320";
718static const char kSessionVersion[] = "18446462598732840960";
719
deadbeef9d3584c2016-02-16 17:54:10 -0800720// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000721static const char kIceOption1[] = "iceoption1";
722static const char kIceOption2[] = "iceoption2";
723static const char kIceOption3[] = "iceoption3";
724
deadbeef9d3584c2016-02-16 17:54:10 -0800725// ICE ufrags/passwords.
726static const char kUfragVoice[] = "ufrag_voice";
727static const char kPwdVoice[] = "pwd_voice";
728static const char kUfragVideo[] = "ufrag_video";
729static const char kPwdVideo[] = "pwd_video";
730static const char kUfragData[] = "ufrag_data";
731static const char kPwdData[] = "pwd_data";
732
733// Extra ufrags/passwords for extra unified plan m= sections.
734static const char kUfragVoice2[] = "ufrag_voice_2";
735static const char kPwdVoice2[] = "pwd_voice_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700736static const char kUfragVoice3[] = "ufrag_voice_3";
737static const char kPwdVoice3[] = "pwd_voice_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800738static const char kUfragVideo2[] = "ufrag_video_2";
739static const char kPwdVideo2[] = "pwd_video_2";
740static const char kUfragVideo3[] = "ufrag_video_3";
741static const char kPwdVideo3[] = "pwd_video_3";
742
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000743// Content name
744static const char kAudioContentName[] = "audio_content_name";
745static const char kVideoContentName[] = "video_content_name";
746static const char kDataContentName[] = "data_content_name";
747
deadbeef9d3584c2016-02-16 17:54:10 -0800748// Extra content names for extra unified plan m= sections.
749static const char kAudioContentName2[] = "audio_content_name_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700750static const char kAudioContentName3[] = "audio_content_name_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800751static const char kVideoContentName2[] = "video_content_name_2";
752static const char kVideoContentName3[] = "video_content_name_3";
753
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000754// MediaStream 1
Seth Hampson845e8782018-03-02 11:34:10 -0800755static const char kStreamId1[] = "local_stream_1";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000756static const char kStream1Cname[] = "stream_1_cname";
757static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200758static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000759static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800760static const uint32_t kVideoTrack1Ssrc1 = 2;
761static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000762
763// MediaStream 2
Seth Hampson845e8782018-03-02 11:34:10 -0800764static const char kStreamId2[] = "local_stream_2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000765static const char kStream2Cname[] = "stream_2_cname";
766static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200767static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800768static const char kVideoTrackId2[] = "video_track_id_2";
769static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000770static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800771static const uint32_t kVideoTrack3Ssrc = 6;
Seth Hampson5b4f0752018-04-02 16:31:36 -0700772static const char kAudioTrackId3[] = "audio_track_id_3";
773static const uint32_t kAudioTrack3Ssrc = 7;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000774
775// DataChannel
776static const char kDataChannelLabel[] = "data_channel";
777static const char kDataChannelMsid[] = "data_channeld0";
778static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200779static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000780
781// Candidate
782static const char kDummyMid[] = "dummy_mid";
783static const int kDummyIndex = 123;
784
785// Misc
Steve Antona3a92c22017-12-07 10:27:41 -0800786static SdpType kDummyType = SdpType::kOffer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000787
788// Helper functions
789
790static bool SdpDeserialize(const std::string& message,
791 JsepSessionDescription* jdesc) {
792 return webrtc::SdpDeserialize(message, jdesc, NULL);
793}
794
795static bool SdpDeserializeCandidate(const std::string& message,
796 JsepIceCandidate* candidate) {
797 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
798}
799
800// Add some extra |newlines| to the |message| after |line|.
801static void InjectAfter(const std::string& line,
802 const std::string& newlines,
803 std::string* message) {
804 const std::string tmp = line + newlines;
Yves Gerey665174f2018-06-19 15:03:05 +0200805 rtc::replace_substrs(line.c_str(), line.length(), tmp.c_str(), tmp.length(),
806 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000807}
808
809static void Replace(const std::string& line,
810 const std::string& newlines,
811 std::string* message) {
Yves Gerey665174f2018-06-19 15:03:05 +0200812 rtc::replace_substrs(line.c_str(), line.length(), newlines.c_str(),
813 newlines.length(), message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000814}
815
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000816// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
817// message.
818static void ExpectParseFailure(const std::string& bad_sdp,
819 const std::string& bad_part) {
Steve Antona3a92c22017-12-07 10:27:41 -0800820 JsepSessionDescription desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000821 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000822 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000823 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000824 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
825}
826
827// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
828static void ExpectParseFailure(const char* good_part, const char* bad_part) {
829 std::string bad_sdp = kSdpFullString;
830 Replace(good_part, bad_part, &bad_sdp);
831 ExpectParseFailure(bad_sdp, bad_part);
832}
833
834// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
835static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
836 const std::string& newlines,
837 const std::string& bad_part) {
838 std::string bad_sdp = kSdpFullString;
839 InjectAfter(injectpoint, newlines, &bad_sdp);
840 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000841}
842
Steve Anton4e70a722017-11-28 14:57:10 -0800843static void ReplaceDirection(RtpTransceiverDirection direction,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844 std::string* message) {
845 std::string new_direction;
846 switch (direction) {
Steve Anton4e70a722017-11-28 14:57:10 -0800847 case RtpTransceiverDirection::kInactive:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000848 new_direction = "a=inactive";
849 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800850 case RtpTransceiverDirection::kSendOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000851 new_direction = "a=sendonly";
852 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800853 case RtpTransceiverDirection::kRecvOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854 new_direction = "a=recvonly";
855 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800856 case RtpTransceiverDirection::kSendRecv:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000857 default:
858 new_direction = "a=sendrecv";
859 break;
860 }
861 Replace("a=sendrecv", new_direction, message);
862}
863
Yves Gerey665174f2018-06-19 15:03:05 +0200864static void ReplaceRejected(bool audio_rejected,
865 bool video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000866 std::string* message) {
867 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800868 Replace("m=audio 9", "m=audio 0", message);
869 Replace(kAttributeIceUfragVoice, "", message);
870 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000871 }
872 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800873 Replace("m=video 9", "m=video 0", message);
874 Replace(kAttributeIceUfragVideo, "", message);
875 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876 }
877}
878
879// WebRtcSdpTest
880
881class WebRtcSdpTest : public testing::Test {
882 public:
Steve Antona3a92c22017-12-07 10:27:41 -0800883 WebRtcSdpTest() : jdesc_(kDummyType) {
phoglund37ebcf02016-01-08 05:04:57 -0800884#ifdef WEBRTC_ANDROID
885 webrtc::InitializeAndroidObjects();
886#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000887 // AudioContentDescription
888 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -0800889 StreamParams audio_stream;
890 audio_stream.id = kAudioTrackId1;
891 audio_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -0800892 audio_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -0800893 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
894 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 11:04:53 -0700895 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
896 audio_desc_->set_connection_address(audio_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -0800897 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000898
899 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -0800900 video_desc_ = CreateVideoContentDescription();
901 StreamParams video_stream;
902 video_stream.id = kVideoTrackId1;
903 video_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -0800904 video_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -0800905 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
906 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
907 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
908 video_stream.ssrc_groups.push_back(ssrc_group);
909 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 11:04:53 -0700910 rtc::SocketAddress video_addr("74.125.224.39", 3457);
911 video_desc_->set_connection_address(video_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -0800912 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000913
914 // TransportInfo
deadbeef9d3584c2016-02-16 17:54:10 -0800915 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
916 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice))));
917 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
918 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919
920 // v4 host
921 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000922 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000923 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000924 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
925 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000926 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000927 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000928 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
929 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000930 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000931 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000932 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
933 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000934 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000935 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000936 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
937 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000938
939 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000940 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000941 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
942 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000943 cricket::LOCAL_PORT_TYPE,
944 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000946 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
947 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000948 cricket::LOCAL_PORT_TYPE,
949 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000950 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000951 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
952 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000953 cricket::LOCAL_PORT_TYPE,
954 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000955 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000956 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
957 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000958 cricket::LOCAL_PORT_TYPE,
959 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000960
961 // stun
962 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000963 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
964 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000965 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
966 address_stun, kCandidatePriority, "", "",
967 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000968 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969 candidate9.set_related_address(rel_address_stun);
970
971 address_stun.SetPort(port_stun++);
972 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000973 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
974 address_stun, kCandidatePriority, "", "",
975 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000976 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000977 candidate10.set_related_address(rel_address_stun);
978
979 // relay
980 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000981 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000982 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
983 address_relay, kCandidatePriority, "", "",
984 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000985 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000986 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000987 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
988 address_relay, kCandidatePriority, "", "",
989 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000990 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000991
992 // voice
993 candidates_.push_back(candidate1);
994 candidates_.push_back(candidate2);
995 candidates_.push_back(candidate5);
996 candidates_.push_back(candidate6);
997 candidates_.push_back(candidate9);
998 candidates_.push_back(candidate10);
999
1000 // video
1001 candidates_.push_back(candidate3);
1002 candidates_.push_back(candidate4);
1003 candidates_.push_back(candidate7);
1004 candidates_.push_back(candidate8);
1005 candidates_.push_back(candidate11);
1006 candidates_.push_back(candidate12);
1007
Yves Gerey665174f2018-06-19 15:03:05 +02001008 jcandidate_.reset(
1009 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001010
1011 // Set up JsepSessionDescription.
1012 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
1013 std::string mline_id;
1014 int mline_index = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001015 for (size_t i = 0; i < candidates_.size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001016 // In this test, the audio m line index will be 0, and the video m line
1017 // will be 1.
1018 bool is_video = (i > 5);
1019 mline_id = is_video ? "video_content_name" : "audio_content_name";
1020 mline_index = is_video ? 1 : 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001021 JsepIceCandidate jice(mline_id, mline_index, candidates_.at(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001022 jdesc_.AddCandidate(&jice);
1023 }
1024 }
1025
Seth Hampson5b4f0752018-04-02 16:31:36 -07001026 void RemoveVideoCandidates() {
deadbeef25ed4352016-12-12 18:37:36 -08001027 const IceCandidateCollection* video_candidates_collection =
1028 jdesc_.candidates(1);
1029 ASSERT_NE(nullptr, video_candidates_collection);
1030 std::vector<cricket::Candidate> video_candidates;
1031 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1032 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1033 c.set_transport_name("video_content_name");
1034 video_candidates.push_back(c);
1035 }
1036 jdesc_.RemoveCandidates(video_candidates);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001037 }
1038
1039 // Turns the existing reference description into a description using
1040 // a=bundle-only. This means no transport attributes and a 0 port value on
1041 // the m= sections not associated with the BUNDLE-tag.
1042 void MakeBundleOnlyDescription() {
1043 RemoveVideoCandidates();
deadbeef25ed4352016-12-12 18:37:36 -08001044
1045 // And the rest of the transport attributes.
1046 desc_.transport_infos()[1].description.ice_ufrag.clear();
1047 desc_.transport_infos()[1].description.ice_pwd.clear();
1048 desc_.transport_infos()[1].description.connection_role =
1049 cricket::CONNECTIONROLE_NONE;
1050
1051 // Set bundle-only flag.
1052 desc_.contents()[1].bundle_only = true;
1053
1054 // Add BUNDLE group.
1055 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1056 group.AddContentName(kAudioContentName);
1057 group.AddContentName(kVideoContentName);
1058 desc_.AddGroup(group);
1059
1060 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1061 jdesc_.session_version()));
1062 }
1063
deadbeef9d3584c2016-02-16 17:54:10 -08001064 // Turns the existing reference description into a plan B description,
1065 // with 2 audio tracks and 3 video tracks.
1066 void MakePlanBDescription() {
Steve Antonb1c1de12017-12-21 15:14:30 -08001067 audio_desc_ = audio_desc_->Copy();
1068 video_desc_ = video_desc_->Copy();
deadbeef9d3584c2016-02-16 17:54:10 -08001069
1070 StreamParams audio_track_2;
1071 audio_track_2.id = kAudioTrackId2;
1072 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001073 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001074 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1075 audio_desc_->AddStream(audio_track_2);
1076
1077 StreamParams video_track_2;
1078 video_track_2.id = kVideoTrackId2;
1079 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001080 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001081 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1082 video_desc_->AddStream(video_track_2);
1083
1084 StreamParams video_track_3;
1085 video_track_3.id = kVideoTrackId3;
1086 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001087 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001088 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1089 video_desc_->AddStream(video_track_3);
1090
1091 desc_.RemoveContentByName(kAudioContentName);
1092 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001093 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1094 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001095
1096 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1097 jdesc_.session_version()));
1098 }
1099
1100 // Turns the existing reference description into a unified plan description,
1101 // with 2 audio tracks and 3 video tracks.
1102 void MakeUnifiedPlanDescription() {
1103 // Audio track 2.
1104 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1105 StreamParams audio_track_2;
1106 audio_track_2.id = kAudioTrackId2;
1107 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001108 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001109 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1110 audio_desc_2->AddStream(audio_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001111 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
deadbeef9d3584c2016-02-16 17:54:10 -08001112 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1113 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
deadbeef9d3584c2016-02-16 17:54:10 -08001114 // Video track 2, in stream 2.
1115 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1116 StreamParams video_track_2;
1117 video_track_2.id = kVideoTrackId2;
1118 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001119 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001120 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1121 video_desc_2->AddStream(video_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001122 desc_.AddContent(kVideoContentName2, MediaProtocolType::kRtp, video_desc_2);
deadbeef9d3584c2016-02-16 17:54:10 -08001123 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1124 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2))));
1125
1126 // Video track 3, in stream 2.
1127 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1128 StreamParams video_track_3;
1129 video_track_3.id = kVideoTrackId3;
1130 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001131 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001132 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1133 video_desc_3->AddStream(video_track_3);
Steve Anton5adfafd2017-12-20 16:34:00 -08001134 desc_.AddContent(kVideoContentName3, MediaProtocolType::kRtp, video_desc_3);
deadbeef9d3584c2016-02-16 17:54:10 -08001135 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1136 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3))));
Steve Antone831b8c2018-02-01 12:22:16 -08001137 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
deadbeef9d3584c2016-02-16 17:54:10 -08001138
1139 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1140 jdesc_.session_version()));
1141 }
1142
1143 // Creates an audio content description with no streams, and some default
1144 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001145 AudioContentDescription* CreateAudioContentDescription() {
1146 AudioContentDescription* audio = new AudioContentDescription();
1147 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -08001148 audio->set_rtcp_reduced_size(true);
Yves Gerey665174f2018-06-19 15:03:05 +02001149 audio->AddCrypto(CryptoParams(
1150 1, "AES_CM_128_HMAC_SHA1_32",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001151 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1152 "dummy_session_params"));
1153 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef67cf2c12016-04-13 10:07:16 -07001154 AudioCodec opus(111, "opus", 48000, 0, 2);
deadbeef9d3584c2016-02-16 17:54:10 -08001155 audio->AddCodec(opus);
ossue1405ad2017-01-23 08:55:48 -08001156 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1157 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001158 return audio;
1159 }
1160
Seth Hampson5b4f0752018-04-02 16:31:36 -07001161 // Turns the existing reference description into a unified plan description,
1162 // with 3 audio MediaContentDescriptions with special StreamParams that
1163 // contain 0 or multiple stream ids: - audio track 1 has 1 media stream id -
1164 // audio track 2 has 2 media stream ids - audio track 3 has 0 media stream ids
1165 void MakeUnifiedPlanDescriptionMultipleStreamIds() {
1166 desc_.RemoveContentByName(kVideoContentName);
1167 desc_.RemoveTransportInfoByName(kVideoContentName);
1168 RemoveVideoCandidates();
1169
1170 // Audio track 2 has 2 media stream ids.
1171 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1172 StreamParams audio_track_2;
1173 audio_track_2.id = kAudioTrackId2;
1174 audio_track_2.cname = kStream1Cname;
1175 audio_track_2.set_stream_ids({kStreamId1, kStreamId2});
1176 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1177 audio_desc_2->AddStream(audio_track_2);
1178 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
1179 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1180 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
1181
1182 // Audio track 3 has no stream ids.
1183 AudioContentDescription* audio_desc_3 = CreateAudioContentDescription();
1184 StreamParams audio_track_3;
1185 audio_track_3.id = kAudioTrackId3;
1186 audio_track_3.cname = kStream2Cname;
1187 audio_track_3.set_stream_ids({});
1188 audio_track_3.ssrcs.push_back(kAudioTrack3Ssrc);
1189 audio_desc_3->AddStream(audio_track_3);
1190 desc_.AddContent(kAudioContentName3, MediaProtocolType::kRtp, audio_desc_3);
1191 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1192 kAudioContentName3, TransportDescription(kUfragVoice3, kPwdVoice3))));
1193 // Make sure to create both a=msid lines.
1194 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection |
1195 cricket::kMsidSignalingSsrcAttribute);
1196 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1197 jdesc_.session_version()));
1198 }
1199
Seth Hampson5897a6e2018-04-03 11:16:33 -07001200 // Turns the existing reference description into a unified plan description
1201 // with one audio MediaContentDescription that contains one StreamParams with
1202 // 0 ssrcs.
1203 void MakeUnifiedPlanDescriptionNoSsrcSignaling() {
1204 desc_.RemoveContentByName(kVideoContentName);
1205 desc_.RemoveContentByName(kAudioContentName);
1206 desc_.RemoveTransportInfoByName(kVideoContentName);
1207 RemoveVideoCandidates();
1208
1209 AudioContentDescription* audio_desc = CreateAudioContentDescription();
1210 StreamParams audio_track;
1211 audio_track.id = kAudioTrackId1;
1212 audio_track.set_stream_ids({kStreamId1});
1213 audio_desc->AddStream(audio_track);
1214 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc);
1215
1216 // Enable signaling a=msid lines.
1217 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
1218 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1219 jdesc_.session_version()));
1220 }
1221
deadbeef9d3584c2016-02-16 17:54:10 -08001222 // Creates a video content description with no streams, and some default
1223 // configuration.
1224 VideoContentDescription* CreateVideoContentDescription() {
1225 VideoContentDescription* video = new VideoContentDescription();
1226 video->AddCrypto(CryptoParams(
1227 1, "AES_CM_128_HMAC_SHA1_80",
1228 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1229 video->set_protocol(cricket::kMediaProtocolSavpf);
1230 video->AddCodec(
perkj26752742016-10-24 01:21:16 -07001231 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-16 17:54:10 -08001232 return video;
1233 }
1234
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001235 template <class MCD>
Yves Gerey665174f2018-06-19 15:03:05 +02001236 void CompareMediaContentDescription(const MCD* cd1, const MCD* cd2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001237 // type
1238 EXPECT_EQ(cd1->type(), cd1->type());
1239
1240 // content direction
1241 EXPECT_EQ(cd1->direction(), cd2->direction());
1242
1243 // rtcp_mux
1244 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1245
deadbeef13871492015-12-09 12:37:51 -08001246 // rtcp_reduced_size
1247 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1248
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001249 // cryptos
1250 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1251 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1252 ADD_FAILURE();
1253 return;
1254 }
Yves Gerey665174f2018-06-19 15:03:05 +02001255 for (size_t i = 0; i < cd1->cryptos().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001256 const CryptoParams c1 = cd1->cryptos().at(i);
1257 const CryptoParams c2 = cd2->cryptos().at(i);
1258 EXPECT_TRUE(c1.Matches(c2));
1259 EXPECT_EQ(c1.key_params, c2.key_params);
1260 EXPECT_EQ(c1.session_params, c2.session_params);
1261 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001262
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001263 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001264 // Use an equivalence class here, for old and new versions of the
1265 // protocol description.
Yves Gerey665174f2018-06-19 15:03:05 +02001266 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp ||
1267 cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1268 cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
lally@webrtc.org36300852015-02-24 20:19:35 +00001269 const bool cd2_is_also_dtls_sctp =
Yves Gerey665174f2018-06-19 15:03:05 +02001270 cd2->protocol() == cricket::kMediaProtocolDtlsSctp ||
1271 cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1272 cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
lally@webrtc.org36300852015-02-24 20:19:35 +00001273 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001274 } else {
1275 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1276 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001277
1278 // codecs
1279 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1280
1281 // bandwidth
1282 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1283
1284 // streams
1285 EXPECT_EQ(cd1->streams(), cd2->streams());
1286
Johannes Kron0854eb62018-10-10 22:33:20 +02001287 // extmap-allow-mixed
Johannes Kron9ac3c912018-10-12 10:54:26 +02001288 EXPECT_EQ(cd1->extmap_allow_mixed_headers(),
1289 cd2->extmap_allow_mixed_headers());
Johannes Kron0854eb62018-10-10 22:33:20 +02001290
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001291 // extmap
1292 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1293 cd2->rtp_header_extensions().size());
Yves Gerey665174f2018-06-19 15:03:05 +02001294 for (size_t i = 0; i < cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 11:24:55 -07001295 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1296 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001297 EXPECT_EQ(ext1.uri, ext2.uri);
1298 EXPECT_EQ(ext1.id, ext2.id);
jbauch5869f502017-06-29 12:31:36 -07001299 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001300 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001301 }
1302
zstein4b2e0822017-02-17 19:48:38 -08001303 void CompareDataContentDescription(const DataContentDescription* dcd1,
1304 const DataContentDescription* dcd2) {
1305 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
1306 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
1307 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001308
1309 void CompareSessionDescription(const SessionDescription& desc1,
1310 const SessionDescription& desc2) {
1311 // Compare content descriptions.
1312 if (desc1.contents().size() != desc2.contents().size()) {
1313 ADD_FAILURE();
1314 return;
1315 }
Yves Gerey665174f2018-06-19 15:03:05 +02001316 for (size_t i = 0; i < desc1.contents().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001317 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1318 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-12 18:37:36 -08001319 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001320 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-12 18:37:36 -08001321 EXPECT_EQ(c1.type, c2.type);
1322 EXPECT_EQ(c1.rejected, c2.rejected);
1323 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001324
1325 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1326 if (IsAudioContent(&c1)) {
1327 const AudioContentDescription* acd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001328 c1.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001329 const AudioContentDescription* acd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001330 c2.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001331 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1332 }
1333
1334 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1335 if (IsVideoContent(&c1)) {
1336 const VideoContentDescription* vcd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001337 c1.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001338 const VideoContentDescription* vcd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001339 c2.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001340 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1341 }
1342
1343 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
1344 if (IsDataContent(&c1)) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001345 const DataContentDescription* dcd1 = c1.media_description()->as_data();
1346 const DataContentDescription* dcd2 = c2.media_description()->as_data();
zstein4b2e0822017-02-17 19:48:38 -08001347 CompareDataContentDescription(dcd1, dcd2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001348 }
1349 }
1350
1351 // group
1352 const cricket::ContentGroups groups1 = desc1.groups();
1353 const cricket::ContentGroups groups2 = desc2.groups();
1354 EXPECT_EQ(groups1.size(), groups1.size());
1355 if (groups1.size() != groups2.size()) {
1356 ADD_FAILURE();
1357 return;
1358 }
1359 for (size_t i = 0; i < groups1.size(); ++i) {
1360 const cricket::ContentGroup group1 = groups1.at(i);
1361 const cricket::ContentGroup group2 = groups2.at(i);
1362 EXPECT_EQ(group1.semantics(), group2.semantics());
1363 const cricket::ContentNames names1 = group1.content_names();
1364 const cricket::ContentNames names2 = group2.content_names();
1365 EXPECT_EQ(names1.size(), names2.size());
1366 if (names1.size() != names2.size()) {
1367 ADD_FAILURE();
1368 return;
1369 }
1370 cricket::ContentNames::const_iterator iter1 = names1.begin();
1371 cricket::ContentNames::const_iterator iter2 = names2.begin();
1372 while (iter1 != names1.end()) {
1373 EXPECT_EQ(*iter1++, *iter2++);
1374 }
1375 }
1376
1377 // transport info
1378 const cricket::TransportInfos transports1 = desc1.transport_infos();
1379 const cricket::TransportInfos transports2 = desc2.transport_infos();
1380 EXPECT_EQ(transports1.size(), transports2.size());
1381 if (transports1.size() != transports2.size()) {
1382 ADD_FAILURE();
1383 return;
1384 }
1385 for (size_t i = 0; i < transports1.size(); ++i) {
1386 const cricket::TransportInfo transport1 = transports1.at(i);
1387 const cricket::TransportInfo transport2 = transports2.at(i);
1388 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001389 EXPECT_EQ(transport1.description.ice_ufrag,
1390 transport2.description.ice_ufrag);
Yves Gerey665174f2018-06-19 15:03:05 +02001391 EXPECT_EQ(transport1.description.ice_pwd, transport2.description.ice_pwd);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07001392 EXPECT_EQ(transport1.description.ice_mode,
1393 transport2.description.ice_mode);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001394 if (transport1.description.identity_fingerprint) {
1395 EXPECT_EQ(*transport1.description.identity_fingerprint,
1396 *transport2.description.identity_fingerprint);
1397 } else {
1398 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1399 transport2.description.identity_fingerprint.get());
1400 }
1401 EXPECT_EQ(transport1.description.transport_options,
1402 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001403 }
deadbeefc80741f2015-10-22 13:14:45 -07001404
1405 // global attributes
1406 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
Johannes Kron9ac3c912018-10-12 10:54:26 +02001407 EXPECT_EQ(desc1.extmap_allow_mixed_headers(),
1408 desc2.extmap_allow_mixed_headers());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001409 }
1410
Yves Gerey665174f2018-06-19 15:03:05 +02001411 bool CompareSessionDescription(const JsepSessionDescription& desc1,
1412 const JsepSessionDescription& desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001413 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1414 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1415 CompareSessionDescription(*desc1.description(), *desc2.description());
1416 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1417 return false;
1418 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1419 const IceCandidateCollection* cc1 = desc1.candidates(i);
1420 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-12 18:37:36 -08001421 if (cc1->count() != cc2->count()) {
1422 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001423 return false;
deadbeef25ed4352016-12-12 18:37:36 -08001424 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001425 for (size_t j = 0; j < cc1->count(); ++j) {
1426 const IceCandidateInterface* c1 = cc1->at(j);
1427 const IceCandidateInterface* c2 = cc2->at(j);
1428 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1429 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1430 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1431 }
1432 }
1433 return true;
1434 }
1435
1436 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1437 // them with invalid keywords so that the parser will just ignore them.
1438 bool RemoveCandidateUfragPwd(std::string* sdp) {
1439 const char ice_ufrag[] = "a=ice-ufrag";
1440 const char ice_ufragx[] = "a=xice-ufrag";
1441 const char ice_pwd[] = "a=ice-pwd";
1442 const char ice_pwdx[] = "a=xice-pwd";
Yves Gerey665174f2018-06-19 15:03:05 +02001443 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag), ice_ufragx,
1444 strlen(ice_ufragx), sdp);
1445 rtc::replace_substrs(ice_pwd, strlen(ice_pwd), ice_pwdx, strlen(ice_pwdx),
1446 sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001447 return true;
1448 }
1449
1450 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
Yves Gerey665174f2018-06-19 15:03:05 +02001451 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc,
1452 int mline_index,
1453 const std::string& ufrag,
1454 const std::string& pwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001455 std::string content_name;
1456 if (mline_index == 0) {
1457 content_name = kAudioContentName;
1458 } else if (mline_index == 1) {
1459 content_name = kVideoContentName;
1460 } else {
nissec80e7412017-01-11 05:56:46 -08001461 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001462 }
Yves Gerey665174f2018-06-19 15:03:05 +02001463 TransportInfo transport_info(content_name,
1464 TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001465 SessionDescription* desc =
1466 const_cast<SessionDescription*>(jdesc->description());
1467 desc->RemoveTransportInfoByName(content_name);
1468 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
1469 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1470 const IceCandidateCollection* cc = jdesc_.candidates(i);
1471 for (size_t j = 0; j < cc->count(); ++j) {
1472 if (cc->at(j)->sdp_mline_index() == mline_index) {
Yves Gerey665174f2018-06-19 15:03:05 +02001473 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(ufrag);
1474 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001475 }
1476 }
1477 }
1478 return true;
1479 }
1480
1481 void AddIceOptions(const std::string& content_name,
1482 const std::vector<std::string>& transport_options) {
1483 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1484 cricket::TransportInfo transport_info =
1485 *(desc_.GetTransportInfoByName(content_name));
1486 desc_.RemoveTransportInfoByName(content_name);
1487 transport_info.description.transport_options = transport_options;
1488 desc_.AddTransportInfo(transport_info);
1489 }
1490
deadbeef3f7219b2015-12-28 15:17:14 -08001491 void SetIceUfragPwd(const std::string& content_name,
1492 const std::string& ice_ufrag,
1493 const std::string& ice_pwd) {
1494 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1495 cricket::TransportInfo transport_info =
1496 *(desc_.GetTransportInfoByName(content_name));
1497 desc_.RemoveTransportInfoByName(content_name);
1498 transport_info.description.ice_ufrag = ice_ufrag;
1499 transport_info.description.ice_pwd = ice_pwd;
1500 desc_.AddTransportInfo(transport_info);
1501 }
1502
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001503 void AddFingerprint() {
1504 desc_.RemoveTransportInfoByName(kAudioContentName);
1505 desc_.RemoveTransportInfoByName(kVideoContentName);
Mirko Bonadei6932fb22018-10-15 14:18:03 +00001506 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, kIdentityDigest,
1507 sizeof(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
1551 // Removes all a=ssrc lines from the SDP string.
1552 void RemoveSsrcLinesFromSdpString(std::string* sdp_string) {
1553 const char kAttributeSsrc[] = "a=ssrc";
1554 while (sdp_string->find(kAttributeSsrc) != std::string::npos) {
1555 size_t pos_ssrc_attribute = sdp_string->find(kAttributeSsrc);
1556 size_t beg_line_pos = sdp_string->rfind('\n', pos_ssrc_attribute);
1557 size_t end_line_pos = sdp_string->find('\n', pos_ssrc_attribute);
1558 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1559 }
1560 }
1561
Steve Anton4e70a722017-11-28 14:57:10 -08001562 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001563 audio_desc_->set_direction(direction);
1564 video_desc_->set_direction(direction);
1565 std::string new_sdp = kSdpFullString;
1566 ReplaceDirection(direction, &new_sdp);
1567
Yves Gerey665174f2018-06-19 15:03:05 +02001568 if (!jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001569 jdesc_.session_version())) {
1570 return false;
1571 }
Steve Antone831b8c2018-02-01 12:22:16 -08001572 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001573 EXPECT_EQ(new_sdp, message);
1574 return true;
1575 }
1576
1577 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001578 audio_desc_ = audio_desc_->Copy();
1579 video_desc_ = video_desc_->Copy();
zhihuang38989e52017-03-21 11:04:53 -07001580
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001581 desc_.RemoveContentByName(kAudioContentName);
1582 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001583 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001584 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001585 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001586 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001587 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1588 audio_rejected ? "" : kPwdVoice);
1589 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1590 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001591
1592 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001593 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1594
Steve Antona3a92c22017-12-07 10:27:41 -08001595 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001596 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001597 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001598 EXPECT_EQ(new_sdp, message);
1599 return true;
1600 }
1601
zstein4b2e0822017-02-17 19:48:38 -08001602 void AddSctpDataChannel(bool use_sctpmap) {
kwibergd1fe2812016-04-27 06:47:29 -07001603 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001604 data_desc_ = data.get();
zstein4b2e0822017-02-17 19:48:38 -08001605 data_desc_->set_use_sctpmap(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001606 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
solenberg9fa49752016-10-08 13:02:44 -07001607 DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07001608 cricket::kGoogleSctpDataCodecName);
wu@webrtc.org78187522013-10-07 23:32:02 +00001609 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1610 data_desc_->AddCodec(codec);
Steve Anton5adfafd2017-12-20 16:34:00 -08001611 desc_.AddContent(kDataContentName, MediaProtocolType::kSctp,
1612 data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001613 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1614 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001615 }
1616
1617 void AddRtpDataChannel() {
kwibergd1fe2812016-04-27 06:47:29 -07001618 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001619 data_desc_ = data.get();
1620
deadbeef67cf2c12016-04-13 10:07:16 -07001621 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001622 StreamParams data_stream;
1623 data_stream.id = kDataChannelMsid;
1624 data_stream.cname = kDataChannelCname;
Seth Hampson845e8782018-03-02 11:34:10 -08001625 data_stream.set_stream_ids({kDataChannelLabel});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001626 data_stream.ssrcs.push_back(kDataChannelSsrc);
1627 data_desc_->AddStream(data_stream);
Yves Gerey665174f2018-06-19 15:03:05 +02001628 data_desc_->AddCrypto(
1629 CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
1630 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001631 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
Steve Anton5adfafd2017-12-20 16:34:00 -08001632 desc_.AddContent(kDataContentName, MediaProtocolType::kRtp, data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001633 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1634 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001635 }
1636
Steve Anton4e70a722017-11-28 14:57:10 -08001637 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001638 std::string new_sdp = kSdpFullString;
1639 ReplaceDirection(direction, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001640 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001641
1642 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1643
1644 audio_desc_->set_direction(direction);
1645 video_desc_->set_direction(direction);
Yves Gerey665174f2018-06-19 15:03:05 +02001646 if (!jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001647 jdesc_.session_version())) {
1648 return false;
1649 }
1650 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1651 return true;
1652 }
1653
1654 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001655 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001656 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001657 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001658 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001659
Steve Antonb1c1de12017-12-21 15:14:30 -08001660 audio_desc_ = audio_desc_->Copy();
1661 video_desc_ = video_desc_->Copy();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001662 desc_.RemoveContentByName(kAudioContentName);
1663 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001664 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001665 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001666 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001667 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001668 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1669 audio_rejected ? "" : kPwdVoice);
1670 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1671 video_rejected ? "" : kPwdVideo);
Steve Antona3a92c22017-12-07 10:27:41 -08001672 JsepSessionDescription jdesc_no_candidates(kDummyType);
deadbeef3f7219b2015-12-28 15:17:14 -08001673 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1674 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001675 return false;
1676 }
deadbeef3f7219b2015-12-28 15:17:14 -08001677 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001678 return true;
1679 }
1680
Yves Gerey665174f2018-06-19 15:03:05 +02001681 void TestDeserializeExtmap(bool session_level,
1682 bool media_level,
1683 bool encrypted) {
jbauch5869f502017-06-29 12:31:36 -07001684 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08001685 JsepSessionDescription new_jdesc(SdpType::kOffer);
Yves Gerey665174f2018-06-19 15:03:05 +02001686 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001687 jdesc_.session_version()));
Steve Antona3a92c22017-12-07 10:27:41 -08001688 JsepSessionDescription jdesc_with_extmap(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001689 std::string sdp_with_extmap = kSdpString;
1690 if (session_level) {
jbauch5869f502017-06-29 12:31:36 -07001691 InjectAfter(kSessionTime,
1692 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1693 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001694 &sdp_with_extmap);
1695 }
1696 if (media_level) {
jbauch5869f502017-06-29 12:31:36 -07001697 InjectAfter(kAttributeIcePwdVoice,
1698 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1699 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001700 &sdp_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07001701 InjectAfter(kAttributeIcePwdVideo,
1702 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1703 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001704 &sdp_with_extmap);
1705 }
1706 // The extmap can't be present at the same time in both session level and
1707 // media level.
1708 if (session_level && media_level) {
1709 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02001710 EXPECT_FALSE(
1711 webrtc::SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001712 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1713 } else {
1714 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1715 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1716 }
1717 }
1718
1719 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
Yves Gerey665174f2018-06-19 15:03:05 +02001720 const std::string& name,
1721 int expected_value) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001722 cricket::CodecParameterMap::const_iterator found = params.find(name);
1723 ASSERT_TRUE(found != params.end());
Jonas Olsson6b1985d2018-07-05 11:59:48 +02001724 EXPECT_EQ(found->second, rtc::ToString(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001725 }
1726
1727 void TestDeserializeCodecParams(const CodecParams& params,
1728 JsepSessionDescription* jdesc_output) {
1729 std::string sdp =
1730 "v=0\r\n"
1731 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1732 "s=-\r\n"
1733 "t=0 0\r\n"
1734 // Include semantics for WebRTC Media Streams since it is supported by
1735 // this parser, and will be added to the SDP when serializing a session
1736 // description.
1737 "a=msid-semantic: WMS\r\n"
1738 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001739 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001740 // Pltype 111 listed before 103 and 104 in the map.
1741 "a=rtpmap:111 opus/48000/2\r\n"
1742 // Pltype 103 listed before 104.
1743 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001744 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001745 "a=fmtp:111 0-15,66,70\r\n"
1746 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001747 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001748 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001749 << "; sprop-stereo=" << params.sprop_stereo
1750 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001751 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001752 << "a=ptime:" << params.ptime << "\r\n"
1753 << "a=maxptime:" << params.max_ptime << "\r\n";
1754 sdp += os.str();
1755
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001756 os.clear();
1757 os.str("");
1758 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001759 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001760 << "a=rtpmap:99 VP8/90000\r\n"
1761 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001762 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001763 sdp += os.str();
1764
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765 // Deserialize
1766 SdpParseError error;
1767 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1768
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001769 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001770 GetFirstAudioContentDescription(jdesc_output->description());
1771 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001772 ASSERT_FALSE(acd->codecs().empty());
1773 cricket::AudioCodec opus = acd->codecs()[0];
1774 EXPECT_EQ("opus", opus.name);
1775 EXPECT_EQ(111, opus.id);
1776 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1777 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1778 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1779 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001780 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1781 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001782 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1783 cricket::AudioCodec codec = acd->codecs()[i];
1784 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1785 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001786 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001787
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001788 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001789 GetFirstVideoContentDescription(jdesc_output->description());
1790 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001791 ASSERT_FALSE(vcd->codecs().empty());
1792 cricket::VideoCodec vp8 = vcd->codecs()[0];
1793 EXPECT_EQ("VP8", vp8.name);
1794 EXPECT_EQ(99, vp8.id);
1795 cricket::VideoCodec rtx = vcd->codecs()[1];
1796 EXPECT_EQ("RTX", rtx.name);
1797 EXPECT_EQ(95, rtx.id);
1798 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001799 }
1800
1801 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1802 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001803 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001804 "v=0\r\n"
1805 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1806 "s=-\r\n"
1807 "t=0 0\r\n"
1808 // Include semantics for WebRTC Media Streams since it is supported by
1809 // this parser, and will be added to the SDP when serializing a session
1810 // description.
1811 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001812 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001813 "a=rtpmap:111 opus/48000/2\r\n";
1814 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001815 "m=video 3457 RTP/SAVPF 101\r\n"
1816 "a=rtpmap:101 VP8/90000\r\n"
1817 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001818 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001819 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001820 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001821 os << sdp_session_and_audio;
Yves Gerey665174f2018-06-19 15:03:05 +02001822 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001823 os << sdp_video;
Yves Gerey665174f2018-06-19 15:03:05 +02001824 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001825 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001826 // Deserialize
1827 SdpParseError error;
1828 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001829 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001830 GetFirstAudioContentDescription(jdesc_output->description());
1831 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001832 ASSERT_FALSE(acd->codecs().empty());
1833 cricket::AudioCodec opus = acd->codecs()[0];
1834 EXPECT_EQ(111, opus.id);
Yves Gerey665174f2018-06-19 15:03:05 +02001835 EXPECT_TRUE(opus.HasFeedbackParam(cricket::FeedbackParam(
1836 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001837
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001838 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001839 GetFirstVideoContentDescription(jdesc_output->description());
1840 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001841 ASSERT_FALSE(vcd->codecs().empty());
1842 cricket::VideoCodec vp8 = vcd->codecs()[0];
1843 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1844 vp8.name.c_str());
1845 EXPECT_EQ(101, vp8.id);
Yves Gerey665174f2018-06-19 15:03:05 +02001846 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1847 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
1848 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1849 cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli)));
1850 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1851 cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty)));
1852 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1853 cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001854 }
1855
1856 // Two SDP messages can mean the same thing but be different strings, e.g.
1857 // some of the lines can be serialized in different order.
1858 // However, a deserialized description can be compared field by field and has
1859 // no order. If deserializer has already been tested, serializing then
1860 // deserializing and comparing JsepSessionDescription will test
1861 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 12:22:16 -08001862 void TestSerialize(const JsepSessionDescription& jdesc) {
1863 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 10:27:41 -08001864 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001865 SdpParseError error;
1866 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1867 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1868 }
1869
zhihuang38989e52017-03-21 11:04:53 -07001870 // Calling 'Initialize' with a copy of the inner SessionDescription will
1871 // create a copy of the JsepSessionDescription without candidates. The
1872 // 'connection address' field, previously set from the candidates, must also
1873 // be reset.
1874 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
1875 rtc::SocketAddress audio_addr("0.0.0.0", 9);
1876 rtc::SocketAddress video_addr("0.0.0.0", 9);
1877 audio_desc_->set_connection_address(audio_addr);
1878 video_desc_->set_connection_address(video_addr);
1879 ASSERT_TRUE(jdesc->Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1880 }
1881
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001882 protected:
1883 SessionDescription desc_;
1884 AudioContentDescription* audio_desc_;
1885 VideoContentDescription* video_desc_;
1886 DataContentDescription* data_desc_;
1887 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07001888 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001889 JsepSessionDescription jdesc_;
1890};
1891
1892void TestMismatch(const std::string& string1, const std::string& string2) {
1893 int position = 0;
1894 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1895 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001896 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001897 break;
1898 }
1899 }
1900 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1901 << " character\n"
1902 << " 1: " << string1.substr(position, 20) << "\n"
1903 << " 2: " << string2.substr(position, 20) << "\n";
1904}
1905
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001906TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1907 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 12:22:16 -08001908 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001909 TestMismatch(std::string(kSdpFullString), message);
1910}
1911
1912TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 10:27:41 -08001913 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 12:22:16 -08001914 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001915}
1916
1917// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1918// the case in a DTLS offer.
1919TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1920 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08001921 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001922 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08001923 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001924
1925 std::string sdp_with_fingerprint = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02001926 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1927 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001928
1929 EXPECT_EQ(sdp_with_fingerprint, message);
1930}
1931
1932// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1933// be the case in a DTLS answer.
1934TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1935 AddFingerprint();
1936 RemoveCryptos();
Steve Antona3a92c22017-12-07 10:27:41 -08001937 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001938 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08001939 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001940
1941 std::string sdp_with_fingerprint = kSdpString;
1942 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1943 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
Yves Gerey665174f2018-06-19 15:03:05 +02001944 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1945 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001946
1947 EXPECT_EQ(sdp_with_fingerprint, message);
1948}
1949
1950TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1951 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08001952 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001953 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001954 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001955 EXPECT_EQ(std::string(kSdpString), message);
1956}
1957
1958TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1959 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1960 group.AddContentName(kAudioContentName);
1961 group.AddContentName(kVideoContentName);
1962 desc_.AddGroup(group);
Yves Gerey665174f2018-06-19 15:03:05 +02001963 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001964 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08001965 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001966 std::string sdp_with_bundle = kSdpFullString;
1967 InjectAfter(kSessionTime,
1968 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1969 &sdp_with_bundle);
1970 EXPECT_EQ(sdp_with_bundle, message);
1971}
1972
1973TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001974 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001975 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08001976 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001977 acd->set_bandwidth(50 * 1000);
Yves Gerey665174f2018-06-19 15:03:05 +02001978 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001979 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08001980 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001981 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02001982 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001983 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02001984 InjectAfter("c=IN IP4 74.125.127.126\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001985 &sdp_with_bandwidth);
1986 EXPECT_EQ(sdp_with_bandwidth, message);
1987}
1988
1989TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1990 std::vector<std::string> transport_options;
1991 transport_options.push_back(kIceOption1);
1992 transport_options.push_back(kIceOption3);
1993 AddIceOptions(kAudioContentName, transport_options);
1994 transport_options.clear();
1995 transport_options.push_back(kIceOption2);
1996 transport_options.push_back(kIceOption3);
1997 AddIceOptions(kVideoContentName, transport_options);
Yves Gerey665174f2018-06-19 15:03:05 +02001998 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001999 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002000 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002001 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002002 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002003 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002004 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002005 &sdp_with_ice_options);
2006 EXPECT_EQ(sdp_with_ice_options, message);
2007}
2008
2009TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002010 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002011}
2012
2013TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002014 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002015}
2016
2017TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002018 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002019}
2020
2021TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2022 EXPECT_TRUE(TestSerializeRejected(true, false));
2023}
2024
2025TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2026 EXPECT_TRUE(TestSerializeRejected(false, true));
2027}
2028
2029TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2030 EXPECT_TRUE(TestSerializeRejected(true, true));
2031}
2032
2033TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
2034 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002035 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002036
zhihuang38989e52017-03-21 11:04:53 -07002037 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002038 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002039
2040 std::string expected_sdp = kSdpString;
2041 expected_sdp.append(kSdpRtpDataChannelString);
2042 EXPECT_EQ(expected_sdp, message);
2043}
2044
2045TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08002046 bool use_sctpmap = true;
2047 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002048 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002049
zhihuang38989e52017-03-21 11:04:53 -07002050 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002051 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002052
2053 std::string expected_sdp = kSdpString;
2054 expected_sdp.append(kSdpSctpDataChannelString);
2055 EXPECT_EQ(message, expected_sdp);
2056}
2057
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002058TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08002059 bool use_sctpmap = true;
2060 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002061 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002062 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antonb1c1de12017-12-21 15:14:30 -08002063 DataContentDescription* dcdesc =
2064 jsep_desc.description()
2065 ->GetContentDescriptionByName(kDataContentName)
2066 ->as_data();
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002067
2068 const int kNewPort = 1234;
solenberg9fa49752016-10-08 13:02:44 -07002069 cricket::DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07002070 cricket::kGoogleSctpDataCodecName);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002071 codec.SetParam(cricket::kCodecParamPort, kNewPort);
2072 dcdesc->AddOrReplaceCodec(codec);
2073
Steve Antone831b8c2018-02-01 12:22:16 -08002074 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002075
2076 std::string expected_sdp = kSdpString;
2077 expected_sdp.append(kSdpSctpDataChannelString);
2078
2079 char default_portstr[16];
2080 char new_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002081 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
Yves Gerey665174f2018-06-19 15:03:05 +02002082 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002083 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
Yves Gerey665174f2018-06-19 15:03:05 +02002084 rtc::replace_substrs(default_portstr, strlen(default_portstr), new_portstr,
2085 strlen(new_portstr), &expected_sdp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002086
2087 EXPECT_EQ(expected_sdp, message);
2088}
2089
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002090TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002091 JsepSessionDescription jsep_desc(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002092 AddRtpDataChannel();
Yves Gerey665174f2018-06-19 15:03:05 +02002093 data_desc_->set_bandwidth(100 * 1000);
zhihuang38989e52017-03-21 11:04:53 -07002094 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002095 std::string message = webrtc::SdpSerialize(jsep_desc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002096
2097 std::string expected_sdp = kSdpString;
2098 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002099 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00002100 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02002101 "b=AS:100\r\n", &expected_sdp);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002102 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002103}
2104
Johannes Kron0854eb62018-10-10 22:33:20 +02002105TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9ac3c912018-10-12 10:54:26 +02002106 jdesc_.description()->set_extmap_allow_mixed_headers(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002107 TestSerialize(jdesc_);
2108}
2109
2110TEST_F(WebRtcSdpTest, SerializeMediaContentDescriptionWithExtmapAllowMixed) {
2111 cricket::MediaContentDescription* video_desc =
2112 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2113 ASSERT_TRUE(video_desc);
2114 cricket::MediaContentDescription* audio_desc =
2115 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2116 ASSERT_TRUE(audio_desc);
Johannes Kron9ac3c912018-10-12 10:54:26 +02002117 video_desc->set_extmap_allow_mixed_headers(
Johannes Kron0854eb62018-10-10 22:33:20 +02002118 cricket::MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 10:54:26 +02002119 audio_desc->set_extmap_allow_mixed_headers(
Johannes Kron0854eb62018-10-10 22:33:20 +02002120 cricket::MediaContentDescription::kMedia);
2121 TestSerialize(jdesc_);
2122}
2123
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002124TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002125 bool encrypted = false;
2126 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002127 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002128 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 12:22:16 -08002129 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002130
2131 std::string sdp_with_extmap = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002132 InjectAfter("a=mid:audio_content_name\r\n", kExtmap, &sdp_with_extmap);
2133 InjectAfter("a=mid:video_content_name\r\n", kExtmap, &sdp_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002134
2135 EXPECT_EQ(sdp_with_extmap, message);
2136}
2137
jbauch5869f502017-06-29 12:31:36 -07002138TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2139 bool encrypted = true;
2140 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002141 JsepSessionDescription desc_with_extmap(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002142 ASSERT_TRUE(
2143 desc_with_extmap.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 12:22:16 -08002144 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07002145}
2146
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002147TEST_F(WebRtcSdpTest, SerializeCandidates) {
2148 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002149 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002150
2151 Candidate candidate_with_ufrag(candidates_.front());
2152 candidate_with_ufrag.set_username("ABC");
2153 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2154 candidate_with_ufrag));
2155 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2156 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002157
2158 Candidate candidate_with_network_info(candidates_.front());
2159 candidate_with_network_info.set_network_id(1);
2160 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2161 candidate_with_network_info));
2162 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2163 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2164 candidate_with_network_info.set_network_cost(999);
2165 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2166 candidate_with_network_info));
2167 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2168 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2169 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002170}
2171
Zach Steinb336c272018-08-09 01:16:13 -07002172TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) {
2173 rtc::SocketAddress address("a.test", 1234);
2174 cricket::Candidate candidate(
2175 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
2176 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
2177 JsepIceCandidate jcandidate(std::string("audio_content_name"), 0, candidate);
2178 std::string message = webrtc::SdpSerializeCandidate(jcandidate);
2179 EXPECT_EQ(std::string(kRawHostnameCandidate), message);
2180}
2181
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002182// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2183// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002184TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002185 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002186 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2187 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2188 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002189 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002190 std::unique_ptr<IceCandidateInterface> jcandidate(
2191 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002192
2193 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2194 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2195}
2196
htaa6b99442016-04-12 10:29:17 -07002197TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002198 cricket::VideoCodec h264_codec("H264");
2199 h264_codec.SetParam("profile-level-id", "42e01f");
2200 h264_codec.SetParam("level-asymmetry-allowed", "1");
2201 h264_codec.SetParam("packetization-mode", "1");
2202 video_desc_->AddCodec(h264_codec);
2203
htaa6b99442016-04-12 10:29:17 -07002204 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
2205
Steve Antone831b8c2018-02-01 12:22:16 -08002206 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 10:29:17 -07002207 size_t after_pt = message.find(" H264/90000");
2208 ASSERT_NE(after_pt, std::string::npos);
2209 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2210 ASSERT_NE(before_pt, std::string::npos);
2211 before_pt += strlen("a=rtpmap:");
2212 std::string pt = message.substr(before_pt, after_pt - before_pt);
2213 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2214 std::string to_find = "a=fmtp:" + pt + " ";
2215 size_t fmtp_pos = message.find(to_find);
2216 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
2217 size_t fmtp_endpos = message.find("\n", fmtp_pos);
2218 ASSERT_NE(std::string::npos, fmtp_endpos);
2219 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2220 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2221 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2222 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002223 // Check that there are no spaces after semicolons.
2224 // https://bugs.webrtc.org/5793
2225 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002226}
2227
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002228TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 10:27:41 -08002229 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002230 // Deserialize
2231 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2232 // Verify
2233 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2234}
2235
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002236TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 10:27:41 -08002237 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002238 const char kSdpWithoutMline[] =
Yves Gerey665174f2018-06-19 15:03:05 +02002239 "v=0\r\n"
2240 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2241 "s=-\r\n"
2242 "t=0 0\r\n"
2243 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002244 // Deserialize
2245 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2246 EXPECT_EQ(0u, jdesc.description()->contents().size());
2247}
2248
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002249TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 10:27:41 -08002250 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002251 std::string sdp_without_carriage_return = kSdpFullString;
2252 Replace("\r\n", "\n", &sdp_without_carriage_return);
2253 // Deserialize
2254 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2255 // Verify
2256 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2257}
2258
2259TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2260 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002261 JsepSessionDescription jdesc_no_candidates(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002262 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
2263 kSessionVersion));
Steve Antona3a92c22017-12-07 10:27:41 -08002264 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002265 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2266 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2267}
2268
2269TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2270 static const char kSdpNoRtpmapString[] =
2271 "v=0\r\n"
2272 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2273 "s=-\r\n"
2274 "t=0 0\r\n"
2275 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2276 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002277 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002278 // The rtpmap line for static payload codec is optional.
2279 "a=rtpmap:18 G729/16000\r\n"
2280 "a=rtpmap:103 ISAC/16000\r\n";
2281
Steve Antona3a92c22017-12-07 10:27:41 -08002282 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002283 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2284 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002285 jdesc.description()
2286 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2287 ->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002288 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002289 // The codecs in the AudioContentDescription should be in the same order as
2290 // the payload types (<fmt>s) on the m= line.
2291 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2292 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002293 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002294 EXPECT_EQ(ref_codecs, audio->codecs());
2295}
2296
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002297TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2298 static const char kSdpNoRtpmapString[] =
2299 "v=0\r\n"
2300 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2301 "s=-\r\n"
2302 "t=0 0\r\n"
2303 "m=audio 49232 RTP/AVP 18 103\r\n"
2304 "a=fmtp:18 annexb=yes\r\n"
2305 "a=rtpmap:103 ISAC/16000\r\n";
2306
Steve Antona3a92c22017-12-07 10:27:41 -08002307 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002308 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2309 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002310 jdesc.description()
2311 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2312 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002313
2314 cricket::AudioCodec g729 = audio->codecs()[0];
2315 EXPECT_EQ("G729", g729.name);
2316 EXPECT_EQ(8000, g729.clockrate);
2317 EXPECT_EQ(18, g729.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002318 cricket::CodecParameterMap::iterator found = g729.params.find("annexb");
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002319 ASSERT_TRUE(found != g729.params.end());
2320 EXPECT_EQ(found->second, "yes");
2321
2322 cricket::AudioCodec isac = audio->codecs()[1];
2323 EXPECT_EQ("ISAC", isac.name);
2324 EXPECT_EQ(103, isac.id);
2325 EXPECT_EQ(16000, isac.clockrate);
2326}
2327
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002328// Ensure that we can deserialize SDP with a=fingerprint properly.
2329TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2330 // Add a DTLS a=fingerprint attribute to our session description.
2331 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002332 JsepSessionDescription new_jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002333 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002334 jdesc_.session_version()));
2335
Steve Antona3a92c22017-12-07 10:27:41 -08002336 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002337 std::string sdp_with_fingerprint = kSdpString;
2338 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2339 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2340 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2341 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2342}
2343
2344TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 10:27:41 -08002345 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002346 std::string sdp_with_bundle = kSdpFullString;
2347 InjectAfter(kSessionTime,
2348 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2349 &sdp_with_bundle);
2350 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2351 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2352 group.AddContentName(kAudioContentName);
2353 group.AddContentName(kVideoContentName);
2354 desc_.AddGroup(group);
Yves Gerey665174f2018-06-19 15:03:05 +02002355 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002356 jdesc_.session_version()));
2357 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2358}
2359
2360TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002361 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002362 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002363 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002364 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002365 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002366 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002367 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 15:14:30 -08002368 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002369 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002370 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002371 acd->set_bandwidth(50 * 1000);
Yves Gerey665174f2018-06-19 15:03:05 +02002372 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002373 jdesc_.session_version()));
2374 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2375}
2376
2377TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 10:27:41 -08002378 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002379 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002380 InjectAfter(kSessionTime, "a=ice-options:iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002381 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002382 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002383 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002384 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002385 &sdp_with_ice_options);
2386 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2387 std::vector<std::string> transport_options;
2388 transport_options.push_back(kIceOption3);
2389 transport_options.push_back(kIceOption1);
2390 AddIceOptions(kAudioContentName, transport_options);
2391 transport_options.clear();
2392 transport_options.push_back(kIceOption3);
2393 transport_options.push_back(kIceOption2);
2394 AddIceOptions(kVideoContentName, transport_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002395 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002396 jdesc_.session_version()));
2397 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2398}
2399
2400TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2401 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 10:27:41 -08002402 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002403 std::string sdp_with_ufrag_pwd = kSdpFullString;
2404 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2405 // Add session level ufrag and pwd
2406 InjectAfter(kSessionTime,
Yves Gerey665174f2018-06-19 15:03:05 +02002407 "a=ice-pwd:session+level+icepwd\r\n"
2408 "a=ice-ufrag:session+level+iceufrag\r\n",
2409 &sdp_with_ufrag_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002410 // Add media level ufrag and pwd for audio
Yves Gerey665174f2018-06-19 15:03:05 +02002411 InjectAfter(
2412 "a=mid:audio_content_name\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002413 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2414 &sdp_with_ufrag_pwd);
2415 // Update the candidate ufrag and pwd to the expected ones.
Yves Gerey665174f2018-06-19 15:03:05 +02002416 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, "media+level+iceufrag",
2417 "media+level+icepwd"));
2418 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, "session+level+iceufrag",
2419 "session+level+icepwd"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002420 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2421 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2422}
2423
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002424TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002425 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002426}
2427
2428TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002429 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002430}
2431
2432TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002433 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002434}
2435
2436TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2437 EXPECT_TRUE(TestDeserializeRejected(true, false));
2438}
2439
2440TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2441 EXPECT_TRUE(TestDeserializeRejected(false, true));
2442}
2443
2444TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2445 EXPECT_TRUE(TestDeserializeRejected(true, true));
2446}
2447
2448// Tests that we can still handle the sdp uses mslabel and label instead of
2449// msid for backward compatibility.
2450TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07002451 jdesc_.description()->set_msid_supported(false);
Steve Antona3a92c22017-12-07 10:27:41 -08002452 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002453 std::string sdp_without_msid = kSdpFullString;
2454 Replace("msid", "xmsid", &sdp_without_msid);
2455 // Deserialize
2456 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2457 // Verify
2458 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2459}
2460
Johannes Kron0854eb62018-10-10 22:33:20 +02002461TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9ac3c912018-10-12 10:54:26 +02002462 jdesc_.description()->set_extmap_allow_mixed_headers(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002463 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2464 InjectAfter("t=0 0\r\n", kExtmapAllowMixed, &sdp_with_extmap_allow_mixed);
2465 // Deserialize
2466 JsepSessionDescription jdesc_deserialized(kDummyType);
2467 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2468 // Verify
2469 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2470}
2471
2472TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutExtmapAllowMixed) {
Johannes Kron9ac3c912018-10-12 10:54:26 +02002473 jdesc_.description()->set_extmap_allow_mixed_headers(false);
Johannes Kron0854eb62018-10-10 22:33:20 +02002474 std::string sdp_without_extmap_allow_mixed = kSdpFullString;
2475 // Deserialize
2476 JsepSessionDescription jdesc_deserialized(kDummyType);
2477 EXPECT_TRUE(
2478 SdpDeserialize(sdp_without_extmap_allow_mixed, &jdesc_deserialized));
2479 // Verify
2480 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2481}
2482
2483TEST_F(WebRtcSdpTest, DeserializeMediaContentDescriptionWithExtmapAllowMixed) {
2484 cricket::MediaContentDescription* video_desc =
2485 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2486 ASSERT_TRUE(video_desc);
2487 cricket::MediaContentDescription* audio_desc =
2488 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2489 ASSERT_TRUE(audio_desc);
Johannes Kron9ac3c912018-10-12 10:54:26 +02002490 video_desc->set_extmap_allow_mixed_headers(
Johannes Kron0854eb62018-10-10 22:33:20 +02002491 cricket::MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 10:54:26 +02002492 audio_desc->set_extmap_allow_mixed_headers(
Johannes Kron0854eb62018-10-10 22:33:20 +02002493 cricket::MediaContentDescription::kMedia);
2494
2495 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2496 InjectAfter("a=mid:audio_content_name\r\n", kExtmapAllowMixed,
2497 &sdp_with_extmap_allow_mixed);
2498 InjectAfter("a=mid:video_content_name\r\n", kExtmapAllowMixed,
2499 &sdp_with_extmap_allow_mixed);
2500
2501 // Deserialize
2502 JsepSessionDescription jdesc_deserialized(kDummyType);
2503 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2504 // Verify
2505 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2506}
2507
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002508TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2509 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2510
2511 std::string sdp = kSdpOneCandidate;
2512 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2513 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2514 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2515 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002516 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002517
2518 // Candidate line without generation extension.
2519 sdp = kSdpOneCandidate;
2520 Replace(" generation 2", "", &sdp);
2521 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2522 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2523 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2524 Candidate expected = jcandidate_->candidate();
2525 expected.set_generation(0);
2526 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2527
honghaiza0c44ea2016-03-23 16:07:48 -07002528 // Candidate with network id and/or cost.
2529 sdp = kSdpOneCandidate;
2530 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2531 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2532 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2533 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2534 expected = jcandidate_->candidate();
2535 expected.set_network_id(2);
2536 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2537 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2538 // Add network cost
2539 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2540 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2541 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2542 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2543
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002544 sdp = kSdpTcpActiveCandidate;
2545 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2546 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002547 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002548 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2549 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2550 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002551 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2552 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
Yves Gerey665174f2018-06-19 15:03:05 +02002553 EXPECT_TRUE(
2554 jcandidate.candidate().IsEquivalent(jcandidate_template->candidate()));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002555 sdp = kSdpTcpPassiveCandidate;
2556 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2557 sdp = kSdpTcpSOCandidate;
2558 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002559}
2560
2561// This test verifies the deserialization of candidate-attribute
2562// as per RFC 5245. Candiate-attribute will be of the format
2563// candidate:<blah>. This format will be used when candidates
2564// are trickled.
2565TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2566 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2567
2568 std::string candidate_attribute = kRawCandidate;
2569 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2570 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2571 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2572 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2573 EXPECT_EQ(2u, jcandidate.candidate().generation());
2574
2575 // Candidate line without generation extension.
2576 candidate_attribute = kRawCandidate;
2577 Replace(" generation 2", "", &candidate_attribute);
2578 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2579 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2580 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2581 Candidate expected = jcandidate_->candidate();
2582 expected.set_generation(0);
2583 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2584
2585 // Candidate line without candidate:
2586 candidate_attribute = kRawCandidate;
2587 Replace("candidate:", "", &candidate_attribute);
2588 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2589
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002590 // Candidate line with IPV6 address.
2591 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
Zach Steinb336c272018-08-09 01:16:13 -07002592
2593 // Candidate line with hostname address.
2594 EXPECT_TRUE(SdpDeserializeCandidate(kRawHostnameCandidate, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002595}
2596
2597// This test verifies that the deserialization of an invalid candidate string
2598// fails.
2599TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
Yves Gerey665174f2018-06-19 15:03:05 +02002600 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002601
2602 std::string candidate_attribute = kRawCandidate;
2603 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002604 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002605
2606 candidate_attribute = kSdpOneCandidate;
2607 candidate_attribute.replace(0, 1, "x");
2608 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2609
2610 candidate_attribute = kRawCandidate;
2611 candidate_attribute.append("\r\n");
2612 candidate_attribute.append(kRawCandidate);
2613 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2614
2615 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002616}
2617
2618TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2619 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002620 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002621 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2622
2623 std::string sdp_with_data = kSdpString;
2624 sdp_with_data.append(kSdpRtpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002625 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002626
2627 // Deserialize
2628 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2629 // Verify
2630 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2631}
2632
2633TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002634 bool use_sctpmap = true;
2635 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002636 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002637 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2638
2639 std::string sdp_with_data = kSdpString;
2640 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002641 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002642
lally@webrtc.org36300852015-02-24 20:19:35 +00002643 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2644 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2645 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2646
2647 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002648 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2649 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002650 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2651 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2652
2653 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002654 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2655 kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002656 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2657 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2658}
2659
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002660TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002661 bool use_sctpmap = false;
2662 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002663 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002664 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2665
2666 std::string sdp_with_data = kSdpString;
2667 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002668 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002669
lally@webrtc.org36300852015-02-24 20:19:35 +00002670 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002671 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2672 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002673
lally@webrtc.org36300852015-02-24 20:19:35 +00002674 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002675 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2676 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002677 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2678 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002679
lally@webrtc.org36300852015-02-24 20:19:35 +00002680 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002681 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2682 kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002683 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2684 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2685}
2686
lally69f57602015-10-08 10:15:04 -07002687TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002688 bool use_sctpmap = false;
2689 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002690 JsepSessionDescription jdesc(kDummyType);
lally69f57602015-10-08 10:15:04 -07002691 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2692
2693 std::string sdp_with_data = kSdpString;
2694 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002695 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 10:15:04 -07002696
2697 // Verify with DTLS/SCTP.
2698 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2699 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2700
2701 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002702 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2703 kUdpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002704 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2705 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2706
2707 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002708 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2709 kTcpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002710 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2711 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2712}
2713
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002714// Test to check the behaviour if sctp-port is specified
2715// on the m= line and in a=sctp-port.
2716TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002717 bool use_sctpmap = true;
2718 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002719 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002720 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2721
2722 std::string sdp_with_data = kSdpString;
2723 // Append m= attributes
2724 sdp_with_data.append(kSdpSctpDataChannelString);
2725 // Append a=sctp-port attribute
2726 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 10:27:41 -08002727 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002728
2729 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2730}
2731
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002732// For crbug/344475.
2733TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2734 std::string sdp_with_data = kSdpString;
2735 sdp_with_data.append(kSdpSctpDataChannelString);
2736 // Remove the "\n" at the end.
2737 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 10:27:41 -08002738 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002739
2740 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2741 // No crash is a pass.
2742}
2743
Steve Anton36b29d12017-10-30 09:57:42 -07002744void MutateJsepSctpPort(JsepSessionDescription* jdesc,
zstein4b2e0822017-02-17 19:48:38 -08002745 const SessionDescription& desc) {
wu@webrtc.org78187522013-10-07 23:32:02 +00002746 // take our pre-built session description and change the SCTP port.
zstein4b2e0822017-02-17 19:48:38 -08002747 cricket::SessionDescription* mutant = desc.Copy();
Steve Antonb1c1de12017-12-21 15:14:30 -08002748 DataContentDescription* dcdesc =
2749 mutant->GetContentDescriptionByName(kDataContentName)->as_data();
wu@webrtc.org78187522013-10-07 23:32:02 +00002750 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002751 EXPECT_EQ(1U, codecs.size());
solenberg9fa49752016-10-08 13:02:44 -07002752 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002753 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002754 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002755
2756 // note: mutant's owned by jdesc now.
Steve Anton36b29d12017-10-30 09:57:42 -07002757 ASSERT_TRUE(jdesc->Initialize(mutant, kSessionId, kSessionVersion));
wu@webrtc.org78187522013-10-07 23:32:02 +00002758 mutant = NULL;
zstein4b2e0822017-02-17 19:48:38 -08002759}
2760
2761TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
2762 bool use_sctpmap = true;
2763 AddSctpDataChannel(use_sctpmap);
2764
2765 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 10:27:41 -08002766 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002767 MutateJsepSctpPort(&jdesc, desc_);
wu@webrtc.org78187522013-10-07 23:32:02 +00002768
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002769 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002770 std::string sdp_with_data = kSdpString;
2771 sdp_with_data.append(kSdpSctpDataChannelString);
zstein4b2e0822017-02-17 19:48:38 -08002772 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2773 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2774 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002775 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:02 +00002776
2777 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2778 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08002779}
2780
2781TEST_F(WebRtcSdpTest,
2782 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
2783 bool use_sctpmap = false;
2784 AddSctpDataChannel(use_sctpmap);
2785
Steve Antona3a92c22017-12-07 10:27:41 -08002786 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002787 MutateJsepSctpPort(&jdesc, desc_);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002788
2789 // We need to test the deserialized JsepSessionDescription from
2790 // kSdpSctpDataChannelStringWithSctpPort for
2791 // draft-ietf-mmusic-sctp-sdp-07
2792 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08002793 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002794 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
zstein4b2e0822017-02-17 19:48:38 -08002795 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2796 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2797 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002798 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002799
2800 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2801 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002802}
2803
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002804TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002805 // We want to test that deserializing data content limits bandwidth
2806 // settings (it should never be greater than the default).
2807 // This should prevent someone from using unlimited data bandwidth through
2808 // JS and "breaking the Internet".
2809 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002810 std::string sdp_with_bandwidth = kSdpString;
2811 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02002812 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002813 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002814 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002815
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002816 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2817}
2818
2819TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08002820 bool use_sctpmap = true;
2821 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002822 JsepSessionDescription jdesc(kDummyType);
Steve Antonb1c1de12017-12-21 15:14:30 -08002823 DataContentDescription* dcd = GetFirstDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002824 dcd->set_bandwidth(100 * 1000);
2825 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2826
2827 std::string sdp_with_bandwidth = kSdpString;
2828 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02002829 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002830 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002831 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002832
2833 // SCTP has congestion control, so we shouldn't limit the bandwidth
2834 // as we do for RTP.
2835 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002836 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2837}
2838
Yves Gerey665174f2018-06-19 15:03:05 +02002839class WebRtcSdpExtmapTest : public WebRtcSdpTest,
2840 public testing::WithParamInterface<bool> {};
jbauch5869f502017-06-29 12:31:36 -07002841
2842TEST_P(WebRtcSdpExtmapTest,
Yves Gerey665174f2018-06-19 15:03:05 +02002843 DeserializeSessionDescriptionWithSessionLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002844 bool encrypted = GetParam();
2845 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002846}
2847
Yves Gerey665174f2018-06-19 15:03:05 +02002848TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002849 bool encrypted = GetParam();
2850 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002851}
2852
Yves Gerey665174f2018-06-19 15:03:05 +02002853TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithInvalidExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002854 bool encrypted = GetParam();
2855 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002856}
2857
jbauch5869f502017-06-29 12:31:36 -07002858INSTANTIATE_TEST_CASE_P(Encrypted,
2859 WebRtcSdpExtmapTest,
2860 ::testing::Values(false, true));
2861
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002862TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 10:27:41 -08002863 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002864 std::string sdp = kSdpFullString;
2865 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2866 // Deserialize
2867 SdpParseError error;
2868 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-16 17:54:10 -08002869 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002870 EXPECT_EQ(lastline, error.line);
2871 EXPECT_EQ("Invalid SDP line.", error.description);
2872}
2873
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002874TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2875 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2876 std::string new_sdp = kSdpOneCandidate;
2877 Replace("udp", "unsupported_transport", &new_sdp);
2878 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2879 new_sdp = kSdpOneCandidate;
2880 Replace("udp", "uDP", &new_sdp);
2881 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2882 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2883 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2884 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2885}
2886
honghaiza54a0802015-12-16 18:37:23 -08002887TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002888 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08002889 EXPECT_TRUE(
2890 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002891 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2892 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2893 Candidate ref_candidate = jcandidate_->candidate();
2894 ref_candidate.set_username("user_rtp");
2895 ref_candidate.set_password("password_rtp");
2896 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2897}
2898
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002899TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08002900 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002901
2902 // Deserialize
2903 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2904
2905 // Verify
2906 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002907 jdesc.description()
2908 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2909 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002910 EXPECT_TRUE(audio->conference_mode());
2911
2912 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 15:14:30 -08002913 jdesc.description()
2914 ->GetContentDescriptionByName(cricket::CN_VIDEO)
2915 ->as_video();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002916 EXPECT_TRUE(video->conference_mode());
2917}
2918
deadbeefd45aea82017-09-16 01:24:29 -07002919TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08002920 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 01:24:29 -07002921
2922 // We tested deserialization already above, so just test that if we serialize
2923 // and deserialize the flag doesn't disappear.
2924 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 12:22:16 -08002925 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 01:24:29 -07002926 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
2927
2928 // Verify.
2929 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002930 jdesc.description()
2931 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2932 ->as_audio();
deadbeefd45aea82017-09-16 01:24:29 -07002933 EXPECT_TRUE(audio->conference_mode());
2934
2935 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 15:14:30 -08002936 jdesc.description()
2937 ->GetContentDescriptionByName(cricket::CN_VIDEO)
2938 ->as_video();
deadbeefd45aea82017-09-16 01:24:29 -07002939 EXPECT_TRUE(video->conference_mode());
2940}
2941
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002942TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2943 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002944 const char kSdpEmptyType[] = " =candidate";
2945 const char kSdpEqualAsPlus[] = "a+candidate";
2946 const char kSdpSpaceAfterEqual[] = "a= candidate";
2947 const char kSdpUpperType[] = "A=candidate";
2948 const char kSdpEmptyLine[] = "";
2949 const char kSdpMissingValue[] = "a=";
2950
Yves Gerey665174f2018-06-19 15:03:05 +02002951 const char kSdpBrokenFingerprint[] =
2952 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002953 "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 +02002954 const char kSdpExtraField[] =
2955 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002956 "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 +02002957 const char kSdpMissingSpace[] =
2958 "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002959 "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 +00002960 // MD5 is not allowed in fingerprints.
Yves Gerey665174f2018-06-19 15:03:05 +02002961 const char kSdpMd5[] =
2962 "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002963 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002964
2965 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002966 ExpectParseFailure("v=", kSdpDestroyer);
2967 ExpectParseFailure("o=", kSdpDestroyer);
2968 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002969 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002970 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002971
2972 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002973 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2974 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002975
2976 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002977 ExpectParseFailure("a=candidate", kSdpEmptyType);
2978 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2979 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
2980 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002981
2982 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2983 // because it's orthogonal to what we are replacing and hence
2984 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002985 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
2986 ExpectParseFailure("a=sendrecv", kSdpExtraField);
2987 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
2988 ExpectParseFailure("a=sendrecv", kSdpMd5);
2989
2990 // Empty Line
2991 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
2992 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002993}
2994
2995TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2996 // ssrc
2997 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08002998 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002999 // crypto
3000 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
3001 // rtpmap
3002 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
3003 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
3004 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
3005 // candidate
3006 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
3007 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
3008 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
3009 ExpectParseFailure("rport 2346", "rport badvalue");
3010 ExpectParseFailure("rport 2346 generation 2",
3011 "rport 2346 generation badvalue");
3012 // m line
3013 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
3014 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
3015
3016 // bandwidth
3017 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003018 "b=AS:badvalue\r\n", "b=AS:badvalue");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003019 // rtcp-fb
3020 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3021 "a=rtcp-fb:badvalue nack\r\n",
3022 "a=rtcp-fb:badvalue nack");
3023 // extmap
3024 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3025 "a=extmap:badvalue http://example.com\r\n",
3026 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003027}
3028
3029TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 10:27:41 -08003030 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003031
3032 const char kSdpWithReorderedPlTypesString[] =
3033 "v=0\r\n"
3034 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3035 "s=-\r\n"
3036 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00003037 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
Yves Gerey665174f2018-06-19 15:03:05 +02003038 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
3039 // in the map.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003040 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003041 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003042
3043 // Deserialize
3044 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
3045
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003046 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003047 GetFirstAudioContentDescription(jdesc_output.description());
3048 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003049 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003050 EXPECT_EQ("ISAC", acd->codecs()[0].name);
3051 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003052 EXPECT_EQ(104, acd->codecs()[0].id);
3053}
3054
3055TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 10:27:41 -08003056 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003057 CodecParams params;
3058 params.max_ptime = 40;
3059 params.ptime = 30;
3060 params.min_ptime = 10;
3061 params.sprop_stereo = 1;
3062 params.stereo = 1;
3063 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003064 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003065 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 12:22:16 -08003066 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003067}
3068
3069TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
3070 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 10:27:41 -08003071 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003072 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003073 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003074}
3075
3076TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
3077 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 10:27:41 -08003078 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003079 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003080 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003081}
3082
3083TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 10:27:41 -08003084 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003085
3086 const char kSdpWithFmtpString[] =
3087 "v=0\r\n"
3088 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3089 "s=-\r\n"
3090 "t=0 0\r\n"
3091 "m=video 3457 RTP/SAVPF 120\r\n"
3092 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07003093 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3094
3095 // Deserialize
3096 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07003097 EXPECT_TRUE(
3098 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07003099
Donald Curtis0e07f922015-05-15 09:21:23 -07003100 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003101 GetFirstVideoContentDescription(jdesc_output.description());
3102 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 09:21:23 -07003103 ASSERT_FALSE(vcd->codecs().empty());
3104 cricket::VideoCodec vp8 = vcd->codecs()[0];
3105 EXPECT_EQ("VP8", vp8.name);
3106 EXPECT_EQ(120, vp8.id);
3107 cricket::CodecParameterMap::iterator found =
3108 vp8.params.find("x-google-min-bitrate");
3109 ASSERT_TRUE(found != vp8.params.end());
3110 EXPECT_EQ(found->second, "10");
3111 found = vp8.params.find("x-google-max-quantization");
3112 ASSERT_TRUE(found != vp8.params.end());
3113 EXPECT_EQ(found->second, "40");
3114}
3115
johan2d8d23e2016-06-03 01:22:42 -07003116TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 10:27:41 -08003117 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 01:22:42 -07003118
3119 const char kSdpWithFmtpString[] =
3120 "v=0\r\n"
3121 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3122 "s=-\r\n"
3123 "t=0 0\r\n"
3124 "m=video 49170 RTP/AVP 98\r\n"
3125 "a=rtpmap:98 H264/90000\r\n"
3126 "a=fmtp:98 profile-level-id=42A01E; "
3127 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3128
3129 // Deserialize.
3130 SdpParseError error;
3131 EXPECT_TRUE(
3132 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3133
johan2d8d23e2016-06-03 01:22:42 -07003134 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003135 GetFirstVideoContentDescription(jdesc_output.description());
3136 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 01:22:42 -07003137 ASSERT_FALSE(vcd->codecs().empty());
3138 cricket::VideoCodec h264 = vcd->codecs()[0];
3139 EXPECT_EQ("H264", h264.name);
3140 EXPECT_EQ(98, h264.id);
3141 cricket::CodecParameterMap::const_iterator found =
3142 h264.params.find("profile-level-id");
3143 ASSERT_TRUE(found != h264.params.end());
3144 EXPECT_EQ(found->second, "42A01E");
3145 found = h264.params.find("sprop-parameter-sets");
3146 ASSERT_TRUE(found != h264.params.end());
3147 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3148}
3149
Donald Curtis0e07f922015-05-15 09:21:23 -07003150TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 10:27:41 -08003151 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 09:21:23 -07003152
3153 const char kSdpWithFmtpString[] =
3154 "v=0\r\n"
3155 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3156 "s=-\r\n"
3157 "t=0 0\r\n"
3158 "m=video 3457 RTP/SAVPF 120\r\n"
3159 "a=rtpmap:120 VP8/90000\r\n"
3160 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003161
3162 // Deserialize
3163 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02003164 EXPECT_TRUE(
3165 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003166
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003167 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003168 GetFirstVideoContentDescription(jdesc_output.description());
3169 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003170 ASSERT_FALSE(vcd->codecs().empty());
3171 cricket::VideoCodec vp8 = vcd->codecs()[0];
3172 EXPECT_EQ("VP8", vp8.name);
3173 EXPECT_EQ(120, vp8.id);
3174 cricket::CodecParameterMap::iterator found =
3175 vp8.params.find("x-google-min-bitrate");
3176 ASSERT_TRUE(found != vp8.params.end());
3177 EXPECT_EQ(found->second, "10");
3178 found = vp8.params.find("x-google-max-quantization");
3179 ASSERT_TRUE(found != vp8.params.end());
3180 EXPECT_EQ(found->second, "40");
3181}
3182
ossuaa4b0772017-01-30 07:41:18 -08003183TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003184 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003185
3186 cricket::AudioCodecs codecs = acd->codecs();
3187 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3188 acd->set_codecs(codecs);
3189
Yves Gerey665174f2018-06-19 15:03:05 +02003190 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003191 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003192 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003193 std::string sdp_with_fmtp = kSdpFullString;
3194 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3195 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3196 &sdp_with_fmtp);
3197 EXPECT_EQ(sdp_with_fmtp, message);
3198}
3199
3200TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003201 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003202
3203 cricket::AudioCodecs codecs = acd->codecs();
3204 codecs[0].params["stereo"] = "1";
3205 acd->set_codecs(codecs);
3206
Yves Gerey665174f2018-06-19 15:03:05 +02003207 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003208 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003209 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003210 std::string sdp_with_fmtp = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003211 InjectAfter("a=rtpmap:111 opus/48000/2\r\n", "a=fmtp:111 stereo=1\r\n",
ossuaa4b0772017-01-30 07:41:18 -08003212 &sdp_with_fmtp);
3213 EXPECT_EQ(sdp_with_fmtp, message);
3214}
3215
3216TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003217 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003218
3219 cricket::AudioCodecs codecs = acd->codecs();
3220 codecs[0].params["ptime"] = "20";
3221 codecs[0].params["maxptime"] = "120";
3222 acd->set_codecs(codecs);
3223
Yves Gerey665174f2018-06-19 15:03:05 +02003224 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003225 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003226 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003227 std::string sdp_with_fmtp = kSdpFullString;
3228 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3229 "a=maxptime:120\r\n" // No comma here. String merging!
3230 "a=ptime:20\r\n",
3231 &sdp_with_fmtp);
3232 EXPECT_EQ(sdp_with_fmtp, message);
3233}
3234
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003235TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003236 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003237
3238 cricket::VideoCodecs codecs = vcd->codecs();
3239 codecs[0].params["x-google-min-bitrate"] = "10";
3240 vcd->set_codecs(codecs);
3241
Yves Gerey665174f2018-06-19 15:03:05 +02003242 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003243 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003244 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003245 std::string sdp_with_fmtp = kSdpFullString;
3246 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003247 "a=fmtp:120 x-google-min-bitrate=10\r\n", &sdp_with_fmtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003248 EXPECT_EQ(sdp_with_fmtp, message);
3249}
3250
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003251TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) {
3252 // Deserialize the baseline description, making sure it's ICE full.
Steve Antona3a92c22017-12-07 10:27:41 -08003253 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003254 std::string sdp_with_icelite = kSdpFullString;
3255 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3256 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3257 const cricket::TransportInfo* tinfo1 =
3258 desc->GetTransportInfoByName("audio_content_name");
3259 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3260 const cricket::TransportInfo* tinfo2 =
3261 desc->GetTransportInfoByName("video_content_name");
3262 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003263
3264 // Add "a=ice-lite" and deserialize, making sure it's ICE lite.
Yves Gerey665174f2018-06-19 15:03:05 +02003265 InjectAfter(kSessionTime, "a=ice-lite\r\n", &sdp_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003266 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3267 desc = jdesc_with_icelite.description();
3268 const cricket::TransportInfo* atinfo =
3269 desc->GetTransportInfoByName("audio_content_name");
3270 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3271 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003272 desc->GetTransportInfoByName("video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003273 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003274
3275 // Now that we know deserialization works, we can use TestSerialize to test
3276 // serialization.
3277 TestSerialize(jdesc_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003278}
3279
3280// Verifies that the candidates in the input SDP are parsed and serialized
3281// correctly in the output SDP.
3282TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3283 std::string sdp_with_data = kSdpString;
3284 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 10:27:41 -08003285 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003286
3287 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 12:22:16 -08003288 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003289}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003290
3291TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3292 AddFingerprint();
3293 TransportInfo audio_transport_info =
3294 *(desc_.GetTransportInfoByName(kAudioContentName));
3295 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3296 audio_transport_info.description.connection_role);
3297 audio_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003298 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003299
3300 TransportInfo video_transport_info =
3301 *(desc_.GetTransportInfoByName(kVideoContentName));
3302 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3303 video_transport_info.description.connection_role);
3304 video_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003305 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003306
3307 desc_.RemoveTransportInfoByName(kAudioContentName);
3308 desc_.RemoveTransportInfoByName(kVideoContentName);
3309
3310 desc_.AddTransportInfo(audio_transport_info);
3311 desc_.AddTransportInfo(video_transport_info);
3312
Yves Gerey665174f2018-06-19 15:03:05 +02003313 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003314 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003315 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003316 std::string sdp_with_dtlssetup = kSdpFullString;
3317
3318 // Fingerprint attribute is necessary to add DTLS setup attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003319 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_dtlssetup);
3320 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003321 // Now adding |setup| attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003322 InjectAfter(kFingerprint, "a=setup:active\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003323 EXPECT_EQ(sdp_with_dtlssetup, message);
3324}
3325
3326TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
Steve Antona3a92c22017-12-07 10:27:41 -08003327 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003328 std::string sdp_with_dtlssetup = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003329 InjectAfter(kSessionTime, "a=setup:actpass\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003330 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3331 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3332 const cricket::TransportInfo* atinfo =
3333 desc->GetTransportInfoByName("audio_content_name");
3334 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3335 atinfo->description.connection_role);
3336 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003337 desc->GetTransportInfoByName("video_content_name");
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003338 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3339 vtinfo->description.connection_role);
3340}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003341
3342// Verifies that the order of the serialized m-lines follows the order of the
3343// ContentInfo in SessionDescription, and vise versa for deserialization.
3344TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 10:27:41 -08003345 JsepSessionDescription jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02003346 const std::string media_content_sdps[3] = {kSdpAudioString, kSdpVideoString,
3347 kSdpSctpDataChannelString};
3348 const cricket::MediaType media_types[3] = {cricket::MEDIA_TYPE_AUDIO,
3349 cricket::MEDIA_TYPE_VIDEO,
3350 cricket::MEDIA_TYPE_DATA};
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003351
3352 // Verifies all 6 permutations.
3353 for (size_t i = 0; i < 6; ++i) {
3354 size_t media_content_in_sdp[3];
3355 // The index of the first media content.
3356 media_content_in_sdp[0] = i / 2;
3357 // The index of the second media content.
3358 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3359 // The index of the third media content.
3360 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3361
3362 std::string sdp_string = kSdpSessionString;
3363 for (size_t i = 0; i < 3; ++i)
3364 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3365
3366 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3367 cricket::SessionDescription* desc = jdesc.description();
3368 EXPECT_EQ(3u, desc->contents().size());
3369
3370 for (size_t i = 0; i < 3; ++i) {
3371 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 15:14:30 -08003372 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003373 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3374 }
3375
Steve Antone831b8c2018-02-01 12:22:16 -08003376 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003377 EXPECT_EQ(sdp_string, serialized_sdp);
3378 }
3379}
deadbeef9d3584c2016-02-16 17:54:10 -08003380
deadbeef25ed4352016-12-12 18:37:36 -08003381TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3382 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 10:27:41 -08003383 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003384 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003385 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3386 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3387}
3388
deadbeef12771a12017-01-03 13:53:47 -08003389// The semantics of "a=bundle-only" are only defined when it's used in
3390// combination with a 0 port on the m= line. We should ignore it if used with a
3391// nonzero port.
3392TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3393 // Make the base bundle-only description but unset the bundle-only flag.
3394 MakeBundleOnlyDescription();
3395 jdesc_.description()->contents()[1].bundle_only = false;
3396
3397 std::string modified_sdp = kBundleOnlySdpFullString;
3398 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08003399 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003400 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3401 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003402}
3403
3404TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3405 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003406 TestSerialize(jdesc_);
deadbeef25ed4352016-12-12 18:37:36 -08003407}
3408
deadbeef9d3584c2016-02-16 17:54:10 -08003409TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3410 MakePlanBDescription();
3411
Steve Antona3a92c22017-12-07 10:27:41 -08003412 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003413 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3414
3415 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3416}
3417
3418TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3419 MakePlanBDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003420 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-16 17:54:10 -08003421}
3422
3423TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3424 MakeUnifiedPlanDescription();
3425
Steve Antona3a92c22017-12-07 10:27:41 -08003426 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003427 EXPECT_TRUE(
3428 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3429
3430 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3431}
3432
3433TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3434 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003435 TestSerialize(jdesc_);
3436}
3437
Seth Hampson5b4f0752018-04-02 16:31:36 -07003438// This tests deserializing a Unified Plan SDP that is compatible with both
3439// Unified Plan and Plan B style SDP. It tests the case for audio/video tracks
3440// with no stream ids and multiple stream ids. For parsing this, the Unified
3441// Plan a=msid lines should take priority, because the Plan B style a=ssrc msid
3442// lines do not support multiple stream ids and no stream ids.
3443TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionSpecialMsid) {
3444 MakeUnifiedPlanDescriptionMultipleStreamIds();
3445
3446 JsepSessionDescription deserialized_description(kDummyType);
3447 EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid,
3448 &deserialized_description));
3449
3450 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3451}
3452
3453TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionSpecialMsid) {
3454 MakeUnifiedPlanDescriptionMultipleStreamIds();
3455 TestSerialize(jdesc_);
3456}
3457
Seth Hampson5897a6e2018-04-03 11:16:33 -07003458// This tests that a Unified Plan SDP with no a=ssrc lines is
3459// serialized/deserialized appropriately. In this case the
3460// MediaContentDescription will contain a StreamParams object that doesn't have
3461// any SSRCs. Vice versa, this will be created upon deserializing an SDP with no
3462// SSRC lines.
3463TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3464 MakeUnifiedPlanDescription();
3465 RemoveSsrcSignalingFromStreamParams();
3466 std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString;
3467 RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string);
3468
3469 JsepSessionDescription deserialized_description(kDummyType);
3470 EXPECT_TRUE(
3471 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3472 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3473}
3474
3475TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3476 MakeUnifiedPlanDescription();
3477 RemoveSsrcSignalingFromStreamParams();
3478
3479 TestSerialize(jdesc_);
3480}
3481
Steve Antone831b8c2018-02-01 12:22:16 -08003482TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
3483 JsepSessionDescription jsep_desc(kDummyType);
3484 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
3485 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3486}
3487
3488TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
3489 JsepSessionDescription jsep_desc(kDummyType);
3490 std::string sdp = kSdpSessionString;
3491 sdp += kSdpSctpDataChannelString;
3492 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3493 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3494}
3495
3496TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
3497 JsepSessionDescription jsep_desc(kDummyType);
3498 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
3499 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
3500 jsep_desc.description()->msid_signaling());
3501}
3502
3503TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
3504 JsepSessionDescription jsep_desc(kDummyType);
3505 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
3506 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
3507 jsep_desc.description()->msid_signaling());
3508}
3509
3510const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
3511const char kSsrcAttributeMsidLine[] =
3512 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
3513
3514TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
3515 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
3516 std::string sdp = webrtc::SdpSerialize(jdesc_);
3517
3518 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3519 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3520}
3521
3522TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
3523 jdesc_.description()->set_msid_signaling(
3524 cricket::kMsidSignalingSsrcAttribute);
3525 std::string sdp = webrtc::SdpSerialize(jdesc_);
3526
3527 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
3528 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3529}
3530
3531TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
3532 jdesc_.description()->set_msid_signaling(
3533 cricket::kMsidSignalingMediaSection |
3534 cricket::kMsidSignalingSsrcAttribute);
3535 std::string sdp = webrtc::SdpSerialize(jdesc_);
3536
3537 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3538 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-16 17:54:10 -08003539}
deadbeef7e146cb2016-09-28 10:04:34 -07003540
3541// Regression test for heap overflow bug:
3542// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3543TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 10:04:34 -07003544 // The issue occurs when the sctp-port attribute is found in a video
3545 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 12:43:58 -08003546 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 10:04:34 -07003547 "v=0\r\n"
3548 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3549 "s=-\r\n"
3550 "t=0 0\r\n"
3551 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3552 "a=sctp-port 5000\r\n"
3553 "a=fmtp:108 foo=10\r\n";
3554
3555 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3556 "sctp-port");
3557}
deadbeefb2362572016-12-13 16:37:06 -08003558
3559// Regression test for integer overflow bug:
3560// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3561TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003562 // Bandwidth attribute is the max signed 32-bit int, which will get
3563 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003564 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003565 "v=0\r\n"
3566 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3567 "s=-\r\n"
3568 "t=0 0\r\n"
3569 "m=video 3457 RTP/SAVPF 120\r\n"
3570 "b=AS:2147483647\r\n"
3571 "foo=fail\r\n";
3572
3573 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3574}
deadbeef7bcdb692017-01-20 12:43:58 -08003575
deadbeefbc88c6b2017-08-02 11:26:34 -07003576// Similar to the above, except that negative values are illegal, not just
3577// error-prone as large values are.
3578// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3579TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3580 static const char kSdpWithNegativeBandwidth[] =
3581 "v=0\r\n"
3582 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3583 "s=-\r\n"
3584 "t=0 0\r\n"
3585 "m=video 3457 RTP/SAVPF 120\r\n"
3586 "b=AS:-1000\r\n";
3587
3588 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3589}
3590
deadbeef3e8016e2017-08-03 17:49:30 -07003591// An exception to the above rule: a value of -1 for b=AS should just be
3592// ignored, resulting in "kAutoBandwidth" in the deserialized object.
3593// Applications historically may be using "b=AS:-1" to mean "no bandwidth
3594// limit", but this is now what ommitting the attribute entirely will do, so
3595// ignoring it will have the intended effect.
3596TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
3597 static const char kSdpWithBandwidthOfNegativeOne[] =
3598 "v=0\r\n"
3599 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3600 "s=-\r\n"
3601 "t=0 0\r\n"
3602 "m=video 3457 RTP/SAVPF 120\r\n"
3603 "b=AS:-1\r\n";
3604
Steve Antona3a92c22017-12-07 10:27:41 -08003605 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-03 17:49:30 -07003606 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-03 17:49:30 -07003607 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003608 GetFirstVideoContentDescription(jdesc_output.description());
3609 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-03 17:49:30 -07003610 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
3611}
3612
deadbeef7bcdb692017-01-20 12:43:58 -08003613// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3614// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3615// Regression test for:
3616// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3617TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3618 // Important piece is "ufrag foo pwd bar".
3619 static const char kSdpWithIceCredentialsInCandidateString[] =
3620 "v=0\r\n"
3621 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3622 "s=-\r\n"
3623 "t=0 0\r\n"
3624 "m=audio 9 RTP/SAVPF 111\r\n"
3625 "c=IN IP4 0.0.0.0\r\n"
3626 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3627 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3628 "a=rtpmap:111 opus/48000/2\r\n"
3629 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3630 "generation 2 ufrag foo pwd bar\r\n";
3631
Steve Antona3a92c22017-12-07 10:27:41 -08003632 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 12:43:58 -08003633 EXPECT_TRUE(
3634 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
3635 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3636 ASSERT_NE(nullptr, candidates);
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003637 ASSERT_EQ(1U, candidates->count());
deadbeef7bcdb692017-01-20 12:43:58 -08003638 cricket::Candidate c = candidates->at(0)->candidate();
3639 EXPECT_EQ("ufrag_voice", c.username());
3640 EXPECT_EQ("pwd_voice", c.password());
3641}
deadbeef90f1e1e2017-02-10 12:35:05 -08003642
Johannes Kron211856b2018-09-06 12:12:28 +02003643// Test that attribute lines "a=ice-ufrag-something"/"a=ice-pwd-something" are
3644// ignored, and only the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3645// Regression test for:
3646// https://bugs.chromium.org/p/webrtc/issues/detail?id=9712
3647TEST_F(WebRtcSdpTest, AttributeWithPartialMatchingNameIsIgnored) {
3648 static const char kSdpWithFooIceCredentials[] =
3649 "v=0\r\n"
3650 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3651 "s=-\r\n"
3652 "t=0 0\r\n"
3653 "m=audio 9 RTP/SAVPF 111\r\n"
3654 "c=IN IP4 0.0.0.0\r\n"
3655 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3656 "a=ice-ufrag-something:foo\r\na=ice-pwd-something:bar\r\n"
3657 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3658 "a=rtpmap:111 opus/48000/2\r\n"
3659 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3660 "generation 2\r\n";
3661
3662 JsepSessionDescription jdesc_output(kDummyType);
3663 EXPECT_TRUE(SdpDeserialize(kSdpWithFooIceCredentials, &jdesc_output));
3664 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3665 ASSERT_NE(nullptr, candidates);
3666 ASSERT_EQ(1U, candidates->count());
3667 cricket::Candidate c = candidates->at(0)->candidate();
3668 EXPECT_EQ("ufrag_voice", c.username());
3669 EXPECT_EQ("pwd_voice", c.password());
3670}
3671
deadbeef90f1e1e2017-02-10 12:35:05 -08003672// Test that SDP with an invalid port number in "a=candidate" lines is
3673// rejected, without crashing.
3674// Regression test for:
3675// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
3676TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
3677 static const char kSdpWithInvalidCandidatePort[] =
3678 "v=0\r\n"
3679 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3680 "s=-\r\n"
3681 "t=0 0\r\n"
3682 "m=audio 9 RTP/SAVPF 111\r\n"
3683 "c=IN IP4 0.0.0.0\r\n"
3684 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3685 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3686 "a=rtpmap:111 opus/48000/2\r\n"
3687 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
3688 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
3689
Steve Antona3a92c22017-12-07 10:27:41 -08003690 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 12:35:05 -08003691 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
3692}
deadbeefa4549d62017-02-10 17:26:22 -08003693
3694// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
3695// Regression test for:
3696// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
3697TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
3698 static const char kSdpWithMissingTrackId[] =
3699 "v=0\r\n"
3700 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3701 "s=-\r\n"
3702 "t=0 0\r\n"
3703 "m=audio 9 RTP/SAVPF 111\r\n"
3704 "c=IN IP4 0.0.0.0\r\n"
3705 "a=rtpmap:111 opus/48000/2\r\n"
3706 "a=msid:stream_id \r\n";
3707
Steve Antona3a92c22017-12-07 10:27:41 -08003708 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003709 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
3710}
3711
3712TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
3713 static const char kSdpWithMissingStreamId[] =
3714 "v=0\r\n"
3715 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3716 "s=-\r\n"
3717 "t=0 0\r\n"
3718 "m=audio 9 RTP/SAVPF 111\r\n"
3719 "c=IN IP4 0.0.0.0\r\n"
3720 "a=rtpmap:111 opus/48000/2\r\n"
3721 "a=msid: track_id\r\n";
3722
Steve Antona3a92c22017-12-07 10:27:41 -08003723 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003724 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
3725}
zhihuang38989e52017-03-21 11:04:53 -07003726
3727// Tests that if both session-level address and media-level address exist, use
3728// the media-level address.
3729TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 10:27:41 -08003730 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003731
3732 // Sesssion-level address.
3733 std::string sdp = kSdpFullString;
3734 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3735 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3736
3737 const auto& content1 = jsep_desc.description()->contents()[0];
3738 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 15:14:30 -08003739 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003740 const auto& content2 = jsep_desc.description()->contents()[1];
3741 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 15:14:30 -08003742 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003743}
3744
3745// Tests that the session-level connection address will be used if the media
3746// level-addresses are not specified.
3747TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 10:27:41 -08003748 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003749
3750 // Sesssion-level address.
3751 std::string sdp = kSdpString;
3752 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3753 // Remove the media level addresses.
3754 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3755 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3756 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3757
3758 const auto& content1 = jsep_desc.description()->contents()[0];
3759 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003760 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003761 const auto& content2 = jsep_desc.description()->contents()[1];
3762 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003763 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003764}
3765
3766TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 10:27:41 -08003767 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003768
3769 std::string sdp = kSdpString;
3770 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3771 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
3772 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
3773 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
3774 &sdp);
3775 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
3776 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
3777 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
3778 &sdp);
3779 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3780 const auto& content1 = jsep_desc.description()->contents()[0];
3781 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003782 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003783 const auto& content2 = jsep_desc.description()->contents()[1];
3784 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003785 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003786}
3787
3788// Test that the invalid or unsupprted connection data cannot be parsed.
3789TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 10:27:41 -08003790 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003791 std::string sdp = kSdpString;
3792 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3793
3794 // Unsupported multicast IPv4 address.
3795 sdp = kSdpFullString;
3796 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
3797 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3798
3799 // Unsupported multicast IPv6 address.
3800 sdp = kSdpFullString;
3801 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
3802 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3803
3804 // Mismatched address type.
3805 sdp = kSdpFullString;
3806 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
3807 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3808
3809 sdp = kSdpFullString;
3810 Replace("c=IN IP4 74.125.224.39\r\n",
3811 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
3812 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3813}
3814
3815TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 10:27:41 -08003816 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003817 MakeDescriptionWithoutCandidates(&expected_jsep);
3818 // Serialization.
Steve Antone831b8c2018-02-01 12:22:16 -08003819 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 11:04:53 -07003820 // Deserialization.
Steve Antona3a92c22017-12-07 10:27:41 -08003821 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003822 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 15:14:30 -08003823 auto audio_desc = jdesc.description()
3824 ->GetContentByName(kAudioContentName)
3825 ->media_description();
3826 auto video_desc = jdesc.description()
3827 ->GetContentByName(kVideoContentName)
3828 ->media_description();
zhihuang38989e52017-03-21 11:04:53 -07003829 EXPECT_EQ(audio_desc_->connection_address().ToString(),
3830 audio_desc->connection_address().ToString());
3831 EXPECT_EQ(video_desc_->connection_address().ToString(),
3832 video_desc->connection_address().ToString());
3833}
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07003834
3835// RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be
3836// used (i.e., a single space as the session name)." So we should accept that.
3837TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) {
3838 JsepSessionDescription jsep_desc(kDummyType);
3839 std::string sdp = kSdpString;
3840 Replace("s=-\r\n", "s= \r\n", &sdp);
3841 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3842}