blob: 44655fd1668f8ba89ea993c41afe022a8bf1bb45 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2011 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
Yves Gerey3e707812018-11-28 16:47:49 +010011#include <stdio.h>
12#include <string.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020013
Harald Alvestrand4d7160e2019-04-12 07:01:29 +020014#include <algorithm>
Yves Gerey3e707812018-11-28 16:47:49 +010015#include <cstdint>
16#include <map>
kwibergd1fe2812016-04-27 06:47:29 -070017#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000018#include <string>
Yves Gerey3e707812018-11-28 16:47:49 +010019#include <utility>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000020#include <vector>
21
Steve Anton64b626b2019-01-28 17:25:26 -080022#include "absl/algorithm/container.h"
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -080023#include "absl/memory/memory.h"
Steve Anton1c9c9fc2019-02-14 15:13:09 -080024#include "absl/strings/str_replace.h"
Yves Gerey3e707812018-11-28 16:47:49 +010025#include "api/array_view.h"
Steve Anton10542f22019-01-11 09:11:00 -080026#include "api/crypto_params.h"
27#include "api/jsep_session_description.h"
28#include "api/media_types.h"
29#include "api/rtp_parameters.h"
30#include "api/rtp_transceiver_interface.h"
Yves Gerey3e707812018-11-28 16:47:49 +010031#include "media/base/codec.h"
Steve Anton10542f22019-01-11 09:11:00 -080032#include "media/base/media_constants.h"
33#include "media/base/stream_params.h"
34#include "p2p/base/p2p_constants.h"
Yves Gerey665174f2018-06-19 15:03:05 +020035#include "p2p/base/port.h"
Steve Anton10542f22019-01-11 09:11:00 -080036#include "p2p/base/transport_description.h"
37#include "p2p/base/transport_info.h"
38#include "pc/media_session.h"
39#include "pc/session_description.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020040#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 09:11:00 -080041#include "rtc_base/message_digest.h"
42#include "rtc_base/socket_address.h"
43#include "rtc_base/ssl_fingerprint.h"
44#include "rtc_base/string_encode.h"
Steve Anton06817cd2018-12-18 15:55:30 -080045#include "test/gmock.h"
Yves Gerey3e707812018-11-28 16:47:49 +010046#include "test/gtest.h"
Patrik Höglund563934e2017-09-15 09:04:28 +020047
ossu7bb87ee2017-01-23 04:56:25 -080048#ifdef WEBRTC_ANDROID
Steve Anton10542f22019-01-11 09:11:00 -080049#include "pc/test/android_test_initializer.h"
ossu7bb87ee2017-01-23 04:56:25 -080050#endif
Steve Anton10542f22019-01-11 09:11:00 -080051#include "pc/webrtc_sdp.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000052
53using cricket::AudioCodec;
54using cricket::AudioContentDescription;
55using cricket::Candidate;
Steve Anton06817cd2018-12-18 15:55:30 -080056using cricket::ContentGroup;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057using cricket::ContentInfo;
58using cricket::CryptoParams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059using cricket::DataCodec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
61using cricket::ICE_CANDIDATE_COMPONENT_RTP;
62using cricket::kFecSsrcGroupSemantics;
63using cricket::LOCAL_PORT_TYPE;
Steve Anton5adfafd2017-12-20 16:34:00 -080064using cricket::MediaProtocolType;
Steve Anton06817cd2018-12-18 15:55:30 -080065using cricket::RELAY_PORT_TYPE;
Amit Hilbuchc57d5732018-12-11 15:30:11 -080066using cricket::RidDescription;
67using cricket::RidDirection;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020068using cricket::RtpDataContentDescription;
69using cricket::SctpDataContentDescription;
Steve Anton06817cd2018-12-18 15:55:30 -080070using cricket::SessionDescription;
Amit Hilbucha2012042018-12-03 11:35:05 -080071using cricket::SimulcastDescription;
72using cricket::SimulcastLayer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073using cricket::StreamParams;
74using cricket::STUN_PORT_TYPE;
75using cricket::TransportDescription;
76using cricket::TransportInfo;
77using cricket::VideoCodec;
78using cricket::VideoContentDescription;
Steve Anton06817cd2018-12-18 15:55:30 -080079using ::testing::ElementsAre;
80using ::testing::Field;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000081using webrtc::IceCandidateCollection;
82using webrtc::IceCandidateInterface;
83using webrtc::JsepIceCandidate;
84using webrtc::JsepSessionDescription;
isheriff6f8d6862016-05-26 11:24:55 -070085using webrtc::RtpExtension;
Steve Anton4e70a722017-11-28 14:57:10 -080086using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087using webrtc::SdpParseError;
Steve Antona3a92c22017-12-07 10:27:41 -080088using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000089using webrtc::SessionDescriptionInterface;
90
91typedef std::vector<AudioCodec> AudioCodecs;
92typedef std::vector<Candidate> Candidates;
93
Peter Boström0c4e06b2015-10-07 12:23:21 +020094static const uint32_t kDefaultSctpPort = 5000;
zstein4b2e0822017-02-17 19:48:38 -080095static const uint16_t kUnusualSctpPort = 9556;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000096static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020097static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 15:17:14 -080098static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 15:17:14 -0800100static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000101static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200102static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103static const char kCandidateFoundation1[] = "a0+B/1";
104static const char kCandidateFoundation2[] = "a0+B/2";
105static const char kCandidateFoundation3[] = "a0+B/3";
106static const char kCandidateFoundation4[] = "a0+B/4";
107static const char kAttributeCryptoVoice[] =
108 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
109 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
110 "dummy_session_params\r\n";
111static const char kAttributeCryptoVideo[] =
112 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
113 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
Yves Gerey665174f2018-06-19 15:03:05 +0200114static const char kFingerprint[] =
115 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116 "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 +0200117static const char kExtmapAllowMixed[] = "a=extmap-allow-mixed\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000118static const int kExtmapId = 1;
119static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
120static const char kExtmap[] =
121 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
122static const char kExtmapWithDirectionAndAttribute[] =
123 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
jbauch5869f502017-06-29 12:31:36 -0700124static const char kExtmapWithDirectionAndAttributeEncrypted[] =
125 "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt "
126 "http://example.com/082005/ext.htm#ttime a1 a2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000127
Peter Boström0c4e06b2015-10-07 12:23:21 +0200128static const uint8_t kIdentityDigest[] = {
129 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
130 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000131
lally@webrtc.org34807282015-02-24 20:19:39 +0000132static const char kDtlsSctp[] = "DTLS/SCTP";
133static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
134static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +0000135
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000136struct CodecParams {
137 int max_ptime;
138 int ptime;
139 int min_ptime;
140 int sprop_stereo;
141 int stereo;
142 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000143 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000144};
145
deadbeef9d3584c2016-02-16 17:54:10 -0800146// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
147// instead of "a=crypto", and have an explicit test for adding "a=crypto".
148// Currently it's the other way around.
149
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000150// Reference sdp string
151static const char kSdpFullString[] =
152 "v=0\r\n"
153 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
154 "s=-\r\n"
155 "t=0 0\r\n"
Emil Lundmark801c9992021-01-19 13:06:32 +0100156 "a=extmap-allow-mixed\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800157 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000158 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
159 "c=IN IP4 74.125.127.126\r\n"
160 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
161 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
162 "generation 2\r\n"
163 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
164 "generation 2\r\n"
165 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
166 "generation 2\r\n"
167 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
168 "generation 2\r\n"
169 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
170 "raddr 192.168.1.5 rport 2346 "
171 "generation 2\r\n"
172 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
173 "raddr 192.168.1.5 rport 2348 "
174 "generation 2\r\n"
175 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
176 "a=mid:audio_content_name\r\n"
177 "a=sendrecv\r\n"
178 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800179 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000180 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
181 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
182 "dummy_session_params\r\n"
183 "a=rtpmap:111 opus/48000/2\r\n"
184 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000185 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000186 "a=ssrc:1 cname:stream_1_cname\r\n"
187 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000188 "a=ssrc:1 mslabel:local_stream_1\r\n"
189 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000190 "m=video 3457 RTP/SAVPF 120\r\n"
191 "c=IN IP4 74.125.224.39\r\n"
192 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
193 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
194 "generation 2\r\n"
195 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
196 "generation 2\r\n"
197 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
198 "generation 2\r\n"
199 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
200 "generation 2\r\n"
201 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
202 "generation 2\r\n"
203 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
204 "generation 2\r\n"
205 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
206 "a=mid:video_content_name\r\n"
207 "a=sendrecv\r\n"
208 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
209 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
210 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800211 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000212 "a=ssrc:2 cname:stream_1_cname\r\n"
213 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000214 "a=ssrc:2 mslabel:local_stream_1\r\n"
215 "a=ssrc:2 label:video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000216 "a=ssrc:3 cname:stream_1_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000217 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
218 "a=ssrc:3 mslabel:local_stream_1\r\n"
219 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000220
221// SDP reference string without the candidates.
222static const char kSdpString[] =
223 "v=0\r\n"
224 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
225 "s=-\r\n"
226 "t=0 0\r\n"
Emil Lundmark801c9992021-01-19 13:06:32 +0100227 "a=extmap-allow-mixed\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800228 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000229 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000230 "c=IN IP4 0.0.0.0\r\n"
231 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000232 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
233 "a=mid:audio_content_name\r\n"
234 "a=sendrecv\r\n"
235 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800236 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000237 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
238 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
239 "dummy_session_params\r\n"
240 "a=rtpmap:111 opus/48000/2\r\n"
241 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000242 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000243 "a=ssrc:1 cname:stream_1_cname\r\n"
244 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000245 "a=ssrc:1 mslabel:local_stream_1\r\n"
246 "a=ssrc:1 label:audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000247 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000248 "c=IN IP4 0.0.0.0\r\n"
249 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000250 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
251 "a=mid:video_content_name\r\n"
252 "a=sendrecv\r\n"
253 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
254 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
255 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800256 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000257 "a=ssrc:2 cname:stream_1_cname\r\n"
258 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000259 "a=ssrc:2 mslabel:local_stream_1\r\n"
260 "a=ssrc:2 label:video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000261 "a=ssrc:3 cname:stream_1_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000262 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
263 "a=ssrc:3 mslabel:local_stream_1\r\n"
264 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000265
266static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000267 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000268 "c=IN IP4 0.0.0.0\r\n"
269 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000270 "a=ice-ufrag:ufrag_data\r\n"
271 "a=ice-pwd:pwd_data\r\n"
272 "a=mid:data_content_name\r\n"
273 "a=sendrecv\r\n"
274 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
275 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
276 "a=rtpmap:101 google-data/90000\r\n"
277 "a=ssrc:10 cname:data_channel_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000278 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
279 "a=ssrc:10 mslabel:data_channel\r\n"
280 "a=ssrc:10 label:data_channeld0\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000281
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200282// draft-ietf-mmusic-sctp-sdp-03
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000283static const char kSdpSctpDataChannelString[] =
Guido Urdanetacecf87f2019-05-31 10:17:38 +0000284 "m=application 9 UDP/DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000285 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000286 "a=ice-ufrag:ufrag_data\r\n"
287 "a=ice-pwd:pwd_data\r\n"
288 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000289 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000290
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000291// draft-ietf-mmusic-sctp-sdp-12
Harald Alvestrand48cce4d2019-04-11 10:41:24 +0200292// Note - this is invalid per draft-ietf-mmusic-sctp-sdp-26,
293// since the separator after "sctp-port" needs to be a colon.
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000294static const char kSdpSctpDataChannelStringWithSctpPort[] =
Guido Urdanetacecf87f2019-05-31 10:17:38 +0000295 "m=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\n"
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000296 "a=sctp-port 5000\r\n"
297 "c=IN IP4 0.0.0.0\r\n"
298 "a=ice-ufrag:ufrag_data\r\n"
299 "a=ice-pwd:pwd_data\r\n"
300 "a=mid:data_content_name\r\n";
301
Harald Alvestrand48cce4d2019-04-11 10:41:24 +0200302// draft-ietf-mmusic-sctp-sdp-26
lally69f57602015-10-08 10:15:04 -0700303static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
Guido Urdanetacecf87f2019-05-31 10:17:38 +0000304 "m=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\n"
lally69f57602015-10-08 10:15:04 -0700305 "a=sctp-port:5000\r\n"
306 "c=IN IP4 0.0.0.0\r\n"
307 "a=ice-ufrag:ufrag_data\r\n"
308 "a=ice-pwd:pwd_data\r\n"
309 "a=mid:data_content_name\r\n";
310
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311static const char kSdpSctpDataChannelWithCandidatesString[] =
Guido Urdanetacecf87f2019-05-31 10:17:38 +0000312 "m=application 2345 UDP/DTLS/SCTP 5000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000313 "c=IN IP4 74.125.127.126\r\n"
314 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
315 "generation 2\r\n"
316 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
317 "generation 2\r\n"
318 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
319 "raddr 192.168.1.5 rport 2346 "
320 "generation 2\r\n"
321 "a=ice-ufrag:ufrag_data\r\n"
322 "a=ice-pwd:pwd_data\r\n"
323 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000324 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000325
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000326static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000327 "v=0\r\n"
328 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
329 "s=-\r\n"
330 "t=0 0\r\n"
331 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000332 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000333 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000334 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000335 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000336 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000337 "a=x-google-flag:conference\r\n";
338
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000339static const char kSdpSessionString[] =
340 "v=0\r\n"
341 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
342 "s=-\r\n"
343 "t=0 0\r\n"
344 "a=msid-semantic: WMS local_stream\r\n";
345
346static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000347 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000348 "c=IN IP4 0.0.0.0\r\n"
349 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000350 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
351 "a=mid:audio_content_name\r\n"
352 "a=sendrecv\r\n"
353 "a=rtpmap:111 opus/48000/2\r\n"
354 "a=ssrc:1 cname:stream_1_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000355 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
356 "a=ssrc:1 mslabel:local_stream\r\n"
357 "a=ssrc:1 label:audio_track_id_1\r\n";
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000358
359static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000360 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000361 "c=IN IP4 0.0.0.0\r\n"
362 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000363 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
364 "a=mid:video_content_name\r\n"
365 "a=sendrecv\r\n"
366 "a=rtpmap:120 VP8/90000\r\n"
367 "a=ssrc:2 cname:stream_1_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000368 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
369 "a=ssrc:2 mslabel:local_stream\r\n"
370 "a=ssrc:2 label:video_track_id_1\r\n";
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000371
deadbeef25ed4352016-12-12 18:37:36 -0800372// Reference sdp string using bundle-only.
373static const char kBundleOnlySdpFullString[] =
374 "v=0\r\n"
375 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
376 "s=-\r\n"
377 "t=0 0\r\n"
Emil Lundmark801c9992021-01-19 13:06:32 +0100378 "a=extmap-allow-mixed\r\n"
deadbeef25ed4352016-12-12 18:37:36 -0800379 "a=group:BUNDLE audio_content_name video_content_name\r\n"
380 "a=msid-semantic: WMS local_stream_1\r\n"
381 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
382 "c=IN IP4 74.125.127.126\r\n"
383 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
384 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
385 "generation 2\r\n"
386 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
387 "generation 2\r\n"
388 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
389 "generation 2\r\n"
390 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
391 "generation 2\r\n"
392 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
393 "raddr 192.168.1.5 rport 2346 "
394 "generation 2\r\n"
395 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
396 "raddr 192.168.1.5 rport 2348 "
397 "generation 2\r\n"
398 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
399 "a=mid:audio_content_name\r\n"
400 "a=sendrecv\r\n"
401 "a=rtcp-mux\r\n"
402 "a=rtcp-rsize\r\n"
403 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
404 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
405 "dummy_session_params\r\n"
406 "a=rtpmap:111 opus/48000/2\r\n"
407 "a=rtpmap:103 ISAC/16000\r\n"
408 "a=rtpmap:104 ISAC/32000\r\n"
409 "a=ssrc:1 cname:stream_1_cname\r\n"
410 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000411 "a=ssrc:1 mslabel:local_stream_1\r\n"
412 "a=ssrc:1 label:audio_track_id_1\r\n"
deadbeef25ed4352016-12-12 18:37:36 -0800413 "m=video 0 RTP/SAVPF 120\r\n"
414 "c=IN IP4 0.0.0.0\r\n"
415 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
416 "a=bundle-only\r\n"
417 "a=mid:video_content_name\r\n"
418 "a=sendrecv\r\n"
419 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
420 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
421 "a=rtpmap:120 VP8/90000\r\n"
422 "a=ssrc-group:FEC 2 3\r\n"
423 "a=ssrc:2 cname:stream_1_cname\r\n"
424 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000425 "a=ssrc:2 mslabel:local_stream_1\r\n"
426 "a=ssrc:2 label:video_track_id_1\r\n"
deadbeef25ed4352016-12-12 18:37:36 -0800427 "a=ssrc:3 cname:stream_1_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000428 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
429 "a=ssrc:3 mslabel:local_stream_1\r\n"
430 "a=ssrc:3 label:video_track_id_1\r\n";
deadbeef25ed4352016-12-12 18:37:36 -0800431
deadbeef9d3584c2016-02-16 17:54:10 -0800432// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
433// tracks.
434static const char kPlanBSdpFullString[] =
435 "v=0\r\n"
436 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
437 "s=-\r\n"
438 "t=0 0\r\n"
Emil Lundmark801c9992021-01-19 13:06:32 +0100439 "a=extmap-allow-mixed\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800440 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
441 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
442 "c=IN IP4 74.125.127.126\r\n"
443 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
444 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
445 "generation 2\r\n"
446 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
447 "generation 2\r\n"
448 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
449 "generation 2\r\n"
450 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
451 "generation 2\r\n"
452 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
453 "raddr 192.168.1.5 rport 2346 "
454 "generation 2\r\n"
455 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
456 "raddr 192.168.1.5 rport 2348 "
457 "generation 2\r\n"
458 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
459 "a=mid:audio_content_name\r\n"
460 "a=sendrecv\r\n"
461 "a=rtcp-mux\r\n"
462 "a=rtcp-rsize\r\n"
463 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
464 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
465 "dummy_session_params\r\n"
466 "a=rtpmap:111 opus/48000/2\r\n"
467 "a=rtpmap:103 ISAC/16000\r\n"
468 "a=rtpmap:104 ISAC/32000\r\n"
469 "a=ssrc:1 cname:stream_1_cname\r\n"
470 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000471 "a=ssrc:1 mslabel:local_stream_1\r\n"
472 "a=ssrc:1 label:audio_track_id_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800473 "a=ssrc:4 cname:stream_2_cname\r\n"
474 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000475 "a=ssrc:4 mslabel:local_stream_2\r\n"
476 "a=ssrc:4 label:audio_track_id_2\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800477 "m=video 3457 RTP/SAVPF 120\r\n"
478 "c=IN IP4 74.125.224.39\r\n"
479 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
480 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
481 "generation 2\r\n"
482 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
483 "generation 2\r\n"
484 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
485 "generation 2\r\n"
486 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
487 "generation 2\r\n"
488 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
489 "generation 2\r\n"
490 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
491 "generation 2\r\n"
492 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
493 "a=mid:video_content_name\r\n"
494 "a=sendrecv\r\n"
495 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
496 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
497 "a=rtpmap:120 VP8/90000\r\n"
498 "a=ssrc-group:FEC 2 3\r\n"
499 "a=ssrc:2 cname:stream_1_cname\r\n"
500 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000501 "a=ssrc:2 mslabel:local_stream_1\r\n"
502 "a=ssrc:2 label:video_track_id_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800503 "a=ssrc:3 cname:stream_1_cname\r\n"
504 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000505 "a=ssrc:3 mslabel:local_stream_1\r\n"
506 "a=ssrc:3 label:video_track_id_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800507 "a=ssrc:5 cname:stream_2_cname\r\n"
508 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000509 "a=ssrc:5 mslabel:local_stream_2\r\n"
510 "a=ssrc:5 label:video_track_id_2\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800511 "a=ssrc:6 cname:stream_2_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000512 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
513 "a=ssrc:6 mslabel:local_stream_2\r\n"
514 "a=ssrc:6 label:video_track_id_3\r\n";
deadbeef9d3584c2016-02-16 17:54:10 -0800515
516// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
517// tracks.
518static const char kUnifiedPlanSdpFullString[] =
519 "v=0\r\n"
520 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
521 "s=-\r\n"
522 "t=0 0\r\n"
Emil Lundmark801c9992021-01-19 13:06:32 +0100523 "a=extmap-allow-mixed\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800524 "a=msid-semantic: WMS local_stream_1\r\n"
525 // Audio track 1, stream 1 (with candidates).
526 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
527 "c=IN IP4 74.125.127.126\r\n"
528 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
529 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
530 "generation 2\r\n"
531 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
532 "generation 2\r\n"
533 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
534 "generation 2\r\n"
535 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
536 "generation 2\r\n"
537 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
538 "raddr 192.168.1.5 rport 2346 "
539 "generation 2\r\n"
540 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
541 "raddr 192.168.1.5 rport 2348 "
542 "generation 2\r\n"
543 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
544 "a=mid:audio_content_name\r\n"
545 "a=msid:local_stream_1 audio_track_id_1\r\n"
546 "a=sendrecv\r\n"
547 "a=rtcp-mux\r\n"
548 "a=rtcp-rsize\r\n"
549 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
550 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
551 "dummy_session_params\r\n"
552 "a=rtpmap:111 opus/48000/2\r\n"
553 "a=rtpmap:103 ISAC/16000\r\n"
554 "a=rtpmap:104 ISAC/32000\r\n"
555 "a=ssrc:1 cname:stream_1_cname\r\n"
556 // Video track 1, stream 1 (with candidates).
557 "m=video 3457 RTP/SAVPF 120\r\n"
558 "c=IN IP4 74.125.224.39\r\n"
559 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
560 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
561 "generation 2\r\n"
562 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
563 "generation 2\r\n"
564 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
565 "generation 2\r\n"
566 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
567 "generation 2\r\n"
568 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
569 "generation 2\r\n"
570 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
571 "generation 2\r\n"
572 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
573 "a=mid:video_content_name\r\n"
574 "a=msid:local_stream_1 video_track_id_1\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-group:FEC 2 3\r\n"
580 "a=ssrc:2 cname:stream_1_cname\r\n"
581 "a=ssrc:3 cname:stream_1_cname\r\n"
582 // Audio track 2, stream 2.
583 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
584 "c=IN IP4 0.0.0.0\r\n"
585 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
586 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
587 "a=mid:audio_content_name_2\r\n"
588 "a=msid:local_stream_2 audio_track_id_2\r\n"
589 "a=sendrecv\r\n"
590 "a=rtcp-mux\r\n"
591 "a=rtcp-rsize\r\n"
592 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
593 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
594 "dummy_session_params\r\n"
595 "a=rtpmap:111 opus/48000/2\r\n"
596 "a=rtpmap:103 ISAC/16000\r\n"
597 "a=rtpmap:104 ISAC/32000\r\n"
598 "a=ssrc:4 cname:stream_2_cname\r\n"
599 // Video track 2, stream 2.
600 "m=video 9 RTP/SAVPF 120\r\n"
601 "c=IN IP4 0.0.0.0\r\n"
602 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
603 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
604 "a=mid:video_content_name_2\r\n"
605 "a=msid:local_stream_2 video_track_id_2\r\n"
606 "a=sendrecv\r\n"
607 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
608 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
609 "a=rtpmap:120 VP8/90000\r\n"
610 "a=ssrc:5 cname:stream_2_cname\r\n"
611 // Video track 3, stream 2.
612 "m=video 9 RTP/SAVPF 120\r\n"
613 "c=IN IP4 0.0.0.0\r\n"
614 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
615 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
616 "a=mid:video_content_name_3\r\n"
617 "a=msid:local_stream_2 video_track_id_3\r\n"
618 "a=sendrecv\r\n"
619 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
620 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
621 "a=rtpmap:120 VP8/90000\r\n"
622 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000623
Seth Hampson5b4f0752018-04-02 16:31:36 -0700624// Unified Plan SDP reference string:
625// - audio track 1 has 1 a=msid lines
626// - audio track 2 has 2 a=msid lines
627// - audio track 3 has 1 a=msid line with the special "-" marker signifying that
628// there are 0 media stream ids.
629// This Unified Plan SDP represents a SDP that signals the msid using both
630// a=msid and a=ssrc msid semantics.
631static const char kUnifiedPlanSdpFullStringWithSpecialMsid[] =
632 "v=0\r\n"
633 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
634 "s=-\r\n"
635 "t=0 0\r\n"
Emil Lundmark801c9992021-01-19 13:06:32 +0100636 "a=extmap-allow-mixed\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700637 "a=msid-semantic: WMS local_stream_1\r\n"
638 // Audio track 1, with 1 stream id.
639 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
640 "c=IN IP4 74.125.127.126\r\n"
641 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
642 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
643 "generation 2\r\n"
644 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
645 "generation 2\r\n"
646 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
647 "generation 2\r\n"
648 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
649 "generation 2\r\n"
650 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
651 "raddr 192.168.1.5 rport 2346 "
652 "generation 2\r\n"
653 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
654 "raddr 192.168.1.5 rport 2348 "
655 "generation 2\r\n"
656 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
657 "a=mid:audio_content_name\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700658 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700659 "a=msid:local_stream_1 audio_track_id_1\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700660 "a=rtcp-mux\r\n"
661 "a=rtcp-rsize\r\n"
662 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
663 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
664 "dummy_session_params\r\n"
665 "a=rtpmap:111 opus/48000/2\r\n"
666 "a=rtpmap:103 ISAC/16000\r\n"
667 "a=rtpmap:104 ISAC/32000\r\n"
668 "a=ssrc:1 cname:stream_1_cname\r\n"
669 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000670 "a=ssrc:1 mslabel:local_stream_1\r\n"
671 "a=ssrc:1 label:audio_track_id_1\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700672 // Audio track 2, with two stream ids.
673 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
674 "c=IN IP4 0.0.0.0\r\n"
675 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
676 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
677 "a=mid:audio_content_name_2\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700678 "a=sendrecv\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700679 "a=msid:local_stream_1 audio_track_id_2\r\n"
680 "a=msid:local_stream_2 audio_track_id_2\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700681 "a=rtcp-mux\r\n"
682 "a=rtcp-rsize\r\n"
683 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
684 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
685 "dummy_session_params\r\n"
686 "a=rtpmap:111 opus/48000/2\r\n"
687 "a=rtpmap:103 ISAC/16000\r\n"
688 "a=rtpmap:104 ISAC/32000\r\n"
689 "a=ssrc:4 cname:stream_1_cname\r\n"
690 // The support for Plan B msid signaling only includes the
691 // first media stream id "local_stream_1."
692 "a=ssrc:4 msid:local_stream_1 audio_track_id_2\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000693 "a=ssrc:4 mslabel:local_stream_1\r\n"
694 "a=ssrc:4 label:audio_track_id_2\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700695 // Audio track 3, with no stream ids.
696 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
697 "c=IN IP4 0.0.0.0\r\n"
698 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
699 "a=ice-ufrag:ufrag_voice_3\r\na=ice-pwd:pwd_voice_3\r\n"
700 "a=mid:audio_content_name_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700701 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700702 "a=msid:- audio_track_id_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700703 "a=rtcp-mux\r\n"
704 "a=rtcp-rsize\r\n"
705 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
706 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
707 "dummy_session_params\r\n"
708 "a=rtpmap:111 opus/48000/2\r\n"
709 "a=rtpmap:103 ISAC/16000\r\n"
710 "a=rtpmap:104 ISAC/32000\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700711 "a=ssrc:7 cname:stream_2_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000712 "a=ssrc:7 msid:- audio_track_id_3\r\n"
713 "a=ssrc:7 mslabel:-\r\n"
714 "a=ssrc:7 label:audio_track_id_3\r\n";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700715
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800716// SDP string for unified plan without SSRCs
717static const char kUnifiedPlanSdpFullStringNoSsrc[] =
718 "v=0\r\n"
719 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
720 "s=-\r\n"
721 "t=0 0\r\n"
722 "a=msid-semantic: WMS local_stream_1\r\n"
723 // Audio track 1, stream 1 (with candidates).
724 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
725 "c=IN IP4 74.125.127.126\r\n"
726 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
727 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
728 "generation 2\r\n"
729 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
730 "generation 2\r\n"
731 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
732 "generation 2\r\n"
733 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
734 "generation 2\r\n"
735 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
736 "raddr 192.168.1.5 rport 2346 "
737 "generation 2\r\n"
738 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
739 "raddr 192.168.1.5 rport 2348 "
740 "generation 2\r\n"
741 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
742 "a=mid:audio_content_name\r\n"
743 "a=msid:local_stream_1 audio_track_id_1\r\n"
744 "a=sendrecv\r\n"
745 "a=rtcp-mux\r\n"
746 "a=rtcp-rsize\r\n"
747 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
748 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
749 "dummy_session_params\r\n"
750 "a=rtpmap:111 opus/48000/2\r\n"
751 "a=rtpmap:103 ISAC/16000\r\n"
752 "a=rtpmap:104 ISAC/32000\r\n"
753 // Video track 1, stream 1 (with candidates).
754 "m=video 3457 RTP/SAVPF 120\r\n"
755 "c=IN IP4 74.125.224.39\r\n"
756 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
757 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
758 "generation 2\r\n"
759 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
760 "generation 2\r\n"
761 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
762 "generation 2\r\n"
763 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
764 "generation 2\r\n"
765 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
766 "generation 2\r\n"
767 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
768 "generation 2\r\n"
769 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
770 "a=mid:video_content_name\r\n"
771 "a=msid:local_stream_1 video_track_id_1\r\n"
772 "a=sendrecv\r\n"
773 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
774 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
775 "a=rtpmap:120 VP8/90000\r\n"
776 // Audio track 2, stream 2.
777 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
778 "c=IN IP4 0.0.0.0\r\n"
779 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
780 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
781 "a=mid:audio_content_name_2\r\n"
782 "a=msid:local_stream_2 audio_track_id_2\r\n"
783 "a=sendrecv\r\n"
784 "a=rtcp-mux\r\n"
785 "a=rtcp-rsize\r\n"
786 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
787 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
788 "dummy_session_params\r\n"
789 "a=rtpmap:111 opus/48000/2\r\n"
790 "a=rtpmap:103 ISAC/16000\r\n"
791 "a=rtpmap:104 ISAC/32000\r\n"
792 // Video track 2, stream 2.
793 "m=video 9 RTP/SAVPF 120\r\n"
794 "c=IN IP4 0.0.0.0\r\n"
795 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
796 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
797 "a=mid:video_content_name_2\r\n"
798 "a=msid:local_stream_2 video_track_id_2\r\n"
799 "a=sendrecv\r\n"
800 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
801 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
802 "a=rtpmap:120 VP8/90000\r\n"
803 // Video track 3, stream 2.
804 "m=video 9 RTP/SAVPF 120\r\n"
805 "c=IN IP4 0.0.0.0\r\n"
806 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
807 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
808 "a=mid:video_content_name_3\r\n"
809 "a=msid:local_stream_2 video_track_id_3\r\n"
810 "a=sendrecv\r\n"
811 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
812 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
813 "a=rtpmap:120 VP8/90000\r\n";
814
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000815// One candidate reference string as per W3c spec.
816// candidate:<blah> not a=candidate:<blah>CRLF
817static const char kRawCandidate[] =
818 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
819// One candidate reference string.
820static const char kSdpOneCandidate[] =
821 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
822 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000823
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000824static const char kSdpTcpActiveCandidate[] =
825 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
826 "tcptype active generation 2";
827static const char kSdpTcpPassiveCandidate[] =
828 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
829 "tcptype passive generation 2";
830static const char kSdpTcpSOCandidate[] =
831 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
832 "tcptype so generation 2";
833static const char kSdpTcpInvalidCandidate[] =
834 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
835 "tcptype invalid generation 2";
836
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000837// One candidate reference string with IPV6 address.
838static const char kRawIPV6Candidate[] =
839 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 12:04:36 -0700840 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000841
842// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800843static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800845 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000846
Zach Steinb336c272018-08-09 01:16:13 -0700847static const char kRawHostnameCandidate[] =
848 "candidate:a0+B/1 1 udp 2130706432 a.test 1234 typ host generation 2";
849
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000850// Session id and version
851static const char kSessionId[] = "18446744069414584320";
852static const char kSessionVersion[] = "18446462598732840960";
853
deadbeef9d3584c2016-02-16 17:54:10 -0800854// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000855static const char kIceOption1[] = "iceoption1";
856static const char kIceOption2[] = "iceoption2";
857static const char kIceOption3[] = "iceoption3";
858
deadbeef9d3584c2016-02-16 17:54:10 -0800859// ICE ufrags/passwords.
860static const char kUfragVoice[] = "ufrag_voice";
861static const char kPwdVoice[] = "pwd_voice";
862static const char kUfragVideo[] = "ufrag_video";
863static const char kPwdVideo[] = "pwd_video";
864static const char kUfragData[] = "ufrag_data";
865static const char kPwdData[] = "pwd_data";
866
867// Extra ufrags/passwords for extra unified plan m= sections.
868static const char kUfragVoice2[] = "ufrag_voice_2";
869static const char kPwdVoice2[] = "pwd_voice_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700870static const char kUfragVoice3[] = "ufrag_voice_3";
871static const char kPwdVoice3[] = "pwd_voice_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800872static const char kUfragVideo2[] = "ufrag_video_2";
873static const char kPwdVideo2[] = "pwd_video_2";
874static const char kUfragVideo3[] = "ufrag_video_3";
875static const char kPwdVideo3[] = "pwd_video_3";
876
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000877// Content name
878static const char kAudioContentName[] = "audio_content_name";
879static const char kVideoContentName[] = "video_content_name";
880static const char kDataContentName[] = "data_content_name";
881
deadbeef9d3584c2016-02-16 17:54:10 -0800882// Extra content names for extra unified plan m= sections.
883static const char kAudioContentName2[] = "audio_content_name_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700884static const char kAudioContentName3[] = "audio_content_name_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800885static const char kVideoContentName2[] = "video_content_name_2";
886static const char kVideoContentName3[] = "video_content_name_3";
887
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000888// MediaStream 1
Seth Hampson845e8782018-03-02 11:34:10 -0800889static const char kStreamId1[] = "local_stream_1";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890static const char kStream1Cname[] = "stream_1_cname";
891static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200892static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000893static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800894static const uint32_t kVideoTrack1Ssrc1 = 2;
895static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000896
897// MediaStream 2
Seth Hampson845e8782018-03-02 11:34:10 -0800898static const char kStreamId2[] = "local_stream_2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000899static const char kStream2Cname[] = "stream_2_cname";
900static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200901static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800902static const char kVideoTrackId2[] = "video_track_id_2";
903static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000904static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800905static const uint32_t kVideoTrack3Ssrc = 6;
Seth Hampson5b4f0752018-04-02 16:31:36 -0700906static const char kAudioTrackId3[] = "audio_track_id_3";
907static const uint32_t kAudioTrack3Ssrc = 7;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000908
909// DataChannel
910static const char kDataChannelLabel[] = "data_channel";
911static const char kDataChannelMsid[] = "data_channeld0";
912static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200913static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000914
915// Candidate
916static const char kDummyMid[] = "dummy_mid";
917static const int kDummyIndex = 123;
918
919// Misc
Steve Antona3a92c22017-12-07 10:27:41 -0800920static SdpType kDummyType = SdpType::kOffer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000921
922// Helper functions
923
924static bool SdpDeserialize(const std::string& message,
925 JsepSessionDescription* jdesc) {
926 return webrtc::SdpDeserialize(message, jdesc, NULL);
927}
928
929static bool SdpDeserializeCandidate(const std::string& message,
930 JsepIceCandidate* candidate) {
931 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
932}
933
934// Add some extra |newlines| to the |message| after |line|.
935static void InjectAfter(const std::string& line,
936 const std::string& newlines,
937 std::string* message) {
Steve Anton1c9c9fc2019-02-14 15:13:09 -0800938 absl::StrReplaceAll({{line, line + newlines}}, message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000939}
940
941static void Replace(const std::string& line,
942 const std::string& newlines,
943 std::string* message) {
Steve Anton1c9c9fc2019-02-14 15:13:09 -0800944 absl::StrReplaceAll({{line, newlines}}, message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945}
946
Philipp Hanckeb70c9532021-01-13 10:40:06 +0100947// Expect a parse failure on the line containing |bad_part| when attempting to
948// parse |bad_sdp|.
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000949static void ExpectParseFailure(const std::string& bad_sdp,
950 const std::string& bad_part) {
Steve Antona3a92c22017-12-07 10:27:41 -0800951 JsepSessionDescription desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000952 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000953 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000954 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000955 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
956}
957
958// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
959static void ExpectParseFailure(const char* good_part, const char* bad_part) {
960 std::string bad_sdp = kSdpFullString;
961 Replace(good_part, bad_part, &bad_sdp);
962 ExpectParseFailure(bad_sdp, bad_part);
963}
964
965// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
966static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
967 const std::string& newlines,
968 const std::string& bad_part) {
969 std::string bad_sdp = kSdpFullString;
970 InjectAfter(injectpoint, newlines, &bad_sdp);
971 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000972}
973
Steve Anton4e70a722017-11-28 14:57:10 -0800974static void ReplaceDirection(RtpTransceiverDirection direction,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000975 std::string* message) {
976 std::string new_direction;
977 switch (direction) {
Steve Anton4e70a722017-11-28 14:57:10 -0800978 case RtpTransceiverDirection::kInactive:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000979 new_direction = "a=inactive";
980 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800981 case RtpTransceiverDirection::kSendOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000982 new_direction = "a=sendonly";
983 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800984 case RtpTransceiverDirection::kRecvOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000985 new_direction = "a=recvonly";
986 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800987 case RtpTransceiverDirection::kSendRecv:
Markus Handell45c104b2020-03-11 10:51:13 +0100988 new_direction = "a=sendrecv";
989 break;
990 case RtpTransceiverDirection::kStopped:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000991 default:
Markus Handell45c104b2020-03-11 10:51:13 +0100992 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000993 new_direction = "a=sendrecv";
994 break;
995 }
996 Replace("a=sendrecv", new_direction, message);
997}
998
Yves Gerey665174f2018-06-19 15:03:05 +0200999static void ReplaceRejected(bool audio_rejected,
1000 bool video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001001 std::string* message) {
1002 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001003 Replace("m=audio 9", "m=audio 0", message);
1004 Replace(kAttributeIceUfragVoice, "", message);
1005 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001006 }
1007 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001008 Replace("m=video 9", "m=video 0", message);
1009 Replace(kAttributeIceUfragVideo, "", message);
1010 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001011 }
1012}
1013
1014// WebRtcSdpTest
1015
Mirko Bonadei6a489f22019-04-09 15:11:12 +02001016class WebRtcSdpTest : public ::testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001017 public:
Steve Antona3a92c22017-12-07 10:27:41 -08001018 WebRtcSdpTest() : jdesc_(kDummyType) {
phoglund37ebcf02016-01-08 05:04:57 -08001019#ifdef WEBRTC_ANDROID
1020 webrtc::InitializeAndroidObjects();
1021#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001022 // AudioContentDescription
1023 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -08001024 StreamParams audio_stream;
1025 audio_stream.id = kAudioTrackId1;
1026 audio_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001027 audio_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -08001028 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
1029 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 11:04:53 -07001030 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
1031 audio_desc_->set_connection_address(audio_addr);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001032 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1033 absl::WrapUnique(audio_desc_));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001034
1035 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -08001036 video_desc_ = CreateVideoContentDescription();
1037 StreamParams video_stream;
1038 video_stream.id = kVideoTrackId1;
1039 video_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001040 video_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -08001041 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
1042 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
1043 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
1044 video_stream.ssrc_groups.push_back(ssrc_group);
1045 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 11:04:53 -07001046 rtc::SocketAddress video_addr("74.125.224.39", 3457);
1047 video_desc_->set_connection_address(video_addr);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001048 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp,
1049 absl::WrapUnique(video_desc_));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001050
1051 // TransportInfo
Steve Anton06817cd2018-12-18 15:55:30 -08001052 desc_.AddTransportInfo(TransportInfo(
1053 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice)));
1054 desc_.AddTransportInfo(TransportInfo(
1055 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001056
1057 // v4 host
1058 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001059 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001060 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001061 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1062 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001063 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001064 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001065 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1066 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001067 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001068 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001069 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1070 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001071 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001072 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001073 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1074 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001075
1076 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001077 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001078 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1079 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001080 cricket::LOCAL_PORT_TYPE,
1081 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001082 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001083 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1084 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001085 cricket::LOCAL_PORT_TYPE,
1086 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001087 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001088 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1089 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001090 cricket::LOCAL_PORT_TYPE,
1091 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001092 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001093 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1094 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001095 cricket::LOCAL_PORT_TYPE,
1096 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001097
1098 // stun
1099 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001100 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
1101 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001102 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1103 address_stun, kCandidatePriority, "", "",
1104 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001105 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001106 candidate9.set_related_address(rel_address_stun);
1107
1108 address_stun.SetPort(port_stun++);
1109 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001110 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1111 address_stun, kCandidatePriority, "", "",
1112 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001113 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001114 candidate10.set_related_address(rel_address_stun);
1115
1116 // relay
1117 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001118 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001119 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1120 address_relay, kCandidatePriority, "", "",
1121 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001122 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001123 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001124 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1125 address_relay, kCandidatePriority, "", "",
1126 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001127 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001128
1129 // voice
1130 candidates_.push_back(candidate1);
1131 candidates_.push_back(candidate2);
1132 candidates_.push_back(candidate5);
1133 candidates_.push_back(candidate6);
1134 candidates_.push_back(candidate9);
1135 candidates_.push_back(candidate10);
1136
1137 // video
1138 candidates_.push_back(candidate3);
1139 candidates_.push_back(candidate4);
1140 candidates_.push_back(candidate7);
1141 candidates_.push_back(candidate8);
1142 candidates_.push_back(candidate11);
1143 candidates_.push_back(candidate12);
1144
Yves Gerey665174f2018-06-19 15:03:05 +02001145 jcandidate_.reset(
1146 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001147
1148 // Set up JsepSessionDescription.
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001149 jdesc_.Initialize(desc_.Clone(), kSessionId, kSessionVersion);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001150 std::string mline_id;
1151 int mline_index = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001152 for (size_t i = 0; i < candidates_.size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001153 // In this test, the audio m line index will be 0, and the video m line
1154 // will be 1.
1155 bool is_video = (i > 5);
1156 mline_id = is_video ? "video_content_name" : "audio_content_name";
1157 mline_index = is_video ? 1 : 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001158 JsepIceCandidate jice(mline_id, mline_index, candidates_.at(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001159 jdesc_.AddCandidate(&jice);
1160 }
1161 }
1162
Seth Hampson5b4f0752018-04-02 16:31:36 -07001163 void RemoveVideoCandidates() {
deadbeef25ed4352016-12-12 18:37:36 -08001164 const IceCandidateCollection* video_candidates_collection =
1165 jdesc_.candidates(1);
1166 ASSERT_NE(nullptr, video_candidates_collection);
1167 std::vector<cricket::Candidate> video_candidates;
1168 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1169 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1170 c.set_transport_name("video_content_name");
1171 video_candidates.push_back(c);
1172 }
1173 jdesc_.RemoveCandidates(video_candidates);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001174 }
1175
1176 // Turns the existing reference description into a description using
1177 // a=bundle-only. This means no transport attributes and a 0 port value on
1178 // the m= sections not associated with the BUNDLE-tag.
1179 void MakeBundleOnlyDescription() {
1180 RemoveVideoCandidates();
deadbeef25ed4352016-12-12 18:37:36 -08001181
1182 // And the rest of the transport attributes.
1183 desc_.transport_infos()[1].description.ice_ufrag.clear();
1184 desc_.transport_infos()[1].description.ice_pwd.clear();
1185 desc_.transport_infos()[1].description.connection_role =
1186 cricket::CONNECTIONROLE_NONE;
1187
1188 // Set bundle-only flag.
1189 desc_.contents()[1].bundle_only = true;
1190
1191 // Add BUNDLE group.
1192 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1193 group.AddContentName(kAudioContentName);
1194 group.AddContentName(kVideoContentName);
1195 desc_.AddGroup(group);
1196
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001197 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef25ed4352016-12-12 18:37:36 -08001198 jdesc_.session_version()));
1199 }
1200
deadbeef9d3584c2016-02-16 17:54:10 -08001201 // Turns the existing reference description into a plan B description,
1202 // with 2 audio tracks and 3 video tracks.
1203 void MakePlanBDescription() {
Harald Alvestrandb97d2fe2020-02-28 11:54:40 +01001204 audio_desc_ = new AudioContentDescription(*audio_desc_);
1205 video_desc_ = new VideoContentDescription(*video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001206
1207 StreamParams audio_track_2;
1208 audio_track_2.id = kAudioTrackId2;
1209 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001210 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001211 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1212 audio_desc_->AddStream(audio_track_2);
1213
1214 StreamParams video_track_2;
1215 video_track_2.id = kVideoTrackId2;
1216 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001217 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001218 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1219 video_desc_->AddStream(video_track_2);
1220
1221 StreamParams video_track_3;
1222 video_track_3.id = kVideoTrackId3;
1223 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001224 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001225 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1226 video_desc_->AddStream(video_track_3);
1227
1228 desc_.RemoveContentByName(kAudioContentName);
1229 desc_.RemoveContentByName(kVideoContentName);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001230 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1231 absl::WrapUnique(audio_desc_));
1232 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp,
1233 absl::WrapUnique(video_desc_));
deadbeef9d3584c2016-02-16 17:54:10 -08001234
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001235 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef9d3584c2016-02-16 17:54:10 -08001236 jdesc_.session_version()));
1237 }
1238
1239 // Turns the existing reference description into a unified plan description,
1240 // with 2 audio tracks and 3 video tracks.
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001241 void MakeUnifiedPlanDescription(bool use_ssrcs = true) {
deadbeef9d3584c2016-02-16 17:54:10 -08001242 // Audio track 2.
1243 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1244 StreamParams audio_track_2;
1245 audio_track_2.id = kAudioTrackId2;
Seth Hampson845e8782018-03-02 11:34:10 -08001246 audio_track_2.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001247 if (use_ssrcs) {
1248 audio_track_2.cname = kStream2Cname;
1249 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1250 }
deadbeef9d3584c2016-02-16 17:54:10 -08001251 audio_desc_2->AddStream(audio_track_2);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001252 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp,
1253 absl::WrapUnique(audio_desc_2));
Steve Anton06817cd2018-12-18 15:55:30 -08001254 desc_.AddTransportInfo(TransportInfo(
1255 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2)));
deadbeef9d3584c2016-02-16 17:54:10 -08001256 // Video track 2, in stream 2.
1257 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1258 StreamParams video_track_2;
1259 video_track_2.id = kVideoTrackId2;
Seth Hampson845e8782018-03-02 11:34:10 -08001260 video_track_2.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001261 if (use_ssrcs) {
1262 video_track_2.cname = kStream2Cname;
1263 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1264 }
deadbeef9d3584c2016-02-16 17:54:10 -08001265 video_desc_2->AddStream(video_track_2);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001266 desc_.AddContent(kVideoContentName2, MediaProtocolType::kRtp,
1267 absl::WrapUnique(video_desc_2));
Steve Anton06817cd2018-12-18 15:55:30 -08001268 desc_.AddTransportInfo(TransportInfo(
1269 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2)));
deadbeef9d3584c2016-02-16 17:54:10 -08001270
1271 // Video track 3, in stream 2.
1272 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1273 StreamParams video_track_3;
1274 video_track_3.id = kVideoTrackId3;
Seth Hampson845e8782018-03-02 11:34:10 -08001275 video_track_3.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001276 if (use_ssrcs) {
1277 video_track_3.cname = kStream2Cname;
1278 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1279 }
deadbeef9d3584c2016-02-16 17:54:10 -08001280 video_desc_3->AddStream(video_track_3);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001281 desc_.AddContent(kVideoContentName3, MediaProtocolType::kRtp,
1282 absl::WrapUnique(video_desc_3));
Steve Anton06817cd2018-12-18 15:55:30 -08001283 desc_.AddTransportInfo(TransportInfo(
1284 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3)));
Steve Antone831b8c2018-02-01 12:22:16 -08001285 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
deadbeef9d3584c2016-02-16 17:54:10 -08001286
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001287 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef9d3584c2016-02-16 17:54:10 -08001288 jdesc_.session_version()));
1289 }
1290
1291 // Creates an audio content description with no streams, and some default
1292 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001293 AudioContentDescription* CreateAudioContentDescription() {
1294 AudioContentDescription* audio = new AudioContentDescription();
1295 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -08001296 audio->set_rtcp_reduced_size(true);
Yves Gerey665174f2018-06-19 15:03:05 +02001297 audio->AddCrypto(CryptoParams(
1298 1, "AES_CM_128_HMAC_SHA1_32",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001299 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1300 "dummy_session_params"));
1301 audio->set_protocol(cricket::kMediaProtocolSavpf);
Philipp Hanckef2a4ec12020-07-01 21:07:32 +02001302 audio->AddCodec(AudioCodec(111, "opus", 48000, 0, 2));
ossue1405ad2017-01-23 08:55:48 -08001303 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1304 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001305 return audio;
1306 }
1307
Seth Hampson5b4f0752018-04-02 16:31:36 -07001308 // Turns the existing reference description into a unified plan description,
1309 // with 3 audio MediaContentDescriptions with special StreamParams that
1310 // contain 0 or multiple stream ids: - audio track 1 has 1 media stream id -
1311 // audio track 2 has 2 media stream ids - audio track 3 has 0 media stream ids
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001312 void MakeUnifiedPlanDescriptionMultipleStreamIds(const int msid_signaling) {
Seth Hampson5b4f0752018-04-02 16:31:36 -07001313 desc_.RemoveContentByName(kVideoContentName);
1314 desc_.RemoveTransportInfoByName(kVideoContentName);
1315 RemoveVideoCandidates();
1316
1317 // Audio track 2 has 2 media stream ids.
1318 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1319 StreamParams audio_track_2;
1320 audio_track_2.id = kAudioTrackId2;
1321 audio_track_2.cname = kStream1Cname;
1322 audio_track_2.set_stream_ids({kStreamId1, kStreamId2});
1323 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1324 audio_desc_2->AddStream(audio_track_2);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001325 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp,
1326 absl::WrapUnique(audio_desc_2));
Steve Anton06817cd2018-12-18 15:55:30 -08001327 desc_.AddTransportInfo(TransportInfo(
1328 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2)));
Seth Hampson5b4f0752018-04-02 16:31:36 -07001329
1330 // Audio track 3 has no stream ids.
1331 AudioContentDescription* audio_desc_3 = CreateAudioContentDescription();
1332 StreamParams audio_track_3;
1333 audio_track_3.id = kAudioTrackId3;
1334 audio_track_3.cname = kStream2Cname;
1335 audio_track_3.set_stream_ids({});
1336 audio_track_3.ssrcs.push_back(kAudioTrack3Ssrc);
1337 audio_desc_3->AddStream(audio_track_3);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001338 desc_.AddContent(kAudioContentName3, MediaProtocolType::kRtp,
1339 absl::WrapUnique(audio_desc_3));
Steve Anton06817cd2018-12-18 15:55:30 -08001340 desc_.AddTransportInfo(TransportInfo(
1341 kAudioContentName3, TransportDescription(kUfragVoice3, kPwdVoice3)));
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001342 desc_.set_msid_signaling(msid_signaling);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001343 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
Seth Hampson5b4f0752018-04-02 16:31:36 -07001344 jdesc_.session_version()));
1345 }
1346
Seth Hampson5897a6e2018-04-03 11:16:33 -07001347 // Turns the existing reference description into a unified plan description
1348 // with one audio MediaContentDescription that contains one StreamParams with
1349 // 0 ssrcs.
1350 void MakeUnifiedPlanDescriptionNoSsrcSignaling() {
1351 desc_.RemoveContentByName(kVideoContentName);
1352 desc_.RemoveContentByName(kAudioContentName);
1353 desc_.RemoveTransportInfoByName(kVideoContentName);
1354 RemoveVideoCandidates();
1355
1356 AudioContentDescription* audio_desc = CreateAudioContentDescription();
1357 StreamParams audio_track;
1358 audio_track.id = kAudioTrackId1;
1359 audio_track.set_stream_ids({kStreamId1});
1360 audio_desc->AddStream(audio_track);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001361 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1362 absl::WrapUnique(audio_desc));
Seth Hampson5897a6e2018-04-03 11:16:33 -07001363
1364 // Enable signaling a=msid lines.
1365 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001366 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
Seth Hampson5897a6e2018-04-03 11:16:33 -07001367 jdesc_.session_version()));
1368 }
1369
deadbeef9d3584c2016-02-16 17:54:10 -08001370 // Creates a video content description with no streams, and some default
1371 // configuration.
1372 VideoContentDescription* CreateVideoContentDescription() {
1373 VideoContentDescription* video = new VideoContentDescription();
1374 video->AddCrypto(CryptoParams(
1375 1, "AES_CM_128_HMAC_SHA1_80",
1376 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1377 video->set_protocol(cricket::kMediaProtocolSavpf);
1378 video->AddCodec(
perkj26752742016-10-24 01:21:16 -07001379 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-16 17:54:10 -08001380 return video;
1381 }
1382
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001383 template <class MCD>
Yves Gerey665174f2018-06-19 15:03:05 +02001384 void CompareMediaContentDescription(const MCD* cd1, const MCD* cd2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001385 // type
Harald Alvestrand1716d392019-06-03 20:35:45 +02001386 EXPECT_EQ(cd1->type(), cd2->type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001387
1388 // content direction
1389 EXPECT_EQ(cd1->direction(), cd2->direction());
1390
1391 // rtcp_mux
1392 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1393
deadbeef13871492015-12-09 12:37:51 -08001394 // rtcp_reduced_size
1395 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1396
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001397 // cryptos
1398 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1399 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1400 ADD_FAILURE();
1401 return;
1402 }
Yves Gerey665174f2018-06-19 15:03:05 +02001403 for (size_t i = 0; i < cd1->cryptos().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001404 const CryptoParams c1 = cd1->cryptos().at(i);
1405 const CryptoParams c2 = cd2->cryptos().at(i);
1406 EXPECT_TRUE(c1.Matches(c2));
1407 EXPECT_EQ(c1.key_params, c2.key_params);
1408 EXPECT_EQ(c1.session_params, c2.session_params);
1409 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001410
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001411 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001412 // Use an equivalence class here, for old and new versions of the
1413 // protocol description.
Yves Gerey665174f2018-06-19 15:03:05 +02001414 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp ||
1415 cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1416 cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
lally@webrtc.org36300852015-02-24 20:19:35 +00001417 const bool cd2_is_also_dtls_sctp =
Yves Gerey665174f2018-06-19 15:03:05 +02001418 cd2->protocol() == cricket::kMediaProtocolDtlsSctp ||
1419 cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1420 cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
lally@webrtc.org36300852015-02-24 20:19:35 +00001421 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001422 } else {
1423 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1424 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001425
1426 // codecs
1427 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1428
1429 // bandwidth
1430 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1431
1432 // streams
1433 EXPECT_EQ(cd1->streams(), cd2->streams());
1434
Johannes Kron0854eb62018-10-10 22:33:20 +02001435 // extmap-allow-mixed
Johannes Kron9581bc42018-10-23 10:17:39 +02001436 EXPECT_EQ(cd1->extmap_allow_mixed_enum(), cd2->extmap_allow_mixed_enum());
Johannes Kron0854eb62018-10-10 22:33:20 +02001437
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001438 // extmap
1439 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1440 cd2->rtp_header_extensions().size());
Yves Gerey665174f2018-06-19 15:03:05 +02001441 for (size_t i = 0; i < cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 11:24:55 -07001442 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1443 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001444 EXPECT_EQ(ext1.uri, ext2.uri);
1445 EXPECT_EQ(ext1.id, ext2.id);
jbauch5869f502017-06-29 12:31:36 -07001446 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001447 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001448 }
1449
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001450 void CompareRidDescriptionIds(const std::vector<RidDescription>& rids,
1451 const std::vector<std::string>& ids) {
1452 // Order of elements does not matter, only equivalence of sets.
1453 EXPECT_EQ(rids.size(), ids.size());
1454 for (const std::string& id : ids) {
Steve Anton64b626b2019-01-28 17:25:26 -08001455 EXPECT_EQ(1l, absl::c_count_if(rids, [id](const RidDescription& rid) {
1456 return rid.rid == id;
1457 }));
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001458 }
1459 }
1460
Amit Hilbucha2012042018-12-03 11:35:05 -08001461 void CompareSimulcastDescription(const SimulcastDescription& simulcast1,
1462 const SimulcastDescription& simulcast2) {
1463 EXPECT_EQ(simulcast1.send_layers().size(), simulcast2.send_layers().size());
1464 EXPECT_EQ(simulcast1.receive_layers().size(),
1465 simulcast2.receive_layers().size());
1466 }
1467
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001468 void CompareRtpDataContentDescription(const RtpDataContentDescription* dcd1,
1469 const RtpDataContentDescription* dcd2) {
1470 CompareMediaContentDescription<RtpDataContentDescription>(dcd1, dcd2);
1471 }
1472
1473 void CompareSctpDataContentDescription(
1474 const SctpDataContentDescription* dcd1,
1475 const SctpDataContentDescription* dcd2) {
Harald Alvestrand26bf7c42019-04-23 05:20:17 +00001476 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001477 EXPECT_EQ(dcd1->port(), dcd2->port());
1478 EXPECT_EQ(dcd1->max_message_size(), dcd2->max_message_size());
Harald Alvestrand26bf7c42019-04-23 05:20:17 +00001479 }
1480
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001481 void CompareSessionDescription(const SessionDescription& desc1,
1482 const SessionDescription& desc2) {
1483 // Compare content descriptions.
1484 if (desc1.contents().size() != desc2.contents().size()) {
1485 ADD_FAILURE();
1486 return;
1487 }
Yves Gerey665174f2018-06-19 15:03:05 +02001488 for (size_t i = 0; i < desc1.contents().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001489 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1490 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-12 18:37:36 -08001491 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001492 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-12 18:37:36 -08001493 EXPECT_EQ(c1.type, c2.type);
1494 EXPECT_EQ(c1.rejected, c2.rejected);
1495 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001496
1497 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1498 if (IsAudioContent(&c1)) {
1499 const AudioContentDescription* acd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001500 c1.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001501 const AudioContentDescription* acd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001502 c2.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001503 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1504 }
1505
1506 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1507 if (IsVideoContent(&c1)) {
1508 const VideoContentDescription* vcd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001509 c1.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001510 const VideoContentDescription* vcd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001511 c2.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001512 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1513 }
1514
1515 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001516 if (c1.media_description()->as_sctp()) {
1517 ASSERT_TRUE(c2.media_description()->as_sctp());
1518 const SctpDataContentDescription* scd1 =
1519 c1.media_description()->as_sctp();
1520 const SctpDataContentDescription* scd2 =
1521 c2.media_description()->as_sctp();
1522 CompareSctpDataContentDescription(scd1, scd2);
1523 } else {
1524 if (IsDataContent(&c1)) {
1525 const RtpDataContentDescription* dcd1 =
1526 c1.media_description()->as_rtp_data();
1527 const RtpDataContentDescription* dcd2 =
1528 c2.media_description()->as_rtp_data();
1529 CompareRtpDataContentDescription(dcd1, dcd2);
1530 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001531 }
Amit Hilbucha2012042018-12-03 11:35:05 -08001532
1533 CompareSimulcastDescription(
1534 c1.media_description()->simulcast_description(),
1535 c2.media_description()->simulcast_description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001536 }
1537
1538 // group
1539 const cricket::ContentGroups groups1 = desc1.groups();
1540 const cricket::ContentGroups groups2 = desc2.groups();
1541 EXPECT_EQ(groups1.size(), groups1.size());
1542 if (groups1.size() != groups2.size()) {
1543 ADD_FAILURE();
1544 return;
1545 }
1546 for (size_t i = 0; i < groups1.size(); ++i) {
1547 const cricket::ContentGroup group1 = groups1.at(i);
1548 const cricket::ContentGroup group2 = groups2.at(i);
1549 EXPECT_EQ(group1.semantics(), group2.semantics());
1550 const cricket::ContentNames names1 = group1.content_names();
1551 const cricket::ContentNames names2 = group2.content_names();
1552 EXPECT_EQ(names1.size(), names2.size());
1553 if (names1.size() != names2.size()) {
1554 ADD_FAILURE();
1555 return;
1556 }
1557 cricket::ContentNames::const_iterator iter1 = names1.begin();
1558 cricket::ContentNames::const_iterator iter2 = names2.begin();
1559 while (iter1 != names1.end()) {
1560 EXPECT_EQ(*iter1++, *iter2++);
1561 }
1562 }
1563
1564 // transport info
1565 const cricket::TransportInfos transports1 = desc1.transport_infos();
1566 const cricket::TransportInfos transports2 = desc2.transport_infos();
1567 EXPECT_EQ(transports1.size(), transports2.size());
1568 if (transports1.size() != transports2.size()) {
1569 ADD_FAILURE();
1570 return;
1571 }
1572 for (size_t i = 0; i < transports1.size(); ++i) {
1573 const cricket::TransportInfo transport1 = transports1.at(i);
1574 const cricket::TransportInfo transport2 = transports2.at(i);
1575 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001576 EXPECT_EQ(transport1.description.ice_ufrag,
1577 transport2.description.ice_ufrag);
Yves Gerey665174f2018-06-19 15:03:05 +02001578 EXPECT_EQ(transport1.description.ice_pwd, transport2.description.ice_pwd);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07001579 EXPECT_EQ(transport1.description.ice_mode,
1580 transport2.description.ice_mode);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001581 if (transport1.description.identity_fingerprint) {
1582 EXPECT_EQ(*transport1.description.identity_fingerprint,
1583 *transport2.description.identity_fingerprint);
1584 } else {
1585 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1586 transport2.description.identity_fingerprint.get());
1587 }
1588 EXPECT_EQ(transport1.description.transport_options,
1589 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001590 }
deadbeefc80741f2015-10-22 13:14:45 -07001591
1592 // global attributes
1593 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
Johannes Kron9581bc42018-10-23 10:17:39 +02001594 EXPECT_EQ(desc1.extmap_allow_mixed(), desc2.extmap_allow_mixed());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001595 }
1596
Yves Gerey665174f2018-06-19 15:03:05 +02001597 bool CompareSessionDescription(const JsepSessionDescription& desc1,
1598 const JsepSessionDescription& desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001599 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1600 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1601 CompareSessionDescription(*desc1.description(), *desc2.description());
1602 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1603 return false;
1604 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1605 const IceCandidateCollection* cc1 = desc1.candidates(i);
1606 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-12 18:37:36 -08001607 if (cc1->count() != cc2->count()) {
1608 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001609 return false;
deadbeef25ed4352016-12-12 18:37:36 -08001610 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001611 for (size_t j = 0; j < cc1->count(); ++j) {
1612 const IceCandidateInterface* c1 = cc1->at(j);
1613 const IceCandidateInterface* c2 = cc2->at(j);
1614 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1615 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1616 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1617 }
1618 }
1619 return true;
1620 }
1621
1622 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1623 // them with invalid keywords so that the parser will just ignore them.
1624 bool RemoveCandidateUfragPwd(std::string* sdp) {
Steve Anton1c9c9fc2019-02-14 15:13:09 -08001625 absl::StrReplaceAll(
1626 {{"a=ice-ufrag", "a=xice-ufrag"}, {"a=ice-pwd", "a=xice-pwd"}}, sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001627 return true;
1628 }
1629
1630 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
Yves Gerey665174f2018-06-19 15:03:05 +02001631 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc,
1632 int mline_index,
1633 const std::string& ufrag,
1634 const std::string& pwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001635 std::string content_name;
1636 if (mline_index == 0) {
1637 content_name = kAudioContentName;
1638 } else if (mline_index == 1) {
1639 content_name = kVideoContentName;
1640 } else {
nissec80e7412017-01-11 05:56:46 -08001641 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001642 }
Yves Gerey665174f2018-06-19 15:03:05 +02001643 TransportInfo transport_info(content_name,
1644 TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001645 SessionDescription* desc =
1646 const_cast<SessionDescription*>(jdesc->description());
1647 desc->RemoveTransportInfoByName(content_name);
Steve Anton06817cd2018-12-18 15:55:30 -08001648 desc->AddTransportInfo(transport_info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001649 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1650 const IceCandidateCollection* cc = jdesc_.candidates(i);
1651 for (size_t j = 0; j < cc->count(); ++j) {
1652 if (cc->at(j)->sdp_mline_index() == mline_index) {
Yves Gerey665174f2018-06-19 15:03:05 +02001653 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(ufrag);
1654 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001655 }
1656 }
1657 }
1658 return true;
1659 }
1660
1661 void AddIceOptions(const std::string& content_name,
1662 const std::vector<std::string>& transport_options) {
1663 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1664 cricket::TransportInfo transport_info =
1665 *(desc_.GetTransportInfoByName(content_name));
1666 desc_.RemoveTransportInfoByName(content_name);
1667 transport_info.description.transport_options = transport_options;
1668 desc_.AddTransportInfo(transport_info);
1669 }
1670
deadbeef3f7219b2015-12-28 15:17:14 -08001671 void SetIceUfragPwd(const std::string& content_name,
1672 const std::string& ice_ufrag,
1673 const std::string& ice_pwd) {
1674 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1675 cricket::TransportInfo transport_info =
1676 *(desc_.GetTransportInfoByName(content_name));
1677 desc_.RemoveTransportInfoByName(content_name);
1678 transport_info.description.ice_ufrag = ice_ufrag;
1679 transport_info.description.ice_pwd = ice_pwd;
1680 desc_.AddTransportInfo(transport_info);
1681 }
1682
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001683 void AddFingerprint() {
1684 desc_.RemoveTransportInfoByName(kAudioContentName);
1685 desc_.RemoveTransportInfoByName(kVideoContentName);
Steve Anton4905edb2018-10-15 19:27:44 -07001686 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, kIdentityDigest);
Steve Anton06817cd2018-12-18 15:55:30 -08001687 desc_.AddTransportInfo(TransportInfo(
deadbeef46eed762016-01-28 13:24:37 -08001688 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001689 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1690 cricket::ICEMODE_FULL,
Steve Anton06817cd2018-12-18 15:55:30 -08001691 cricket::CONNECTIONROLE_NONE, &fingerprint)));
1692 desc_.AddTransportInfo(TransportInfo(
deadbeef46eed762016-01-28 13:24:37 -08001693 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001694 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1695 cricket::ICEMODE_FULL,
Steve Anton06817cd2018-12-18 15:55:30 -08001696 cricket::CONNECTIONROLE_NONE, &fingerprint)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001697 }
1698
jbauch5869f502017-06-29 12:31:36 -07001699 void AddExtmap(bool encrypted) {
Harald Alvestrandb97d2fe2020-02-28 11:54:40 +01001700 audio_desc_ = new AudioContentDescription(*audio_desc_);
1701 video_desc_ = new VideoContentDescription(*video_desc_);
jbauch5869f502017-06-29 12:31:36 -07001702 audio_desc_->AddRtpHeaderExtension(
1703 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1704 video_desc_->AddRtpHeaderExtension(
1705 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001706 desc_.RemoveContentByName(kAudioContentName);
1707 desc_.RemoveContentByName(kVideoContentName);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001708 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1709 absl::WrapUnique(audio_desc_));
1710 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp,
1711 absl::WrapUnique(video_desc_));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001712 }
1713
1714 void RemoveCryptos() {
1715 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1716 video_desc_->set_cryptos(std::vector<CryptoParams>());
1717 }
1718
Seth Hampson5897a6e2018-04-03 11:16:33 -07001719 // Removes everything in StreamParams from the session description that is
1720 // used for a=ssrc lines.
1721 void RemoveSsrcSignalingFromStreamParams() {
Harald Alvestrand1716d392019-06-03 20:35:45 +02001722 for (cricket::ContentInfo& content_info :
1723 jdesc_.description()->contents()) {
Seth Hampson5897a6e2018-04-03 11:16:33 -07001724 // With Unified Plan there should be one StreamParams per m= section.
1725 StreamParams& stream =
1726 content_info.media_description()->mutable_streams()[0];
1727 stream.ssrcs.clear();
1728 stream.ssrc_groups.clear();
1729 stream.cname.clear();
1730 }
1731 }
1732
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001733 // Removes all a=ssrc lines from the SDP string, except for the
1734 // "a=ssrc:... cname:..." lines.
1735 void RemoveSsrcMsidLinesFromSdpString(std::string* sdp_string) {
1736 const char kAttributeSsrc[] = "a=ssrc";
1737 const char kAttributeCname[] = "cname";
1738 size_t ssrc_line_pos = sdp_string->find(kAttributeSsrc);
1739 while (ssrc_line_pos != std::string::npos) {
1740 size_t beg_line_pos = sdp_string->rfind('\n', ssrc_line_pos);
1741 size_t end_line_pos = sdp_string->find('\n', ssrc_line_pos);
1742 size_t cname_pos = sdp_string->find(kAttributeCname, ssrc_line_pos);
1743 if (cname_pos == std::string::npos || cname_pos > end_line_pos) {
1744 // Only erase a=ssrc lines that don't contain "cname".
1745 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1746 ssrc_line_pos = sdp_string->find(kAttributeSsrc, beg_line_pos);
1747 } else {
1748 // Skip the "a=ssrc:... cname" line and find the next "a=ssrc" line.
1749 ssrc_line_pos = sdp_string->find(kAttributeSsrc, end_line_pos);
1750 }
1751 }
1752 }
1753
Seth Hampson5897a6e2018-04-03 11:16:33 -07001754 // Removes all a=ssrc lines from the SDP string.
1755 void RemoveSsrcLinesFromSdpString(std::string* sdp_string) {
1756 const char kAttributeSsrc[] = "a=ssrc";
1757 while (sdp_string->find(kAttributeSsrc) != std::string::npos) {
1758 size_t pos_ssrc_attribute = sdp_string->find(kAttributeSsrc);
1759 size_t beg_line_pos = sdp_string->rfind('\n', pos_ssrc_attribute);
1760 size_t end_line_pos = sdp_string->find('\n', pos_ssrc_attribute);
1761 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1762 }
1763 }
1764
Steve Anton4e70a722017-11-28 14:57:10 -08001765 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001766 audio_desc_->set_direction(direction);
1767 video_desc_->set_direction(direction);
1768 std::string new_sdp = kSdpFullString;
1769 ReplaceDirection(direction, &new_sdp);
1770
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001771 if (!jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001772 jdesc_.session_version())) {
1773 return false;
1774 }
Steve Antone831b8c2018-02-01 12:22:16 -08001775 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001776 EXPECT_EQ(new_sdp, message);
1777 return true;
1778 }
1779
1780 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
Harald Alvestrandb97d2fe2020-02-28 11:54:40 +01001781 audio_desc_ = new AudioContentDescription(*audio_desc_);
1782 video_desc_ = new VideoContentDescription(*video_desc_);
zhihuang38989e52017-03-21 11:04:53 -07001783
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001784 desc_.RemoveContentByName(kAudioContentName);
1785 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001786 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001787 absl::WrapUnique(audio_desc_));
Steve Anton5adfafd2017-12-20 16:34:00 -08001788 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001789 absl::WrapUnique(video_desc_));
deadbeef9d3584c2016-02-16 17:54:10 -08001790 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1791 audio_rejected ? "" : kPwdVoice);
1792 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1793 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001794
1795 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001796 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1797
Steve Antona3a92c22017-12-07 10:27:41 -08001798 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001799 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001800 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001801 EXPECT_EQ(new_sdp, message);
1802 return true;
1803 }
1804
zstein4b2e0822017-02-17 19:48:38 -08001805 void AddSctpDataChannel(bool use_sctpmap) {
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001806 std::unique_ptr<SctpDataContentDescription> data(
1807 new SctpDataContentDescription());
1808 sctp_desc_ = data.get();
1809 sctp_desc_->set_use_sctpmap(use_sctpmap);
Guido Urdanetacecf87f2019-05-31 10:17:38 +00001810 sctp_desc_->set_protocol(cricket::kMediaProtocolUdpDtlsSctp);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001811 sctp_desc_->set_port(kDefaultSctpPort);
Steve Anton5adfafd2017-12-20 16:34:00 -08001812 desc_.AddContent(kDataContentName, MediaProtocolType::kSctp,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001813 std::move(data));
Steve Anton06817cd2018-12-18 15:55:30 -08001814 desc_.AddTransportInfo(TransportInfo(
1815 kDataContentName, TransportDescription(kUfragData, kPwdData)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001816 }
1817
1818 void AddRtpDataChannel() {
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001819 std::unique_ptr<RtpDataContentDescription> data(
1820 new RtpDataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001821 data_desc_ = data.get();
1822
deadbeef67cf2c12016-04-13 10:07:16 -07001823 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001824 StreamParams data_stream;
1825 data_stream.id = kDataChannelMsid;
1826 data_stream.cname = kDataChannelCname;
Seth Hampson845e8782018-03-02 11:34:10 -08001827 data_stream.set_stream_ids({kDataChannelLabel});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001828 data_stream.ssrcs.push_back(kDataChannelSsrc);
1829 data_desc_->AddStream(data_stream);
Yves Gerey665174f2018-06-19 15:03:05 +02001830 data_desc_->AddCrypto(
1831 CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
1832 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001833 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001834 desc_.AddContent(kDataContentName, MediaProtocolType::kRtp,
1835 std::move(data));
Steve Anton06817cd2018-12-18 15:55:30 -08001836 desc_.AddTransportInfo(TransportInfo(
1837 kDataContentName, TransportDescription(kUfragData, kPwdData)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001838 }
1839
Steve Anton4e70a722017-11-28 14:57:10 -08001840 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001841 std::string new_sdp = kSdpFullString;
1842 ReplaceDirection(direction, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001843 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001844
1845 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1846
1847 audio_desc_->set_direction(direction);
1848 video_desc_->set_direction(direction);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001849 if (!jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001850 jdesc_.session_version())) {
1851 return false;
1852 }
1853 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1854 return true;
1855 }
1856
1857 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001858 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001859 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001860 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001861 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001862
Harald Alvestrandb97d2fe2020-02-28 11:54:40 +01001863 audio_desc_ = new AudioContentDescription(*audio_desc_);
1864 video_desc_ = new VideoContentDescription(*video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001865 desc_.RemoveContentByName(kAudioContentName);
1866 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001867 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001868 absl::WrapUnique(audio_desc_));
Steve Anton5adfafd2017-12-20 16:34:00 -08001869 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001870 absl::WrapUnique(video_desc_));
deadbeef9d3584c2016-02-16 17:54:10 -08001871 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1872 audio_rejected ? "" : kPwdVoice);
1873 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1874 video_rejected ? "" : kPwdVideo);
Steve Antona3a92c22017-12-07 10:27:41 -08001875 JsepSessionDescription jdesc_no_candidates(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001876 if (!jdesc_no_candidates.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef3f7219b2015-12-28 15:17:14 -08001877 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001878 return false;
1879 }
deadbeef3f7219b2015-12-28 15:17:14 -08001880 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001881 return true;
1882 }
1883
Yves Gerey665174f2018-06-19 15:03:05 +02001884 void TestDeserializeExtmap(bool session_level,
1885 bool media_level,
1886 bool encrypted) {
jbauch5869f502017-06-29 12:31:36 -07001887 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08001888 JsepSessionDescription new_jdesc(SdpType::kOffer);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001889 ASSERT_TRUE(new_jdesc.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001890 jdesc_.session_version()));
Steve Antona3a92c22017-12-07 10:27:41 -08001891 JsepSessionDescription jdesc_with_extmap(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001892 std::string sdp_with_extmap = kSdpString;
1893 if (session_level) {
jbauch5869f502017-06-29 12:31:36 -07001894 InjectAfter(kSessionTime,
1895 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1896 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001897 &sdp_with_extmap);
1898 }
1899 if (media_level) {
jbauch5869f502017-06-29 12:31:36 -07001900 InjectAfter(kAttributeIcePwdVoice,
1901 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1902 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001903 &sdp_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07001904 InjectAfter(kAttributeIcePwdVideo,
1905 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1906 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001907 &sdp_with_extmap);
1908 }
1909 // The extmap can't be present at the same time in both session level and
1910 // media level.
1911 if (session_level && media_level) {
1912 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02001913 EXPECT_FALSE(
1914 webrtc::SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001915 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1916 } else {
1917 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1918 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1919 }
1920 }
1921
1922 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
Yves Gerey665174f2018-06-19 15:03:05 +02001923 const std::string& name,
1924 int expected_value) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001925 cricket::CodecParameterMap::const_iterator found = params.find(name);
1926 ASSERT_TRUE(found != params.end());
Jonas Olsson6b1985d2018-07-05 11:59:48 +02001927 EXPECT_EQ(found->second, rtc::ToString(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001928 }
1929
1930 void TestDeserializeCodecParams(const CodecParams& params,
1931 JsepSessionDescription* jdesc_output) {
1932 std::string sdp =
1933 "v=0\r\n"
1934 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1935 "s=-\r\n"
1936 "t=0 0\r\n"
1937 // Include semantics for WebRTC Media Streams since it is supported by
1938 // this parser, and will be added to the SDP when serializing a session
1939 // description.
1940 "a=msid-semantic: WMS\r\n"
1941 // Pl type 111 preferred.
Philipp Hanckef2a4ec12020-07-01 21:07:32 +02001942 "m=audio 9 RTP/SAVPF 111 104 103 105\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001943 // Pltype 111 listed before 103 and 104 in the map.
1944 "a=rtpmap:111 opus/48000/2\r\n"
1945 // Pltype 103 listed before 104.
1946 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001947 "a=rtpmap:104 ISAC/32000\r\n"
Philipp Hanckef2a4ec12020-07-01 21:07:32 +02001948 "a=rtpmap:105 telephone-event/8000\r\n"
1949 "a=fmtp:105 0-15,66,70\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001950 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001951 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001952 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001953 << "; sprop-stereo=" << params.sprop_stereo
1954 << "; useinbandfec=" << params.useinband
Jonas Olssonb2b20312020-01-14 12:11:31 +01001955 << "; maxaveragebitrate=" << params.maxaveragebitrate
1956 << "\r\n"
1957 "a=ptime:"
1958 << params.ptime
1959 << "\r\n"
1960 "a=maxptime:"
1961 << params.max_ptime << "\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001962 sdp += os.str();
1963
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001964 os.clear();
1965 os.str("");
1966 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001967 os << "m=video 9 RTP/SAVPF 99 95\r\n"
Jonas Olssonb2b20312020-01-14 12:11:31 +01001968 "a=rtpmap:99 VP8/90000\r\n"
1969 "a=rtpmap:95 RTX/90000\r\n"
1970 "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001971 sdp += os.str();
1972
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001973 // Deserialize
1974 SdpParseError error;
1975 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1976
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001977 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001978 GetFirstAudioContentDescription(jdesc_output->description());
1979 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001980 ASSERT_FALSE(acd->codecs().empty());
1981 cricket::AudioCodec opus = acd->codecs()[0];
1982 EXPECT_EQ("opus", opus.name);
1983 EXPECT_EQ(111, opus.id);
1984 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1985 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1986 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1987 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001988 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1989 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001990 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1991 cricket::AudioCodec codec = acd->codecs()[i];
1992 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1993 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001994 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001995
Philipp Hanckef2a4ec12020-07-01 21:07:32 +02001996 cricket::AudioCodec dtmf = acd->codecs()[3];
1997 EXPECT_EQ("telephone-event", dtmf.name);
1998 EXPECT_EQ(105, dtmf.id);
1999 EXPECT_EQ(3u,
2000 dtmf.params.size()); // ptime and max_ptime count as parameters.
2001 EXPECT_EQ(dtmf.params.begin()->first, "");
2002 EXPECT_EQ(dtmf.params.begin()->second, "0-15,66,70");
2003
stefan@webrtc.org85d27942014-06-09 12:51:39 +00002004 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08002005 GetFirstVideoContentDescription(jdesc_output->description());
2006 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:39 +00002007 ASSERT_FALSE(vcd->codecs().empty());
2008 cricket::VideoCodec vp8 = vcd->codecs()[0];
2009 EXPECT_EQ("VP8", vp8.name);
2010 EXPECT_EQ(99, vp8.id);
2011 cricket::VideoCodec rtx = vcd->codecs()[1];
2012 EXPECT_EQ("RTX", rtx.name);
2013 EXPECT_EQ(95, rtx.id);
2014 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002015 }
2016
2017 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
2018 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00002019 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002020 "v=0\r\n"
2021 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2022 "s=-\r\n"
2023 "t=0 0\r\n"
2024 // Include semantics for WebRTC Media Streams since it is supported by
2025 // this parser, and will be added to the SDP when serializing a session
2026 // description.
2027 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00002028 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00002029 "a=rtpmap:111 opus/48000/2\r\n";
2030 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002031 "m=video 3457 RTP/SAVPF 101\r\n"
2032 "a=rtpmap:101 VP8/90000\r\n"
Elad Alonfadb1812019-05-24 13:40:02 +02002033 "a=rtcp-fb:101 goog-lntf\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002034 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002035 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00002036 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002037 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00002038 os << sdp_session_and_audio;
Yves Gerey665174f2018-06-19 15:03:05 +02002039 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00002040 os << sdp_video;
Yves Gerey665174f2018-06-19 15:03:05 +02002041 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00002042 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002043 // Deserialize
2044 SdpParseError error;
2045 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002046 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08002047 GetFirstAudioContentDescription(jdesc_output->description());
2048 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002049 ASSERT_FALSE(acd->codecs().empty());
2050 cricket::AudioCodec opus = acd->codecs()[0];
2051 EXPECT_EQ(111, opus.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002052 EXPECT_TRUE(opus.HasFeedbackParam(cricket::FeedbackParam(
2053 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002054
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002055 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08002056 GetFirstVideoContentDescription(jdesc_output->description());
2057 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002058 ASSERT_FALSE(vcd->codecs().empty());
2059 cricket::VideoCodec vp8 = vcd->codecs()[0];
2060 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
2061 vp8.name.c_str());
2062 EXPECT_EQ(101, vp8.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002063 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
Elad Alonfadb1812019-05-24 13:40:02 +02002064 cricket::kRtcpFbParamLntf, cricket::kParamValueEmpty)));
2065 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
Yves Gerey665174f2018-06-19 15:03:05 +02002066 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
2067 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2068 cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli)));
2069 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2070 cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty)));
2071 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2072 cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002073 }
2074
2075 // Two SDP messages can mean the same thing but be different strings, e.g.
2076 // some of the lines can be serialized in different order.
2077 // However, a deserialized description can be compared field by field and has
2078 // no order. If deserializer has already been tested, serializing then
2079 // deserializing and comparing JsepSessionDescription will test
2080 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 12:22:16 -08002081 void TestSerialize(const JsepSessionDescription& jdesc) {
2082 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 10:27:41 -08002083 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002084 SdpParseError error;
2085 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
2086 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
2087 }
2088
zhihuang38989e52017-03-21 11:04:53 -07002089 // Calling 'Initialize' with a copy of the inner SessionDescription will
2090 // create a copy of the JsepSessionDescription without candidates. The
2091 // 'connection address' field, previously set from the candidates, must also
2092 // be reset.
2093 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
2094 rtc::SocketAddress audio_addr("0.0.0.0", 9);
2095 rtc::SocketAddress video_addr("0.0.0.0", 9);
2096 audio_desc_->set_connection_address(audio_addr);
2097 video_desc_->set_connection_address(video_addr);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002098 ASSERT_TRUE(jdesc->Initialize(desc_.Clone(), kSessionId, kSessionVersion));
zhihuang38989e52017-03-21 11:04:53 -07002099 }
2100
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002101 protected:
2102 SessionDescription desc_;
2103 AudioContentDescription* audio_desc_;
2104 VideoContentDescription* video_desc_;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002105 RtpDataContentDescription* data_desc_;
2106 SctpDataContentDescription* sctp_desc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002107 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07002108 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002109 JsepSessionDescription jdesc_;
2110};
2111
2112void TestMismatch(const std::string& string1, const std::string& string2) {
2113 int position = 0;
2114 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
2115 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002116 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002117 break;
2118 }
2119 }
2120 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
2121 << " character\n"
Jonas Olssonb2b20312020-01-14 12:11:31 +01002122 " 1: "
2123 << string1.substr(position, 20)
2124 << "\n"
2125 " 2: "
2126 << string2.substr(position, 20) << "\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002127}
2128
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002129TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
2130 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 12:22:16 -08002131 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002132 TestMismatch(std::string(kSdpFullString), message);
2133}
2134
2135TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 10:27:41 -08002136 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 12:22:16 -08002137 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002138}
2139
2140// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
2141// the case in a DTLS offer.
2142TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
2143 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002144 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002145 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08002146 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002147
2148 std::string sdp_with_fingerprint = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002149 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2150 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002151
2152 EXPECT_EQ(sdp_with_fingerprint, message);
2153}
2154
2155// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
2156// be the case in a DTLS answer.
2157TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
2158 AddFingerprint();
2159 RemoveCryptos();
Steve Antona3a92c22017-12-07 10:27:41 -08002160 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002161 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08002162 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002163
2164 std::string sdp_with_fingerprint = kSdpString;
2165 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
2166 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
Yves Gerey665174f2018-06-19 15:03:05 +02002167 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2168 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002169
2170 EXPECT_EQ(sdp_with_fingerprint, message);
2171}
2172
2173TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
2174 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002175 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002176 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08002177 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002178 EXPECT_EQ(std::string(kSdpString), message);
2179}
2180
2181TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
2182 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2183 group.AddContentName(kAudioContentName);
2184 group.AddContentName(kVideoContentName);
2185 desc_.AddGroup(group);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002186 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002187 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002188 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002189 std::string sdp_with_bundle = kSdpFullString;
2190 InjectAfter(kSessionTime,
2191 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2192 &sdp_with_bundle);
2193 EXPECT_EQ(sdp_with_bundle, message);
2194}
2195
2196TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 15:14:30 -08002197 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
Taylor Brandstetteree8c2462020-07-27 15:52:02 -07002198 vcd->set_bandwidth(100 * 1000 + 755); // Integer division will drop the 755.
2199 vcd->set_bandwidth_type("AS");
Steve Antonb1c1de12017-12-21 15:14:30 -08002200 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
Taylor Brandstetteree8c2462020-07-27 15:52:02 -07002201 acd->set_bandwidth(555);
2202 acd->set_bandwidth_type("TIAS");
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002203 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002204 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002205 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002206 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002207 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002208 &sdp_with_bandwidth);
Taylor Brandstetteree8c2462020-07-27 15:52:02 -07002209 InjectAfter("c=IN IP4 74.125.127.126\r\n", "b=TIAS:555\r\n",
2210 &sdp_with_bandwidth);
2211 EXPECT_EQ(sdp_with_bandwidth, message);
2212}
2213
2214// Should default to b=AS if bandwidth_type isn't set.
2215TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithMissingBandwidthType) {
2216 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
2217 vcd->set_bandwidth(100 * 1000);
2218 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2219 jdesc_.session_version()));
2220 std::string message = webrtc::SdpSerialize(jdesc_);
2221 std::string sdp_with_bandwidth = kSdpFullString;
2222 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002223 &sdp_with_bandwidth);
2224 EXPECT_EQ(sdp_with_bandwidth, message);
2225}
2226
2227TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
2228 std::vector<std::string> transport_options;
2229 transport_options.push_back(kIceOption1);
2230 transport_options.push_back(kIceOption3);
2231 AddIceOptions(kAudioContentName, transport_options);
2232 transport_options.clear();
2233 transport_options.push_back(kIceOption2);
2234 transport_options.push_back(kIceOption3);
2235 AddIceOptions(kVideoContentName, transport_options);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002236 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002237 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002238 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002239 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002240 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002241 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002242 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002243 &sdp_with_ice_options);
2244 EXPECT_EQ(sdp_with_ice_options, message);
2245}
2246
2247TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002248 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002249}
2250
2251TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002252 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002253}
2254
2255TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002256 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002257}
2258
2259TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2260 EXPECT_TRUE(TestSerializeRejected(true, false));
2261}
2262
2263TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2264 EXPECT_TRUE(TestSerializeRejected(false, true));
2265}
2266
2267TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2268 EXPECT_TRUE(TestSerializeRejected(true, true));
2269}
2270
2271TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
2272 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002273 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002274
zhihuang38989e52017-03-21 11:04:53 -07002275 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002276 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002277
2278 std::string expected_sdp = kSdpString;
2279 expected_sdp.append(kSdpRtpDataChannelString);
2280 EXPECT_EQ(expected_sdp, message);
2281}
2282
2283TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08002284 bool use_sctpmap = true;
2285 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002286 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002287
zhihuang38989e52017-03-21 11:04:53 -07002288 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002289 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002290
2291 std::string expected_sdp = kSdpString;
2292 expected_sdp.append(kSdpSctpDataChannelString);
2293 EXPECT_EQ(message, expected_sdp);
2294}
2295
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002296void MutateJsepSctpPort(JsepSessionDescription* jdesc,
2297 const SessionDescription& desc,
2298 int port) {
2299 // Take our pre-built session description and change the SCTP port.
2300 std::unique_ptr<cricket::SessionDescription> mutant = desc.Clone();
2301 SctpDataContentDescription* dcdesc =
2302 mutant->GetContentDescriptionByName(kDataContentName)->as_sctp();
2303 dcdesc->set_port(port);
2304 ASSERT_TRUE(
2305 jdesc->Initialize(std::move(mutant), kSessionId, kSessionVersion));
2306}
2307
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002308TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08002309 bool use_sctpmap = true;
2310 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002311 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002312 MakeDescriptionWithoutCandidates(&jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002313
2314 const int kNewPort = 1234;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002315 MutateJsepSctpPort(&jsep_desc, desc_, kNewPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002316
Steve Antone831b8c2018-02-01 12:22:16 -08002317 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002318
2319 std::string expected_sdp = kSdpString;
2320 expected_sdp.append(kSdpSctpDataChannelString);
2321
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002322 absl::StrReplaceAll(
2323 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kNewPort)}},
2324 &expected_sdp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002325
2326 EXPECT_EQ(expected_sdp, message);
2327}
2328
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002329TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002330 JsepSessionDescription jsep_desc(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002331 AddRtpDataChannel();
Yves Gerey665174f2018-06-19 15:03:05 +02002332 data_desc_->set_bandwidth(100 * 1000);
Taylor Brandstetteree8c2462020-07-27 15:52:02 -07002333 data_desc_->set_bandwidth_type("AS");
zhihuang38989e52017-03-21 11:04:53 -07002334 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002335 std::string message = webrtc::SdpSerialize(jsep_desc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002336
2337 std::string expected_sdp = kSdpString;
2338 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002339 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00002340 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02002341 "b=AS:100\r\n", &expected_sdp);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002342 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002343}
2344
Johannes Kron0854eb62018-10-10 22:33:20 +02002345TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002346 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002347 TestSerialize(jdesc_);
2348}
2349
2350TEST_F(WebRtcSdpTest, SerializeMediaContentDescriptionWithExtmapAllowMixed) {
2351 cricket::MediaContentDescription* video_desc =
2352 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2353 ASSERT_TRUE(video_desc);
2354 cricket::MediaContentDescription* audio_desc =
2355 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2356 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002357 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002358 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002359 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002360 cricket::MediaContentDescription::kMedia);
2361 TestSerialize(jdesc_);
2362}
2363
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002364TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002365 bool encrypted = false;
2366 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002367 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002368 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 12:22:16 -08002369 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002370
2371 std::string sdp_with_extmap = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002372 InjectAfter("a=mid:audio_content_name\r\n", kExtmap, &sdp_with_extmap);
2373 InjectAfter("a=mid:video_content_name\r\n", kExtmap, &sdp_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002374
2375 EXPECT_EQ(sdp_with_extmap, message);
2376}
2377
jbauch5869f502017-06-29 12:31:36 -07002378TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2379 bool encrypted = true;
2380 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002381 JsepSessionDescription desc_with_extmap(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002382 ASSERT_TRUE(
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002383 desc_with_extmap.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 12:22:16 -08002384 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07002385}
2386
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002387TEST_F(WebRtcSdpTest, SerializeCandidates) {
2388 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002389 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002390
2391 Candidate candidate_with_ufrag(candidates_.front());
2392 candidate_with_ufrag.set_username("ABC");
2393 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2394 candidate_with_ufrag));
2395 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2396 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002397
2398 Candidate candidate_with_network_info(candidates_.front());
2399 candidate_with_network_info.set_network_id(1);
2400 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2401 candidate_with_network_info));
2402 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2403 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2404 candidate_with_network_info.set_network_cost(999);
2405 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2406 candidate_with_network_info));
2407 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2408 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2409 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002410}
2411
Zach Steinb336c272018-08-09 01:16:13 -07002412TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) {
2413 rtc::SocketAddress address("a.test", 1234);
2414 cricket::Candidate candidate(
2415 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
2416 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
2417 JsepIceCandidate jcandidate(std::string("audio_content_name"), 0, candidate);
2418 std::string message = webrtc::SdpSerializeCandidate(jcandidate);
2419 EXPECT_EQ(std::string(kRawHostnameCandidate), message);
2420}
2421
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002422TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002423 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002424 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2425 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2426 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002427 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002428 std::unique_ptr<IceCandidateInterface> jcandidate(
2429 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002430
2431 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2432 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2433}
2434
Taylor Brandstetter8206bc02020-04-02 12:36:38 -07002435// Test serializing a TCP candidate that came in with a missing tcptype. This
2436// shouldn't happen according to the spec, but our implementation has been
2437// accepting this for quite some time, treating it as a passive candidate.
2438//
2439// So, we should be able to at least convert such candidates to and from SDP.
2440// See: bugs.webrtc.org/11423
2441TEST_F(WebRtcSdpTest, ParseTcpCandidateWithoutTcptype) {
2442 std::string missing_tcptype =
2443 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9999 typ host";
2444 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2445 EXPECT_TRUE(SdpDeserializeCandidate(missing_tcptype, &jcandidate));
2446
2447 EXPECT_EQ(std::string(cricket::TCPTYPE_PASSIVE_STR),
2448 jcandidate.candidate().tcptype());
2449}
2450
2451TEST_F(WebRtcSdpTest, ParseSslTcpCandidate) {
2452 std::string ssltcp =
2453 "candidate:a0+B/1 1 ssltcp 2130706432 192.168.1.5 9999 typ host tcptype "
2454 "passive";
2455 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2456 EXPECT_TRUE(SdpDeserializeCandidate(ssltcp, &jcandidate));
2457
2458 EXPECT_EQ(std::string("ssltcp"), jcandidate.candidate().protocol());
2459}
2460
htaa6b99442016-04-12 10:29:17 -07002461TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002462 cricket::VideoCodec h264_codec("H264");
2463 h264_codec.SetParam("profile-level-id", "42e01f");
2464 h264_codec.SetParam("level-asymmetry-allowed", "1");
2465 h264_codec.SetParam("packetization-mode", "1");
2466 video_desc_->AddCodec(h264_codec);
2467
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002468 jdesc_.Initialize(desc_.Clone(), kSessionId, kSessionVersion);
htaa6b99442016-04-12 10:29:17 -07002469
Steve Antone831b8c2018-02-01 12:22:16 -08002470 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 10:29:17 -07002471 size_t after_pt = message.find(" H264/90000");
2472 ASSERT_NE(after_pt, std::string::npos);
2473 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2474 ASSERT_NE(before_pt, std::string::npos);
2475 before_pt += strlen("a=rtpmap:");
2476 std::string pt = message.substr(before_pt, after_pt - before_pt);
2477 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2478 std::string to_find = "a=fmtp:" + pt + " ";
2479 size_t fmtp_pos = message.find(to_find);
2480 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
Mirko Bonadei37ec55e2019-01-28 11:43:52 +01002481 size_t fmtp_endpos = message.find('\n', fmtp_pos);
htaa6b99442016-04-12 10:29:17 -07002482 ASSERT_NE(std::string::npos, fmtp_endpos);
2483 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2484 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2485 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2486 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002487 // Check that there are no spaces after semicolons.
2488 // https://bugs.webrtc.org/5793
2489 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002490}
2491
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002492TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 10:27:41 -08002493 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002494 // Deserialize
2495 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2496 // Verify
2497 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2498}
2499
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002500TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 10:27:41 -08002501 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002502 const char kSdpWithoutMline[] =
Yves Gerey665174f2018-06-19 15:03:05 +02002503 "v=0\r\n"
2504 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2505 "s=-\r\n"
2506 "t=0 0\r\n"
2507 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002508 // Deserialize
2509 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2510 EXPECT_EQ(0u, jdesc.description()->contents().size());
2511}
2512
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002513TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 10:27:41 -08002514 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002515 std::string sdp_without_carriage_return = kSdpFullString;
2516 Replace("\r\n", "\n", &sdp_without_carriage_return);
2517 // Deserialize
2518 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2519 // Verify
2520 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2521}
2522
2523TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2524 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002525 JsepSessionDescription jdesc_no_candidates(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002526 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Clone(), kSessionId,
Yves Gerey665174f2018-06-19 15:03:05 +02002527 kSessionVersion));
Steve Antona3a92c22017-12-07 10:27:41 -08002528 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002529 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2530 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2531}
2532
2533TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2534 static const char kSdpNoRtpmapString[] =
2535 "v=0\r\n"
2536 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2537 "s=-\r\n"
2538 "t=0 0\r\n"
2539 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2540 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002541 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002542 // The rtpmap line for static payload codec is optional.
2543 "a=rtpmap:18 G729/16000\r\n"
2544 "a=rtpmap:103 ISAC/16000\r\n";
2545
Steve Antona3a92c22017-12-07 10:27:41 -08002546 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002547 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2548 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08002549 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002550 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002551 // The codecs in the AudioContentDescription should be in the same order as
2552 // the payload types (<fmt>s) on the m= line.
2553 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2554 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002555 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002556 EXPECT_EQ(ref_codecs, audio->codecs());
2557}
2558
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002559TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2560 static const char kSdpNoRtpmapString[] =
2561 "v=0\r\n"
2562 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2563 "s=-\r\n"
2564 "t=0 0\r\n"
2565 "m=audio 49232 RTP/AVP 18 103\r\n"
2566 "a=fmtp:18 annexb=yes\r\n"
2567 "a=rtpmap:103 ISAC/16000\r\n";
2568
Steve Antona3a92c22017-12-07 10:27:41 -08002569 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002570 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2571 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08002572 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002573
2574 cricket::AudioCodec g729 = audio->codecs()[0];
2575 EXPECT_EQ("G729", g729.name);
2576 EXPECT_EQ(8000, g729.clockrate);
2577 EXPECT_EQ(18, g729.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002578 cricket::CodecParameterMap::iterator found = g729.params.find("annexb");
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002579 ASSERT_TRUE(found != g729.params.end());
2580 EXPECT_EQ(found->second, "yes");
2581
2582 cricket::AudioCodec isac = audio->codecs()[1];
2583 EXPECT_EQ("ISAC", isac.name);
2584 EXPECT_EQ(103, isac.id);
2585 EXPECT_EQ(16000, isac.clockrate);
2586}
2587
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002588// Ensure that we can deserialize SDP with a=fingerprint properly.
2589TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2590 // Add a DTLS a=fingerprint attribute to our session description.
2591 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002592 JsepSessionDescription new_jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002593 ASSERT_TRUE(new_jdesc.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002594 jdesc_.session_version()));
2595
Steve Antona3a92c22017-12-07 10:27:41 -08002596 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002597 std::string sdp_with_fingerprint = kSdpString;
2598 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2599 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2600 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2601 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2602}
2603
2604TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 10:27:41 -08002605 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002606 std::string sdp_with_bundle = kSdpFullString;
2607 InjectAfter(kSessionTime,
2608 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2609 &sdp_with_bundle);
2610 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2611 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2612 group.AddContentName(kAudioContentName);
2613 group.AddContentName(kVideoContentName);
2614 desc_.AddGroup(group);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002615 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002616 jdesc_.session_version()));
2617 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2618}
2619
2620TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002621 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002622 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002623 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002624 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002625 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002626 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002627 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 15:14:30 -08002628 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002629 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002630 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002631 acd->set_bandwidth(50 * 1000);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002632 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002633 jdesc_.session_version()));
2634 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2635}
2636
Taylor Brandstetteree8c2462020-07-27 15:52:02 -07002637TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithTiasBandwidth) {
2638 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
2639 std::string sdp_with_bandwidth = kSdpFullString;
2640 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=TIAS:100000\r\n",
2641 &sdp_with_bandwidth);
2642 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=TIAS:50000\r\n",
2643 &sdp_with_bandwidth);
2644 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2645 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
2646 vcd->set_bandwidth(100 * 1000);
2647 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
2648 acd->set_bandwidth(50 * 1000);
2649 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2650 jdesc_.session_version()));
2651 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2652}
2653
Philipp Hanckefbbfc022020-07-31 08:30:50 +02002654TEST_F(WebRtcSdpTest,
2655 DeserializeSessionDescriptionWithUnknownBandwidthModifier) {
2656 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
2657 std::string sdp_with_bandwidth = kSdpFullString;
2658 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
2659 "b=unknown:100000\r\n", &sdp_with_bandwidth);
2660 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
2661 "b=unknown:50000\r\n", &sdp_with_bandwidth);
2662 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2663 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
2664 vcd->set_bandwidth(-1);
2665 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
2666 acd->set_bandwidth(-1);
2667 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2668 jdesc_.session_version()));
2669 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2670}
2671
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002672TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 10:27:41 -08002673 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002674 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002675 InjectAfter(kSessionTime, "a=ice-options:iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002676 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002677 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002678 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002679 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002680 &sdp_with_ice_options);
2681 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2682 std::vector<std::string> transport_options;
2683 transport_options.push_back(kIceOption3);
2684 transport_options.push_back(kIceOption1);
2685 AddIceOptions(kAudioContentName, transport_options);
2686 transport_options.clear();
2687 transport_options.push_back(kIceOption3);
2688 transport_options.push_back(kIceOption2);
2689 AddIceOptions(kVideoContentName, transport_options);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002690 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002691 jdesc_.session_version()));
2692 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2693}
2694
2695TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2696 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 10:27:41 -08002697 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002698 std::string sdp_with_ufrag_pwd = kSdpFullString;
2699 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2700 // Add session level ufrag and pwd
2701 InjectAfter(kSessionTime,
Yves Gerey665174f2018-06-19 15:03:05 +02002702 "a=ice-pwd:session+level+icepwd\r\n"
2703 "a=ice-ufrag:session+level+iceufrag\r\n",
2704 &sdp_with_ufrag_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002705 // Add media level ufrag and pwd for audio
Yves Gerey665174f2018-06-19 15:03:05 +02002706 InjectAfter(
2707 "a=mid:audio_content_name\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002708 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2709 &sdp_with_ufrag_pwd);
2710 // Update the candidate ufrag and pwd to the expected ones.
Yves Gerey665174f2018-06-19 15:03:05 +02002711 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, "media+level+iceufrag",
2712 "media+level+icepwd"));
2713 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, "session+level+iceufrag",
2714 "session+level+icepwd"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002715 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2716 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2717}
2718
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002719TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002720 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002721}
2722
2723TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002724 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002725}
2726
2727TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002728 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002729}
2730
2731TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2732 EXPECT_TRUE(TestDeserializeRejected(true, false));
2733}
2734
2735TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2736 EXPECT_TRUE(TestDeserializeRejected(false, true));
2737}
2738
2739TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2740 EXPECT_TRUE(TestDeserializeRejected(true, true));
2741}
2742
Artem Titovf0a34f22020-03-16 17:52:04 +00002743// Tests that we can still handle the sdp uses mslabel and label instead of
2744// msid for backward compatibility.
2745TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
2746 jdesc_.description()->set_msid_supported(false);
2747 JsepSessionDescription jdesc(kDummyType);
2748 std::string sdp_without_msid = kSdpFullString;
2749 Replace("msid", "xmsid", &sdp_without_msid);
2750 // Deserialize
2751 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2752 // Verify
2753 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2754 EXPECT_FALSE(jdesc.description()->msid_signaling() &
2755 ~cricket::kMsidSignalingSsrcAttribute);
2756}
2757
Johannes Kron0854eb62018-10-10 22:33:20 +02002758TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002759 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002760 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
Johannes Kron0854eb62018-10-10 22:33:20 +02002761 // Deserialize
2762 JsepSessionDescription jdesc_deserialized(kDummyType);
Emil Lundmark801c9992021-01-19 13:06:32 +01002763 ASSERT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
Johannes Kron0854eb62018-10-10 22:33:20 +02002764 // Verify
2765 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2766}
2767
2768TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002769 jdesc_.description()->set_extmap_allow_mixed(false);
Johannes Kron0854eb62018-10-10 22:33:20 +02002770 std::string sdp_without_extmap_allow_mixed = kSdpFullString;
Emil Lundmark801c9992021-01-19 13:06:32 +01002771 Replace(kExtmapAllowMixed, "", &sdp_without_extmap_allow_mixed);
Johannes Kron0854eb62018-10-10 22:33:20 +02002772 // Deserialize
2773 JsepSessionDescription jdesc_deserialized(kDummyType);
Emil Lundmark801c9992021-01-19 13:06:32 +01002774 ASSERT_TRUE(
Johannes Kron0854eb62018-10-10 22:33:20 +02002775 SdpDeserialize(sdp_without_extmap_allow_mixed, &jdesc_deserialized));
2776 // Verify
2777 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2778}
2779
2780TEST_F(WebRtcSdpTest, DeserializeMediaContentDescriptionWithExtmapAllowMixed) {
2781 cricket::MediaContentDescription* video_desc =
2782 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2783 ASSERT_TRUE(video_desc);
2784 cricket::MediaContentDescription* audio_desc =
2785 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2786 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002787 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002788 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002789 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002790 cricket::MediaContentDescription::kMedia);
2791
2792 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2793 InjectAfter("a=mid:audio_content_name\r\n", kExtmapAllowMixed,
2794 &sdp_with_extmap_allow_mixed);
2795 InjectAfter("a=mid:video_content_name\r\n", kExtmapAllowMixed,
2796 &sdp_with_extmap_allow_mixed);
2797
2798 // Deserialize
2799 JsepSessionDescription jdesc_deserialized(kDummyType);
2800 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2801 // Verify
2802 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2803}
2804
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002805TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2806 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2807
2808 std::string sdp = kSdpOneCandidate;
2809 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2810 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2811 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2812 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002813 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002814
2815 // Candidate line without generation extension.
2816 sdp = kSdpOneCandidate;
2817 Replace(" generation 2", "", &sdp);
2818 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2819 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2820 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2821 Candidate expected = jcandidate_->candidate();
2822 expected.set_generation(0);
2823 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2824
honghaiza0c44ea2016-03-23 16:07:48 -07002825 // Candidate with network id and/or cost.
2826 sdp = kSdpOneCandidate;
2827 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2828 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2829 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2830 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2831 expected = jcandidate_->candidate();
2832 expected.set_network_id(2);
2833 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2834 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2835 // Add network cost
2836 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2837 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2838 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2839 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2840
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002841 sdp = kSdpTcpActiveCandidate;
2842 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2843 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002844 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002845 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2846 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2847 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002848 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2849 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
Yves Gerey665174f2018-06-19 15:03:05 +02002850 EXPECT_TRUE(
2851 jcandidate.candidate().IsEquivalent(jcandidate_template->candidate()));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002852 sdp = kSdpTcpPassiveCandidate;
2853 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2854 sdp = kSdpTcpSOCandidate;
2855 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002856}
2857
2858// This test verifies the deserialization of candidate-attribute
2859// as per RFC 5245. Candiate-attribute will be of the format
2860// candidate:<blah>. This format will be used when candidates
2861// are trickled.
2862TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2863 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2864
2865 std::string candidate_attribute = kRawCandidate;
2866 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2867 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2868 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2869 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2870 EXPECT_EQ(2u, jcandidate.candidate().generation());
2871
2872 // Candidate line without generation extension.
2873 candidate_attribute = kRawCandidate;
2874 Replace(" generation 2", "", &candidate_attribute);
2875 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2876 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2877 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2878 Candidate expected = jcandidate_->candidate();
2879 expected.set_generation(0);
2880 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2881
2882 // Candidate line without candidate:
2883 candidate_attribute = kRawCandidate;
2884 Replace("candidate:", "", &candidate_attribute);
2885 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2886
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002887 // Candidate line with IPV6 address.
2888 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
Zach Steinb336c272018-08-09 01:16:13 -07002889
2890 // Candidate line with hostname address.
2891 EXPECT_TRUE(SdpDeserializeCandidate(kRawHostnameCandidate, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002892}
2893
2894// This test verifies that the deserialization of an invalid candidate string
2895// fails.
2896TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
Yves Gerey665174f2018-06-19 15:03:05 +02002897 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002898
2899 std::string candidate_attribute = kRawCandidate;
2900 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002901 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002902
2903 candidate_attribute = kSdpOneCandidate;
2904 candidate_attribute.replace(0, 1, "x");
2905 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2906
2907 candidate_attribute = kRawCandidate;
2908 candidate_attribute.append("\r\n");
2909 candidate_attribute.append(kRawCandidate);
2910 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2911
2912 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002913}
2914
2915TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2916 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002917 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002918 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002919
2920 std::string sdp_with_data = kSdpString;
2921 sdp_with_data.append(kSdpRtpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002922 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002923
2924 // Deserialize
2925 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2926 // Verify
2927 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2928}
2929
2930TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002931 bool use_sctpmap = true;
2932 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002933 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002934 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002935
2936 std::string sdp_with_data = kSdpString;
2937 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002938 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002939
Guido Urdanetacecf87f2019-05-31 10:17:38 +00002940 // Verify with UDP/DTLS/SCTP (already in kSdpSctpDataChannelString).
lally@webrtc.org36300852015-02-24 20:19:35 +00002941 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2942 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2943
Guido Urdanetacecf87f2019-05-31 10:17:38 +00002944 // Verify with DTLS/SCTP.
2945 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2946 kDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002947 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2948 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2949
2950 // Verify with TCP/DTLS/SCTP.
Guido Urdanetacecf87f2019-05-31 10:17:38 +00002951 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
Yves Gerey665174f2018-06-19 15:03:05 +02002952 kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002953 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2954 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2955}
2956
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002957TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002958 bool use_sctpmap = false;
2959 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002960 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002961 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002962
2963 std::string sdp_with_data = kSdpString;
2964 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002965 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002966
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002967 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2968 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2969}
2970
lally69f57602015-10-08 10:15:04 -07002971TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002972 bool use_sctpmap = false;
2973 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002974 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002975 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
lally69f57602015-10-08 10:15:04 -07002976
2977 std::string sdp_with_data = kSdpString;
2978 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002979 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 10:15:04 -07002980
lally69f57602015-10-08 10:15:04 -07002981 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2982 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2983}
2984
Philipp Hanckeefc55b02020-06-26 10:17:05 +02002985TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsButWrongMediaType) {
2986 bool use_sctpmap = true;
2987 AddSctpDataChannel(use_sctpmap);
2988 JsepSessionDescription jdesc(kDummyType);
2989 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
2990
2991 std::string sdp = kSdpSessionString;
2992 sdp += kSdpSctpDataChannelString;
2993
2994 const char needle[] = "m=application ";
2995 sdp.replace(sdp.find(needle), strlen(needle), "m=application:bogus ");
2996
2997 JsepSessionDescription jdesc_output(kDummyType);
2998 EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output));
2999
Philipp Hancke4e8c1152020-10-13 12:43:15 +02003000 EXPECT_EQ(1u, jdesc_output.description()->contents().size());
3001 EXPECT_TRUE(jdesc_output.description()->contents()[0].rejected);
Philipp Hanckeefc55b02020-06-26 10:17:05 +02003002}
3003
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02003004// Helper function to set the max-message-size parameter in the
3005// SCTP data codec.
3006void MutateJsepSctpMaxMessageSize(const SessionDescription& desc,
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003007 int new_value,
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02003008 JsepSessionDescription* jdesc) {
Harald Alvestrand8da35a62019-05-10 09:31:04 +02003009 std::unique_ptr<cricket::SessionDescription> mutant = desc.Clone();
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003010 SctpDataContentDescription* dcdesc =
3011 mutant->GetContentDescriptionByName(kDataContentName)->as_sctp();
3012 dcdesc->set_max_message_size(new_value);
Harald Alvestrand8da35a62019-05-10 09:31:04 +02003013 jdesc->Initialize(std::move(mutant), kSessionId, kSessionVersion);
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02003014}
3015
3016TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithMaxMessageSize) {
3017 bool use_sctpmap = false;
3018 AddSctpDataChannel(use_sctpmap);
3019 JsepSessionDescription jdesc(kDummyType);
3020 std::string sdp_with_data = kSdpString;
3021
3022 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
3023 sdp_with_data.append("a=max-message-size:12345\r\n");
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003024 MutateJsepSctpMaxMessageSize(desc_, 12345, &jdesc);
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02003025 JsepSessionDescription jdesc_output(kDummyType);
3026
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02003027 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3028 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
3029}
3030
Harald Alvestrandfbb45bd2019-05-15 08:07:47 +02003031TEST_F(WebRtcSdpTest, SerializeSdpWithSctpDataChannelWithMaxMessageSize) {
3032 bool use_sctpmap = false;
3033 AddSctpDataChannel(use_sctpmap);
3034 JsepSessionDescription jdesc(kDummyType);
3035 MutateJsepSctpMaxMessageSize(desc_, 12345, &jdesc);
3036 std::string message = webrtc::SdpSerialize(jdesc);
3037 EXPECT_NE(std::string::npos,
3038 message.find("\r\na=max-message-size:12345\r\n"));
3039 JsepSessionDescription jdesc_output(kDummyType);
3040 EXPECT_TRUE(SdpDeserialize(message, &jdesc_output));
3041 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
3042}
3043
3044TEST_F(WebRtcSdpTest,
3045 SerializeSdpWithSctpDataChannelWithDefaultMaxMessageSize) {
3046 // https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-26#section-6
3047 // The default max message size is 64K.
3048 bool use_sctpmap = false;
3049 AddSctpDataChannel(use_sctpmap);
3050 JsepSessionDescription jdesc(kDummyType);
3051 MutateJsepSctpMaxMessageSize(desc_, 65536, &jdesc);
3052 std::string message = webrtc::SdpSerialize(jdesc);
3053 EXPECT_EQ(std::string::npos, message.find("\r\na=max-message-size:"));
3054 JsepSessionDescription jdesc_output(kDummyType);
3055 EXPECT_TRUE(SdpDeserialize(message, &jdesc_output));
3056 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
3057}
3058
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003059// Test to check the behaviour if sctp-port is specified
3060// on the m= line and in a=sctp-port.
3061TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08003062 bool use_sctpmap = true;
3063 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08003064 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003065 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003066
3067 std::string sdp_with_data = kSdpString;
3068 // Append m= attributes
3069 sdp_with_data.append(kSdpSctpDataChannelString);
3070 // Append a=sctp-port attribute
3071 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 10:27:41 -08003072 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003073
3074 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
3075}
3076
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003077// Test behavior if a=rtpmap occurs in an SCTP section.
3078TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpmapAttribute) {
3079 std::string sdp_with_data = kSdpString;
3080 // Append m= attributes
3081 sdp_with_data.append(kSdpSctpDataChannelString);
3082 // Append a=rtpmap attribute
3083 sdp_with_data.append("a=rtpmap:111 opus/48000/2\r\n");
3084 JsepSessionDescription jdesc_output(kDummyType);
3085 // Correct behavior is to ignore the extra attribute.
3086 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3087}
3088
3089TEST_F(WebRtcSdpTest, DeserializeSdpWithStrangeApplicationProtocolNames) {
3090 static const char* bad_strings[] = {"DTLS/SCTPRTP/", "obviously-bogus",
3091 "UDP/TL/RTSP/SAVPF", "UDP/TL/RTSP/S"};
3092 for (auto proto : bad_strings) {
3093 std::string sdp_with_data = kSdpString;
3094 sdp_with_data.append("m=application 9 ");
3095 sdp_with_data.append(proto);
3096 sdp_with_data.append(" 47\r\n");
3097 JsepSessionDescription jdesc_output(kDummyType);
3098 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output))
3099 << "Parsing should have failed on " << proto;
3100 }
3101 // The following strings are strange, but acceptable as RTP.
3102 static const char* weird_strings[] = {"DTLS/SCTP/RTP/FOO",
3103 "obviously-bogus/RTP/"};
3104 for (auto proto : weird_strings) {
3105 std::string sdp_with_data = kSdpString;
3106 sdp_with_data.append("m=application 9 ");
3107 sdp_with_data.append(proto);
3108 sdp_with_data.append(" 47\r\n");
3109 JsepSessionDescription jdesc_output(kDummyType);
3110 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output))
3111 << "Parsing should have succeeded on " << proto;
3112 }
3113}
3114
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00003115// For crbug/344475.
3116TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
3117 std::string sdp_with_data = kSdpString;
3118 sdp_with_data.append(kSdpSctpDataChannelString);
3119 // Remove the "\n" at the end.
3120 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 10:27:41 -08003121 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00003122
3123 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
3124 // No crash is a pass.
3125}
3126
zstein4b2e0822017-02-17 19:48:38 -08003127TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
3128 bool use_sctpmap = true;
3129 AddSctpDataChannel(use_sctpmap);
3130
3131 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 10:27:41 -08003132 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003133 MutateJsepSctpPort(&jdesc, desc_, kUnusualSctpPort);
wu@webrtc.org78187522013-10-07 23:32:02 +00003134
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00003135 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00003136 std::string sdp_with_data = kSdpString;
3137 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Anton1c9c9fc2019-02-14 15:13:09 -08003138 absl::StrReplaceAll(
3139 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}},
3140 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08003141 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:02 +00003142
3143 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3144 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08003145}
3146
3147TEST_F(WebRtcSdpTest,
3148 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
3149 bool use_sctpmap = false;
3150 AddSctpDataChannel(use_sctpmap);
3151
Steve Antona3a92c22017-12-07 10:27:41 -08003152 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003153 MutateJsepSctpPort(&jdesc, desc_, kUnusualSctpPort);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003154
3155 // We need to test the deserialized JsepSessionDescription from
3156 // kSdpSctpDataChannelStringWithSctpPort for
3157 // draft-ietf-mmusic-sctp-sdp-07
3158 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08003159 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003160 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Anton1c9c9fc2019-02-14 15:13:09 -08003161 absl::StrReplaceAll(
3162 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}},
3163 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08003164 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003165
3166 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3167 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00003168}
3169
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003170TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003171 // We want to test that deserializing data content limits bandwidth
3172 // settings (it should never be greater than the default).
3173 // This should prevent someone from using unlimited data bandwidth through
3174 // JS and "breaking the Internet".
3175 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003176 std::string sdp_with_bandwidth = kSdpString;
3177 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02003178 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003179 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08003180 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003181
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003182 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
3183}
3184
3185TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08003186 bool use_sctpmap = true;
3187 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08003188 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003189 SctpDataContentDescription* dcd = GetFirstSctpDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003190 dcd->set_bandwidth(100 * 1000);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003191 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003192
3193 std::string sdp_with_bandwidth = kSdpString;
3194 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02003195 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003196 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08003197 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003198
3199 // SCTP has congestion control, so we shouldn't limit the bandwidth
3200 // as we do for RTP.
3201 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003202 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
3203}
3204
Yves Gerey665174f2018-06-19 15:03:05 +02003205class WebRtcSdpExtmapTest : public WebRtcSdpTest,
Mirko Bonadei6a489f22019-04-09 15:11:12 +02003206 public ::testing::WithParamInterface<bool> {};
jbauch5869f502017-06-29 12:31:36 -07003207
3208TEST_P(WebRtcSdpExtmapTest,
Yves Gerey665174f2018-06-19 15:03:05 +02003209 DeserializeSessionDescriptionWithSessionLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003210 bool encrypted = GetParam();
3211 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003212}
3213
Yves Gerey665174f2018-06-19 15:03:05 +02003214TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003215 bool encrypted = GetParam();
3216 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003217}
3218
Yves Gerey665174f2018-06-19 15:03:05 +02003219TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithInvalidExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003220 bool encrypted = GetParam();
3221 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003222}
3223
Mirko Bonadeic84f6612019-01-31 12:20:57 +01003224INSTANTIATE_TEST_SUITE_P(Encrypted,
3225 WebRtcSdpExtmapTest,
3226 ::testing::Values(false, true));
jbauch5869f502017-06-29 12:31:36 -07003227
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003228TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 10:27:41 -08003229 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003230 std::string sdp = kSdpFullString;
3231 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
3232 // Deserialize
3233 SdpParseError error;
3234 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
Artem Titovf0a34f22020-03-16 17:52:04 +00003235 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003236 EXPECT_EQ(lastline, error.line);
3237 EXPECT_EQ("Invalid SDP line.", error.description);
3238}
3239
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003240TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
3241 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
3242 std::string new_sdp = kSdpOneCandidate;
3243 Replace("udp", "unsupported_transport", &new_sdp);
3244 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3245 new_sdp = kSdpOneCandidate;
3246 Replace("udp", "uDP", &new_sdp);
3247 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3248 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3249 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3250 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
3251}
3252
honghaiza54a0802015-12-16 18:37:23 -08003253TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003254 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08003255 EXPECT_TRUE(
3256 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003257 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3258 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3259 Candidate ref_candidate = jcandidate_->candidate();
3260 ref_candidate.set_username("user_rtp");
3261 ref_candidate.set_password("password_rtp");
3262 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
3263}
3264
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003265TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08003266 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003267
3268 // Deserialize
3269 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
3270
3271 // Verify
3272 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08003273 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003274 EXPECT_TRUE(audio->conference_mode());
3275
3276 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 15:55:30 -08003277 cricket::GetFirstVideoContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003278 EXPECT_TRUE(video->conference_mode());
3279}
3280
deadbeefd45aea82017-09-16 01:24:29 -07003281TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08003282 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 01:24:29 -07003283
3284 // We tested deserialization already above, so just test that if we serialize
3285 // and deserialize the flag doesn't disappear.
3286 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 12:22:16 -08003287 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 01:24:29 -07003288 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
3289
3290 // Verify.
3291 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08003292 cricket::GetFirstAudioContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 01:24:29 -07003293 EXPECT_TRUE(audio->conference_mode());
3294
3295 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 15:55:30 -08003296 cricket::GetFirstVideoContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 01:24:29 -07003297 EXPECT_TRUE(video->conference_mode());
3298}
3299
Sebastian Jansson97321b62019-07-24 14:01:18 +02003300TEST_F(WebRtcSdpTest, SerializeAndDeserializeRemoteNetEstimate) {
3301 {
3302 // By default remote estimates are disabled.
3303 JsepSessionDescription dst(kDummyType);
3304 SdpDeserialize(webrtc::SdpSerialize(jdesc_), &dst);
3305 EXPECT_FALSE(cricket::GetFirstVideoContentDescription(dst.description())
3306 ->remote_estimate());
3307 }
3308 {
3309 // When remote estimate is enabled, the setting is propagated via SDP.
3310 cricket::GetFirstVideoContentDescription(jdesc_.description())
3311 ->set_remote_estimate(true);
3312 JsepSessionDescription dst(kDummyType);
3313 SdpDeserialize(webrtc::SdpSerialize(jdesc_), &dst);
3314 EXPECT_TRUE(cricket::GetFirstVideoContentDescription(dst.description())
3315 ->remote_estimate());
3316 }
3317}
3318
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003319TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
3320 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003321 const char kSdpEmptyType[] = " =candidate";
3322 const char kSdpEqualAsPlus[] = "a+candidate";
3323 const char kSdpSpaceAfterEqual[] = "a= candidate";
3324 const char kSdpUpperType[] = "A=candidate";
3325 const char kSdpEmptyLine[] = "";
3326 const char kSdpMissingValue[] = "a=";
3327
Yves Gerey665174f2018-06-19 15:03:05 +02003328 const char kSdpBrokenFingerprint[] =
3329 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003330 "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 +02003331 const char kSdpExtraField[] =
3332 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003333 "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 +02003334 const char kSdpMissingSpace[] =
3335 "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003336 "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 +00003337 // MD5 is not allowed in fingerprints.
Yves Gerey665174f2018-06-19 15:03:05 +02003338 const char kSdpMd5[] =
3339 "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003340 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003341
3342 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003343 ExpectParseFailure("v=", kSdpDestroyer);
3344 ExpectParseFailure("o=", kSdpDestroyer);
3345 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003346 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003347 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003348
3349 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003350 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
3351 ExpectParseFailure("m=video", kSdpDestroyer);
Philipp Hanckeefc55b02020-06-26 10:17:05 +02003352 ExpectParseFailure("m=", "c=IN IP4 74.125.224.39");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003353
3354 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003355 ExpectParseFailure("a=candidate", kSdpEmptyType);
3356 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
3357 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
3358 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003359
3360 // Bogus fingerprint replacing a=sendrev. We selected this attribute
3361 // because it's orthogonal to what we are replacing and hence
3362 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003363 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
3364 ExpectParseFailure("a=sendrecv", kSdpExtraField);
3365 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
3366 ExpectParseFailure("a=sendrecv", kSdpMd5);
3367
3368 // Empty Line
3369 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
3370 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003371}
3372
3373TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
3374 // ssrc
3375 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08003376 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003377 // crypto
3378 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
3379 // rtpmap
3380 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
3381 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
3382 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
3383 // candidate
3384 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
3385 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
3386 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
3387 ExpectParseFailure("rport 2346", "rport badvalue");
3388 ExpectParseFailure("rport 2346 generation 2",
3389 "rport 2346 generation badvalue");
3390 // m line
3391 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
3392 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
3393
3394 // bandwidth
3395 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003396 "b=AS:badvalue\r\n", "b=AS:badvalue");
Philipp Hanckefbbfc022020-07-31 08:30:50 +02003397 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", "b=AS\r\n",
3398 "b=AS");
3399 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", "b=AS:\r\n",
3400 "b=AS:");
3401 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3402 "b=AS:12:34\r\n", "b=AS:12:34");
3403
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003404 // rtcp-fb
3405 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3406 "a=rtcp-fb:badvalue nack\r\n",
3407 "a=rtcp-fb:badvalue nack");
3408 // extmap
3409 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3410 "a=extmap:badvalue http://example.com\r\n",
3411 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003412}
3413
3414TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 10:27:41 -08003415 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003416
3417 const char kSdpWithReorderedPlTypesString[] =
3418 "v=0\r\n"
3419 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3420 "s=-\r\n"
3421 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00003422 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
Yves Gerey665174f2018-06-19 15:03:05 +02003423 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
3424 // in the map.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003425 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003426 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003427
3428 // Deserialize
3429 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
3430
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003431 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003432 GetFirstAudioContentDescription(jdesc_output.description());
3433 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003434 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003435 EXPECT_EQ("ISAC", acd->codecs()[0].name);
3436 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003437 EXPECT_EQ(104, acd->codecs()[0].id);
3438}
3439
3440TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 10:27:41 -08003441 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003442 CodecParams params;
3443 params.max_ptime = 40;
3444 params.ptime = 30;
3445 params.min_ptime = 10;
3446 params.sprop_stereo = 1;
3447 params.stereo = 1;
3448 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003449 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003450 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 12:22:16 -08003451 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003452}
3453
3454TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
3455 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 10:27:41 -08003456 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003457 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003458 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003459}
3460
3461TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
3462 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 10:27:41 -08003463 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003464 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003465 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003466}
3467
3468TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 10:27:41 -08003469 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003470
3471 const char kSdpWithFmtpString[] =
3472 "v=0\r\n"
3473 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3474 "s=-\r\n"
3475 "t=0 0\r\n"
3476 "m=video 3457 RTP/SAVPF 120\r\n"
3477 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07003478 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3479
3480 // Deserialize
3481 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07003482 EXPECT_TRUE(
3483 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07003484
Donald Curtis0e07f922015-05-15 09:21:23 -07003485 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003486 GetFirstVideoContentDescription(jdesc_output.description());
3487 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 09:21:23 -07003488 ASSERT_FALSE(vcd->codecs().empty());
3489 cricket::VideoCodec vp8 = vcd->codecs()[0];
3490 EXPECT_EQ("VP8", vp8.name);
3491 EXPECT_EQ(120, vp8.id);
3492 cricket::CodecParameterMap::iterator found =
3493 vp8.params.find("x-google-min-bitrate");
3494 ASSERT_TRUE(found != vp8.params.end());
3495 EXPECT_EQ(found->second, "10");
3496 found = vp8.params.find("x-google-max-quantization");
3497 ASSERT_TRUE(found != vp8.params.end());
3498 EXPECT_EQ(found->second, "40");
3499}
3500
johan2d8d23e2016-06-03 01:22:42 -07003501TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 10:27:41 -08003502 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 01:22:42 -07003503
3504 const char kSdpWithFmtpString[] =
3505 "v=0\r\n"
3506 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3507 "s=-\r\n"
3508 "t=0 0\r\n"
3509 "m=video 49170 RTP/AVP 98\r\n"
3510 "a=rtpmap:98 H264/90000\r\n"
3511 "a=fmtp:98 profile-level-id=42A01E; "
3512 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3513
3514 // Deserialize.
3515 SdpParseError error;
3516 EXPECT_TRUE(
3517 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3518
johan2d8d23e2016-06-03 01:22:42 -07003519 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003520 GetFirstVideoContentDescription(jdesc_output.description());
3521 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 01:22:42 -07003522 ASSERT_FALSE(vcd->codecs().empty());
3523 cricket::VideoCodec h264 = vcd->codecs()[0];
3524 EXPECT_EQ("H264", h264.name);
3525 EXPECT_EQ(98, h264.id);
3526 cricket::CodecParameterMap::const_iterator found =
3527 h264.params.find("profile-level-id");
3528 ASSERT_TRUE(found != h264.params.end());
3529 EXPECT_EQ(found->second, "42A01E");
3530 found = h264.params.find("sprop-parameter-sets");
3531 ASSERT_TRUE(found != h264.params.end());
3532 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3533}
3534
Donald Curtis0e07f922015-05-15 09:21:23 -07003535TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 10:27:41 -08003536 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 09:21:23 -07003537
3538 const char kSdpWithFmtpString[] =
3539 "v=0\r\n"
3540 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3541 "s=-\r\n"
3542 "t=0 0\r\n"
3543 "m=video 3457 RTP/SAVPF 120\r\n"
3544 "a=rtpmap:120 VP8/90000\r\n"
3545 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003546
3547 // Deserialize
3548 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02003549 EXPECT_TRUE(
3550 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003551
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003552 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003553 GetFirstVideoContentDescription(jdesc_output.description());
3554 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003555 ASSERT_FALSE(vcd->codecs().empty());
3556 cricket::VideoCodec vp8 = vcd->codecs()[0];
3557 EXPECT_EQ("VP8", vp8.name);
3558 EXPECT_EQ(120, vp8.id);
3559 cricket::CodecParameterMap::iterator found =
3560 vp8.params.find("x-google-min-bitrate");
3561 ASSERT_TRUE(found != vp8.params.end());
3562 EXPECT_EQ(found->second, "10");
3563 found = vp8.params.find("x-google-max-quantization");
3564 ASSERT_TRUE(found != vp8.params.end());
3565 EXPECT_EQ(found->second, "40");
3566}
3567
Mirta Dvornicic479a3c02019-06-04 15:38:50 +02003568TEST_F(WebRtcSdpTest, DeserializePacketizationAttributeWithIllegalValue) {
3569 JsepSessionDescription jdesc_output(kDummyType);
3570
3571 const char kSdpWithPacketizationString[] =
3572 "v=0\r\n"
3573 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3574 "s=-\r\n"
3575 "t=0 0\r\n"
3576 "m=audio 9 RTP/SAVPF 111\r\n"
3577 "a=rtpmap:111 opus/48000/2\r\n"
3578 "a=packetization:111 unknownpacketizationattributeforaudio\r\n"
3579 "m=video 3457 RTP/SAVPF 120 121 122\r\n"
3580 "a=rtpmap:120 VP8/90000\r\n"
3581 "a=packetization:120 raw\r\n"
3582 "a=rtpmap:121 VP9/90000\r\n"
3583 "a=rtpmap:122 H264/90000\r\n"
3584 "a=packetization:122 unknownpacketizationattributevalue\r\n";
3585
3586 SdpParseError error;
3587 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithPacketizationString, &jdesc_output,
3588 &error));
3589
3590 AudioContentDescription* acd =
3591 GetFirstAudioContentDescription(jdesc_output.description());
3592 ASSERT_TRUE(acd);
3593 ASSERT_THAT(acd->codecs(), testing::SizeIs(1));
3594 cricket::AudioCodec opus = acd->codecs()[0];
3595 EXPECT_EQ(opus.name, "opus");
3596 EXPECT_EQ(opus.id, 111);
3597
3598 const VideoContentDescription* vcd =
3599 GetFirstVideoContentDescription(jdesc_output.description());
3600 ASSERT_TRUE(vcd);
3601 ASSERT_THAT(vcd->codecs(), testing::SizeIs(3));
3602 cricket::VideoCodec vp8 = vcd->codecs()[0];
3603 EXPECT_EQ(vp8.name, "VP8");
3604 EXPECT_EQ(vp8.id, 120);
3605 EXPECT_EQ(vp8.packetization, "raw");
3606 cricket::VideoCodec vp9 = vcd->codecs()[1];
3607 EXPECT_EQ(vp9.name, "VP9");
3608 EXPECT_EQ(vp9.id, 121);
3609 EXPECT_EQ(vp9.packetization, absl::nullopt);
3610 cricket::VideoCodec h264 = vcd->codecs()[2];
3611 EXPECT_EQ(h264.name, "H264");
3612 EXPECT_EQ(h264.id, 122);
3613 EXPECT_EQ(h264.packetization, absl::nullopt);
3614}
3615
ossuaa4b0772017-01-30 07:41:18 -08003616TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003617 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003618
3619 cricket::AudioCodecs codecs = acd->codecs();
3620 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3621 acd->set_codecs(codecs);
3622
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003623 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003624 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003625 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003626 std::string sdp_with_fmtp = kSdpFullString;
3627 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3628 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3629 &sdp_with_fmtp);
3630 EXPECT_EQ(sdp_with_fmtp, message);
3631}
3632
3633TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003634 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003635
3636 cricket::AudioCodecs codecs = acd->codecs();
3637 codecs[0].params["stereo"] = "1";
3638 acd->set_codecs(codecs);
3639
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003640 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003641 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003642 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003643 std::string sdp_with_fmtp = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003644 InjectAfter("a=rtpmap:111 opus/48000/2\r\n", "a=fmtp:111 stereo=1\r\n",
ossuaa4b0772017-01-30 07:41:18 -08003645 &sdp_with_fmtp);
3646 EXPECT_EQ(sdp_with_fmtp, message);
3647}
3648
3649TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003650 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003651
3652 cricket::AudioCodecs codecs = acd->codecs();
3653 codecs[0].params["ptime"] = "20";
3654 codecs[0].params["maxptime"] = "120";
3655 acd->set_codecs(codecs);
3656
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003657 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003658 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003659 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003660 std::string sdp_with_fmtp = kSdpFullString;
3661 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3662 "a=maxptime:120\r\n" // No comma here. String merging!
3663 "a=ptime:20\r\n",
3664 &sdp_with_fmtp);
3665 EXPECT_EQ(sdp_with_fmtp, message);
3666}
3667
Philipp Hanckef2a4ec12020-07-01 21:07:32 +02003668TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithTelephoneEvent) {
3669 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
3670
3671 cricket::AudioCodecs codecs = acd->codecs();
3672 cricket::AudioCodec dtmf(105, "telephone-event", 8000, 0, 1);
3673 dtmf.params[""] = "0-15";
3674 codecs.push_back(dtmf);
3675 acd->set_codecs(codecs);
3676
3677 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
3678 jdesc_.session_version()));
3679 std::string message = webrtc::SdpSerialize(jdesc_);
3680 std::string sdp_with_fmtp = kSdpFullString;
3681 InjectAfter("m=audio 2345 RTP/SAVPF 111 103 104", " 105", &sdp_with_fmtp);
3682 InjectAfter(
3683 "a=rtpmap:104 ISAC/32000\r\n",
3684 "a=rtpmap:105 telephone-event/8000\r\n" // No comma here. String merging!
3685 "a=fmtp:105 0-15\r\n",
3686 &sdp_with_fmtp);
3687 EXPECT_EQ(sdp_with_fmtp, message);
3688}
3689
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003690TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003691 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003692
3693 cricket::VideoCodecs codecs = vcd->codecs();
3694 codecs[0].params["x-google-min-bitrate"] = "10";
3695 vcd->set_codecs(codecs);
3696
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003697 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003698 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003699 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003700 std::string sdp_with_fmtp = kSdpFullString;
3701 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003702 "a=fmtp:120 x-google-min-bitrate=10\r\n", &sdp_with_fmtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003703 EXPECT_EQ(sdp_with_fmtp, message);
3704}
3705
Mirta Dvornicic479a3c02019-06-04 15:38:50 +02003706TEST_F(WebRtcSdpTest, SerializeVideoPacketizationAttribute) {
3707 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
3708
3709 cricket::VideoCodecs codecs = vcd->codecs();
3710 codecs[0].packetization = "raw";
3711 vcd->set_codecs(codecs);
3712
3713 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
3714 jdesc_.session_version()));
3715 std::string message = webrtc::SdpSerialize(jdesc_);
3716 std::string sdp_with_packetization = kSdpFullString;
3717 InjectAfter("a=rtpmap:120 VP8/90000\r\n", "a=packetization:120 raw\r\n",
3718 &sdp_with_packetization);
3719 EXPECT_EQ(sdp_with_packetization, message);
3720}
3721
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003722TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) {
3723 // Deserialize the baseline description, making sure it's ICE full.
Steve Antona3a92c22017-12-07 10:27:41 -08003724 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003725 std::string sdp_with_icelite = kSdpFullString;
3726 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3727 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3728 const cricket::TransportInfo* tinfo1 =
3729 desc->GetTransportInfoByName("audio_content_name");
3730 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3731 const cricket::TransportInfo* tinfo2 =
3732 desc->GetTransportInfoByName("video_content_name");
3733 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003734
3735 // Add "a=ice-lite" and deserialize, making sure it's ICE lite.
Yves Gerey665174f2018-06-19 15:03:05 +02003736 InjectAfter(kSessionTime, "a=ice-lite\r\n", &sdp_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003737 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3738 desc = jdesc_with_icelite.description();
3739 const cricket::TransportInfo* atinfo =
3740 desc->GetTransportInfoByName("audio_content_name");
3741 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3742 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003743 desc->GetTransportInfoByName("video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003744 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003745
3746 // Now that we know deserialization works, we can use TestSerialize to test
3747 // serialization.
3748 TestSerialize(jdesc_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003749}
3750
3751// Verifies that the candidates in the input SDP are parsed and serialized
3752// correctly in the output SDP.
3753TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3754 std::string sdp_with_data = kSdpString;
3755 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 10:27:41 -08003756 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003757
3758 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 12:22:16 -08003759 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003760}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003761
3762TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3763 AddFingerprint();
3764 TransportInfo audio_transport_info =
3765 *(desc_.GetTransportInfoByName(kAudioContentName));
3766 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3767 audio_transport_info.description.connection_role);
3768 audio_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003769 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003770
3771 TransportInfo video_transport_info =
3772 *(desc_.GetTransportInfoByName(kVideoContentName));
3773 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3774 video_transport_info.description.connection_role);
3775 video_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003776 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003777
3778 desc_.RemoveTransportInfoByName(kAudioContentName);
3779 desc_.RemoveTransportInfoByName(kVideoContentName);
3780
3781 desc_.AddTransportInfo(audio_transport_info);
3782 desc_.AddTransportInfo(video_transport_info);
3783
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003784 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003785 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003786 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003787 std::string sdp_with_dtlssetup = kSdpFullString;
3788
3789 // Fingerprint attribute is necessary to add DTLS setup attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003790 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_dtlssetup);
3791 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003792 // Now adding |setup| attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003793 InjectAfter(kFingerprint, "a=setup:active\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003794 EXPECT_EQ(sdp_with_dtlssetup, message);
3795}
3796
3797TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
Steve Antona3a92c22017-12-07 10:27:41 -08003798 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003799 std::string sdp_with_dtlssetup = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003800 InjectAfter(kSessionTime, "a=setup:actpass\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003801 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3802 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3803 const cricket::TransportInfo* atinfo =
3804 desc->GetTransportInfoByName("audio_content_name");
3805 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3806 atinfo->description.connection_role);
3807 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003808 desc->GetTransportInfoByName("video_content_name");
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003809 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3810 vtinfo->description.connection_role);
3811}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003812
3813// Verifies that the order of the serialized m-lines follows the order of the
3814// ContentInfo in SessionDescription, and vise versa for deserialization.
3815TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 10:27:41 -08003816 JsepSessionDescription jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02003817 const std::string media_content_sdps[3] = {kSdpAudioString, kSdpVideoString,
3818 kSdpSctpDataChannelString};
3819 const cricket::MediaType media_types[3] = {cricket::MEDIA_TYPE_AUDIO,
3820 cricket::MEDIA_TYPE_VIDEO,
3821 cricket::MEDIA_TYPE_DATA};
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003822
3823 // Verifies all 6 permutations.
3824 for (size_t i = 0; i < 6; ++i) {
3825 size_t media_content_in_sdp[3];
3826 // The index of the first media content.
3827 media_content_in_sdp[0] = i / 2;
3828 // The index of the second media content.
3829 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3830 // The index of the third media content.
3831 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3832
3833 std::string sdp_string = kSdpSessionString;
3834 for (size_t i = 0; i < 3; ++i)
3835 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3836
3837 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3838 cricket::SessionDescription* desc = jdesc.description();
3839 EXPECT_EQ(3u, desc->contents().size());
3840
3841 for (size_t i = 0; i < 3; ++i) {
3842 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 15:14:30 -08003843 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003844 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3845 }
3846
Steve Antone831b8c2018-02-01 12:22:16 -08003847 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003848 EXPECT_EQ(sdp_string, serialized_sdp);
3849 }
3850}
deadbeef9d3584c2016-02-16 17:54:10 -08003851
deadbeef25ed4352016-12-12 18:37:36 -08003852TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3853 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 10:27:41 -08003854 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003855 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003856 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3857 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3858}
3859
deadbeef12771a12017-01-03 13:53:47 -08003860// The semantics of "a=bundle-only" are only defined when it's used in
3861// combination with a 0 port on the m= line. We should ignore it if used with a
3862// nonzero port.
3863TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3864 // Make the base bundle-only description but unset the bundle-only flag.
3865 MakeBundleOnlyDescription();
3866 jdesc_.description()->contents()[1].bundle_only = false;
3867
3868 std::string modified_sdp = kBundleOnlySdpFullString;
3869 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08003870 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003871 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3872 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003873}
3874
3875TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3876 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003877 TestSerialize(jdesc_);
deadbeef25ed4352016-12-12 18:37:36 -08003878}
3879
deadbeef9d3584c2016-02-16 17:54:10 -08003880TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3881 MakePlanBDescription();
3882
Steve Antona3a92c22017-12-07 10:27:41 -08003883 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003884 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3885
3886 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3887}
3888
3889TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3890 MakePlanBDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003891 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-16 17:54:10 -08003892}
3893
3894TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3895 MakeUnifiedPlanDescription();
3896
Steve Antona3a92c22017-12-07 10:27:41 -08003897 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003898 EXPECT_TRUE(
3899 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3900
3901 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3902}
3903
3904TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3905 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003906 TestSerialize(jdesc_);
3907}
3908
Seth Hampson5b4f0752018-04-02 16:31:36 -07003909// This tests deserializing a Unified Plan SDP that is compatible with both
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003910// Unified Plan and Plan B style SDP, meaning that it contains both "a=ssrc
3911// msid" lines and "a=msid " lines. It tests the case for audio/video tracks
Seth Hampson5b4f0752018-04-02 16:31:36 -07003912// with no stream ids and multiple stream ids. For parsing this, the Unified
3913// Plan a=msid lines should take priority, because the Plan B style a=ssrc msid
3914// lines do not support multiple stream ids and no stream ids.
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003915TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionSpecialMsid) {
3916 // Create both msid lines for Plan B and Unified Plan support.
3917 MakeUnifiedPlanDescriptionMultipleStreamIds(
3918 cricket::kMsidSignalingMediaSection |
3919 cricket::kMsidSignalingSsrcAttribute);
Seth Hampson5b4f0752018-04-02 16:31:36 -07003920
3921 JsepSessionDescription deserialized_description(kDummyType);
3922 EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid,
3923 &deserialized_description));
3924
3925 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
Henrik Boström5b147782018-12-04 11:25:05 +01003926 EXPECT_EQ(cricket::kMsidSignalingMediaSection |
3927 cricket::kMsidSignalingSsrcAttribute,
3928 deserialized_description.description()->msid_signaling());
Seth Hampson5b4f0752018-04-02 16:31:36 -07003929}
3930
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003931// Tests the serialization of a Unified Plan SDP that is compatible for both
3932// Unified Plan and Plan B style SDPs, meaning that it contains both "a=ssrc
3933// msid" lines and "a=msid " lines. It tests the case for no stream ids and
3934// multiple stream ids.
3935TEST_F(WebRtcSdpTest, SerializeSessionDescriptionSpecialMsid) {
3936 // Create both msid lines for Plan B and Unified Plan support.
3937 MakeUnifiedPlanDescriptionMultipleStreamIds(
3938 cricket::kMsidSignalingMediaSection |
3939 cricket::kMsidSignalingSsrcAttribute);
3940 std::string serialized_sdp = webrtc::SdpSerialize(jdesc_);
3941 // We explicitly test that the serialized SDP string is equal to the hard
3942 // coded SDP string. This is necessary, because in the parser "a=msid" lines
3943 // take priority over "a=ssrc msid" lines. This means if we just used
3944 // TestSerialize(), it could serialize an SDP that omits "a=ssrc msid" lines,
3945 // and still pass, because the deserialized version would be the same.
3946 EXPECT_EQ(kUnifiedPlanSdpFullStringWithSpecialMsid, serialized_sdp);
3947}
3948
3949// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3950// that signal stream IDs) is deserialized appropriately. It tests the case for
3951// no stream ids and multiple stream ids.
3952TEST_F(WebRtcSdpTest, UnifiedPlanDeserializeSessionDescriptionSpecialMsid) {
3953 // Only create a=msid lines for strictly Unified Plan stream ID support.
3954 MakeUnifiedPlanDescriptionMultipleStreamIds(
3955 cricket::kMsidSignalingMediaSection);
3956
3957 JsepSessionDescription deserialized_description(kDummyType);
3958 std::string unified_plan_sdp_string =
3959 kUnifiedPlanSdpFullStringWithSpecialMsid;
3960 RemoveSsrcMsidLinesFromSdpString(&unified_plan_sdp_string);
3961 EXPECT_TRUE(
3962 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3963
3964 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3965}
3966
3967// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3968// that signal stream IDs) is serialized appropriately. It tests the case for no
3969// stream ids and multiple stream ids.
3970TEST_F(WebRtcSdpTest, UnifiedPlanSerializeSessionDescriptionSpecialMsid) {
3971 // Only create a=msid lines for strictly Unified Plan stream ID support.
3972 MakeUnifiedPlanDescriptionMultipleStreamIds(
3973 cricket::kMsidSignalingMediaSection);
3974
Seth Hampson5b4f0752018-04-02 16:31:36 -07003975 TestSerialize(jdesc_);
3976}
3977
Seth Hampson5897a6e2018-04-03 11:16:33 -07003978// This tests that a Unified Plan SDP with no a=ssrc lines is
3979// serialized/deserialized appropriately. In this case the
3980// MediaContentDescription will contain a StreamParams object that doesn't have
3981// any SSRCs. Vice versa, this will be created upon deserializing an SDP with no
3982// SSRC lines.
3983TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3984 MakeUnifiedPlanDescription();
3985 RemoveSsrcSignalingFromStreamParams();
3986 std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString;
3987 RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string);
3988
3989 JsepSessionDescription deserialized_description(kDummyType);
3990 EXPECT_TRUE(
3991 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3992 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3993}
3994
3995TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3996 MakeUnifiedPlanDescription();
3997 RemoveSsrcSignalingFromStreamParams();
3998
3999 TestSerialize(jdesc_);
4000}
4001
Steve Antone831b8c2018-02-01 12:22:16 -08004002TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
4003 JsepSessionDescription jsep_desc(kDummyType);
4004 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
4005 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
4006}
4007
4008TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
4009 JsepSessionDescription jsep_desc(kDummyType);
4010 std::string sdp = kSdpSessionString;
4011 sdp += kSdpSctpDataChannelString;
4012 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4013 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
4014}
4015
4016TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
4017 JsepSessionDescription jsep_desc(kDummyType);
4018 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
4019 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
4020 jsep_desc.description()->msid_signaling());
4021}
4022
4023TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
4024 JsepSessionDescription jsep_desc(kDummyType);
4025 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
4026 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
4027 jsep_desc.description()->msid_signaling());
4028}
4029
4030const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
4031const char kSsrcAttributeMsidLine[] =
4032 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
4033
4034TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
4035 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
4036 std::string sdp = webrtc::SdpSerialize(jdesc_);
4037
4038 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
4039 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
4040}
4041
4042TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
4043 jdesc_.description()->set_msid_signaling(
4044 cricket::kMsidSignalingSsrcAttribute);
4045 std::string sdp = webrtc::SdpSerialize(jdesc_);
4046
4047 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
4048 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
4049}
4050
4051TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
4052 jdesc_.description()->set_msid_signaling(
4053 cricket::kMsidSignalingMediaSection |
4054 cricket::kMsidSignalingSsrcAttribute);
4055 std::string sdp = webrtc::SdpSerialize(jdesc_);
4056
4057 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
4058 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-16 17:54:10 -08004059}
deadbeef7e146cb2016-09-28 10:04:34 -07004060
deadbeefb2362572016-12-13 16:37:06 -08004061// Regression test for integer overflow bug:
4062// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
4063TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08004064 // Bandwidth attribute is the max signed 32-bit int, which will get
4065 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08004066 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08004067 "v=0\r\n"
4068 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4069 "s=-\r\n"
4070 "t=0 0\r\n"
4071 "m=video 3457 RTP/SAVPF 120\r\n"
4072 "b=AS:2147483647\r\n"
4073 "foo=fail\r\n";
4074
4075 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
4076}
deadbeef7bcdb692017-01-20 12:43:58 -08004077
deadbeefbc88c6b2017-08-02 11:26:34 -07004078// Similar to the above, except that negative values are illegal, not just
4079// error-prone as large values are.
4080// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
4081TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
4082 static const char kSdpWithNegativeBandwidth[] =
4083 "v=0\r\n"
4084 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4085 "s=-\r\n"
4086 "t=0 0\r\n"
4087 "m=video 3457 RTP/SAVPF 120\r\n"
4088 "b=AS:-1000\r\n";
4089
4090 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
4091}
4092
deadbeef3e8016e2017-08-03 17:49:30 -07004093// An exception to the above rule: a value of -1 for b=AS should just be
4094// ignored, resulting in "kAutoBandwidth" in the deserialized object.
4095// Applications historically may be using "b=AS:-1" to mean "no bandwidth
4096// limit", but this is now what ommitting the attribute entirely will do, so
4097// ignoring it will have the intended effect.
4098TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
4099 static const char kSdpWithBandwidthOfNegativeOne[] =
4100 "v=0\r\n"
4101 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4102 "s=-\r\n"
4103 "t=0 0\r\n"
4104 "m=video 3457 RTP/SAVPF 120\r\n"
4105 "b=AS:-1\r\n";
4106
Steve Antona3a92c22017-12-07 10:27:41 -08004107 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-03 17:49:30 -07004108 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-03 17:49:30 -07004109 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08004110 GetFirstVideoContentDescription(jdesc_output.description());
4111 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-03 17:49:30 -07004112 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
4113}
4114
deadbeef7bcdb692017-01-20 12:43:58 -08004115// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
4116// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
4117// Regression test for:
4118// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
4119TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
4120 // Important piece is "ufrag foo pwd bar".
4121 static const char kSdpWithIceCredentialsInCandidateString[] =
4122 "v=0\r\n"
4123 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4124 "s=-\r\n"
4125 "t=0 0\r\n"
4126 "m=audio 9 RTP/SAVPF 111\r\n"
4127 "c=IN IP4 0.0.0.0\r\n"
4128 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4129 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4130 "a=rtpmap:111 opus/48000/2\r\n"
4131 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
4132 "generation 2 ufrag foo pwd bar\r\n";
4133
Steve Antona3a92c22017-12-07 10:27:41 -08004134 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 12:43:58 -08004135 EXPECT_TRUE(
4136 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
4137 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
4138 ASSERT_NE(nullptr, candidates);
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02004139 ASSERT_EQ(1U, candidates->count());
deadbeef7bcdb692017-01-20 12:43:58 -08004140 cricket::Candidate c = candidates->at(0)->candidate();
4141 EXPECT_EQ("ufrag_voice", c.username());
4142 EXPECT_EQ("pwd_voice", c.password());
4143}
deadbeef90f1e1e2017-02-10 12:35:05 -08004144
Johannes Kron211856b2018-09-06 12:12:28 +02004145// Test that attribute lines "a=ice-ufrag-something"/"a=ice-pwd-something" are
4146// ignored, and only the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
4147// Regression test for:
4148// https://bugs.chromium.org/p/webrtc/issues/detail?id=9712
4149TEST_F(WebRtcSdpTest, AttributeWithPartialMatchingNameIsIgnored) {
4150 static const char kSdpWithFooIceCredentials[] =
4151 "v=0\r\n"
4152 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4153 "s=-\r\n"
4154 "t=0 0\r\n"
4155 "m=audio 9 RTP/SAVPF 111\r\n"
4156 "c=IN IP4 0.0.0.0\r\n"
4157 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4158 "a=ice-ufrag-something:foo\r\na=ice-pwd-something:bar\r\n"
4159 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4160 "a=rtpmap:111 opus/48000/2\r\n"
4161 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
4162 "generation 2\r\n";
4163
4164 JsepSessionDescription jdesc_output(kDummyType);
4165 EXPECT_TRUE(SdpDeserialize(kSdpWithFooIceCredentials, &jdesc_output));
4166 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
4167 ASSERT_NE(nullptr, candidates);
4168 ASSERT_EQ(1U, candidates->count());
4169 cricket::Candidate c = candidates->at(0)->candidate();
4170 EXPECT_EQ("ufrag_voice", c.username());
4171 EXPECT_EQ("pwd_voice", c.password());
4172}
4173
deadbeef90f1e1e2017-02-10 12:35:05 -08004174// Test that SDP with an invalid port number in "a=candidate" lines is
4175// rejected, without crashing.
4176// Regression test for:
4177// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
4178TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
4179 static const char kSdpWithInvalidCandidatePort[] =
4180 "v=0\r\n"
4181 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4182 "s=-\r\n"
4183 "t=0 0\r\n"
4184 "m=audio 9 RTP/SAVPF 111\r\n"
4185 "c=IN IP4 0.0.0.0\r\n"
4186 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4187 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4188 "a=rtpmap:111 opus/48000/2\r\n"
4189 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
4190 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
4191
Steve Antona3a92c22017-12-07 10:27:41 -08004192 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 12:35:05 -08004193 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
4194}
deadbeefa4549d62017-02-10 17:26:22 -08004195
4196// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
4197// Regression test for:
4198// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
4199TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
4200 static const char kSdpWithMissingTrackId[] =
4201 "v=0\r\n"
4202 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4203 "s=-\r\n"
4204 "t=0 0\r\n"
4205 "m=audio 9 RTP/SAVPF 111\r\n"
4206 "c=IN IP4 0.0.0.0\r\n"
4207 "a=rtpmap:111 opus/48000/2\r\n"
4208 "a=msid:stream_id \r\n";
4209
Steve Antona3a92c22017-12-07 10:27:41 -08004210 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08004211 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
4212}
4213
4214TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
4215 static const char kSdpWithMissingStreamId[] =
4216 "v=0\r\n"
4217 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4218 "s=-\r\n"
4219 "t=0 0\r\n"
4220 "m=audio 9 RTP/SAVPF 111\r\n"
4221 "c=IN IP4 0.0.0.0\r\n"
4222 "a=rtpmap:111 opus/48000/2\r\n"
4223 "a=msid: track_id\r\n";
4224
Steve Antona3a92c22017-12-07 10:27:41 -08004225 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08004226 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
4227}
zhihuang38989e52017-03-21 11:04:53 -07004228
4229// Tests that if both session-level address and media-level address exist, use
4230// the media-level address.
4231TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 10:27:41 -08004232 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004233
4234 // Sesssion-level address.
4235 std::string sdp = kSdpFullString;
4236 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
4237 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4238
4239 const auto& content1 = jsep_desc.description()->contents()[0];
4240 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 15:14:30 -08004241 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004242 const auto& content2 = jsep_desc.description()->contents()[1];
4243 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 15:14:30 -08004244 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004245}
4246
4247// Tests that the session-level connection address will be used if the media
4248// level-addresses are not specified.
4249TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 10:27:41 -08004250 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004251
4252 // Sesssion-level address.
4253 std::string sdp = kSdpString;
4254 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
4255 // Remove the media level addresses.
4256 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
4257 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
4258 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4259
4260 const auto& content1 = jsep_desc.description()->contents()[0];
4261 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004262 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004263 const auto& content2 = jsep_desc.description()->contents()[1];
4264 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004265 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004266}
4267
4268TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 10:27:41 -08004269 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004270
4271 std::string sdp = kSdpString;
4272 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4273 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
4274 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
4275 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
4276 &sdp);
4277 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
4278 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
4279 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
4280 &sdp);
4281 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4282 const auto& content1 = jsep_desc.description()->contents()[0];
4283 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004284 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004285 const auto& content2 = jsep_desc.description()->contents()[1];
4286 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004287 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004288}
4289
Qingsi Wang56991422019-02-08 12:53:06 -08004290// Test that a c= line that contains a hostname connection address can be
4291// parsed.
4292TEST_F(WebRtcSdpTest, ParseConnectionDataWithHostnameConnectionAddress) {
4293 JsepSessionDescription jsep_desc(kDummyType);
4294 std::string sdp = kSdpString;
4295 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4296
4297 sdp = kSdpString;
4298 Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp);
4299 Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp);
4300 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4301
4302 ASSERT_NE(nullptr, jsep_desc.description());
4303 const auto& content1 = jsep_desc.description()->contents()[0];
4304 EXPECT_EQ("example.local:9",
4305 content1.media_description()->connection_address().ToString());
4306 const auto& content2 = jsep_desc.description()->contents()[1];
4307 EXPECT_EQ("example.local:9",
4308 content2.media_description()->connection_address().ToString());
4309}
4310
4311// Test that the invalid or unsupported connection data cannot be parsed.
zhihuang38989e52017-03-21 11:04:53 -07004312TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 10:27:41 -08004313 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004314 std::string sdp = kSdpString;
4315 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4316
4317 // Unsupported multicast IPv4 address.
4318 sdp = kSdpFullString;
4319 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
4320 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4321
4322 // Unsupported multicast IPv6 address.
4323 sdp = kSdpFullString;
4324 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
4325 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4326
4327 // Mismatched address type.
4328 sdp = kSdpFullString;
4329 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
4330 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4331
4332 sdp = kSdpFullString;
4333 Replace("c=IN IP4 74.125.224.39\r\n",
4334 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
4335 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4336}
4337
4338TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 10:27:41 -08004339 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004340 MakeDescriptionWithoutCandidates(&expected_jsep);
4341 // Serialization.
Steve Antone831b8c2018-02-01 12:22:16 -08004342 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 11:04:53 -07004343 // Deserialization.
Steve Antona3a92c22017-12-07 10:27:41 -08004344 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004345 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 15:14:30 -08004346 auto audio_desc = jdesc.description()
4347 ->GetContentByName(kAudioContentName)
4348 ->media_description();
4349 auto video_desc = jdesc.description()
4350 ->GetContentByName(kVideoContentName)
4351 ->media_description();
zhihuang38989e52017-03-21 11:04:53 -07004352 EXPECT_EQ(audio_desc_->connection_address().ToString(),
4353 audio_desc->connection_address().ToString());
4354 EXPECT_EQ(video_desc_->connection_address().ToString(),
4355 video_desc->connection_address().ToString());
4356}
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07004357
4358// RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be
4359// used (i.e., a single space as the session name)." So we should accept that.
4360TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) {
4361 JsepSessionDescription jsep_desc(kDummyType);
4362 std::string sdp = kSdpString;
4363 Replace("s=-\r\n", "s= \r\n", &sdp);
4364 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4365}
Amit Hilbucha2012042018-12-03 11:35:05 -08004366
4367// Simulcast malformed input test for invalid format.
4368TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_EmptyAttribute) {
Artem Titovf0a34f22020-03-16 17:52:04 +00004369 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
4370 "a=simulcast:\r\n", "a=simulcast:");
Amit Hilbucha2012042018-12-03 11:35:05 -08004371}
4372
4373// Tests that duplicate simulcast entries in the SDP triggers a parse failure.
4374TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_DuplicateAttribute) {
Artem Titovf0a34f22020-03-16 17:52:04 +00004375 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
4376 "a=simulcast:send 1\r\na=simulcast:recv 2\r\n",
4377 "a=simulcast:");
Amit Hilbucha2012042018-12-03 11:35:05 -08004378}
4379
4380// Validates that deserialization uses the a=simulcast: attribute
4381TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttribute) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004382 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4383 sdp += "a=rid:1 send\r\n";
4384 sdp += "a=rid:2 send\r\n";
4385 sdp += "a=rid:3 send\r\n";
4386 sdp += "a=rid:4 recv\r\n";
4387 sdp += "a=rid:5 recv\r\n";
4388 sdp += "a=rid:6 recv\r\n";
Amit Hilbucha2012042018-12-03 11:35:05 -08004389 sdp += "a=simulcast:send 1,2;3 recv 4;5;6\r\n";
4390 JsepSessionDescription output(kDummyType);
4391 SdpParseError error;
4392 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4393 const cricket::ContentInfos& contents = output.description()->contents();
4394 const cricket::MediaContentDescription* media =
4395 contents.back().media_description();
4396 EXPECT_TRUE(media->HasSimulcast());
4397 EXPECT_EQ(2ul, media->simulcast_description().send_layers().size());
4398 EXPECT_EQ(3ul, media->simulcast_description().receive_layers().size());
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004399 EXPECT_FALSE(media->streams().empty());
4400 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4401 CompareRidDescriptionIds(rids, {"1", "2", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004402}
4403
4404// Validates that deserialization removes rids that do not appear in SDP
4405TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttributeRemovesUnknownRids) {
4406 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4407 sdp += "a=rid:1 send\r\n";
4408 sdp += "a=rid:3 send\r\n";
4409 sdp += "a=rid:4 recv\r\n";
4410 sdp += "a=simulcast:send 1,2;3 recv 4;5,6\r\n";
4411 JsepSessionDescription output(kDummyType);
4412 SdpParseError error;
4413 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4414 const cricket::ContentInfos& contents = output.description()->contents();
4415 const cricket::MediaContentDescription* media =
4416 contents.back().media_description();
4417 EXPECT_TRUE(media->HasSimulcast());
4418 const SimulcastDescription& simulcast = media->simulcast_description();
4419 EXPECT_EQ(2ul, simulcast.send_layers().size());
4420 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4421
4422 std::vector<SimulcastLayer> all_send_layers =
4423 simulcast.send_layers().GetAllLayers();
4424 EXPECT_EQ(2ul, all_send_layers.size());
Steve Anton64b626b2019-01-28 17:25:26 -08004425 EXPECT_EQ(0,
4426 absl::c_count_if(all_send_layers, [](const SimulcastLayer& layer) {
4427 return layer.rid == "2";
4428 }));
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004429
4430 std::vector<SimulcastLayer> all_receive_layers =
4431 simulcast.receive_layers().GetAllLayers();
4432 ASSERT_EQ(1ul, all_receive_layers.size());
4433 EXPECT_EQ("4", all_receive_layers[0].rid);
4434
4435 EXPECT_FALSE(media->streams().empty());
4436 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4437 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004438}
4439
4440// Validates that Simulcast removes rids that appear in both send and receive.
4441TEST_F(WebRtcSdpTest,
4442 TestDeserializeSimulcastAttributeRemovesDuplicateSendReceive) {
4443 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4444 sdp += "a=rid:1 send\r\n";
4445 sdp += "a=rid:2 send\r\n";
4446 sdp += "a=rid:3 send\r\n";
4447 sdp += "a=rid:4 recv\r\n";
4448 sdp += "a=simulcast:send 1;2;3 recv 2;4\r\n";
4449 JsepSessionDescription output(kDummyType);
4450 SdpParseError error;
4451 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4452 const cricket::ContentInfos& contents = output.description()->contents();
4453 const cricket::MediaContentDescription* media =
4454 contents.back().media_description();
4455 EXPECT_TRUE(media->HasSimulcast());
4456 const SimulcastDescription& simulcast = media->simulcast_description();
4457 EXPECT_EQ(2ul, simulcast.send_layers().size());
4458 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4459 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4460 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4461
4462 EXPECT_FALSE(media->streams().empty());
4463 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4464 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004465}
4466
4467// Ignores empty rid line.
4468TEST_F(WebRtcSdpTest, TestDeserializeIgnoresEmptyRidLines) {
4469 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4470 sdp += "a=rid:1 send\r\n";
4471 sdp += "a=rid:2 send\r\n";
4472 sdp += "a=rid\r\n"; // Should ignore this line.
4473 sdp += "a=rid:\r\n"; // Should ignore this line.
4474 sdp += "a=simulcast:send 1;2\r\n";
4475 JsepSessionDescription output(kDummyType);
4476 SdpParseError error;
4477 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4478 const cricket::ContentInfos& contents = output.description()->contents();
4479 const cricket::MediaContentDescription* media =
4480 contents.back().media_description();
4481 EXPECT_TRUE(media->HasSimulcast());
4482 const SimulcastDescription& simulcast = media->simulcast_description();
4483 EXPECT_TRUE(simulcast.receive_layers().empty());
4484 EXPECT_EQ(2ul, simulcast.send_layers().size());
4485 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4486
4487 EXPECT_FALSE(media->streams().empty());
4488 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4489 CompareRidDescriptionIds(rids, {"1", "2"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004490}
4491
4492// Ignores malformed rid lines.
4493TEST_F(WebRtcSdpTest, TestDeserializeIgnoresMalformedRidLines) {
4494 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4495 sdp += "a=rid:1 send pt=\r\n"; // Should ignore this line.
4496 sdp += "a=rid:2 receive\r\n"; // Should ignore this line.
4497 sdp += "a=rid:3 max-width=720;pt=120\r\n"; // Should ignore this line.
4498 sdp += "a=rid:4\r\n"; // Should ignore this line.
4499 sdp += "a=rid:5 send\r\n";
4500 sdp += "a=simulcast:send 1,2,3;4,5\r\n";
4501 JsepSessionDescription output(kDummyType);
4502 SdpParseError error;
4503 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4504 const cricket::ContentInfos& contents = output.description()->contents();
4505 const cricket::MediaContentDescription* media =
4506 contents.back().media_description();
4507 EXPECT_TRUE(media->HasSimulcast());
4508 const SimulcastDescription& simulcast = media->simulcast_description();
4509 EXPECT_TRUE(simulcast.receive_layers().empty());
4510 EXPECT_EQ(1ul, simulcast.send_layers().size());
4511 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4512
4513 EXPECT_FALSE(media->streams().empty());
4514 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4515 CompareRidDescriptionIds(rids, {"5"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004516}
4517
4518// Removes RIDs that specify a different format than the m= section.
4519TEST_F(WebRtcSdpTest, TestDeserializeRemovesRidsWithInvalidCodec) {
4520 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4521 sdp += "a=rid:1 send pt=121,120\r\n"; // Should remove 121 and keep RID.
4522 sdp += "a=rid:2 send pt=121\r\n"; // Should remove RID altogether.
4523 sdp += "a=simulcast:send 1;2\r\n";
4524 JsepSessionDescription output(kDummyType);
4525 SdpParseError error;
4526 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4527 const cricket::ContentInfos& contents = output.description()->contents();
4528 const cricket::MediaContentDescription* media =
4529 contents.back().media_description();
4530 EXPECT_TRUE(media->HasSimulcast());
4531 const SimulcastDescription& simulcast = media->simulcast_description();
4532 EXPECT_TRUE(simulcast.receive_layers().empty());
4533 EXPECT_EQ(1ul, simulcast.send_layers().size());
4534 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4535 EXPECT_EQ("1", simulcast.send_layers()[0][0].rid);
4536 EXPECT_EQ(1ul, media->streams().size());
4537 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4538 EXPECT_EQ(1ul, rids.size());
4539 EXPECT_EQ("1", rids[0].rid);
4540 EXPECT_EQ(1ul, rids[0].payload_types.size());
4541 EXPECT_EQ(120, rids[0].payload_types[0]);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004542}
4543
4544// Ignores duplicate rid lines
4545TEST_F(WebRtcSdpTest, TestDeserializeIgnoresDuplicateRidLines) {
4546 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4547 sdp += "a=rid:1 send\r\n";
4548 sdp += "a=rid:2 send\r\n";
4549 sdp += "a=rid:2 send\r\n";
4550 sdp += "a=rid:3 send\r\n";
4551 sdp += "a=rid:4 recv\r\n";
4552 sdp += "a=simulcast:send 1,2;3 recv 4\r\n";
4553 JsepSessionDescription output(kDummyType);
4554 SdpParseError error;
4555 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4556 const cricket::ContentInfos& contents = output.description()->contents();
4557 const cricket::MediaContentDescription* media =
4558 contents.back().media_description();
4559 EXPECT_TRUE(media->HasSimulcast());
4560 const SimulcastDescription& simulcast = media->simulcast_description();
4561 EXPECT_EQ(2ul, simulcast.send_layers().size());
4562 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4563 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4564 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4565
4566 EXPECT_FALSE(media->streams().empty());
4567 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4568 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbucha2012042018-12-03 11:35:05 -08004569}
4570
Florent Castellic4421972019-07-02 20:27:42 +02004571TEST_F(WebRtcSdpTest, TestDeserializeRidSendDirection) {
4572 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4573 sdp += "a=rid:1 recv\r\n";
4574 sdp += "a=rid:2 recv\r\n";
4575 sdp += "a=simulcast:send 1;2\r\n";
4576 JsepSessionDescription output(kDummyType);
4577 SdpParseError error;
4578 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4579 const cricket::ContentInfos& contents = output.description()->contents();
4580 const cricket::MediaContentDescription* media =
4581 contents.back().media_description();
4582 EXPECT_FALSE(media->HasSimulcast());
4583}
4584
4585TEST_F(WebRtcSdpTest, TestDeserializeRidRecvDirection) {
4586 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4587 sdp += "a=rid:1 send\r\n";
4588 sdp += "a=rid:2 send\r\n";
4589 sdp += "a=simulcast:recv 1;2\r\n";
4590 JsepSessionDescription output(kDummyType);
4591 SdpParseError error;
4592 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4593 const cricket::ContentInfos& contents = output.description()->contents();
4594 const cricket::MediaContentDescription* media =
4595 contents.back().media_description();
4596 EXPECT_FALSE(media->HasSimulcast());
4597}
4598
4599TEST_F(WebRtcSdpTest, TestDeserializeIgnoresWrongRidDirectionLines) {
4600 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4601 sdp += "a=rid:1 send\r\n";
4602 sdp += "a=rid:2 send\r\n";
4603 sdp += "a=rid:3 send\r\n";
4604 sdp += "a=rid:4 recv\r\n";
4605 sdp += "a=rid:5 recv\r\n";
4606 sdp += "a=rid:6 recv\r\n";
4607 sdp += "a=simulcast:send 1;5;3 recv 4;2;6\r\n";
4608 JsepSessionDescription output(kDummyType);
4609 SdpParseError error;
4610 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4611 const cricket::ContentInfos& contents = output.description()->contents();
4612 const cricket::MediaContentDescription* media =
4613 contents.back().media_description();
4614 EXPECT_TRUE(media->HasSimulcast());
4615 const SimulcastDescription& simulcast = media->simulcast_description();
4616 EXPECT_EQ(2ul, simulcast.send_layers().size());
4617 EXPECT_EQ(2ul, simulcast.receive_layers().size());
4618 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4619 EXPECT_EQ(2ul, simulcast.receive_layers().GetAllLayers().size());
4620
4621 EXPECT_FALSE(media->streams().empty());
4622 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4623 CompareRidDescriptionIds(rids, {"1", "3"});
4624}
4625
Amit Hilbucha2012042018-12-03 11:35:05 -08004626// Simulcast serialization integration test.
4627// This test will serialize and deserialize the description and compare.
4628// More detailed tests for parsing simulcast can be found in
4629// unit tests for SdpSerializer.
4630TEST_F(WebRtcSdpTest, SerializeSimulcast_ComplexSerialization) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004631 MakeUnifiedPlanDescription(/* use_ssrcs = */ false);
Amit Hilbucha2012042018-12-03 11:35:05 -08004632 auto description = jdesc_.description();
4633 auto media = description->GetContentDescriptionByName(kVideoContentName3);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004634 ASSERT_EQ(media->streams().size(), 1ul);
4635 StreamParams& send_stream = media->mutable_streams()[0];
4636 std::vector<RidDescription> send_rids;
4637 send_rids.push_back(RidDescription("1", RidDirection::kSend));
4638 send_rids.push_back(RidDescription("2", RidDirection::kSend));
4639 send_rids.push_back(RidDescription("3", RidDirection::kSend));
4640 send_rids.push_back(RidDescription("4", RidDirection::kSend));
4641 send_stream.set_rids(send_rids);
Florent Castellib60141b2019-07-03 12:47:54 +02004642 std::vector<RidDescription> receive_rids;
4643 receive_rids.push_back(RidDescription("5", RidDirection::kReceive));
4644 receive_rids.push_back(RidDescription("6", RidDirection::kReceive));
4645 receive_rids.push_back(RidDescription("7", RidDirection::kReceive));
4646 media->set_receive_rids(receive_rids);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004647
Amit Hilbucha2012042018-12-03 11:35:05 -08004648 SimulcastDescription& simulcast = media->simulcast_description();
4649 simulcast.send_layers().AddLayerWithAlternatives(
4650 {SimulcastLayer("2", false), SimulcastLayer("1", true)});
4651 simulcast.send_layers().AddLayerWithAlternatives(
4652 {SimulcastLayer("4", false), SimulcastLayer("3", false)});
Florent Castellib60141b2019-07-03 12:47:54 +02004653 simulcast.receive_layers().AddLayer({SimulcastLayer("5", false)});
4654 simulcast.receive_layers().AddLayer({SimulcastLayer("6", false)});
4655 simulcast.receive_layers().AddLayer({SimulcastLayer("7", false)});
Amit Hilbucha2012042018-12-03 11:35:05 -08004656
Amit Hilbucha2012042018-12-03 11:35:05 -08004657 TestSerialize(jdesc_);
4658}
Steve Anton06817cd2018-12-18 15:55:30 -08004659
4660// Test that the content name is empty if the media section does not have an
4661// a=mid line.
4662TEST_F(WebRtcSdpTest, ParseNoMid) {
4663 std::string sdp = kSdpString;
4664 Replace("a=mid:audio_content_name\r\n", "", &sdp);
4665 Replace("a=mid:video_content_name\r\n", "", &sdp);
4666
4667 JsepSessionDescription output(kDummyType);
4668 SdpParseError error;
4669 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4670
4671 EXPECT_THAT(output.description()->contents(),
4672 ElementsAre(Field("name", &cricket::ContentInfo::name, ""),
4673 Field("name", &cricket::ContentInfo::name, "")));
4674}
Piotr (Peter) Slatala13e570f2019-02-27 11:34:26 -08004675
Guido Urdanetacecf87f2019-05-31 10:17:38 +00004676TEST_F(WebRtcSdpTest, SerializeWithDefaultSctpProtocol) {
4677 AddSctpDataChannel(false); // Don't use sctpmap
4678 JsepSessionDescription jsep_desc(kDummyType);
4679 MakeDescriptionWithoutCandidates(&jsep_desc);
4680 std::string message = webrtc::SdpSerialize(jsep_desc);
4681 EXPECT_NE(std::string::npos,
4682 message.find(cricket::kMediaProtocolUdpDtlsSctp));
4683}
4684
4685TEST_F(WebRtcSdpTest, DeserializeWithAllSctpProtocols) {
4686 AddSctpDataChannel(false);
4687 std::string protocols[] = {cricket::kMediaProtocolDtlsSctp,
4688 cricket::kMediaProtocolUdpDtlsSctp,
4689 cricket::kMediaProtocolTcpDtlsSctp};
4690 for (const auto& protocol : protocols) {
4691 sctp_desc_->set_protocol(protocol);
4692 JsepSessionDescription jsep_desc(kDummyType);
4693 MakeDescriptionWithoutCandidates(&jsep_desc);
4694 std::string message = webrtc::SdpSerialize(jsep_desc);
4695 EXPECT_NE(std::string::npos, message.find(protocol));
4696 JsepSessionDescription jsep_output(kDummyType);
4697 SdpParseError error;
4698 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jsep_output, &error));
4699 }
4700}
Taylor Brandstetter4256df02020-02-18 14:05:07 -08004701
4702// According to https://tools.ietf.org/html/rfc5576#section-6.1, the CNAME
4703// attribute is mandatory, but we relax that restriction.
4704TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCname) {
4705 std::string sdp_without_cname = kSdpFullString;
4706 Replace("a=ssrc:1 cname:stream_1_cname\r\n", "", &sdp_without_cname);
4707 JsepSessionDescription new_jdesc(kDummyType);
4708 EXPECT_TRUE(SdpDeserialize(sdp_without_cname, &new_jdesc));
4709
4710 audio_desc_->mutable_streams()[0].cname = "";
4711 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
4712 jdesc_.session_version()));
4713 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
4714}
Philipp Hanckeefc55b02020-06-26 10:17:05 +02004715
4716TEST_F(WebRtcSdpTest, DeserializeSdpWithUnsupportedMediaType) {
Philipp Hanckeefc55b02020-06-26 10:17:05 +02004717 std::string sdp = kSdpSessionString;
4718 sdp +=
4719 "m=bogus 9 RTP/SAVPF 0 8\r\n"
Philipp Hancke4e8c1152020-10-13 12:43:15 +02004720 "c=IN IP4 0.0.0.0\r\n"
4721 "a=mid:bogusmid\r\n";
Philipp Hanckeefc55b02020-06-26 10:17:05 +02004722 sdp +=
4723 "m=audio/something 9 RTP/SAVPF 0 8\r\n"
Philipp Hancke4e8c1152020-10-13 12:43:15 +02004724 "c=IN IP4 0.0.0.0\r\n"
4725 "a=mid:somethingmid\r\n";
Philipp Hanckeefc55b02020-06-26 10:17:05 +02004726
4727 JsepSessionDescription jdesc_output(kDummyType);
4728 EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output));
4729
Philipp Hancke4e8c1152020-10-13 12:43:15 +02004730 ASSERT_EQ(2u, jdesc_output.description()->contents().size());
4731 ASSERT_NE(nullptr, jdesc_output.description()
4732 ->contents()[0]
4733 .media_description()
4734 ->as_unsupported());
4735 ASSERT_NE(nullptr, jdesc_output.description()
4736 ->contents()[1]
4737 .media_description()
4738 ->as_unsupported());
4739
4740 EXPECT_TRUE(jdesc_output.description()->contents()[0].rejected);
4741 EXPECT_TRUE(jdesc_output.description()->contents()[1].rejected);
4742
4743 EXPECT_EQ(jdesc_output.description()->contents()[0].name, "bogusmid");
4744 EXPECT_EQ(jdesc_output.description()->contents()[1].name, "somethingmid");
Philipp Hanckeefc55b02020-06-26 10:17:05 +02004745}
Philipp Hanckeb70c9532021-01-13 10:40:06 +01004746
4747TEST_F(WebRtcSdpTest, MediaTypeProtocolMismatch) {
4748 std::string sdp =
4749 "v=0\r\n"
4750 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4751 "s=-\r\n"
4752 "t=0 0\r\n";
4753
4754 ExpectParseFailure(std::string(sdp + "m=audio 9 UDP/DTLS/SCTP 120\r\n"),
4755 "m=audio");
4756 ExpectParseFailure(std::string(sdp + "m=video 9 UDP/DTLS/SCTP 120\r\n"),
4757 "m=video");
4758 ExpectParseFailure(std::string(sdp + "m=video 9 SOMETHING 120\r\n"),
4759 "m=video");
4760 ExpectParseFailure(std::string(sdp + "m=application 9 SOMETHING 120\r\n"),
4761 "m=application");
4762}