blob: a081d74aa4f889cfa35f570ecf29e7ed79158a06 [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
Yves Gerey3e707812018-11-28 16:47:49 +010014#include <cstdint>
15#include <map>
kwibergd1fe2812016-04-27 06:47:29 -070016#include <memory>
Harald Alvestrandc24a2182022-02-23 13:44:59 +000017#include <sstream>
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"
Harald Alvestrandc24a2182022-02-23 13:44:59 +000025#include "absl/strings/string_view.h"
26#include "absl/types/optional.h"
Yves Gerey3e707812018-11-28 16:47:49 +010027#include "api/array_view.h"
Harald Alvestrand0d018412021-11-04 13:52:31 +000028#include "api/crypto_params.h"
Steve Anton10542f22019-01-11 09:11:00 -080029#include "api/jsep_session_description.h"
30#include "api/media_types.h"
31#include "api/rtp_parameters.h"
Harald Alvestrandc24a2182022-02-23 13:44:59 +000032#include "api/rtp_transceiver_direction.h"
Yves Gerey3e707812018-11-28 16:47:49 +010033#include "media/base/codec.h"
Steve Anton10542f22019-01-11 09:11:00 -080034#include "media/base/media_constants.h"
Harald Alvestrandc24a2182022-02-23 13:44:59 +000035#include "media/base/rid_description.h"
Steve Anton10542f22019-01-11 09:11:00 -080036#include "media/base/stream_params.h"
37#include "p2p/base/p2p_constants.h"
Yves Gerey665174f2018-06-19 15:03:05 +020038#include "p2p/base/port.h"
Steve Anton10542f22019-01-11 09:11:00 -080039#include "p2p/base/transport_description.h"
40#include "p2p/base/transport_info.h"
Harald Alvestrandc24a2182022-02-23 13:44:59 +000041#include "pc/media_protocol_names.h"
Steve Anton10542f22019-01-11 09:11:00 -080042#include "pc/media_session.h"
43#include "pc/session_description.h"
Harald Alvestrandc24a2182022-02-23 13:44:59 +000044#include "pc/simulcast_description.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020045#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 09:11:00 -080046#include "rtc_base/message_digest.h"
47#include "rtc_base/socket_address.h"
48#include "rtc_base/ssl_fingerprint.h"
49#include "rtc_base/string_encode.h"
Steve Anton06817cd2018-12-18 15:55:30 -080050#include "test/gmock.h"
Yves Gerey3e707812018-11-28 16:47:49 +010051#include "test/gtest.h"
Patrik Höglund563934e2017-09-15 09:04:28 +020052
ossu7bb87ee2017-01-23 04:56:25 -080053#ifdef WEBRTC_ANDROID
Steve Anton10542f22019-01-11 09:11:00 -080054#include "pc/test/android_test_initializer.h"
ossu7bb87ee2017-01-23 04:56:25 -080055#endif
Steve Anton10542f22019-01-11 09:11:00 -080056#include "pc/webrtc_sdp.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057
58using cricket::AudioCodec;
59using cricket::AudioContentDescription;
60using cricket::Candidate;
Steve Anton06817cd2018-12-18 15:55:30 -080061using cricket::ContentGroup;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062using cricket::ContentInfo;
Harald Alvestrand0d018412021-11-04 13:52:31 +000063using cricket::CryptoParams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
65using cricket::ICE_CANDIDATE_COMPONENT_RTP;
66using cricket::kFecSsrcGroupSemantics;
67using cricket::LOCAL_PORT_TYPE;
Steve Anton5adfafd2017-12-20 16:34:00 -080068using cricket::MediaProtocolType;
Steve Anton06817cd2018-12-18 15:55:30 -080069using cricket::RELAY_PORT_TYPE;
Amit Hilbuchc57d5732018-12-11 15:30:11 -080070using cricket::RidDescription;
71using cricket::RidDirection;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020072using cricket::SctpDataContentDescription;
Steve Anton06817cd2018-12-18 15:55:30 -080073using cricket::SessionDescription;
Amit Hilbucha2012042018-12-03 11:35:05 -080074using cricket::SimulcastDescription;
75using cricket::SimulcastLayer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076using cricket::StreamParams;
77using cricket::STUN_PORT_TYPE;
78using cricket::TransportDescription;
79using cricket::TransportInfo;
80using cricket::VideoCodec;
81using cricket::VideoContentDescription;
Steve Anton06817cd2018-12-18 15:55:30 -080082using ::testing::ElementsAre;
83using ::testing::Field;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084using webrtc::IceCandidateCollection;
85using webrtc::IceCandidateInterface;
86using webrtc::JsepIceCandidate;
87using webrtc::JsepSessionDescription;
isheriff6f8d6862016-05-26 11:24:55 -070088using webrtc::RtpExtension;
Steve Anton4e70a722017-11-28 14:57:10 -080089using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090using webrtc::SdpParseError;
Steve Antona3a92c22017-12-07 10:27:41 -080091using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092using webrtc::SessionDescriptionInterface;
93
94typedef std::vector<AudioCodec> AudioCodecs;
95typedef std::vector<Candidate> Candidates;
96
Peter Boström0c4e06b2015-10-07 12:23:21 +020097static const uint32_t kDefaultSctpPort = 5000;
zstein4b2e0822017-02-17 19:48:38 -080098static const uint16_t kUnusualSctpPort = 9556;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200100static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 15:17:14 -0800101static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 15:17:14 -0800103static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000104static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200105static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000106static const char kCandidateFoundation1[] = "a0+B/1";
107static const char kCandidateFoundation2[] = "a0+B/2";
108static const char kCandidateFoundation3[] = "a0+B/3";
109static const char kCandidateFoundation4[] = "a0+B/4";
110static const char kAttributeCryptoVoice[] =
111 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
112 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
113 "dummy_session_params\r\n";
114static const char kAttributeCryptoVideo[] =
115 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
116 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
Yves Gerey665174f2018-06-19 15:03:05 +0200117static const char kFingerprint[] =
118 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000119 "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 +0200120static const char kExtmapAllowMixed[] = "a=extmap-allow-mixed\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121static const int kExtmapId = 1;
122static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
123static const char kExtmap[] =
124 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
125static const char kExtmapWithDirectionAndAttribute[] =
126 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
jbauch5869f502017-06-29 12:31:36 -0700127static const char kExtmapWithDirectionAndAttributeEncrypted[] =
128 "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt "
129 "http://example.com/082005/ext.htm#ttime a1 a2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000130
Peter Boström0c4e06b2015-10-07 12:23:21 +0200131static const uint8_t kIdentityDigest[] = {
132 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
133 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000134
lally@webrtc.org34807282015-02-24 20:19:39 +0000135static const char kDtlsSctp[] = "DTLS/SCTP";
136static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
137static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +0000138
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000139struct CodecParams {
140 int max_ptime;
141 int ptime;
142 int min_ptime;
143 int sprop_stereo;
144 int stereo;
145 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000146 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000147};
148
Harald Alvestrand0d018412021-11-04 13:52:31 +0000149// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
150// instead of "a=crypto", and have an explicit test for adding "a=crypto".
151// Currently it's the other way around.
deadbeef9d3584c2016-02-16 17:54:10 -0800152
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000153// Reference sdp string
154static const char kSdpFullString[] =
155 "v=0\r\n"
156 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
157 "s=-\r\n"
158 "t=0 0\r\n"
Emil Lundmark801c9992021-01-19 13:06:32 +0100159 "a=extmap-allow-mixed\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800160 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000161 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
162 "c=IN IP4 74.125.127.126\r\n"
163 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
164 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
165 "generation 2\r\n"
166 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
167 "generation 2\r\n"
168 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
169 "generation 2\r\n"
170 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
171 "generation 2\r\n"
172 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
173 "raddr 192.168.1.5 rport 2346 "
174 "generation 2\r\n"
175 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
176 "raddr 192.168.1.5 rport 2348 "
177 "generation 2\r\n"
178 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
179 "a=mid:audio_content_name\r\n"
180 "a=sendrecv\r\n"
181 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800182 "a=rtcp-rsize\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000183 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
184 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
185 "dummy_session_params\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000186 "a=rtpmap:111 opus/48000/2\r\n"
187 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000188 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000189 "a=ssrc:1 cname:stream_1_cname\r\n"
190 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000191 "a=ssrc:1 mslabel:local_stream_1\r\n"
192 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000193 "m=video 3457 RTP/SAVPF 120\r\n"
194 "c=IN IP4 74.125.224.39\r\n"
195 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
196 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
197 "generation 2\r\n"
198 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
199 "generation 2\r\n"
200 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
201 "generation 2\r\n"
202 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
203 "generation 2\r\n"
204 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
205 "generation 2\r\n"
206 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
207 "generation 2\r\n"
208 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
209 "a=mid:video_content_name\r\n"
210 "a=sendrecv\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000211 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
212 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800214 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000215 "a=ssrc:2 cname:stream_1_cname\r\n"
216 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000217 "a=ssrc:2 mslabel:local_stream_1\r\n"
218 "a=ssrc:2 label:video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000219 "a=ssrc:3 cname:stream_1_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000220 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
221 "a=ssrc:3 mslabel:local_stream_1\r\n"
222 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000223
224// SDP reference string without the candidates.
225static const char kSdpString[] =
226 "v=0\r\n"
227 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
228 "s=-\r\n"
229 "t=0 0\r\n"
Emil Lundmark801c9992021-01-19 13:06:32 +0100230 "a=extmap-allow-mixed\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800231 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000232 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000233 "c=IN IP4 0.0.0.0\r\n"
234 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000235 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
236 "a=mid:audio_content_name\r\n"
237 "a=sendrecv\r\n"
238 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800239 "a=rtcp-rsize\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000240 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
241 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
242 "dummy_session_params\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000243 "a=rtpmap:111 opus/48000/2\r\n"
244 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000245 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000246 "a=ssrc:1 cname:stream_1_cname\r\n"
247 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000248 "a=ssrc:1 mslabel:local_stream_1\r\n"
249 "a=ssrc:1 label:audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000250 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000251 "c=IN IP4 0.0.0.0\r\n"
252 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000253 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
254 "a=mid:video_content_name\r\n"
255 "a=sendrecv\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000256 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
257 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000258 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800259 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000260 "a=ssrc:2 cname:stream_1_cname\r\n"
261 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000262 "a=ssrc:2 mslabel:local_stream_1\r\n"
263 "a=ssrc:2 label:video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000264 "a=ssrc:3 cname:stream_1_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000265 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
266 "a=ssrc:3 mslabel:local_stream_1\r\n"
267 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000268
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200269// draft-ietf-mmusic-sctp-sdp-03
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000270static const char kSdpSctpDataChannelString[] =
Guido Urdanetacecf87f2019-05-31 10:17:38 +0000271 "m=application 9 UDP/DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000272 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000273 "a=ice-ufrag:ufrag_data\r\n"
274 "a=ice-pwd:pwd_data\r\n"
275 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000276 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000277
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000278// draft-ietf-mmusic-sctp-sdp-12
Harald Alvestrand48cce4d2019-04-11 10:41:24 +0200279// Note - this is invalid per draft-ietf-mmusic-sctp-sdp-26,
280// since the separator after "sctp-port" needs to be a colon.
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000281static const char kSdpSctpDataChannelStringWithSctpPort[] =
Guido Urdanetacecf87f2019-05-31 10:17:38 +0000282 "m=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\n"
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000283 "a=sctp-port 5000\r\n"
284 "c=IN IP4 0.0.0.0\r\n"
285 "a=ice-ufrag:ufrag_data\r\n"
286 "a=ice-pwd:pwd_data\r\n"
287 "a=mid:data_content_name\r\n";
288
Harald Alvestrand48cce4d2019-04-11 10:41:24 +0200289// draft-ietf-mmusic-sctp-sdp-26
lally69f57602015-10-08 10:15:04 -0700290static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
Guido Urdanetacecf87f2019-05-31 10:17:38 +0000291 "m=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\n"
lally69f57602015-10-08 10:15:04 -0700292 "a=sctp-port:5000\r\n"
293 "c=IN IP4 0.0.0.0\r\n"
294 "a=ice-ufrag:ufrag_data\r\n"
295 "a=ice-pwd:pwd_data\r\n"
296 "a=mid:data_content_name\r\n";
297
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000298static const char kSdpSctpDataChannelWithCandidatesString[] =
Guido Urdanetacecf87f2019-05-31 10:17:38 +0000299 "m=application 2345 UDP/DTLS/SCTP 5000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000300 "c=IN IP4 74.125.127.126\r\n"
301 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
302 "generation 2\r\n"
303 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
304 "generation 2\r\n"
305 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
306 "raddr 192.168.1.5 rport 2346 "
307 "generation 2\r\n"
308 "a=ice-ufrag:ufrag_data\r\n"
309 "a=ice-pwd:pwd_data\r\n"
310 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000311 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000312
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000313static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000314 "v=0\r\n"
315 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
316 "s=-\r\n"
317 "t=0 0\r\n"
318 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000319 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000320 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000321 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000322 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000323 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000324 "a=x-google-flag:conference\r\n";
325
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000326static const char kSdpSessionString[] =
327 "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 local_stream\r\n";
332
333static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000334 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000335 "c=IN IP4 0.0.0.0\r\n"
336 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000337 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
338 "a=mid:audio_content_name\r\n"
339 "a=sendrecv\r\n"
340 "a=rtpmap:111 opus/48000/2\r\n"
341 "a=ssrc:1 cname:stream_1_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000342 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
343 "a=ssrc:1 mslabel:local_stream\r\n"
344 "a=ssrc:1 label:audio_track_id_1\r\n";
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000345
346static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000347 "m=video 9 RTP/SAVPF 120\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_video\r\na=ice-pwd:pwd_video\r\n"
351 "a=mid:video_content_name\r\n"
352 "a=sendrecv\r\n"
353 "a=rtpmap:120 VP8/90000\r\n"
354 "a=ssrc:2 cname:stream_1_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000355 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
356 "a=ssrc:2 mslabel:local_stream\r\n"
357 "a=ssrc:2 label:video_track_id_1\r\n";
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000358
deadbeef25ed4352016-12-12 18:37:36 -0800359// Reference sdp string using bundle-only.
360static const char kBundleOnlySdpFullString[] =
361 "v=0\r\n"
362 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
363 "s=-\r\n"
364 "t=0 0\r\n"
Emil Lundmark801c9992021-01-19 13:06:32 +0100365 "a=extmap-allow-mixed\r\n"
deadbeef25ed4352016-12-12 18:37:36 -0800366 "a=group:BUNDLE audio_content_name video_content_name\r\n"
367 "a=msid-semantic: WMS local_stream_1\r\n"
368 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
369 "c=IN IP4 74.125.127.126\r\n"
370 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
371 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
372 "generation 2\r\n"
373 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
374 "generation 2\r\n"
375 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
376 "generation 2\r\n"
377 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
378 "generation 2\r\n"
379 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
380 "raddr 192.168.1.5 rport 2346 "
381 "generation 2\r\n"
382 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
383 "raddr 192.168.1.5 rport 2348 "
384 "generation 2\r\n"
385 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
386 "a=mid:audio_content_name\r\n"
387 "a=sendrecv\r\n"
388 "a=rtcp-mux\r\n"
389 "a=rtcp-rsize\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000390 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
391 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
392 "dummy_session_params\r\n"
deadbeef25ed4352016-12-12 18:37:36 -0800393 "a=rtpmap:111 opus/48000/2\r\n"
394 "a=rtpmap:103 ISAC/16000\r\n"
395 "a=rtpmap:104 ISAC/32000\r\n"
396 "a=ssrc:1 cname:stream_1_cname\r\n"
397 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000398 "a=ssrc:1 mslabel:local_stream_1\r\n"
399 "a=ssrc:1 label:audio_track_id_1\r\n"
deadbeef25ed4352016-12-12 18:37:36 -0800400 "m=video 0 RTP/SAVPF 120\r\n"
401 "c=IN IP4 0.0.0.0\r\n"
402 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
403 "a=bundle-only\r\n"
404 "a=mid:video_content_name\r\n"
405 "a=sendrecv\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000406 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
407 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
deadbeef25ed4352016-12-12 18:37:36 -0800408 "a=rtpmap:120 VP8/90000\r\n"
409 "a=ssrc-group:FEC 2 3\r\n"
410 "a=ssrc:2 cname:stream_1_cname\r\n"
411 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000412 "a=ssrc:2 mslabel:local_stream_1\r\n"
413 "a=ssrc:2 label:video_track_id_1\r\n"
deadbeef25ed4352016-12-12 18:37:36 -0800414 "a=ssrc:3 cname:stream_1_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000415 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
416 "a=ssrc:3 mslabel:local_stream_1\r\n"
417 "a=ssrc:3 label:video_track_id_1\r\n";
deadbeef25ed4352016-12-12 18:37:36 -0800418
deadbeef9d3584c2016-02-16 17:54:10 -0800419// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
420// tracks.
421static const char kPlanBSdpFullString[] =
422 "v=0\r\n"
423 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
424 "s=-\r\n"
425 "t=0 0\r\n"
Emil Lundmark801c9992021-01-19 13:06:32 +0100426 "a=extmap-allow-mixed\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800427 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
428 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
429 "c=IN IP4 74.125.127.126\r\n"
430 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
431 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
432 "generation 2\r\n"
433 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
434 "generation 2\r\n"
435 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
436 "generation 2\r\n"
437 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
438 "generation 2\r\n"
439 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
440 "raddr 192.168.1.5 rport 2346 "
441 "generation 2\r\n"
442 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
443 "raddr 192.168.1.5 rport 2348 "
444 "generation 2\r\n"
445 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
446 "a=mid:audio_content_name\r\n"
447 "a=sendrecv\r\n"
448 "a=rtcp-mux\r\n"
449 "a=rtcp-rsize\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000450 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
451 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
452 "dummy_session_params\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800453 "a=rtpmap:111 opus/48000/2\r\n"
454 "a=rtpmap:103 ISAC/16000\r\n"
455 "a=rtpmap:104 ISAC/32000\r\n"
456 "a=ssrc:1 cname:stream_1_cname\r\n"
457 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000458 "a=ssrc:1 mslabel:local_stream_1\r\n"
459 "a=ssrc:1 label:audio_track_id_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800460 "a=ssrc:4 cname:stream_2_cname\r\n"
461 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000462 "a=ssrc:4 mslabel:local_stream_2\r\n"
463 "a=ssrc:4 label:audio_track_id_2\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800464 "m=video 3457 RTP/SAVPF 120\r\n"
465 "c=IN IP4 74.125.224.39\r\n"
466 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
467 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
468 "generation 2\r\n"
469 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
470 "generation 2\r\n"
471 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
472 "generation 2\r\n"
473 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
474 "generation 2\r\n"
475 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
476 "generation 2\r\n"
477 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
478 "generation 2\r\n"
479 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
480 "a=mid:video_content_name\r\n"
481 "a=sendrecv\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000482 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
483 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800484 "a=rtpmap:120 VP8/90000\r\n"
485 "a=ssrc-group:FEC 2 3\r\n"
486 "a=ssrc:2 cname:stream_1_cname\r\n"
487 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000488 "a=ssrc:2 mslabel:local_stream_1\r\n"
489 "a=ssrc:2 label:video_track_id_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800490 "a=ssrc:3 cname:stream_1_cname\r\n"
491 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000492 "a=ssrc:3 mslabel:local_stream_1\r\n"
493 "a=ssrc:3 label:video_track_id_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800494 "a=ssrc:5 cname:stream_2_cname\r\n"
495 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000496 "a=ssrc:5 mslabel:local_stream_2\r\n"
497 "a=ssrc:5 label:video_track_id_2\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800498 "a=ssrc:6 cname:stream_2_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000499 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
500 "a=ssrc:6 mslabel:local_stream_2\r\n"
501 "a=ssrc:6 label:video_track_id_3\r\n";
deadbeef9d3584c2016-02-16 17:54:10 -0800502
503// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
504// tracks.
505static const char kUnifiedPlanSdpFullString[] =
506 "v=0\r\n"
507 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
508 "s=-\r\n"
509 "t=0 0\r\n"
Emil Lundmark801c9992021-01-19 13:06:32 +0100510 "a=extmap-allow-mixed\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800511 "a=msid-semantic: WMS local_stream_1\r\n"
512 // Audio track 1, stream 1 (with candidates).
513 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
514 "c=IN IP4 74.125.127.126\r\n"
515 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
516 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
517 "generation 2\r\n"
518 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
519 "generation 2\r\n"
520 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
521 "generation 2\r\n"
522 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
523 "generation 2\r\n"
524 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
525 "raddr 192.168.1.5 rport 2346 "
526 "generation 2\r\n"
527 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
528 "raddr 192.168.1.5 rport 2348 "
529 "generation 2\r\n"
530 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
531 "a=mid:audio_content_name\r\n"
532 "a=msid:local_stream_1 audio_track_id_1\r\n"
533 "a=sendrecv\r\n"
534 "a=rtcp-mux\r\n"
535 "a=rtcp-rsize\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000536 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
537 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
538 "dummy_session_params\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800539 "a=rtpmap:111 opus/48000/2\r\n"
540 "a=rtpmap:103 ISAC/16000\r\n"
541 "a=rtpmap:104 ISAC/32000\r\n"
542 "a=ssrc:1 cname:stream_1_cname\r\n"
543 // Video track 1, stream 1 (with candidates).
544 "m=video 3457 RTP/SAVPF 120\r\n"
545 "c=IN IP4 74.125.224.39\r\n"
546 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
547 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
548 "generation 2\r\n"
549 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
550 "generation 2\r\n"
551 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
552 "generation 2\r\n"
553 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
554 "generation 2\r\n"
555 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
556 "generation 2\r\n"
557 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
558 "generation 2\r\n"
559 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
560 "a=mid:video_content_name\r\n"
561 "a=msid:local_stream_1 video_track_id_1\r\n"
562 "a=sendrecv\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000563 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
564 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800565 "a=rtpmap:120 VP8/90000\r\n"
566 "a=ssrc-group:FEC 2 3\r\n"
567 "a=ssrc:2 cname:stream_1_cname\r\n"
568 "a=ssrc:3 cname:stream_1_cname\r\n"
569 // Audio track 2, stream 2.
570 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
571 "c=IN IP4 0.0.0.0\r\n"
572 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
573 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
574 "a=mid:audio_content_name_2\r\n"
575 "a=msid:local_stream_2 audio_track_id_2\r\n"
576 "a=sendrecv\r\n"
577 "a=rtcp-mux\r\n"
578 "a=rtcp-rsize\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000579 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
580 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
581 "dummy_session_params\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800582 "a=rtpmap:111 opus/48000/2\r\n"
583 "a=rtpmap:103 ISAC/16000\r\n"
584 "a=rtpmap:104 ISAC/32000\r\n"
585 "a=ssrc:4 cname:stream_2_cname\r\n"
586 // Video track 2, stream 2.
587 "m=video 9 RTP/SAVPF 120\r\n"
588 "c=IN IP4 0.0.0.0\r\n"
589 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
590 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
591 "a=mid:video_content_name_2\r\n"
592 "a=msid:local_stream_2 video_track_id_2\r\n"
593 "a=sendrecv\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000594 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
595 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800596 "a=rtpmap:120 VP8/90000\r\n"
597 "a=ssrc:5 cname:stream_2_cname\r\n"
598 // Video track 3, stream 2.
599 "m=video 9 RTP/SAVPF 120\r\n"
600 "c=IN IP4 0.0.0.0\r\n"
601 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
602 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
603 "a=mid:video_content_name_3\r\n"
604 "a=msid:local_stream_2 video_track_id_3\r\n"
605 "a=sendrecv\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000606 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
607 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800608 "a=rtpmap:120 VP8/90000\r\n"
609 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000610
Seth Hampson5b4f0752018-04-02 16:31:36 -0700611// Unified Plan SDP reference string:
612// - audio track 1 has 1 a=msid lines
613// - audio track 2 has 2 a=msid lines
614// - audio track 3 has 1 a=msid line with the special "-" marker signifying that
615// there are 0 media stream ids.
616// This Unified Plan SDP represents a SDP that signals the msid using both
617// a=msid and a=ssrc msid semantics.
618static const char kUnifiedPlanSdpFullStringWithSpecialMsid[] =
619 "v=0\r\n"
620 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
621 "s=-\r\n"
622 "t=0 0\r\n"
Emil Lundmark801c9992021-01-19 13:06:32 +0100623 "a=extmap-allow-mixed\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700624 "a=msid-semantic: WMS local_stream_1\r\n"
625 // Audio track 1, with 1 stream id.
626 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
627 "c=IN IP4 74.125.127.126\r\n"
628 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
629 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
630 "generation 2\r\n"
631 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
632 "generation 2\r\n"
633 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
634 "generation 2\r\n"
635 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
636 "generation 2\r\n"
637 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
638 "raddr 192.168.1.5 rport 2346 "
639 "generation 2\r\n"
640 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
641 "raddr 192.168.1.5 rport 2348 "
642 "generation 2\r\n"
643 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
644 "a=mid:audio_content_name\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700645 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700646 "a=msid:local_stream_1 audio_track_id_1\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700647 "a=rtcp-mux\r\n"
648 "a=rtcp-rsize\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000649 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
650 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
651 "dummy_session_params\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700652 "a=rtpmap:111 opus/48000/2\r\n"
653 "a=rtpmap:103 ISAC/16000\r\n"
654 "a=rtpmap:104 ISAC/32000\r\n"
655 "a=ssrc:1 cname:stream_1_cname\r\n"
656 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000657 "a=ssrc:1 mslabel:local_stream_1\r\n"
658 "a=ssrc:1 label:audio_track_id_1\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700659 // Audio track 2, with two stream ids.
660 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
661 "c=IN IP4 0.0.0.0\r\n"
662 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
663 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
664 "a=mid:audio_content_name_2\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700665 "a=sendrecv\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700666 "a=msid:local_stream_1 audio_track_id_2\r\n"
667 "a=msid:local_stream_2 audio_track_id_2\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700668 "a=rtcp-mux\r\n"
669 "a=rtcp-rsize\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000670 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
671 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
672 "dummy_session_params\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700673 "a=rtpmap:111 opus/48000/2\r\n"
674 "a=rtpmap:103 ISAC/16000\r\n"
675 "a=rtpmap:104 ISAC/32000\r\n"
676 "a=ssrc:4 cname:stream_1_cname\r\n"
677 // The support for Plan B msid signaling only includes the
678 // first media stream id "local_stream_1."
679 "a=ssrc:4 msid:local_stream_1 audio_track_id_2\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000680 "a=ssrc:4 mslabel:local_stream_1\r\n"
681 "a=ssrc:4 label:audio_track_id_2\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700682 // Audio track 3, with no stream ids.
683 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
684 "c=IN IP4 0.0.0.0\r\n"
685 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
686 "a=ice-ufrag:ufrag_voice_3\r\na=ice-pwd:pwd_voice_3\r\n"
687 "a=mid:audio_content_name_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700688 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700689 "a=msid:- audio_track_id_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700690 "a=rtcp-mux\r\n"
691 "a=rtcp-rsize\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000692 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
693 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
694 "dummy_session_params\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700695 "a=rtpmap:111 opus/48000/2\r\n"
696 "a=rtpmap:103 ISAC/16000\r\n"
697 "a=rtpmap:104 ISAC/32000\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700698 "a=ssrc:7 cname:stream_2_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000699 "a=ssrc:7 msid:- audio_track_id_3\r\n"
700 "a=ssrc:7 mslabel:-\r\n"
701 "a=ssrc:7 label:audio_track_id_3\r\n";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700702
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800703// SDP string for unified plan without SSRCs
704static const char kUnifiedPlanSdpFullStringNoSsrc[] =
705 "v=0\r\n"
706 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
707 "s=-\r\n"
708 "t=0 0\r\n"
709 "a=msid-semantic: WMS local_stream_1\r\n"
710 // Audio track 1, stream 1 (with candidates).
711 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
712 "c=IN IP4 74.125.127.126\r\n"
713 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
714 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
715 "generation 2\r\n"
716 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
717 "generation 2\r\n"
718 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
719 "generation 2\r\n"
720 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
721 "generation 2\r\n"
722 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
723 "raddr 192.168.1.5 rport 2346 "
724 "generation 2\r\n"
725 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
726 "raddr 192.168.1.5 rport 2348 "
727 "generation 2\r\n"
728 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
729 "a=mid:audio_content_name\r\n"
730 "a=msid:local_stream_1 audio_track_id_1\r\n"
731 "a=sendrecv\r\n"
732 "a=rtcp-mux\r\n"
733 "a=rtcp-rsize\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000734 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
735 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
736 "dummy_session_params\r\n"
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800737 "a=rtpmap:111 opus/48000/2\r\n"
738 "a=rtpmap:103 ISAC/16000\r\n"
739 "a=rtpmap:104 ISAC/32000\r\n"
740 // Video track 1, stream 1 (with candidates).
741 "m=video 3457 RTP/SAVPF 120\r\n"
742 "c=IN IP4 74.125.224.39\r\n"
743 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
744 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
745 "generation 2\r\n"
746 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
747 "generation 2\r\n"
748 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
749 "generation 2\r\n"
750 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
751 "generation 2\r\n"
752 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
753 "generation 2\r\n"
754 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
755 "generation 2\r\n"
756 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
757 "a=mid:video_content_name\r\n"
758 "a=msid:local_stream_1 video_track_id_1\r\n"
759 "a=sendrecv\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000760 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
761 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800762 "a=rtpmap:120 VP8/90000\r\n"
763 // Audio track 2, stream 2.
764 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
765 "c=IN IP4 0.0.0.0\r\n"
766 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
767 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
768 "a=mid:audio_content_name_2\r\n"
769 "a=msid:local_stream_2 audio_track_id_2\r\n"
770 "a=sendrecv\r\n"
771 "a=rtcp-mux\r\n"
772 "a=rtcp-rsize\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000773 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
774 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
775 "dummy_session_params\r\n"
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800776 "a=rtpmap:111 opus/48000/2\r\n"
777 "a=rtpmap:103 ISAC/16000\r\n"
778 "a=rtpmap:104 ISAC/32000\r\n"
779 // Video track 2, stream 2.
780 "m=video 9 RTP/SAVPF 120\r\n"
781 "c=IN IP4 0.0.0.0\r\n"
782 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
783 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
784 "a=mid:video_content_name_2\r\n"
785 "a=msid:local_stream_2 video_track_id_2\r\n"
786 "a=sendrecv\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000787 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
788 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800789 "a=rtpmap:120 VP8/90000\r\n"
790 // Video track 3, stream 2.
791 "m=video 9 RTP/SAVPF 120\r\n"
792 "c=IN IP4 0.0.0.0\r\n"
793 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
794 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
795 "a=mid:video_content_name_3\r\n"
796 "a=msid:local_stream_2 video_track_id_3\r\n"
797 "a=sendrecv\r\n"
Harald Alvestrand0d018412021-11-04 13:52:31 +0000798 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
799 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800800 "a=rtpmap:120 VP8/90000\r\n";
801
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802// One candidate reference string as per W3c spec.
803// candidate:<blah> not a=candidate:<blah>CRLF
804static const char kRawCandidate[] =
805 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
806// One candidate reference string.
807static const char kSdpOneCandidate[] =
808 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
809 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000810
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000811static const char kSdpTcpActiveCandidate[] =
812 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
813 "tcptype active generation 2";
814static const char kSdpTcpPassiveCandidate[] =
815 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
816 "tcptype passive generation 2";
817static const char kSdpTcpSOCandidate[] =
818 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
819 "tcptype so generation 2";
820static const char kSdpTcpInvalidCandidate[] =
821 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
822 "tcptype invalid generation 2";
823
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000824// One candidate reference string with IPV6 address.
825static const char kRawIPV6Candidate[] =
826 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 12:04:36 -0700827 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000828
829// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800830static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000831 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800832 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000833
Zach Steinb336c272018-08-09 01:16:13 -0700834static const char kRawHostnameCandidate[] =
835 "candidate:a0+B/1 1 udp 2130706432 a.test 1234 typ host generation 2";
836
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000837// Session id and version
838static const char kSessionId[] = "18446744069414584320";
839static const char kSessionVersion[] = "18446462598732840960";
840
deadbeef9d3584c2016-02-16 17:54:10 -0800841// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842static const char kIceOption1[] = "iceoption1";
843static const char kIceOption2[] = "iceoption2";
844static const char kIceOption3[] = "iceoption3";
845
deadbeef9d3584c2016-02-16 17:54:10 -0800846// ICE ufrags/passwords.
847static const char kUfragVoice[] = "ufrag_voice";
848static const char kPwdVoice[] = "pwd_voice";
849static const char kUfragVideo[] = "ufrag_video";
850static const char kPwdVideo[] = "pwd_video";
851static const char kUfragData[] = "ufrag_data";
852static const char kPwdData[] = "pwd_data";
853
854// Extra ufrags/passwords for extra unified plan m= sections.
855static const char kUfragVoice2[] = "ufrag_voice_2";
856static const char kPwdVoice2[] = "pwd_voice_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700857static const char kUfragVoice3[] = "ufrag_voice_3";
858static const char kPwdVoice3[] = "pwd_voice_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800859static const char kUfragVideo2[] = "ufrag_video_2";
860static const char kPwdVideo2[] = "pwd_video_2";
861static const char kUfragVideo3[] = "ufrag_video_3";
862static const char kPwdVideo3[] = "pwd_video_3";
863
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000864// Content name
865static const char kAudioContentName[] = "audio_content_name";
866static const char kVideoContentName[] = "video_content_name";
867static const char kDataContentName[] = "data_content_name";
868
deadbeef9d3584c2016-02-16 17:54:10 -0800869// Extra content names for extra unified plan m= sections.
870static const char kAudioContentName2[] = "audio_content_name_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700871static const char kAudioContentName3[] = "audio_content_name_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800872static const char kVideoContentName2[] = "video_content_name_2";
873static const char kVideoContentName3[] = "video_content_name_3";
874
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000875// MediaStream 1
Seth Hampson845e8782018-03-02 11:34:10 -0800876static const char kStreamId1[] = "local_stream_1";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000877static const char kStream1Cname[] = "stream_1_cname";
878static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200879static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000880static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800881static const uint32_t kVideoTrack1Ssrc1 = 2;
882static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883
884// MediaStream 2
Seth Hampson845e8782018-03-02 11:34:10 -0800885static const char kStreamId2[] = "local_stream_2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000886static const char kStream2Cname[] = "stream_2_cname";
887static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200888static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800889static const char kVideoTrackId2[] = "video_track_id_2";
890static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000891static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800892static const uint32_t kVideoTrack3Ssrc = 6;
Seth Hampson5b4f0752018-04-02 16:31:36 -0700893static const char kAudioTrackId3[] = "audio_track_id_3";
894static const uint32_t kAudioTrack3Ssrc = 7;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000895
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000896// Candidate
897static const char kDummyMid[] = "dummy_mid";
898static const int kDummyIndex = 123;
899
900// Misc
Steve Antona3a92c22017-12-07 10:27:41 -0800901static SdpType kDummyType = SdpType::kOffer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902
903// Helper functions
904
905static bool SdpDeserialize(const std::string& message,
906 JsepSessionDescription* jdesc) {
907 return webrtc::SdpDeserialize(message, jdesc, NULL);
908}
909
910static bool SdpDeserializeCandidate(const std::string& message,
911 JsepIceCandidate* candidate) {
912 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
913}
914
Artem Titov880fa812021-07-30 22:30:23 +0200915// Add some extra `newlines` to the `message` after `line`.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000916static void InjectAfter(const std::string& line,
917 const std::string& newlines,
918 std::string* message) {
Steve Anton1c9c9fc2019-02-14 15:13:09 -0800919 absl::StrReplaceAll({{line, line + newlines}}, message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000920}
921
922static void Replace(const std::string& line,
923 const std::string& newlines,
924 std::string* message) {
Steve Anton1c9c9fc2019-02-14 15:13:09 -0800925 absl::StrReplaceAll({{line, newlines}}, message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000926}
927
Artem Titov880fa812021-07-30 22:30:23 +0200928// Expect a parse failure on the line containing `bad_part` when attempting to
929// parse `bad_sdp`.
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000930static void ExpectParseFailure(const std::string& bad_sdp,
931 const std::string& bad_part) {
Steve Antona3a92c22017-12-07 10:27:41 -0800932 JsepSessionDescription desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000934 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
Harald Alvestrand99bcf602021-03-03 07:44:39 +0000935 ASSERT_FALSE(ret);
936 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()))
937 << "Did not find " << bad_part << " in " << error.line;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000938}
939
Artem Titov880fa812021-07-30 22:30:23 +0200940// Expect fail to parse kSdpFullString if replace `good_part` with `bad_part`.
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000941static void ExpectParseFailure(const char* good_part, const char* bad_part) {
942 std::string bad_sdp = kSdpFullString;
943 Replace(good_part, bad_part, &bad_sdp);
944 ExpectParseFailure(bad_sdp, bad_part);
945}
946
Artem Titov880fa812021-07-30 22:30:23 +0200947// Expect fail to parse kSdpFullString if add `newlines` after `injectpoint`.
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000948static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
949 const std::string& newlines,
950 const std::string& bad_part) {
951 std::string bad_sdp = kSdpFullString;
952 InjectAfter(injectpoint, newlines, &bad_sdp);
953 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000954}
955
Steve Anton4e70a722017-11-28 14:57:10 -0800956static void ReplaceDirection(RtpTransceiverDirection direction,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000957 std::string* message) {
958 std::string new_direction;
959 switch (direction) {
Steve Anton4e70a722017-11-28 14:57:10 -0800960 case RtpTransceiverDirection::kInactive:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000961 new_direction = "a=inactive";
962 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800963 case RtpTransceiverDirection::kSendOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000964 new_direction = "a=sendonly";
965 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800966 case RtpTransceiverDirection::kRecvOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000967 new_direction = "a=recvonly";
968 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800969 case RtpTransceiverDirection::kSendRecv:
Markus Handell45c104b2020-03-11 10:51:13 +0100970 new_direction = "a=sendrecv";
971 break;
972 case RtpTransceiverDirection::kStopped:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000973 default:
Artem Titovd3251962021-11-15 16:57:07 +0100974 RTC_DCHECK_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000975 new_direction = "a=sendrecv";
976 break;
977 }
978 Replace("a=sendrecv", new_direction, message);
979}
980
Yves Gerey665174f2018-06-19 15:03:05 +0200981static void ReplaceRejected(bool audio_rejected,
982 bool video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000983 std::string* message) {
984 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800985 Replace("m=audio 9", "m=audio 0", message);
986 Replace(kAttributeIceUfragVoice, "", message);
987 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000988 }
989 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800990 Replace("m=video 9", "m=video 0", message);
991 Replace(kAttributeIceUfragVideo, "", message);
992 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000993 }
994}
995
996// WebRtcSdpTest
997
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200998class WebRtcSdpTest : public ::testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000999 public:
Steve Antona3a92c22017-12-07 10:27:41 -08001000 WebRtcSdpTest() : jdesc_(kDummyType) {
phoglund37ebcf02016-01-08 05:04:57 -08001001#ifdef WEBRTC_ANDROID
1002 webrtc::InitializeAndroidObjects();
1003#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001004 // AudioContentDescription
1005 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -08001006 StreamParams audio_stream;
1007 audio_stream.id = kAudioTrackId1;
1008 audio_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001009 audio_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -08001010 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
1011 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 11:04:53 -07001012 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
1013 audio_desc_->set_connection_address(audio_addr);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001014 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1015 absl::WrapUnique(audio_desc_));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001016
1017 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -08001018 video_desc_ = CreateVideoContentDescription();
1019 StreamParams video_stream;
1020 video_stream.id = kVideoTrackId1;
1021 video_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001022 video_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -08001023 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
1024 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
1025 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
1026 video_stream.ssrc_groups.push_back(ssrc_group);
1027 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 11:04:53 -07001028 rtc::SocketAddress video_addr("74.125.224.39", 3457);
1029 video_desc_->set_connection_address(video_addr);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001030 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp,
1031 absl::WrapUnique(video_desc_));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001032
1033 // TransportInfo
Steve Anton06817cd2018-12-18 15:55:30 -08001034 desc_.AddTransportInfo(TransportInfo(
1035 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice)));
1036 desc_.AddTransportInfo(TransportInfo(
1037 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001038
1039 // v4 host
1040 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001041 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001042 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001043 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1044 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001045 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001046 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001047 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1048 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001049 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001050 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001051 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1052 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001053 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001054 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001055 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1056 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001057
1058 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001059 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001060 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1061 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001062 cricket::LOCAL_PORT_TYPE,
1063 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001064 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001065 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1066 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001067 cricket::LOCAL_PORT_TYPE,
1068 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001069 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001070 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1071 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001072 cricket::LOCAL_PORT_TYPE,
1073 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001074 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001075 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1076 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001077 cricket::LOCAL_PORT_TYPE,
1078 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001079
1080 // stun
1081 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001082 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
1083 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001084 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1085 address_stun, kCandidatePriority, "", "",
1086 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001087 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001088 candidate9.set_related_address(rel_address_stun);
1089
1090 address_stun.SetPort(port_stun++);
1091 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001092 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1093 address_stun, kCandidatePriority, "", "",
1094 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001095 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001096 candidate10.set_related_address(rel_address_stun);
1097
1098 // relay
1099 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001100 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001101 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1102 address_relay, kCandidatePriority, "", "",
1103 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001104 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001105 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001106 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1107 address_relay, kCandidatePriority, "", "",
1108 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001109 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001110
1111 // voice
1112 candidates_.push_back(candidate1);
1113 candidates_.push_back(candidate2);
1114 candidates_.push_back(candidate5);
1115 candidates_.push_back(candidate6);
1116 candidates_.push_back(candidate9);
1117 candidates_.push_back(candidate10);
1118
1119 // video
1120 candidates_.push_back(candidate3);
1121 candidates_.push_back(candidate4);
1122 candidates_.push_back(candidate7);
1123 candidates_.push_back(candidate8);
1124 candidates_.push_back(candidate11);
1125 candidates_.push_back(candidate12);
1126
Yves Gerey665174f2018-06-19 15:03:05 +02001127 jcandidate_.reset(
1128 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001129
1130 // Set up JsepSessionDescription.
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001131 jdesc_.Initialize(desc_.Clone(), kSessionId, kSessionVersion);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001132 std::string mline_id;
1133 int mline_index = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001134 for (size_t i = 0; i < candidates_.size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001135 // In this test, the audio m line index will be 0, and the video m line
1136 // will be 1.
1137 bool is_video = (i > 5);
1138 mline_id = is_video ? "video_content_name" : "audio_content_name";
1139 mline_index = is_video ? 1 : 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001140 JsepIceCandidate jice(mline_id, mline_index, candidates_.at(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001141 jdesc_.AddCandidate(&jice);
1142 }
1143 }
1144
Seth Hampson5b4f0752018-04-02 16:31:36 -07001145 void RemoveVideoCandidates() {
deadbeef25ed4352016-12-12 18:37:36 -08001146 const IceCandidateCollection* video_candidates_collection =
1147 jdesc_.candidates(1);
1148 ASSERT_NE(nullptr, video_candidates_collection);
1149 std::vector<cricket::Candidate> video_candidates;
1150 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1151 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1152 c.set_transport_name("video_content_name");
1153 video_candidates.push_back(c);
1154 }
1155 jdesc_.RemoveCandidates(video_candidates);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001156 }
1157
1158 // Turns the existing reference description into a description using
1159 // a=bundle-only. This means no transport attributes and a 0 port value on
1160 // the m= sections not associated with the BUNDLE-tag.
1161 void MakeBundleOnlyDescription() {
1162 RemoveVideoCandidates();
deadbeef25ed4352016-12-12 18:37:36 -08001163
1164 // And the rest of the transport attributes.
1165 desc_.transport_infos()[1].description.ice_ufrag.clear();
1166 desc_.transport_infos()[1].description.ice_pwd.clear();
1167 desc_.transport_infos()[1].description.connection_role =
1168 cricket::CONNECTIONROLE_NONE;
1169
1170 // Set bundle-only flag.
1171 desc_.contents()[1].bundle_only = true;
1172
1173 // Add BUNDLE group.
1174 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1175 group.AddContentName(kAudioContentName);
1176 group.AddContentName(kVideoContentName);
1177 desc_.AddGroup(group);
1178
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001179 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef25ed4352016-12-12 18:37:36 -08001180 jdesc_.session_version()));
1181 }
1182
deadbeef9d3584c2016-02-16 17:54:10 -08001183 // Turns the existing reference description into a plan B description,
1184 // with 2 audio tracks and 3 video tracks.
1185 void MakePlanBDescription() {
Harald Alvestrandb97d2fe2020-02-28 11:54:40 +01001186 audio_desc_ = new AudioContentDescription(*audio_desc_);
1187 video_desc_ = new VideoContentDescription(*video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001188
1189 StreamParams audio_track_2;
1190 audio_track_2.id = kAudioTrackId2;
1191 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001192 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001193 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1194 audio_desc_->AddStream(audio_track_2);
1195
1196 StreamParams video_track_2;
1197 video_track_2.id = kVideoTrackId2;
1198 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001199 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001200 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1201 video_desc_->AddStream(video_track_2);
1202
1203 StreamParams video_track_3;
1204 video_track_3.id = kVideoTrackId3;
1205 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001206 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001207 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1208 video_desc_->AddStream(video_track_3);
1209
1210 desc_.RemoveContentByName(kAudioContentName);
1211 desc_.RemoveContentByName(kVideoContentName);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001212 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1213 absl::WrapUnique(audio_desc_));
1214 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp,
1215 absl::WrapUnique(video_desc_));
deadbeef9d3584c2016-02-16 17:54:10 -08001216
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001217 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef9d3584c2016-02-16 17:54:10 -08001218 jdesc_.session_version()));
1219 }
1220
1221 // Turns the existing reference description into a unified plan description,
1222 // with 2 audio tracks and 3 video tracks.
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001223 void MakeUnifiedPlanDescription(bool use_ssrcs = true) {
deadbeef9d3584c2016-02-16 17:54:10 -08001224 // Audio track 2.
1225 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1226 StreamParams audio_track_2;
1227 audio_track_2.id = kAudioTrackId2;
Seth Hampson845e8782018-03-02 11:34:10 -08001228 audio_track_2.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001229 if (use_ssrcs) {
1230 audio_track_2.cname = kStream2Cname;
1231 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1232 }
deadbeef9d3584c2016-02-16 17:54:10 -08001233 audio_desc_2->AddStream(audio_track_2);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001234 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp,
1235 absl::WrapUnique(audio_desc_2));
Steve Anton06817cd2018-12-18 15:55:30 -08001236 desc_.AddTransportInfo(TransportInfo(
1237 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2)));
deadbeef9d3584c2016-02-16 17:54:10 -08001238 // Video track 2, in stream 2.
1239 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1240 StreamParams video_track_2;
1241 video_track_2.id = kVideoTrackId2;
Seth Hampson845e8782018-03-02 11:34:10 -08001242 video_track_2.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001243 if (use_ssrcs) {
1244 video_track_2.cname = kStream2Cname;
1245 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1246 }
deadbeef9d3584c2016-02-16 17:54:10 -08001247 video_desc_2->AddStream(video_track_2);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001248 desc_.AddContent(kVideoContentName2, MediaProtocolType::kRtp,
1249 absl::WrapUnique(video_desc_2));
Steve Anton06817cd2018-12-18 15:55:30 -08001250 desc_.AddTransportInfo(TransportInfo(
1251 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2)));
deadbeef9d3584c2016-02-16 17:54:10 -08001252
1253 // Video track 3, in stream 2.
1254 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1255 StreamParams video_track_3;
1256 video_track_3.id = kVideoTrackId3;
Seth Hampson845e8782018-03-02 11:34:10 -08001257 video_track_3.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001258 if (use_ssrcs) {
1259 video_track_3.cname = kStream2Cname;
1260 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1261 }
deadbeef9d3584c2016-02-16 17:54:10 -08001262 video_desc_3->AddStream(video_track_3);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001263 desc_.AddContent(kVideoContentName3, MediaProtocolType::kRtp,
1264 absl::WrapUnique(video_desc_3));
Steve Anton06817cd2018-12-18 15:55:30 -08001265 desc_.AddTransportInfo(TransportInfo(
1266 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3)));
Steve Antone831b8c2018-02-01 12:22:16 -08001267 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
deadbeef9d3584c2016-02-16 17:54:10 -08001268
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001269 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef9d3584c2016-02-16 17:54:10 -08001270 jdesc_.session_version()));
1271 }
1272
1273 // Creates an audio content description with no streams, and some default
1274 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001275 AudioContentDescription* CreateAudioContentDescription() {
1276 AudioContentDescription* audio = new AudioContentDescription();
1277 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -08001278 audio->set_rtcp_reduced_size(true);
Harald Alvestrand0d018412021-11-04 13:52:31 +00001279 audio->AddCrypto(CryptoParams(
1280 1, "AES_CM_128_HMAC_SHA1_32",
1281 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1282 "dummy_session_params"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001283 audio->set_protocol(cricket::kMediaProtocolSavpf);
Philipp Hanckef2a4ec12020-07-01 21:07:32 +02001284 audio->AddCodec(AudioCodec(111, "opus", 48000, 0, 2));
ossue1405ad2017-01-23 08:55:48 -08001285 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1286 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001287 return audio;
1288 }
1289
Seth Hampson5b4f0752018-04-02 16:31:36 -07001290 // Turns the existing reference description into a unified plan description,
1291 // with 3 audio MediaContentDescriptions with special StreamParams that
1292 // contain 0 or multiple stream ids: - audio track 1 has 1 media stream id -
1293 // audio track 2 has 2 media stream ids - audio track 3 has 0 media stream ids
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001294 void MakeUnifiedPlanDescriptionMultipleStreamIds(const int msid_signaling) {
Seth Hampson5b4f0752018-04-02 16:31:36 -07001295 desc_.RemoveContentByName(kVideoContentName);
1296 desc_.RemoveTransportInfoByName(kVideoContentName);
1297 RemoveVideoCandidates();
1298
1299 // Audio track 2 has 2 media stream ids.
1300 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1301 StreamParams audio_track_2;
1302 audio_track_2.id = kAudioTrackId2;
1303 audio_track_2.cname = kStream1Cname;
1304 audio_track_2.set_stream_ids({kStreamId1, kStreamId2});
1305 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1306 audio_desc_2->AddStream(audio_track_2);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001307 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp,
1308 absl::WrapUnique(audio_desc_2));
Steve Anton06817cd2018-12-18 15:55:30 -08001309 desc_.AddTransportInfo(TransportInfo(
1310 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2)));
Seth Hampson5b4f0752018-04-02 16:31:36 -07001311
1312 // Audio track 3 has no stream ids.
1313 AudioContentDescription* audio_desc_3 = CreateAudioContentDescription();
1314 StreamParams audio_track_3;
1315 audio_track_3.id = kAudioTrackId3;
1316 audio_track_3.cname = kStream2Cname;
1317 audio_track_3.set_stream_ids({});
1318 audio_track_3.ssrcs.push_back(kAudioTrack3Ssrc);
1319 audio_desc_3->AddStream(audio_track_3);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001320 desc_.AddContent(kAudioContentName3, MediaProtocolType::kRtp,
1321 absl::WrapUnique(audio_desc_3));
Steve Anton06817cd2018-12-18 15:55:30 -08001322 desc_.AddTransportInfo(TransportInfo(
1323 kAudioContentName3, TransportDescription(kUfragVoice3, kPwdVoice3)));
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001324 desc_.set_msid_signaling(msid_signaling);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001325 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
Seth Hampson5b4f0752018-04-02 16:31:36 -07001326 jdesc_.session_version()));
1327 }
1328
Seth Hampson5897a6e2018-04-03 11:16:33 -07001329 // Turns the existing reference description into a unified plan description
1330 // with one audio MediaContentDescription that contains one StreamParams with
1331 // 0 ssrcs.
1332 void MakeUnifiedPlanDescriptionNoSsrcSignaling() {
1333 desc_.RemoveContentByName(kVideoContentName);
1334 desc_.RemoveContentByName(kAudioContentName);
1335 desc_.RemoveTransportInfoByName(kVideoContentName);
1336 RemoveVideoCandidates();
1337
1338 AudioContentDescription* audio_desc = CreateAudioContentDescription();
1339 StreamParams audio_track;
1340 audio_track.id = kAudioTrackId1;
1341 audio_track.set_stream_ids({kStreamId1});
1342 audio_desc->AddStream(audio_track);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001343 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1344 absl::WrapUnique(audio_desc));
Seth Hampson5897a6e2018-04-03 11:16:33 -07001345
1346 // Enable signaling a=msid lines.
1347 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001348 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
Seth Hampson5897a6e2018-04-03 11:16:33 -07001349 jdesc_.session_version()));
1350 }
1351
deadbeef9d3584c2016-02-16 17:54:10 -08001352 // Creates a video content description with no streams, and some default
1353 // configuration.
1354 VideoContentDescription* CreateVideoContentDescription() {
1355 VideoContentDescription* video = new VideoContentDescription();
Harald Alvestrand0d018412021-11-04 13:52:31 +00001356 video->AddCrypto(CryptoParams(
1357 1, "AES_CM_128_HMAC_SHA1_80",
1358 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
deadbeef9d3584c2016-02-16 17:54:10 -08001359 video->set_protocol(cricket::kMediaProtocolSavpf);
1360 video->AddCodec(
perkj26752742016-10-24 01:21:16 -07001361 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-16 17:54:10 -08001362 return video;
1363 }
1364
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001365 template <class MCD>
Yves Gerey665174f2018-06-19 15:03:05 +02001366 void CompareMediaContentDescription(const MCD* cd1, const MCD* cd2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001367 // type
Harald Alvestrand1716d392019-06-03 20:35:45 +02001368 EXPECT_EQ(cd1->type(), cd2->type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001369
1370 // content direction
1371 EXPECT_EQ(cd1->direction(), cd2->direction());
1372
1373 // rtcp_mux
1374 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1375
deadbeef13871492015-12-09 12:37:51 -08001376 // rtcp_reduced_size
1377 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1378
Harald Alvestrand0d018412021-11-04 13:52:31 +00001379 // cryptos
1380 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1381 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1382 ADD_FAILURE();
1383 return;
1384 }
1385 for (size_t i = 0; i < cd1->cryptos().size(); ++i) {
1386 const CryptoParams c1 = cd1->cryptos().at(i);
1387 const CryptoParams c2 = cd2->cryptos().at(i);
1388 EXPECT_TRUE(c1.Matches(c2));
1389 EXPECT_EQ(c1.key_params, c2.key_params);
1390 EXPECT_EQ(c1.session_params, c2.session_params);
1391 }
1392
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001393 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001394 // Use an equivalence class here, for old and new versions of the
1395 // protocol description.
Yves Gerey665174f2018-06-19 15:03:05 +02001396 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp ||
1397 cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1398 cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
lally@webrtc.org36300852015-02-24 20:19:35 +00001399 const bool cd2_is_also_dtls_sctp =
Yves Gerey665174f2018-06-19 15:03:05 +02001400 cd2->protocol() == cricket::kMediaProtocolDtlsSctp ||
1401 cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1402 cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
lally@webrtc.org36300852015-02-24 20:19:35 +00001403 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001404 } else {
1405 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1406 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001407
1408 // codecs
1409 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1410
1411 // bandwidth
1412 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1413
1414 // streams
1415 EXPECT_EQ(cd1->streams(), cd2->streams());
1416
Johannes Kron0854eb62018-10-10 22:33:20 +02001417 // extmap-allow-mixed
Johannes Kron9581bc42018-10-23 10:17:39 +02001418 EXPECT_EQ(cd1->extmap_allow_mixed_enum(), cd2->extmap_allow_mixed_enum());
Johannes Kron0854eb62018-10-10 22:33:20 +02001419
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001420 // extmap
1421 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1422 cd2->rtp_header_extensions().size());
Yves Gerey665174f2018-06-19 15:03:05 +02001423 for (size_t i = 0; i < cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 11:24:55 -07001424 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1425 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001426 EXPECT_EQ(ext1.uri, ext2.uri);
1427 EXPECT_EQ(ext1.id, ext2.id);
jbauch5869f502017-06-29 12:31:36 -07001428 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001429 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001430 }
1431
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001432 void CompareRidDescriptionIds(const std::vector<RidDescription>& rids,
1433 const std::vector<std::string>& ids) {
1434 // Order of elements does not matter, only equivalence of sets.
1435 EXPECT_EQ(rids.size(), ids.size());
1436 for (const std::string& id : ids) {
Steve Anton64b626b2019-01-28 17:25:26 -08001437 EXPECT_EQ(1l, absl::c_count_if(rids, [id](const RidDescription& rid) {
1438 return rid.rid == id;
1439 }));
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001440 }
1441 }
1442
Amit Hilbucha2012042018-12-03 11:35:05 -08001443 void CompareSimulcastDescription(const SimulcastDescription& simulcast1,
1444 const SimulcastDescription& simulcast2) {
1445 EXPECT_EQ(simulcast1.send_layers().size(), simulcast2.send_layers().size());
1446 EXPECT_EQ(simulcast1.receive_layers().size(),
1447 simulcast2.receive_layers().size());
1448 }
1449
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001450 void CompareSctpDataContentDescription(
1451 const SctpDataContentDescription* dcd1,
1452 const SctpDataContentDescription* dcd2) {
Harald Alvestrand26bf7c42019-04-23 05:20:17 +00001453 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001454 EXPECT_EQ(dcd1->port(), dcd2->port());
1455 EXPECT_EQ(dcd1->max_message_size(), dcd2->max_message_size());
Harald Alvestrand26bf7c42019-04-23 05:20:17 +00001456 }
1457
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001458 void CompareSessionDescription(const SessionDescription& desc1,
1459 const SessionDescription& desc2) {
1460 // Compare content descriptions.
1461 if (desc1.contents().size() != desc2.contents().size()) {
1462 ADD_FAILURE();
1463 return;
1464 }
Yves Gerey665174f2018-06-19 15:03:05 +02001465 for (size_t i = 0; i < desc1.contents().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001466 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1467 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-12 18:37:36 -08001468 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001469 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-12 18:37:36 -08001470 EXPECT_EQ(c1.type, c2.type);
1471 EXPECT_EQ(c1.rejected, c2.rejected);
1472 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001473
1474 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1475 if (IsAudioContent(&c1)) {
1476 const AudioContentDescription* acd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001477 c1.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001478 const AudioContentDescription* acd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001479 c2.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001480 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1481 }
1482
1483 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1484 if (IsVideoContent(&c1)) {
1485 const VideoContentDescription* vcd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001486 c1.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001487 const VideoContentDescription* vcd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001488 c2.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001489 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1490 }
1491
1492 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001493 if (c1.media_description()->as_sctp()) {
1494 ASSERT_TRUE(c2.media_description()->as_sctp());
1495 const SctpDataContentDescription* scd1 =
1496 c1.media_description()->as_sctp();
1497 const SctpDataContentDescription* scd2 =
1498 c2.media_description()->as_sctp();
1499 CompareSctpDataContentDescription(scd1, scd2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001500 }
Amit Hilbucha2012042018-12-03 11:35:05 -08001501
1502 CompareSimulcastDescription(
1503 c1.media_description()->simulcast_description(),
1504 c2.media_description()->simulcast_description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001505 }
1506
1507 // group
1508 const cricket::ContentGroups groups1 = desc1.groups();
1509 const cricket::ContentGroups groups2 = desc2.groups();
1510 EXPECT_EQ(groups1.size(), groups1.size());
1511 if (groups1.size() != groups2.size()) {
1512 ADD_FAILURE();
1513 return;
1514 }
1515 for (size_t i = 0; i < groups1.size(); ++i) {
1516 const cricket::ContentGroup group1 = groups1.at(i);
1517 const cricket::ContentGroup group2 = groups2.at(i);
1518 EXPECT_EQ(group1.semantics(), group2.semantics());
1519 const cricket::ContentNames names1 = group1.content_names();
1520 const cricket::ContentNames names2 = group2.content_names();
1521 EXPECT_EQ(names1.size(), names2.size());
1522 if (names1.size() != names2.size()) {
1523 ADD_FAILURE();
1524 return;
1525 }
1526 cricket::ContentNames::const_iterator iter1 = names1.begin();
1527 cricket::ContentNames::const_iterator iter2 = names2.begin();
1528 while (iter1 != names1.end()) {
1529 EXPECT_EQ(*iter1++, *iter2++);
1530 }
1531 }
1532
1533 // transport info
1534 const cricket::TransportInfos transports1 = desc1.transport_infos();
1535 const cricket::TransportInfos transports2 = desc2.transport_infos();
1536 EXPECT_EQ(transports1.size(), transports2.size());
1537 if (transports1.size() != transports2.size()) {
1538 ADD_FAILURE();
1539 return;
1540 }
1541 for (size_t i = 0; i < transports1.size(); ++i) {
1542 const cricket::TransportInfo transport1 = transports1.at(i);
1543 const cricket::TransportInfo transport2 = transports2.at(i);
1544 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001545 EXPECT_EQ(transport1.description.ice_ufrag,
1546 transport2.description.ice_ufrag);
Yves Gerey665174f2018-06-19 15:03:05 +02001547 EXPECT_EQ(transport1.description.ice_pwd, transport2.description.ice_pwd);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07001548 EXPECT_EQ(transport1.description.ice_mode,
1549 transport2.description.ice_mode);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001550 if (transport1.description.identity_fingerprint) {
1551 EXPECT_EQ(*transport1.description.identity_fingerprint,
1552 *transport2.description.identity_fingerprint);
1553 } else {
1554 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1555 transport2.description.identity_fingerprint.get());
1556 }
1557 EXPECT_EQ(transport1.description.transport_options,
1558 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001559 }
deadbeefc80741f2015-10-22 13:14:45 -07001560
1561 // global attributes
1562 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
Johannes Kron9581bc42018-10-23 10:17:39 +02001563 EXPECT_EQ(desc1.extmap_allow_mixed(), desc2.extmap_allow_mixed());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001564 }
1565
Yves Gerey665174f2018-06-19 15:03:05 +02001566 bool CompareSessionDescription(const JsepSessionDescription& desc1,
1567 const JsepSessionDescription& desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001568 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1569 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1570 CompareSessionDescription(*desc1.description(), *desc2.description());
1571 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1572 return false;
1573 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1574 const IceCandidateCollection* cc1 = desc1.candidates(i);
1575 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-12 18:37:36 -08001576 if (cc1->count() != cc2->count()) {
1577 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001578 return false;
deadbeef25ed4352016-12-12 18:37:36 -08001579 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001580 for (size_t j = 0; j < cc1->count(); ++j) {
1581 const IceCandidateInterface* c1 = cc1->at(j);
1582 const IceCandidateInterface* c2 = cc2->at(j);
1583 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1584 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1585 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1586 }
1587 }
1588 return true;
1589 }
1590
Artem Titov880fa812021-07-30 22:30:23 +02001591 // Disable the ice-ufrag and ice-pwd in given `sdp` message by replacing
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001592 // them with invalid keywords so that the parser will just ignore them.
1593 bool RemoveCandidateUfragPwd(std::string* sdp) {
Steve Anton1c9c9fc2019-02-14 15:13:09 -08001594 absl::StrReplaceAll(
1595 {{"a=ice-ufrag", "a=xice-ufrag"}, {"a=ice-pwd", "a=xice-pwd"}}, sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001596 return true;
1597 }
1598
Artem Titov880fa812021-07-30 22:30:23 +02001599 // Update the candidates in `jdesc` to use the given `ufrag` and `pwd`.
Yves Gerey665174f2018-06-19 15:03:05 +02001600 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc,
1601 int mline_index,
1602 const std::string& ufrag,
1603 const std::string& pwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001604 std::string content_name;
1605 if (mline_index == 0) {
1606 content_name = kAudioContentName;
1607 } else if (mline_index == 1) {
1608 content_name = kVideoContentName;
1609 } else {
Artem Titovd3251962021-11-15 16:57:07 +01001610 RTC_DCHECK_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001611 }
Yves Gerey665174f2018-06-19 15:03:05 +02001612 TransportInfo transport_info(content_name,
1613 TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001614 SessionDescription* desc =
1615 const_cast<SessionDescription*>(jdesc->description());
1616 desc->RemoveTransportInfoByName(content_name);
Steve Anton06817cd2018-12-18 15:55:30 -08001617 desc->AddTransportInfo(transport_info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001618 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1619 const IceCandidateCollection* cc = jdesc_.candidates(i);
1620 for (size_t j = 0; j < cc->count(); ++j) {
1621 if (cc->at(j)->sdp_mline_index() == mline_index) {
Yves Gerey665174f2018-06-19 15:03:05 +02001622 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(ufrag);
1623 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001624 }
1625 }
1626 }
1627 return true;
1628 }
1629
1630 void AddIceOptions(const std::string& content_name,
1631 const std::vector<std::string>& transport_options) {
1632 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1633 cricket::TransportInfo transport_info =
1634 *(desc_.GetTransportInfoByName(content_name));
1635 desc_.RemoveTransportInfoByName(content_name);
1636 transport_info.description.transport_options = transport_options;
1637 desc_.AddTransportInfo(transport_info);
1638 }
1639
deadbeef3f7219b2015-12-28 15:17:14 -08001640 void SetIceUfragPwd(const std::string& content_name,
1641 const std::string& ice_ufrag,
1642 const std::string& ice_pwd) {
1643 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1644 cricket::TransportInfo transport_info =
1645 *(desc_.GetTransportInfoByName(content_name));
1646 desc_.RemoveTransportInfoByName(content_name);
1647 transport_info.description.ice_ufrag = ice_ufrag;
1648 transport_info.description.ice_pwd = ice_pwd;
1649 desc_.AddTransportInfo(transport_info);
1650 }
1651
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001652 void AddFingerprint() {
1653 desc_.RemoveTransportInfoByName(kAudioContentName);
1654 desc_.RemoveTransportInfoByName(kVideoContentName);
Steve Anton4905edb2018-10-15 19:27:44 -07001655 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, kIdentityDigest);
Steve Anton06817cd2018-12-18 15:55:30 -08001656 desc_.AddTransportInfo(TransportInfo(
deadbeef46eed762016-01-28 13:24:37 -08001657 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001658 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1659 cricket::ICEMODE_FULL,
Steve Anton06817cd2018-12-18 15:55:30 -08001660 cricket::CONNECTIONROLE_NONE, &fingerprint)));
1661 desc_.AddTransportInfo(TransportInfo(
deadbeef46eed762016-01-28 13:24:37 -08001662 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001663 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1664 cricket::ICEMODE_FULL,
Steve Anton06817cd2018-12-18 15:55:30 -08001665 cricket::CONNECTIONROLE_NONE, &fingerprint)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001666 }
1667
jbauch5869f502017-06-29 12:31:36 -07001668 void AddExtmap(bool encrypted) {
Harald Alvestrandb97d2fe2020-02-28 11:54:40 +01001669 audio_desc_ = new AudioContentDescription(*audio_desc_);
1670 video_desc_ = new VideoContentDescription(*video_desc_);
jbauch5869f502017-06-29 12:31:36 -07001671 audio_desc_->AddRtpHeaderExtension(
1672 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1673 video_desc_->AddRtpHeaderExtension(
1674 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001675 desc_.RemoveContentByName(kAudioContentName);
1676 desc_.RemoveContentByName(kVideoContentName);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001677 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1678 absl::WrapUnique(audio_desc_));
1679 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp,
1680 absl::WrapUnique(video_desc_));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001681 }
1682
Harald Alvestrand0d018412021-11-04 13:52:31 +00001683 void RemoveCryptos() {
1684 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1685 video_desc_->set_cryptos(std::vector<CryptoParams>());
1686 }
1687
Seth Hampson5897a6e2018-04-03 11:16:33 -07001688 // Removes everything in StreamParams from the session description that is
1689 // used for a=ssrc lines.
1690 void RemoveSsrcSignalingFromStreamParams() {
Harald Alvestrand1716d392019-06-03 20:35:45 +02001691 for (cricket::ContentInfo& content_info :
1692 jdesc_.description()->contents()) {
Seth Hampson5897a6e2018-04-03 11:16:33 -07001693 // With Unified Plan there should be one StreamParams per m= section.
1694 StreamParams& stream =
1695 content_info.media_description()->mutable_streams()[0];
1696 stream.ssrcs.clear();
1697 stream.ssrc_groups.clear();
1698 stream.cname.clear();
1699 }
1700 }
1701
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001702 // Removes all a=ssrc lines from the SDP string, except for the
1703 // "a=ssrc:... cname:..." lines.
1704 void RemoveSsrcMsidLinesFromSdpString(std::string* sdp_string) {
1705 const char kAttributeSsrc[] = "a=ssrc";
1706 const char kAttributeCname[] = "cname";
1707 size_t ssrc_line_pos = sdp_string->find(kAttributeSsrc);
1708 while (ssrc_line_pos != std::string::npos) {
1709 size_t beg_line_pos = sdp_string->rfind('\n', ssrc_line_pos);
1710 size_t end_line_pos = sdp_string->find('\n', ssrc_line_pos);
1711 size_t cname_pos = sdp_string->find(kAttributeCname, ssrc_line_pos);
1712 if (cname_pos == std::string::npos || cname_pos > end_line_pos) {
1713 // Only erase a=ssrc lines that don't contain "cname".
1714 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1715 ssrc_line_pos = sdp_string->find(kAttributeSsrc, beg_line_pos);
1716 } else {
1717 // Skip the "a=ssrc:... cname" line and find the next "a=ssrc" line.
1718 ssrc_line_pos = sdp_string->find(kAttributeSsrc, end_line_pos);
1719 }
1720 }
1721 }
1722
Seth Hampson5897a6e2018-04-03 11:16:33 -07001723 // Removes all a=ssrc lines from the SDP string.
1724 void RemoveSsrcLinesFromSdpString(std::string* sdp_string) {
1725 const char kAttributeSsrc[] = "a=ssrc";
1726 while (sdp_string->find(kAttributeSsrc) != std::string::npos) {
1727 size_t pos_ssrc_attribute = sdp_string->find(kAttributeSsrc);
1728 size_t beg_line_pos = sdp_string->rfind('\n', pos_ssrc_attribute);
1729 size_t end_line_pos = sdp_string->find('\n', pos_ssrc_attribute);
1730 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1731 }
1732 }
1733
Steve Anton4e70a722017-11-28 14:57:10 -08001734 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001735 audio_desc_->set_direction(direction);
1736 video_desc_->set_direction(direction);
1737 std::string new_sdp = kSdpFullString;
1738 ReplaceDirection(direction, &new_sdp);
1739
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001740 if (!jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001741 jdesc_.session_version())) {
1742 return false;
1743 }
Steve Antone831b8c2018-02-01 12:22:16 -08001744 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001745 EXPECT_EQ(new_sdp, message);
1746 return true;
1747 }
1748
1749 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
Harald Alvestrandb97d2fe2020-02-28 11:54:40 +01001750 audio_desc_ = new AudioContentDescription(*audio_desc_);
1751 video_desc_ = new VideoContentDescription(*video_desc_);
zhihuang38989e52017-03-21 11:04:53 -07001752
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001753 desc_.RemoveContentByName(kAudioContentName);
1754 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001755 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001756 absl::WrapUnique(audio_desc_));
Steve Anton5adfafd2017-12-20 16:34:00 -08001757 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001758 absl::WrapUnique(video_desc_));
deadbeef9d3584c2016-02-16 17:54:10 -08001759 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1760 audio_rejected ? "" : kPwdVoice);
1761 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1762 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001763
1764 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1766
Steve Antona3a92c22017-12-07 10:27:41 -08001767 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001768 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001769 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001770 EXPECT_EQ(new_sdp, message);
1771 return true;
1772 }
1773
zstein4b2e0822017-02-17 19:48:38 -08001774 void AddSctpDataChannel(bool use_sctpmap) {
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001775 std::unique_ptr<SctpDataContentDescription> data(
1776 new SctpDataContentDescription());
1777 sctp_desc_ = data.get();
1778 sctp_desc_->set_use_sctpmap(use_sctpmap);
Guido Urdanetacecf87f2019-05-31 10:17:38 +00001779 sctp_desc_->set_protocol(cricket::kMediaProtocolUdpDtlsSctp);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001780 sctp_desc_->set_port(kDefaultSctpPort);
Steve Anton5adfafd2017-12-20 16:34:00 -08001781 desc_.AddContent(kDataContentName, MediaProtocolType::kSctp,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001782 std::move(data));
Steve Anton06817cd2018-12-18 15:55:30 -08001783 desc_.AddTransportInfo(TransportInfo(
1784 kDataContentName, TransportDescription(kUfragData, kPwdData)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001785 }
1786
Steve Anton4e70a722017-11-28 14:57:10 -08001787 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001788 std::string new_sdp = kSdpFullString;
1789 ReplaceDirection(direction, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001790 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001791
1792 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1793
1794 audio_desc_->set_direction(direction);
1795 video_desc_->set_direction(direction);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001796 if (!jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001797 jdesc_.session_version())) {
1798 return false;
1799 }
1800 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1801 return true;
1802 }
1803
1804 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001805 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001806 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001807 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001808 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001809
Harald Alvestrandb97d2fe2020-02-28 11:54:40 +01001810 audio_desc_ = new AudioContentDescription(*audio_desc_);
1811 video_desc_ = new VideoContentDescription(*video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001812 desc_.RemoveContentByName(kAudioContentName);
1813 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001814 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001815 absl::WrapUnique(audio_desc_));
Steve Anton5adfafd2017-12-20 16:34:00 -08001816 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001817 absl::WrapUnique(video_desc_));
deadbeef9d3584c2016-02-16 17:54:10 -08001818 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1819 audio_rejected ? "" : kPwdVoice);
1820 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1821 video_rejected ? "" : kPwdVideo);
Steve Antona3a92c22017-12-07 10:27:41 -08001822 JsepSessionDescription jdesc_no_candidates(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001823 if (!jdesc_no_candidates.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef3f7219b2015-12-28 15:17:14 -08001824 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001825 return false;
1826 }
deadbeef3f7219b2015-12-28 15:17:14 -08001827 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001828 return true;
1829 }
1830
Yves Gerey665174f2018-06-19 15:03:05 +02001831 void TestDeserializeExtmap(bool session_level,
1832 bool media_level,
1833 bool encrypted) {
jbauch5869f502017-06-29 12:31:36 -07001834 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08001835 JsepSessionDescription new_jdesc(SdpType::kOffer);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001836 ASSERT_TRUE(new_jdesc.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001837 jdesc_.session_version()));
Steve Antona3a92c22017-12-07 10:27:41 -08001838 JsepSessionDescription jdesc_with_extmap(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001839 std::string sdp_with_extmap = kSdpString;
1840 if (session_level) {
jbauch5869f502017-06-29 12:31:36 -07001841 InjectAfter(kSessionTime,
1842 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1843 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001844 &sdp_with_extmap);
1845 }
1846 if (media_level) {
jbauch5869f502017-06-29 12:31:36 -07001847 InjectAfter(kAttributeIcePwdVoice,
1848 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1849 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001850 &sdp_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07001851 InjectAfter(kAttributeIcePwdVideo,
1852 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1853 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001854 &sdp_with_extmap);
1855 }
1856 // The extmap can't be present at the same time in both session level and
1857 // media level.
1858 if (session_level && media_level) {
1859 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02001860 EXPECT_FALSE(
1861 webrtc::SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001862 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1863 } else {
1864 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1865 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1866 }
1867 }
1868
1869 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
Yves Gerey665174f2018-06-19 15:03:05 +02001870 const std::string& name,
1871 int expected_value) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001872 cricket::CodecParameterMap::const_iterator found = params.find(name);
1873 ASSERT_TRUE(found != params.end());
Jonas Olsson6b1985d2018-07-05 11:59:48 +02001874 EXPECT_EQ(found->second, rtc::ToString(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001875 }
1876
1877 void TestDeserializeCodecParams(const CodecParams& params,
1878 JsepSessionDescription* jdesc_output) {
1879 std::string sdp =
1880 "v=0\r\n"
1881 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1882 "s=-\r\n"
1883 "t=0 0\r\n"
1884 // Include semantics for WebRTC Media Streams since it is supported by
1885 // this parser, and will be added to the SDP when serializing a session
1886 // description.
1887 "a=msid-semantic: WMS\r\n"
1888 // Pl type 111 preferred.
Philipp Hanckef2a4ec12020-07-01 21:07:32 +02001889 "m=audio 9 RTP/SAVPF 111 104 103 105\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001890 // Pltype 111 listed before 103 and 104 in the map.
1891 "a=rtpmap:111 opus/48000/2\r\n"
1892 // Pltype 103 listed before 104.
1893 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001894 "a=rtpmap:104 ISAC/32000\r\n"
Philipp Hanckef2a4ec12020-07-01 21:07:32 +02001895 "a=rtpmap:105 telephone-event/8000\r\n"
1896 "a=fmtp:105 0-15,66,70\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001897 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001898 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001899 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001900 << "; sprop-stereo=" << params.sprop_stereo
1901 << "; useinbandfec=" << params.useinband
Jonas Olssonb2b20312020-01-14 12:11:31 +01001902 << "; maxaveragebitrate=" << params.maxaveragebitrate
1903 << "\r\n"
1904 "a=ptime:"
1905 << params.ptime
1906 << "\r\n"
1907 "a=maxptime:"
1908 << params.max_ptime << "\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001909 sdp += os.str();
1910
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001911 os.clear();
1912 os.str("");
1913 // Pl type 100 preferred.
Philipp Hanckeb7bc2432021-03-11 15:28:00 +01001914 os << "m=video 9 RTP/SAVPF 99 95 96\r\n"
1915 "a=rtpmap:96 VP9/90000\r\n" // out-of-order wrt the m= line.
Jonas Olssonb2b20312020-01-14 12:11:31 +01001916 "a=rtpmap:99 VP8/90000\r\n"
1917 "a=rtpmap:95 RTX/90000\r\n"
1918 "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001919 sdp += os.str();
1920
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001921 // Deserialize
1922 SdpParseError error;
1923 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1924
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001925 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001926 GetFirstAudioContentDescription(jdesc_output->description());
1927 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001928 ASSERT_FALSE(acd->codecs().empty());
1929 cricket::AudioCodec opus = acd->codecs()[0];
1930 EXPECT_EQ("opus", opus.name);
1931 EXPECT_EQ(111, opus.id);
1932 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1933 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1934 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1935 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001936 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1937 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001938 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1939 cricket::AudioCodec codec = acd->codecs()[i];
1940 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1941 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001942 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001943
Philipp Hanckef2a4ec12020-07-01 21:07:32 +02001944 cricket::AudioCodec dtmf = acd->codecs()[3];
1945 EXPECT_EQ("telephone-event", dtmf.name);
1946 EXPECT_EQ(105, dtmf.id);
1947 EXPECT_EQ(3u,
1948 dtmf.params.size()); // ptime and max_ptime count as parameters.
1949 EXPECT_EQ(dtmf.params.begin()->first, "");
1950 EXPECT_EQ(dtmf.params.begin()->second, "0-15,66,70");
1951
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001952 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001953 GetFirstVideoContentDescription(jdesc_output->description());
1954 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001955 ASSERT_FALSE(vcd->codecs().empty());
1956 cricket::VideoCodec vp8 = vcd->codecs()[0];
1957 EXPECT_EQ("VP8", vp8.name);
1958 EXPECT_EQ(99, vp8.id);
1959 cricket::VideoCodec rtx = vcd->codecs()[1];
1960 EXPECT_EQ("RTX", rtx.name);
1961 EXPECT_EQ(95, rtx.id);
1962 VerifyCodecParameter(rtx.params, "apt", vp8.id);
Philipp Hanckeb7bc2432021-03-11 15:28:00 +01001963 // VP9 is listed last in the m= line so should come after VP8 and RTX.
1964 cricket::VideoCodec vp9 = vcd->codecs()[2];
1965 EXPECT_EQ("VP9", vp9.name);
1966 EXPECT_EQ(96, vp9.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001967 }
1968
1969 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1970 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001971 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001972 "v=0\r\n"
1973 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1974 "s=-\r\n"
1975 "t=0 0\r\n"
1976 // Include semantics for WebRTC Media Streams since it is supported by
1977 // this parser, and will be added to the SDP when serializing a session
1978 // description.
1979 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001980 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001981 "a=rtpmap:111 opus/48000/2\r\n";
1982 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001983 "m=video 3457 RTP/SAVPF 101\r\n"
1984 "a=rtpmap:101 VP8/90000\r\n"
Elad Alonfadb1812019-05-24 13:40:02 +02001985 "a=rtcp-fb:101 goog-lntf\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001986 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001987 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001988 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001989 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001990 os << sdp_session_and_audio;
Yves Gerey665174f2018-06-19 15:03:05 +02001991 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001992 os << sdp_video;
Yves Gerey665174f2018-06-19 15:03:05 +02001993 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001994 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001995 // Deserialize
1996 SdpParseError error;
1997 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001998 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001999 GetFirstAudioContentDescription(jdesc_output->description());
2000 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002001 ASSERT_FALSE(acd->codecs().empty());
2002 cricket::AudioCodec opus = acd->codecs()[0];
2003 EXPECT_EQ(111, opus.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002004 EXPECT_TRUE(opus.HasFeedbackParam(cricket::FeedbackParam(
2005 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002006
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002007 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08002008 GetFirstVideoContentDescription(jdesc_output->description());
2009 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002010 ASSERT_FALSE(vcd->codecs().empty());
2011 cricket::VideoCodec vp8 = vcd->codecs()[0];
2012 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
2013 vp8.name.c_str());
2014 EXPECT_EQ(101, vp8.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002015 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
Elad Alonfadb1812019-05-24 13:40:02 +02002016 cricket::kRtcpFbParamLntf, cricket::kParamValueEmpty)));
2017 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
Yves Gerey665174f2018-06-19 15:03:05 +02002018 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
2019 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2020 cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli)));
2021 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2022 cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty)));
2023 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2024 cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002025 }
2026
2027 // Two SDP messages can mean the same thing but be different strings, e.g.
2028 // some of the lines can be serialized in different order.
2029 // However, a deserialized description can be compared field by field and has
2030 // no order. If deserializer has already been tested, serializing then
2031 // deserializing and comparing JsepSessionDescription will test
2032 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 12:22:16 -08002033 void TestSerialize(const JsepSessionDescription& jdesc) {
2034 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 10:27:41 -08002035 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002036 SdpParseError error;
2037 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
2038 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
2039 }
2040
zhihuang38989e52017-03-21 11:04:53 -07002041 // Calling 'Initialize' with a copy of the inner SessionDescription will
2042 // create a copy of the JsepSessionDescription without candidates. The
2043 // 'connection address' field, previously set from the candidates, must also
2044 // be reset.
2045 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
2046 rtc::SocketAddress audio_addr("0.0.0.0", 9);
2047 rtc::SocketAddress video_addr("0.0.0.0", 9);
2048 audio_desc_->set_connection_address(audio_addr);
2049 video_desc_->set_connection_address(video_addr);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002050 ASSERT_TRUE(jdesc->Initialize(desc_.Clone(), kSessionId, kSessionVersion));
zhihuang38989e52017-03-21 11:04:53 -07002051 }
2052
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002053 protected:
2054 SessionDescription desc_;
2055 AudioContentDescription* audio_desc_;
2056 VideoContentDescription* video_desc_;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002057 SctpDataContentDescription* sctp_desc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002058 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07002059 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002060 JsepSessionDescription jdesc_;
2061};
2062
2063void TestMismatch(const std::string& string1, const std::string& string2) {
2064 int position = 0;
2065 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
2066 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002067 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002068 break;
2069 }
2070 }
2071 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
2072 << " character\n"
Jonas Olssonb2b20312020-01-14 12:11:31 +01002073 " 1: "
2074 << string1.substr(position, 20)
2075 << "\n"
2076 " 2: "
2077 << string2.substr(position, 20) << "\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002078}
2079
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002080TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
2081 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 12:22:16 -08002082 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002083 TestMismatch(std::string(kSdpFullString), message);
2084}
2085
2086TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 10:27:41 -08002087 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 12:22:16 -08002088 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002089}
2090
Harald Alvestrand0d018412021-11-04 13:52:31 +00002091// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002092// the case in a DTLS offer.
2093TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
2094 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002095 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002096 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08002097 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002098
2099 std::string sdp_with_fingerprint = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002100 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2101 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002102
2103 EXPECT_EQ(sdp_with_fingerprint, message);
2104}
2105
2106// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
2107// be the case in a DTLS answer.
2108TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
2109 AddFingerprint();
Harald Alvestrand0d018412021-11-04 13:52:31 +00002110 RemoveCryptos();
Steve Antona3a92c22017-12-07 10:27:41 -08002111 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002112 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08002113 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002114
2115 std::string sdp_with_fingerprint = kSdpString;
2116 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
2117 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
Yves Gerey665174f2018-06-19 15:03:05 +02002118 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2119 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002120
2121 EXPECT_EQ(sdp_with_fingerprint, message);
2122}
2123
2124TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
2125 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002126 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002127 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08002128 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002129 EXPECT_EQ(std::string(kSdpString), message);
2130}
2131
Henrik Boströmf8187e02021-04-26 21:04:26 +02002132TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundles) {
2133 ContentGroup group1(cricket::GROUP_TYPE_BUNDLE);
2134 group1.AddContentName(kAudioContentName);
2135 group1.AddContentName(kVideoContentName);
2136 desc_.AddGroup(group1);
2137 ContentGroup group2(cricket::GROUP_TYPE_BUNDLE);
2138 group2.AddContentName(kAudioContentName2);
2139 desc_.AddGroup(group2);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002140 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002141 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002142 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002143 std::string sdp_with_bundle = kSdpFullString;
2144 InjectAfter(kSessionTime,
Henrik Boströmf8187e02021-04-26 21:04:26 +02002145 "a=group:BUNDLE audio_content_name video_content_name\r\n"
2146 "a=group:BUNDLE audio_content_name_2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002147 &sdp_with_bundle);
2148 EXPECT_EQ(sdp_with_bundle, message);
2149}
2150
2151TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 15:14:30 -08002152 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
Taylor Brandstetteree8c2462020-07-27 15:52:02 -07002153 vcd->set_bandwidth(100 * 1000 + 755); // Integer division will drop the 755.
2154 vcd->set_bandwidth_type("AS");
Steve Antonb1c1de12017-12-21 15:14:30 -08002155 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
Taylor Brandstetteree8c2462020-07-27 15:52:02 -07002156 acd->set_bandwidth(555);
2157 acd->set_bandwidth_type("TIAS");
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002158 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002159 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002160 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002161 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002162 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002163 &sdp_with_bandwidth);
Taylor Brandstetteree8c2462020-07-27 15:52:02 -07002164 InjectAfter("c=IN IP4 74.125.127.126\r\n", "b=TIAS:555\r\n",
2165 &sdp_with_bandwidth);
2166 EXPECT_EQ(sdp_with_bandwidth, message);
2167}
2168
2169// Should default to b=AS if bandwidth_type isn't set.
2170TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithMissingBandwidthType) {
2171 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
2172 vcd->set_bandwidth(100 * 1000);
2173 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2174 jdesc_.session_version()));
2175 std::string message = webrtc::SdpSerialize(jdesc_);
2176 std::string sdp_with_bandwidth = kSdpFullString;
2177 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002178 &sdp_with_bandwidth);
2179 EXPECT_EQ(sdp_with_bandwidth, message);
2180}
2181
2182TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
2183 std::vector<std::string> transport_options;
2184 transport_options.push_back(kIceOption1);
2185 transport_options.push_back(kIceOption3);
2186 AddIceOptions(kAudioContentName, transport_options);
2187 transport_options.clear();
2188 transport_options.push_back(kIceOption2);
2189 transport_options.push_back(kIceOption3);
2190 AddIceOptions(kVideoContentName, transport_options);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002191 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002192 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002193 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002194 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002195 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002196 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002197 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002198 &sdp_with_ice_options);
2199 EXPECT_EQ(sdp_with_ice_options, message);
2200}
2201
2202TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002203 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002204}
2205
2206TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002207 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002208}
2209
2210TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002211 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002212}
2213
2214TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2215 EXPECT_TRUE(TestSerializeRejected(true, false));
2216}
2217
2218TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2219 EXPECT_TRUE(TestSerializeRejected(false, true));
2220}
2221
2222TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2223 EXPECT_TRUE(TestSerializeRejected(true, true));
2224}
2225
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002226TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08002227 bool use_sctpmap = true;
2228 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002229 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002230
zhihuang38989e52017-03-21 11:04:53 -07002231 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002232 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002233
2234 std::string expected_sdp = kSdpString;
2235 expected_sdp.append(kSdpSctpDataChannelString);
2236 EXPECT_EQ(message, expected_sdp);
2237}
2238
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002239void MutateJsepSctpPort(JsepSessionDescription* jdesc,
2240 const SessionDescription& desc,
2241 int port) {
2242 // Take our pre-built session description and change the SCTP port.
2243 std::unique_ptr<cricket::SessionDescription> mutant = desc.Clone();
2244 SctpDataContentDescription* dcdesc =
2245 mutant->GetContentDescriptionByName(kDataContentName)->as_sctp();
2246 dcdesc->set_port(port);
2247 ASSERT_TRUE(
2248 jdesc->Initialize(std::move(mutant), kSessionId, kSessionVersion));
2249}
2250
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002251TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08002252 bool use_sctpmap = true;
2253 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002254 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002255 MakeDescriptionWithoutCandidates(&jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002256
2257 const int kNewPort = 1234;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002258 MutateJsepSctpPort(&jsep_desc, desc_, kNewPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002259
Steve Antone831b8c2018-02-01 12:22:16 -08002260 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002261
2262 std::string expected_sdp = kSdpString;
2263 expected_sdp.append(kSdpSctpDataChannelString);
2264
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002265 absl::StrReplaceAll(
2266 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kNewPort)}},
2267 &expected_sdp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002268
2269 EXPECT_EQ(expected_sdp, message);
2270}
2271
Johannes Kron0854eb62018-10-10 22:33:20 +02002272TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002273 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002274 TestSerialize(jdesc_);
2275}
2276
2277TEST_F(WebRtcSdpTest, SerializeMediaContentDescriptionWithExtmapAllowMixed) {
2278 cricket::MediaContentDescription* video_desc =
2279 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2280 ASSERT_TRUE(video_desc);
2281 cricket::MediaContentDescription* audio_desc =
2282 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2283 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002284 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002285 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002286 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002287 cricket::MediaContentDescription::kMedia);
2288 TestSerialize(jdesc_);
2289}
2290
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002291TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002292 bool encrypted = false;
2293 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002294 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002295 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 12:22:16 -08002296 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002297
2298 std::string sdp_with_extmap = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002299 InjectAfter("a=mid:audio_content_name\r\n", kExtmap, &sdp_with_extmap);
2300 InjectAfter("a=mid:video_content_name\r\n", kExtmap, &sdp_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002301
2302 EXPECT_EQ(sdp_with_extmap, message);
2303}
2304
jbauch5869f502017-06-29 12:31:36 -07002305TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2306 bool encrypted = true;
2307 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002308 JsepSessionDescription desc_with_extmap(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002309 ASSERT_TRUE(
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002310 desc_with_extmap.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 12:22:16 -08002311 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07002312}
2313
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002314TEST_F(WebRtcSdpTest, SerializeCandidates) {
2315 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002316 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002317
2318 Candidate candidate_with_ufrag(candidates_.front());
2319 candidate_with_ufrag.set_username("ABC");
2320 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2321 candidate_with_ufrag));
2322 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2323 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002324
2325 Candidate candidate_with_network_info(candidates_.front());
2326 candidate_with_network_info.set_network_id(1);
2327 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2328 candidate_with_network_info));
2329 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2330 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2331 candidate_with_network_info.set_network_cost(999);
2332 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2333 candidate_with_network_info));
2334 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2335 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2336 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002337}
2338
Zach Steinb336c272018-08-09 01:16:13 -07002339TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) {
2340 rtc::SocketAddress address("a.test", 1234);
2341 cricket::Candidate candidate(
2342 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
2343 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
2344 JsepIceCandidate jcandidate(std::string("audio_content_name"), 0, candidate);
2345 std::string message = webrtc::SdpSerializeCandidate(jcandidate);
2346 EXPECT_EQ(std::string(kRawHostnameCandidate), message);
2347}
2348
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002349TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002350 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002351 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2352 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2353 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002354 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002355 std::unique_ptr<IceCandidateInterface> jcandidate(
2356 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002357
2358 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2359 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2360}
2361
Taylor Brandstetter8206bc02020-04-02 12:36:38 -07002362// Test serializing a TCP candidate that came in with a missing tcptype. This
2363// shouldn't happen according to the spec, but our implementation has been
2364// accepting this for quite some time, treating it as a passive candidate.
2365//
2366// So, we should be able to at least convert such candidates to and from SDP.
2367// See: bugs.webrtc.org/11423
2368TEST_F(WebRtcSdpTest, ParseTcpCandidateWithoutTcptype) {
2369 std::string missing_tcptype =
2370 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9999 typ host";
2371 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2372 EXPECT_TRUE(SdpDeserializeCandidate(missing_tcptype, &jcandidate));
2373
2374 EXPECT_EQ(std::string(cricket::TCPTYPE_PASSIVE_STR),
2375 jcandidate.candidate().tcptype());
2376}
2377
2378TEST_F(WebRtcSdpTest, ParseSslTcpCandidate) {
2379 std::string ssltcp =
2380 "candidate:a0+B/1 1 ssltcp 2130706432 192.168.1.5 9999 typ host tcptype "
2381 "passive";
2382 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2383 EXPECT_TRUE(SdpDeserializeCandidate(ssltcp, &jcandidate));
2384
2385 EXPECT_EQ(std::string("ssltcp"), jcandidate.candidate().protocol());
2386}
2387
htaa6b99442016-04-12 10:29:17 -07002388TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002389 cricket::VideoCodec h264_codec("H264");
2390 h264_codec.SetParam("profile-level-id", "42e01f");
2391 h264_codec.SetParam("level-asymmetry-allowed", "1");
2392 h264_codec.SetParam("packetization-mode", "1");
2393 video_desc_->AddCodec(h264_codec);
2394
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002395 jdesc_.Initialize(desc_.Clone(), kSessionId, kSessionVersion);
htaa6b99442016-04-12 10:29:17 -07002396
Steve Antone831b8c2018-02-01 12:22:16 -08002397 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 10:29:17 -07002398 size_t after_pt = message.find(" H264/90000");
2399 ASSERT_NE(after_pt, std::string::npos);
2400 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2401 ASSERT_NE(before_pt, std::string::npos);
2402 before_pt += strlen("a=rtpmap:");
2403 std::string pt = message.substr(before_pt, after_pt - before_pt);
Artem Titov880fa812021-07-30 22:30:23 +02002404 // TODO(hta): Check if payload type `pt` occurs in the m=video line.
htaa6b99442016-04-12 10:29:17 -07002405 std::string to_find = "a=fmtp:" + pt + " ";
2406 size_t fmtp_pos = message.find(to_find);
2407 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
Mirko Bonadei37ec55e2019-01-28 11:43:52 +01002408 size_t fmtp_endpos = message.find('\n', fmtp_pos);
htaa6b99442016-04-12 10:29:17 -07002409 ASSERT_NE(std::string::npos, fmtp_endpos);
2410 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2411 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2412 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2413 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002414 // Check that there are no spaces after semicolons.
2415 // https://bugs.webrtc.org/5793
2416 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002417}
2418
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002419TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 10:27:41 -08002420 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002421 // Deserialize
2422 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2423 // Verify
2424 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2425}
2426
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002427TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 10:27:41 -08002428 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002429 const char kSdpWithoutMline[] =
Yves Gerey665174f2018-06-19 15:03:05 +02002430 "v=0\r\n"
2431 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2432 "s=-\r\n"
2433 "t=0 0\r\n"
2434 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002435 // Deserialize
2436 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2437 EXPECT_EQ(0u, jdesc.description()->contents().size());
2438}
2439
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002440TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 10:27:41 -08002441 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002442 std::string sdp_without_carriage_return = kSdpFullString;
2443 Replace("\r\n", "\n", &sdp_without_carriage_return);
2444 // Deserialize
2445 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2446 // Verify
2447 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2448}
2449
2450TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2451 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002452 JsepSessionDescription jdesc_no_candidates(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002453 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Clone(), kSessionId,
Yves Gerey665174f2018-06-19 15:03:05 +02002454 kSessionVersion));
Steve Antona3a92c22017-12-07 10:27:41 -08002455 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002456 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2457 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2458}
2459
2460TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2461 static const char kSdpNoRtpmapString[] =
2462 "v=0\r\n"
2463 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2464 "s=-\r\n"
2465 "t=0 0\r\n"
2466 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2467 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002468 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002469 // The rtpmap line for static payload codec is optional.
2470 "a=rtpmap:18 G729/16000\r\n"
2471 "a=rtpmap:103 ISAC/16000\r\n";
2472
Steve Antona3a92c22017-12-07 10:27:41 -08002473 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002474 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2475 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08002476 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002477 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002478 // The codecs in the AudioContentDescription should be in the same order as
2479 // the payload types (<fmt>s) on the m= line.
2480 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2481 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002482 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002483 EXPECT_EQ(ref_codecs, audio->codecs());
2484}
2485
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002486TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2487 static const char kSdpNoRtpmapString[] =
2488 "v=0\r\n"
2489 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2490 "s=-\r\n"
2491 "t=0 0\r\n"
2492 "m=audio 49232 RTP/AVP 18 103\r\n"
2493 "a=fmtp:18 annexb=yes\r\n"
2494 "a=rtpmap:103 ISAC/16000\r\n";
2495
Steve Antona3a92c22017-12-07 10:27:41 -08002496 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002497 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2498 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08002499 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002500
2501 cricket::AudioCodec g729 = audio->codecs()[0];
2502 EXPECT_EQ("G729", g729.name);
2503 EXPECT_EQ(8000, g729.clockrate);
2504 EXPECT_EQ(18, g729.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002505 cricket::CodecParameterMap::iterator found = g729.params.find("annexb");
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002506 ASSERT_TRUE(found != g729.params.end());
2507 EXPECT_EQ(found->second, "yes");
2508
2509 cricket::AudioCodec isac = audio->codecs()[1];
2510 EXPECT_EQ("ISAC", isac.name);
2511 EXPECT_EQ(103, isac.id);
2512 EXPECT_EQ(16000, isac.clockrate);
2513}
2514
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002515// Ensure that we can deserialize SDP with a=fingerprint properly.
2516TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2517 // Add a DTLS a=fingerprint attribute to our session description.
2518 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002519 JsepSessionDescription new_jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002520 ASSERT_TRUE(new_jdesc.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002521 jdesc_.session_version()));
2522
Steve Antona3a92c22017-12-07 10:27:41 -08002523 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002524 std::string sdp_with_fingerprint = kSdpString;
2525 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2526 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2527 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2528 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2529}
2530
2531TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 10:27:41 -08002532 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002533 std::string sdp_with_bundle = kSdpFullString;
2534 InjectAfter(kSessionTime,
2535 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2536 &sdp_with_bundle);
2537 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2538 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2539 group.AddContentName(kAudioContentName);
2540 group.AddContentName(kVideoContentName);
2541 desc_.AddGroup(group);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002542 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002543 jdesc_.session_version()));
2544 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2545}
2546
2547TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002548 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002549 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002550 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002551 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002552 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002553 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002554 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 15:14:30 -08002555 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002556 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002557 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002558 acd->set_bandwidth(50 * 1000);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002559 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002560 jdesc_.session_version()));
2561 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2562}
2563
Taylor Brandstetteree8c2462020-07-27 15:52:02 -07002564TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithTiasBandwidth) {
2565 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
2566 std::string sdp_with_bandwidth = kSdpFullString;
2567 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=TIAS:100000\r\n",
2568 &sdp_with_bandwidth);
2569 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=TIAS:50000\r\n",
2570 &sdp_with_bandwidth);
2571 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2572 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
2573 vcd->set_bandwidth(100 * 1000);
2574 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
2575 acd->set_bandwidth(50 * 1000);
2576 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2577 jdesc_.session_version()));
2578 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2579}
2580
Philipp Hanckefbbfc022020-07-31 08:30:50 +02002581TEST_F(WebRtcSdpTest,
2582 DeserializeSessionDescriptionWithUnknownBandwidthModifier) {
2583 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
2584 std::string sdp_with_bandwidth = kSdpFullString;
2585 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
2586 "b=unknown:100000\r\n", &sdp_with_bandwidth);
2587 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
2588 "b=unknown:50000\r\n", &sdp_with_bandwidth);
2589 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2590 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
2591 vcd->set_bandwidth(-1);
2592 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
2593 acd->set_bandwidth(-1);
2594 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2595 jdesc_.session_version()));
2596 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2597}
2598
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002599TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 10:27:41 -08002600 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002601 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002602 InjectAfter(kSessionTime, "a=ice-options:iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002603 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002604 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002605 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002606 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002607 &sdp_with_ice_options);
2608 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2609 std::vector<std::string> transport_options;
2610 transport_options.push_back(kIceOption3);
2611 transport_options.push_back(kIceOption1);
2612 AddIceOptions(kAudioContentName, transport_options);
2613 transport_options.clear();
2614 transport_options.push_back(kIceOption3);
2615 transport_options.push_back(kIceOption2);
2616 AddIceOptions(kVideoContentName, transport_options);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002617 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002618 jdesc_.session_version()));
2619 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2620}
2621
2622TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2623 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 10:27:41 -08002624 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002625 std::string sdp_with_ufrag_pwd = kSdpFullString;
2626 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2627 // Add session level ufrag and pwd
2628 InjectAfter(kSessionTime,
Yves Gerey665174f2018-06-19 15:03:05 +02002629 "a=ice-pwd:session+level+icepwd\r\n"
2630 "a=ice-ufrag:session+level+iceufrag\r\n",
2631 &sdp_with_ufrag_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002632 // Add media level ufrag and pwd for audio
Yves Gerey665174f2018-06-19 15:03:05 +02002633 InjectAfter(
2634 "a=mid:audio_content_name\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002635 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2636 &sdp_with_ufrag_pwd);
2637 // Update the candidate ufrag and pwd to the expected ones.
Yves Gerey665174f2018-06-19 15:03:05 +02002638 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, "media+level+iceufrag",
2639 "media+level+icepwd"));
2640 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, "session+level+iceufrag",
2641 "session+level+icepwd"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002642 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2643 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2644}
2645
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002646TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002647 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002648}
2649
2650TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002651 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002652}
2653
2654TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002655 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002656}
2657
2658TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2659 EXPECT_TRUE(TestDeserializeRejected(true, false));
2660}
2661
2662TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2663 EXPECT_TRUE(TestDeserializeRejected(false, true));
2664}
2665
2666TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2667 EXPECT_TRUE(TestDeserializeRejected(true, true));
2668}
2669
Artem Titovf0a34f22020-03-16 17:52:04 +00002670// Tests that we can still handle the sdp uses mslabel and label instead of
2671// msid for backward compatibility.
2672TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
2673 jdesc_.description()->set_msid_supported(false);
2674 JsepSessionDescription jdesc(kDummyType);
2675 std::string sdp_without_msid = kSdpFullString;
2676 Replace("msid", "xmsid", &sdp_without_msid);
2677 // Deserialize
2678 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2679 // Verify
2680 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2681 EXPECT_FALSE(jdesc.description()->msid_signaling() &
2682 ~cricket::kMsidSignalingSsrcAttribute);
2683}
2684
Johannes Kron0854eb62018-10-10 22:33:20 +02002685TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002686 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002687 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
Johannes Kron0854eb62018-10-10 22:33:20 +02002688 // Deserialize
2689 JsepSessionDescription jdesc_deserialized(kDummyType);
Emil Lundmark801c9992021-01-19 13:06:32 +01002690 ASSERT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
Johannes Kron0854eb62018-10-10 22:33:20 +02002691 // Verify
2692 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2693}
2694
2695TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002696 jdesc_.description()->set_extmap_allow_mixed(false);
Johannes Kron0854eb62018-10-10 22:33:20 +02002697 std::string sdp_without_extmap_allow_mixed = kSdpFullString;
Emil Lundmark801c9992021-01-19 13:06:32 +01002698 Replace(kExtmapAllowMixed, "", &sdp_without_extmap_allow_mixed);
Johannes Kron0854eb62018-10-10 22:33:20 +02002699 // Deserialize
2700 JsepSessionDescription jdesc_deserialized(kDummyType);
Emil Lundmark801c9992021-01-19 13:06:32 +01002701 ASSERT_TRUE(
Johannes Kron0854eb62018-10-10 22:33:20 +02002702 SdpDeserialize(sdp_without_extmap_allow_mixed, &jdesc_deserialized));
2703 // Verify
2704 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2705}
2706
2707TEST_F(WebRtcSdpTest, DeserializeMediaContentDescriptionWithExtmapAllowMixed) {
2708 cricket::MediaContentDescription* video_desc =
2709 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2710 ASSERT_TRUE(video_desc);
2711 cricket::MediaContentDescription* audio_desc =
2712 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2713 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002714 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002715 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002716 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002717 cricket::MediaContentDescription::kMedia);
2718
2719 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2720 InjectAfter("a=mid:audio_content_name\r\n", kExtmapAllowMixed,
2721 &sdp_with_extmap_allow_mixed);
2722 InjectAfter("a=mid:video_content_name\r\n", kExtmapAllowMixed,
2723 &sdp_with_extmap_allow_mixed);
2724
2725 // Deserialize
2726 JsepSessionDescription jdesc_deserialized(kDummyType);
2727 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2728 // Verify
2729 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2730}
2731
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002732TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2733 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2734
2735 std::string sdp = kSdpOneCandidate;
2736 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2737 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2738 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2739 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002740 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002741
2742 // Candidate line without generation extension.
2743 sdp = kSdpOneCandidate;
2744 Replace(" generation 2", "", &sdp);
2745 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2746 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2747 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2748 Candidate expected = jcandidate_->candidate();
2749 expected.set_generation(0);
2750 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2751
honghaiza0c44ea2016-03-23 16:07:48 -07002752 // Candidate with network id and/or cost.
2753 sdp = kSdpOneCandidate;
2754 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2755 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2756 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2757 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2758 expected = jcandidate_->candidate();
2759 expected.set_network_id(2);
2760 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2761 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2762 // Add network cost
2763 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2764 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2765 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2766 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2767
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002768 sdp = kSdpTcpActiveCandidate;
2769 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2770 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002771 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002772 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2773 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2774 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002775 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2776 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
Yves Gerey665174f2018-06-19 15:03:05 +02002777 EXPECT_TRUE(
2778 jcandidate.candidate().IsEquivalent(jcandidate_template->candidate()));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002779 sdp = kSdpTcpPassiveCandidate;
2780 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2781 sdp = kSdpTcpSOCandidate;
2782 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002783}
2784
2785// This test verifies the deserialization of candidate-attribute
David Sanders60c588d2022-03-19 01:43:10 -07002786// as per RFC 5245. Candidate-attribute will be of the format
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002787// candidate:<blah>. This format will be used when candidates
2788// are trickled.
2789TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2790 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2791
2792 std::string candidate_attribute = kRawCandidate;
2793 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2794 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2795 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2796 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2797 EXPECT_EQ(2u, jcandidate.candidate().generation());
2798
2799 // Candidate line without generation extension.
2800 candidate_attribute = kRawCandidate;
2801 Replace(" generation 2", "", &candidate_attribute);
2802 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2803 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2804 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2805 Candidate expected = jcandidate_->candidate();
2806 expected.set_generation(0);
2807 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2808
2809 // Candidate line without candidate:
2810 candidate_attribute = kRawCandidate;
2811 Replace("candidate:", "", &candidate_attribute);
2812 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2813
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002814 // Candidate line with IPV6 address.
2815 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
Zach Steinb336c272018-08-09 01:16:13 -07002816
2817 // Candidate line with hostname address.
2818 EXPECT_TRUE(SdpDeserializeCandidate(kRawHostnameCandidate, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002819}
2820
2821// This test verifies that the deserialization of an invalid candidate string
2822// fails.
2823TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
Yves Gerey665174f2018-06-19 15:03:05 +02002824 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002825
2826 std::string candidate_attribute = kRawCandidate;
2827 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002828 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002829
2830 candidate_attribute = kSdpOneCandidate;
2831 candidate_attribute.replace(0, 1, "x");
2832 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2833
2834 candidate_attribute = kRawCandidate;
2835 candidate_attribute.append("\r\n");
2836 candidate_attribute.append(kRawCandidate);
2837 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2838
2839 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002840}
2841
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002842TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002843 bool use_sctpmap = true;
2844 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002845 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002846 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002847
2848 std::string sdp_with_data = kSdpString;
2849 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002850 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002851
Guido Urdanetacecf87f2019-05-31 10:17:38 +00002852 // Verify with UDP/DTLS/SCTP (already in kSdpSctpDataChannelString).
lally@webrtc.org36300852015-02-24 20:19:35 +00002853 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2854 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2855
Guido Urdanetacecf87f2019-05-31 10:17:38 +00002856 // Verify with DTLS/SCTP.
2857 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2858 kDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002859 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2860 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2861
2862 // Verify with TCP/DTLS/SCTP.
Guido Urdanetacecf87f2019-05-31 10:17:38 +00002863 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
Yves Gerey665174f2018-06-19 15:03:05 +02002864 kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002865 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2866 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2867}
2868
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002869TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002870 bool use_sctpmap = false;
2871 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002872 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002873 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002874
2875 std::string sdp_with_data = kSdpString;
2876 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002877 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002878
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002879 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2880 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2881}
2882
lally69f57602015-10-08 10:15:04 -07002883TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002884 bool use_sctpmap = false;
2885 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002886 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002887 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
lally69f57602015-10-08 10:15:04 -07002888
2889 std::string sdp_with_data = kSdpString;
2890 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002891 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 10:15:04 -07002892
lally69f57602015-10-08 10:15:04 -07002893 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2894 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2895}
2896
Philipp Hanckeefc55b02020-06-26 10:17:05 +02002897TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsButWrongMediaType) {
2898 bool use_sctpmap = true;
2899 AddSctpDataChannel(use_sctpmap);
2900 JsepSessionDescription jdesc(kDummyType);
2901 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
2902
2903 std::string sdp = kSdpSessionString;
2904 sdp += kSdpSctpDataChannelString;
2905
2906 const char needle[] = "m=application ";
2907 sdp.replace(sdp.find(needle), strlen(needle), "m=application:bogus ");
2908
2909 JsepSessionDescription jdesc_output(kDummyType);
2910 EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output));
2911
Philipp Hancke4e8c1152020-10-13 12:43:15 +02002912 EXPECT_EQ(1u, jdesc_output.description()->contents().size());
2913 EXPECT_TRUE(jdesc_output.description()->contents()[0].rejected);
Philipp Hanckeefc55b02020-06-26 10:17:05 +02002914}
2915
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002916// Helper function to set the max-message-size parameter in the
2917// SCTP data codec.
2918void MutateJsepSctpMaxMessageSize(const SessionDescription& desc,
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002919 int new_value,
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002920 JsepSessionDescription* jdesc) {
Harald Alvestrand8da35a62019-05-10 09:31:04 +02002921 std::unique_ptr<cricket::SessionDescription> mutant = desc.Clone();
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002922 SctpDataContentDescription* dcdesc =
2923 mutant->GetContentDescriptionByName(kDataContentName)->as_sctp();
2924 dcdesc->set_max_message_size(new_value);
Harald Alvestrand8da35a62019-05-10 09:31:04 +02002925 jdesc->Initialize(std::move(mutant), kSessionId, kSessionVersion);
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002926}
2927
2928TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithMaxMessageSize) {
2929 bool use_sctpmap = false;
2930 AddSctpDataChannel(use_sctpmap);
2931 JsepSessionDescription jdesc(kDummyType);
2932 std::string sdp_with_data = kSdpString;
2933
2934 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
2935 sdp_with_data.append("a=max-message-size:12345\r\n");
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002936 MutateJsepSctpMaxMessageSize(desc_, 12345, &jdesc);
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002937 JsepSessionDescription jdesc_output(kDummyType);
2938
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002939 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2940 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2941}
2942
Harald Alvestrandfbb45bd2019-05-15 08:07:47 +02002943TEST_F(WebRtcSdpTest, SerializeSdpWithSctpDataChannelWithMaxMessageSize) {
2944 bool use_sctpmap = false;
2945 AddSctpDataChannel(use_sctpmap);
2946 JsepSessionDescription jdesc(kDummyType);
2947 MutateJsepSctpMaxMessageSize(desc_, 12345, &jdesc);
2948 std::string message = webrtc::SdpSerialize(jdesc);
2949 EXPECT_NE(std::string::npos,
2950 message.find("\r\na=max-message-size:12345\r\n"));
2951 JsepSessionDescription jdesc_output(kDummyType);
2952 EXPECT_TRUE(SdpDeserialize(message, &jdesc_output));
2953 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2954}
2955
2956TEST_F(WebRtcSdpTest,
2957 SerializeSdpWithSctpDataChannelWithDefaultMaxMessageSize) {
2958 // https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-26#section-6
2959 // The default max message size is 64K.
2960 bool use_sctpmap = false;
2961 AddSctpDataChannel(use_sctpmap);
2962 JsepSessionDescription jdesc(kDummyType);
2963 MutateJsepSctpMaxMessageSize(desc_, 65536, &jdesc);
2964 std::string message = webrtc::SdpSerialize(jdesc);
2965 EXPECT_EQ(std::string::npos, message.find("\r\na=max-message-size:"));
2966 JsepSessionDescription jdesc_output(kDummyType);
2967 EXPECT_TRUE(SdpDeserialize(message, &jdesc_output));
2968 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2969}
2970
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002971// Test to check the behaviour if sctp-port is specified
2972// on the m= line and in a=sctp-port.
2973TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002974 bool use_sctpmap = true;
2975 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002976 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002977 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002978
2979 std::string sdp_with_data = kSdpString;
2980 // Append m= attributes
2981 sdp_with_data.append(kSdpSctpDataChannelString);
2982 // Append a=sctp-port attribute
2983 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 10:27:41 -08002984 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002985
2986 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2987}
2988
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002989// Test behavior if a=rtpmap occurs in an SCTP section.
2990TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpmapAttribute) {
2991 std::string sdp_with_data = kSdpString;
2992 // Append m= attributes
2993 sdp_with_data.append(kSdpSctpDataChannelString);
2994 // Append a=rtpmap attribute
2995 sdp_with_data.append("a=rtpmap:111 opus/48000/2\r\n");
2996 JsepSessionDescription jdesc_output(kDummyType);
2997 // Correct behavior is to ignore the extra attribute.
2998 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2999}
3000
3001TEST_F(WebRtcSdpTest, DeserializeSdpWithStrangeApplicationProtocolNames) {
Harald Alvestrand7af57c62021-04-16 11:12:14 +00003002 static const char* bad_strings[] = {
3003 "DTLS/SCTPRTP/", "obviously-bogus", "UDP/TL/RTSP/SAVPF",
3004 "UDP/TL/RTSP/S", "DTLS/SCTP/RTP/FOO", "obviously-bogus/RTP/"};
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003005 for (auto proto : bad_strings) {
3006 std::string sdp_with_data = kSdpString;
3007 sdp_with_data.append("m=application 9 ");
3008 sdp_with_data.append(proto);
3009 sdp_with_data.append(" 47\r\n");
3010 JsepSessionDescription jdesc_output(kDummyType);
3011 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output))
3012 << "Parsing should have failed on " << proto;
3013 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003014}
3015
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00003016// For crbug/344475.
3017TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
3018 std::string sdp_with_data = kSdpString;
3019 sdp_with_data.append(kSdpSctpDataChannelString);
3020 // Remove the "\n" at the end.
3021 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 10:27:41 -08003022 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00003023
3024 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
3025 // No crash is a pass.
3026}
3027
zstein4b2e0822017-02-17 19:48:38 -08003028TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
3029 bool use_sctpmap = true;
3030 AddSctpDataChannel(use_sctpmap);
3031
3032 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 10:27:41 -08003033 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003034 MutateJsepSctpPort(&jdesc, desc_, kUnusualSctpPort);
wu@webrtc.org78187522013-10-07 23:32:02 +00003035
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00003036 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00003037 std::string sdp_with_data = kSdpString;
3038 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Anton1c9c9fc2019-02-14 15:13:09 -08003039 absl::StrReplaceAll(
3040 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}},
3041 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08003042 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:02 +00003043
3044 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3045 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08003046}
3047
3048TEST_F(WebRtcSdpTest,
3049 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
3050 bool use_sctpmap = false;
3051 AddSctpDataChannel(use_sctpmap);
3052
Steve Antona3a92c22017-12-07 10:27:41 -08003053 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003054 MutateJsepSctpPort(&jdesc, desc_, kUnusualSctpPort);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003055
3056 // We need to test the deserialized JsepSessionDescription from
3057 // kSdpSctpDataChannelStringWithSctpPort for
3058 // draft-ietf-mmusic-sctp-sdp-07
3059 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08003060 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003061 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Anton1c9c9fc2019-02-14 15:13:09 -08003062 absl::StrReplaceAll(
3063 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}},
3064 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08003065 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003066
3067 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3068 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00003069}
3070
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003071TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08003072 bool use_sctpmap = true;
3073 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08003074 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003075 SctpDataContentDescription* dcd = GetFirstSctpDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003076 dcd->set_bandwidth(100 * 1000);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003077 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003078
3079 std::string sdp_with_bandwidth = kSdpString;
3080 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02003081 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003082 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08003083 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003084
3085 // SCTP has congestion control, so we shouldn't limit the bandwidth
3086 // as we do for RTP.
3087 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003088 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
3089}
3090
Yves Gerey665174f2018-06-19 15:03:05 +02003091class WebRtcSdpExtmapTest : public WebRtcSdpTest,
Mirko Bonadei6a489f22019-04-09 15:11:12 +02003092 public ::testing::WithParamInterface<bool> {};
jbauch5869f502017-06-29 12:31:36 -07003093
3094TEST_P(WebRtcSdpExtmapTest,
Yves Gerey665174f2018-06-19 15:03:05 +02003095 DeserializeSessionDescriptionWithSessionLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003096 bool encrypted = GetParam();
3097 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003098}
3099
Yves Gerey665174f2018-06-19 15:03:05 +02003100TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003101 bool encrypted = GetParam();
3102 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003103}
3104
Yves Gerey665174f2018-06-19 15:03:05 +02003105TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithInvalidExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003106 bool encrypted = GetParam();
3107 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003108}
3109
Mirko Bonadeic84f6612019-01-31 12:20:57 +01003110INSTANTIATE_TEST_SUITE_P(Encrypted,
3111 WebRtcSdpExtmapTest,
3112 ::testing::Values(false, true));
jbauch5869f502017-06-29 12:31:36 -07003113
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003114TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 10:27:41 -08003115 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003116 std::string sdp = kSdpFullString;
3117 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
3118 // Deserialize
3119 SdpParseError error;
3120 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
Artem Titovf0a34f22020-03-16 17:52:04 +00003121 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003122 EXPECT_EQ(lastline, error.line);
3123 EXPECT_EQ("Invalid SDP line.", error.description);
3124}
3125
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003126TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
3127 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
3128 std::string new_sdp = kSdpOneCandidate;
3129 Replace("udp", "unsupported_transport", &new_sdp);
3130 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3131 new_sdp = kSdpOneCandidate;
3132 Replace("udp", "uDP", &new_sdp);
3133 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3134 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3135 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3136 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
3137}
3138
honghaiza54a0802015-12-16 18:37:23 -08003139TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003140 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08003141 EXPECT_TRUE(
3142 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003143 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3144 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3145 Candidate ref_candidate = jcandidate_->candidate();
3146 ref_candidate.set_username("user_rtp");
3147 ref_candidate.set_password("password_rtp");
3148 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
3149}
3150
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003151TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08003152 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003153
3154 // Deserialize
3155 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
3156
3157 // Verify
3158 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08003159 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003160 EXPECT_TRUE(audio->conference_mode());
3161
3162 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 15:55:30 -08003163 cricket::GetFirstVideoContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003164 EXPECT_TRUE(video->conference_mode());
3165}
3166
deadbeefd45aea82017-09-16 01:24:29 -07003167TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08003168 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 01:24:29 -07003169
3170 // We tested deserialization already above, so just test that if we serialize
3171 // and deserialize the flag doesn't disappear.
3172 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 12:22:16 -08003173 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 01:24:29 -07003174 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
3175
3176 // Verify.
3177 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08003178 cricket::GetFirstAudioContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 01:24:29 -07003179 EXPECT_TRUE(audio->conference_mode());
3180
3181 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 15:55:30 -08003182 cricket::GetFirstVideoContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 01:24:29 -07003183 EXPECT_TRUE(video->conference_mode());
3184}
3185
Sebastian Jansson97321b62019-07-24 14:01:18 +02003186TEST_F(WebRtcSdpTest, SerializeAndDeserializeRemoteNetEstimate) {
3187 {
3188 // By default remote estimates are disabled.
3189 JsepSessionDescription dst(kDummyType);
3190 SdpDeserialize(webrtc::SdpSerialize(jdesc_), &dst);
3191 EXPECT_FALSE(cricket::GetFirstVideoContentDescription(dst.description())
3192 ->remote_estimate());
3193 }
3194 {
3195 // When remote estimate is enabled, the setting is propagated via SDP.
3196 cricket::GetFirstVideoContentDescription(jdesc_.description())
3197 ->set_remote_estimate(true);
3198 JsepSessionDescription dst(kDummyType);
3199 SdpDeserialize(webrtc::SdpSerialize(jdesc_), &dst);
3200 EXPECT_TRUE(cricket::GetFirstVideoContentDescription(dst.description())
3201 ->remote_estimate());
3202 }
3203}
3204
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003205TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
3206 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003207 const char kSdpEmptyType[] = " =candidate";
3208 const char kSdpEqualAsPlus[] = "a+candidate";
3209 const char kSdpSpaceAfterEqual[] = "a= candidate";
3210 const char kSdpUpperType[] = "A=candidate";
3211 const char kSdpEmptyLine[] = "";
3212 const char kSdpMissingValue[] = "a=";
3213
Yves Gerey665174f2018-06-19 15:03:05 +02003214 const char kSdpBrokenFingerprint[] =
3215 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003216 "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 +02003217 const char kSdpExtraField[] =
3218 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003219 "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 +02003220 const char kSdpMissingSpace[] =
3221 "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003222 "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 +00003223 // MD5 is not allowed in fingerprints.
Yves Gerey665174f2018-06-19 15:03:05 +02003224 const char kSdpMd5[] =
3225 "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003226 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003227
3228 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003229 ExpectParseFailure("v=", kSdpDestroyer);
3230 ExpectParseFailure("o=", kSdpDestroyer);
3231 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003232 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003233 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003234
3235 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003236 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
3237 ExpectParseFailure("m=video", kSdpDestroyer);
Philipp Hanckeefc55b02020-06-26 10:17:05 +02003238 ExpectParseFailure("m=", "c=IN IP4 74.125.224.39");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003239
3240 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003241 ExpectParseFailure("a=candidate", kSdpEmptyType);
3242 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
3243 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
3244 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003245
3246 // Bogus fingerprint replacing a=sendrev. We selected this attribute
3247 // because it's orthogonal to what we are replacing and hence
3248 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003249 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
3250 ExpectParseFailure("a=sendrecv", kSdpExtraField);
3251 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
3252 ExpectParseFailure("a=sendrecv", kSdpMd5);
3253
3254 // Empty Line
3255 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
3256 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003257}
3258
3259TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
3260 // ssrc
3261 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08003262 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
Harald Alvestrand0d018412021-11-04 13:52:31 +00003263 // crypto
3264 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003265 // rtpmap
3266 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
3267 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
3268 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
3269 // candidate
3270 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
3271 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
3272 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
3273 ExpectParseFailure("rport 2346", "rport badvalue");
3274 ExpectParseFailure("rport 2346 generation 2",
3275 "rport 2346 generation badvalue");
3276 // m line
3277 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
3278 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
3279
3280 // bandwidth
3281 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003282 "b=AS:badvalue\r\n", "b=AS:badvalue");
Philipp Hanckefbbfc022020-07-31 08:30:50 +02003283 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", "b=AS\r\n",
3284 "b=AS");
3285 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", "b=AS:\r\n",
3286 "b=AS:");
3287 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3288 "b=AS:12:34\r\n", "b=AS:12:34");
3289
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003290 // rtcp-fb
3291 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3292 "a=rtcp-fb:badvalue nack\r\n",
3293 "a=rtcp-fb:badvalue nack");
3294 // extmap
3295 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3296 "a=extmap:badvalue http://example.com\r\n",
3297 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003298}
3299
3300TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 10:27:41 -08003301 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003302
3303 const char kSdpWithReorderedPlTypesString[] =
3304 "v=0\r\n"
3305 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3306 "s=-\r\n"
3307 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00003308 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
Yves Gerey665174f2018-06-19 15:03:05 +02003309 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
3310 // in the map.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003311 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003312 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003313
3314 // Deserialize
3315 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
3316
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003317 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003318 GetFirstAudioContentDescription(jdesc_output.description());
3319 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003320 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003321 EXPECT_EQ("ISAC", acd->codecs()[0].name);
3322 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003323 EXPECT_EQ(104, acd->codecs()[0].id);
3324}
3325
3326TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 10:27:41 -08003327 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003328 CodecParams params;
3329 params.max_ptime = 40;
3330 params.ptime = 30;
3331 params.min_ptime = 10;
3332 params.sprop_stereo = 1;
3333 params.stereo = 1;
3334 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003335 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003336 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 12:22:16 -08003337 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003338}
3339
3340TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
3341 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 10:27:41 -08003342 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003343 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003344 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003345}
3346
3347TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
3348 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 10:27:41 -08003349 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003350 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003351 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003352}
3353
3354TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 10:27:41 -08003355 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003356
3357 const char kSdpWithFmtpString[] =
3358 "v=0\r\n"
3359 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3360 "s=-\r\n"
3361 "t=0 0\r\n"
3362 "m=video 3457 RTP/SAVPF 120\r\n"
3363 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07003364 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3365
3366 // Deserialize
3367 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07003368 EXPECT_TRUE(
3369 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07003370
Donald Curtis0e07f922015-05-15 09:21:23 -07003371 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003372 GetFirstVideoContentDescription(jdesc_output.description());
3373 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 09:21:23 -07003374 ASSERT_FALSE(vcd->codecs().empty());
3375 cricket::VideoCodec vp8 = vcd->codecs()[0];
3376 EXPECT_EQ("VP8", vp8.name);
3377 EXPECT_EQ(120, vp8.id);
3378 cricket::CodecParameterMap::iterator found =
3379 vp8.params.find("x-google-min-bitrate");
3380 ASSERT_TRUE(found != vp8.params.end());
3381 EXPECT_EQ(found->second, "10");
3382 found = vp8.params.find("x-google-max-quantization");
3383 ASSERT_TRUE(found != vp8.params.end());
3384 EXPECT_EQ(found->second, "40");
3385}
3386
johan2d8d23e2016-06-03 01:22:42 -07003387TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 10:27:41 -08003388 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 01:22:42 -07003389
3390 const char kSdpWithFmtpString[] =
3391 "v=0\r\n"
3392 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3393 "s=-\r\n"
3394 "t=0 0\r\n"
3395 "m=video 49170 RTP/AVP 98\r\n"
3396 "a=rtpmap:98 H264/90000\r\n"
3397 "a=fmtp:98 profile-level-id=42A01E; "
3398 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3399
3400 // Deserialize.
3401 SdpParseError error;
3402 EXPECT_TRUE(
3403 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3404
johan2d8d23e2016-06-03 01:22:42 -07003405 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003406 GetFirstVideoContentDescription(jdesc_output.description());
3407 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 01:22:42 -07003408 ASSERT_FALSE(vcd->codecs().empty());
3409 cricket::VideoCodec h264 = vcd->codecs()[0];
3410 EXPECT_EQ("H264", h264.name);
3411 EXPECT_EQ(98, h264.id);
3412 cricket::CodecParameterMap::const_iterator found =
3413 h264.params.find("profile-level-id");
3414 ASSERT_TRUE(found != h264.params.end());
3415 EXPECT_EQ(found->second, "42A01E");
3416 found = h264.params.find("sprop-parameter-sets");
3417 ASSERT_TRUE(found != h264.params.end());
3418 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3419}
3420
Donald Curtis0e07f922015-05-15 09:21:23 -07003421TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 10:27:41 -08003422 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 09:21:23 -07003423
3424 const char kSdpWithFmtpString[] =
3425 "v=0\r\n"
3426 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3427 "s=-\r\n"
3428 "t=0 0\r\n"
3429 "m=video 3457 RTP/SAVPF 120\r\n"
3430 "a=rtpmap:120 VP8/90000\r\n"
3431 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003432
3433 // Deserialize
3434 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02003435 EXPECT_TRUE(
3436 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003437
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003438 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003439 GetFirstVideoContentDescription(jdesc_output.description());
3440 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003441 ASSERT_FALSE(vcd->codecs().empty());
3442 cricket::VideoCodec vp8 = vcd->codecs()[0];
3443 EXPECT_EQ("VP8", vp8.name);
3444 EXPECT_EQ(120, vp8.id);
3445 cricket::CodecParameterMap::iterator found =
3446 vp8.params.find("x-google-min-bitrate");
3447 ASSERT_TRUE(found != vp8.params.end());
3448 EXPECT_EQ(found->second, "10");
3449 found = vp8.params.find("x-google-max-quantization");
3450 ASSERT_TRUE(found != vp8.params.end());
3451 EXPECT_EQ(found->second, "40");
3452}
3453
Mirta Dvornicic479a3c02019-06-04 15:38:50 +02003454TEST_F(WebRtcSdpTest, DeserializePacketizationAttributeWithIllegalValue) {
3455 JsepSessionDescription jdesc_output(kDummyType);
3456
3457 const char kSdpWithPacketizationString[] =
3458 "v=0\r\n"
3459 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3460 "s=-\r\n"
3461 "t=0 0\r\n"
3462 "m=audio 9 RTP/SAVPF 111\r\n"
3463 "a=rtpmap:111 opus/48000/2\r\n"
3464 "a=packetization:111 unknownpacketizationattributeforaudio\r\n"
3465 "m=video 3457 RTP/SAVPF 120 121 122\r\n"
3466 "a=rtpmap:120 VP8/90000\r\n"
3467 "a=packetization:120 raw\r\n"
3468 "a=rtpmap:121 VP9/90000\r\n"
3469 "a=rtpmap:122 H264/90000\r\n"
3470 "a=packetization:122 unknownpacketizationattributevalue\r\n";
3471
3472 SdpParseError error;
3473 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithPacketizationString, &jdesc_output,
3474 &error));
3475
3476 AudioContentDescription* acd =
3477 GetFirstAudioContentDescription(jdesc_output.description());
3478 ASSERT_TRUE(acd);
3479 ASSERT_THAT(acd->codecs(), testing::SizeIs(1));
3480 cricket::AudioCodec opus = acd->codecs()[0];
3481 EXPECT_EQ(opus.name, "opus");
3482 EXPECT_EQ(opus.id, 111);
3483
3484 const VideoContentDescription* vcd =
3485 GetFirstVideoContentDescription(jdesc_output.description());
3486 ASSERT_TRUE(vcd);
3487 ASSERT_THAT(vcd->codecs(), testing::SizeIs(3));
3488 cricket::VideoCodec vp8 = vcd->codecs()[0];
3489 EXPECT_EQ(vp8.name, "VP8");
3490 EXPECT_EQ(vp8.id, 120);
3491 EXPECT_EQ(vp8.packetization, "raw");
3492 cricket::VideoCodec vp9 = vcd->codecs()[1];
3493 EXPECT_EQ(vp9.name, "VP9");
3494 EXPECT_EQ(vp9.id, 121);
3495 EXPECT_EQ(vp9.packetization, absl::nullopt);
3496 cricket::VideoCodec h264 = vcd->codecs()[2];
3497 EXPECT_EQ(h264.name, "H264");
3498 EXPECT_EQ(h264.id, 122);
3499 EXPECT_EQ(h264.packetization, absl::nullopt);
3500}
3501
ossuaa4b0772017-01-30 07:41:18 -08003502TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003503 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003504
3505 cricket::AudioCodecs codecs = acd->codecs();
3506 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3507 acd->set_codecs(codecs);
3508
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003509 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003510 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003511 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003512 std::string sdp_with_fmtp = kSdpFullString;
3513 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3514 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3515 &sdp_with_fmtp);
3516 EXPECT_EQ(sdp_with_fmtp, message);
3517}
3518
3519TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003520 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003521
3522 cricket::AudioCodecs codecs = acd->codecs();
3523 codecs[0].params["stereo"] = "1";
3524 acd->set_codecs(codecs);
3525
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003526 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003527 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003528 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003529 std::string sdp_with_fmtp = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003530 InjectAfter("a=rtpmap:111 opus/48000/2\r\n", "a=fmtp:111 stereo=1\r\n",
ossuaa4b0772017-01-30 07:41:18 -08003531 &sdp_with_fmtp);
3532 EXPECT_EQ(sdp_with_fmtp, message);
3533}
3534
3535TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003536 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003537
3538 cricket::AudioCodecs codecs = acd->codecs();
3539 codecs[0].params["ptime"] = "20";
3540 codecs[0].params["maxptime"] = "120";
3541 acd->set_codecs(codecs);
3542
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003543 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003544 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003545 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003546 std::string sdp_with_fmtp = kSdpFullString;
3547 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3548 "a=maxptime:120\r\n" // No comma here. String merging!
3549 "a=ptime:20\r\n",
3550 &sdp_with_fmtp);
3551 EXPECT_EQ(sdp_with_fmtp, message);
3552}
3553
Philipp Hanckef2a4ec12020-07-01 21:07:32 +02003554TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithTelephoneEvent) {
3555 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
3556
3557 cricket::AudioCodecs codecs = acd->codecs();
3558 cricket::AudioCodec dtmf(105, "telephone-event", 8000, 0, 1);
3559 dtmf.params[""] = "0-15";
3560 codecs.push_back(dtmf);
3561 acd->set_codecs(codecs);
3562
3563 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
3564 jdesc_.session_version()));
3565 std::string message = webrtc::SdpSerialize(jdesc_);
3566 std::string sdp_with_fmtp = kSdpFullString;
3567 InjectAfter("m=audio 2345 RTP/SAVPF 111 103 104", " 105", &sdp_with_fmtp);
3568 InjectAfter(
3569 "a=rtpmap:104 ISAC/32000\r\n",
3570 "a=rtpmap:105 telephone-event/8000\r\n" // No comma here. String merging!
3571 "a=fmtp:105 0-15\r\n",
3572 &sdp_with_fmtp);
3573 EXPECT_EQ(sdp_with_fmtp, message);
3574}
3575
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003576TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003577 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003578
3579 cricket::VideoCodecs codecs = vcd->codecs();
3580 codecs[0].params["x-google-min-bitrate"] = "10";
3581 vcd->set_codecs(codecs);
3582
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003583 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003584 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003585 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003586 std::string sdp_with_fmtp = kSdpFullString;
3587 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003588 "a=fmtp:120 x-google-min-bitrate=10\r\n", &sdp_with_fmtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003589 EXPECT_EQ(sdp_with_fmtp, message);
3590}
3591
Mirta Dvornicic479a3c02019-06-04 15:38:50 +02003592TEST_F(WebRtcSdpTest, SerializeVideoPacketizationAttribute) {
3593 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
3594
3595 cricket::VideoCodecs codecs = vcd->codecs();
3596 codecs[0].packetization = "raw";
3597 vcd->set_codecs(codecs);
3598
3599 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
3600 jdesc_.session_version()));
3601 std::string message = webrtc::SdpSerialize(jdesc_);
3602 std::string sdp_with_packetization = kSdpFullString;
3603 InjectAfter("a=rtpmap:120 VP8/90000\r\n", "a=packetization:120 raw\r\n",
3604 &sdp_with_packetization);
3605 EXPECT_EQ(sdp_with_packetization, message);
3606}
3607
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003608TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) {
3609 // Deserialize the baseline description, making sure it's ICE full.
Steve Antona3a92c22017-12-07 10:27:41 -08003610 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003611 std::string sdp_with_icelite = kSdpFullString;
3612 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3613 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3614 const cricket::TransportInfo* tinfo1 =
3615 desc->GetTransportInfoByName("audio_content_name");
3616 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3617 const cricket::TransportInfo* tinfo2 =
3618 desc->GetTransportInfoByName("video_content_name");
3619 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003620
3621 // Add "a=ice-lite" and deserialize, making sure it's ICE lite.
Yves Gerey665174f2018-06-19 15:03:05 +02003622 InjectAfter(kSessionTime, "a=ice-lite\r\n", &sdp_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003623 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3624 desc = jdesc_with_icelite.description();
3625 const cricket::TransportInfo* atinfo =
3626 desc->GetTransportInfoByName("audio_content_name");
3627 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3628 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003629 desc->GetTransportInfoByName("video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003630 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003631
3632 // Now that we know deserialization works, we can use TestSerialize to test
3633 // serialization.
3634 TestSerialize(jdesc_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003635}
3636
3637// Verifies that the candidates in the input SDP are parsed and serialized
3638// correctly in the output SDP.
3639TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3640 std::string sdp_with_data = kSdpString;
3641 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 10:27:41 -08003642 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003643
3644 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 12:22:16 -08003645 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003646}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003647
3648TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3649 AddFingerprint();
3650 TransportInfo audio_transport_info =
3651 *(desc_.GetTransportInfoByName(kAudioContentName));
3652 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3653 audio_transport_info.description.connection_role);
3654 audio_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003655 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003656
3657 TransportInfo video_transport_info =
3658 *(desc_.GetTransportInfoByName(kVideoContentName));
3659 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3660 video_transport_info.description.connection_role);
3661 video_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003662 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003663
3664 desc_.RemoveTransportInfoByName(kAudioContentName);
3665 desc_.RemoveTransportInfoByName(kVideoContentName);
3666
3667 desc_.AddTransportInfo(audio_transport_info);
3668 desc_.AddTransportInfo(video_transport_info);
3669
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003670 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003671 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003672 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003673 std::string sdp_with_dtlssetup = kSdpFullString;
3674
3675 // Fingerprint attribute is necessary to add DTLS setup attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003676 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_dtlssetup);
3677 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_dtlssetup);
Artem Titov880fa812021-07-30 22:30:23 +02003678 // Now adding `setup` attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003679 InjectAfter(kFingerprint, "a=setup:active\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003680 EXPECT_EQ(sdp_with_dtlssetup, message);
3681}
3682
Harald Alvestrandefece422021-08-19 09:12:51 +00003683TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttributeActpass) {
Steve Antona3a92c22017-12-07 10:27:41 -08003684 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003685 std::string sdp_with_dtlssetup = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003686 InjectAfter(kSessionTime, "a=setup:actpass\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003687 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3688 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3689 const cricket::TransportInfo* atinfo =
3690 desc->GetTransportInfoByName("audio_content_name");
3691 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3692 atinfo->description.connection_role);
3693 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003694 desc->GetTransportInfoByName("video_content_name");
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003695 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3696 vtinfo->description.connection_role);
3697}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003698
Harald Alvestrandefece422021-08-19 09:12:51 +00003699TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttributeActive) {
3700 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
3701 std::string sdp_with_dtlssetup = kSdpFullString;
3702 InjectAfter(kSessionTime, "a=setup:active\r\n", &sdp_with_dtlssetup);
3703 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3704 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3705 const cricket::TransportInfo* atinfo =
3706 desc->GetTransportInfoByName("audio_content_name");
3707 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
3708 atinfo->description.connection_role);
3709 const cricket::TransportInfo* vtinfo =
3710 desc->GetTransportInfoByName("video_content_name");
3711 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
3712 vtinfo->description.connection_role);
3713}
3714TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttributePassive) {
3715 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
3716 std::string sdp_with_dtlssetup = kSdpFullString;
3717 InjectAfter(kSessionTime, "a=setup:passive\r\n", &sdp_with_dtlssetup);
3718 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3719 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3720 const cricket::TransportInfo* atinfo =
3721 desc->GetTransportInfoByName("audio_content_name");
3722 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
3723 atinfo->description.connection_role);
3724 const cricket::TransportInfo* vtinfo =
3725 desc->GetTransportInfoByName("video_content_name");
3726 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
3727 vtinfo->description.connection_role);
3728}
3729
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003730// Verifies that the order of the serialized m-lines follows the order of the
3731// ContentInfo in SessionDescription, and vise versa for deserialization.
3732TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 10:27:41 -08003733 JsepSessionDescription jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02003734 const std::string media_content_sdps[3] = {kSdpAudioString, kSdpVideoString,
3735 kSdpSctpDataChannelString};
3736 const cricket::MediaType media_types[3] = {cricket::MEDIA_TYPE_AUDIO,
3737 cricket::MEDIA_TYPE_VIDEO,
3738 cricket::MEDIA_TYPE_DATA};
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003739
3740 // Verifies all 6 permutations.
3741 for (size_t i = 0; i < 6; ++i) {
3742 size_t media_content_in_sdp[3];
3743 // The index of the first media content.
3744 media_content_in_sdp[0] = i / 2;
3745 // The index of the second media content.
3746 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3747 // The index of the third media content.
3748 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3749
3750 std::string sdp_string = kSdpSessionString;
3751 for (size_t i = 0; i < 3; ++i)
3752 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3753
3754 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3755 cricket::SessionDescription* desc = jdesc.description();
3756 EXPECT_EQ(3u, desc->contents().size());
3757
3758 for (size_t i = 0; i < 3; ++i) {
3759 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 15:14:30 -08003760 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003761 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3762 }
3763
Steve Antone831b8c2018-02-01 12:22:16 -08003764 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003765 EXPECT_EQ(sdp_string, serialized_sdp);
3766 }
3767}
deadbeef9d3584c2016-02-16 17:54:10 -08003768
deadbeef25ed4352016-12-12 18:37:36 -08003769TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3770 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 10:27:41 -08003771 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003772 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003773 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3774 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3775}
3776
deadbeef12771a12017-01-03 13:53:47 -08003777// The semantics of "a=bundle-only" are only defined when it's used in
3778// combination with a 0 port on the m= line. We should ignore it if used with a
3779// nonzero port.
3780TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3781 // Make the base bundle-only description but unset the bundle-only flag.
3782 MakeBundleOnlyDescription();
3783 jdesc_.description()->contents()[1].bundle_only = false;
3784
3785 std::string modified_sdp = kBundleOnlySdpFullString;
3786 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08003787 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003788 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3789 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003790}
3791
3792TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3793 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003794 TestSerialize(jdesc_);
deadbeef25ed4352016-12-12 18:37:36 -08003795}
3796
deadbeef9d3584c2016-02-16 17:54:10 -08003797TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3798 MakePlanBDescription();
3799
Steve Antona3a92c22017-12-07 10:27:41 -08003800 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003801 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3802
3803 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3804}
3805
3806TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3807 MakePlanBDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003808 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-16 17:54:10 -08003809}
3810
3811TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3812 MakeUnifiedPlanDescription();
3813
Steve Antona3a92c22017-12-07 10:27:41 -08003814 JsepSessionDescription deserialized_description(kDummyType);
Harald Alvestrand0d018412021-11-04 13:52:31 +00003815 EXPECT_TRUE(
deadbeef9d3584c2016-02-16 17:54:10 -08003816 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3817
3818 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3819}
3820
3821TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3822 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003823 TestSerialize(jdesc_);
3824}
3825
Seth Hampson5b4f0752018-04-02 16:31:36 -07003826// This tests deserializing a Unified Plan SDP that is compatible with both
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003827// Unified Plan and Plan B style SDP, meaning that it contains both "a=ssrc
3828// msid" lines and "a=msid " lines. It tests the case for audio/video tracks
Seth Hampson5b4f0752018-04-02 16:31:36 -07003829// with no stream ids and multiple stream ids. For parsing this, the Unified
3830// Plan a=msid lines should take priority, because the Plan B style a=ssrc msid
3831// lines do not support multiple stream ids and no stream ids.
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003832TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionSpecialMsid) {
3833 // Create both msid lines for Plan B and Unified Plan support.
3834 MakeUnifiedPlanDescriptionMultipleStreamIds(
3835 cricket::kMsidSignalingMediaSection |
3836 cricket::kMsidSignalingSsrcAttribute);
Seth Hampson5b4f0752018-04-02 16:31:36 -07003837
3838 JsepSessionDescription deserialized_description(kDummyType);
3839 EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid,
3840 &deserialized_description));
3841
3842 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
Henrik Boström5b147782018-12-04 11:25:05 +01003843 EXPECT_EQ(cricket::kMsidSignalingMediaSection |
3844 cricket::kMsidSignalingSsrcAttribute,
3845 deserialized_description.description()->msid_signaling());
Seth Hampson5b4f0752018-04-02 16:31:36 -07003846}
3847
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003848// Tests the serialization of a Unified Plan SDP that is compatible for both
3849// Unified Plan and Plan B style SDPs, meaning that it contains both "a=ssrc
3850// msid" lines and "a=msid " lines. It tests the case for no stream ids and
3851// multiple stream ids.
3852TEST_F(WebRtcSdpTest, SerializeSessionDescriptionSpecialMsid) {
3853 // Create both msid lines for Plan B and Unified Plan support.
3854 MakeUnifiedPlanDescriptionMultipleStreamIds(
3855 cricket::kMsidSignalingMediaSection |
3856 cricket::kMsidSignalingSsrcAttribute);
3857 std::string serialized_sdp = webrtc::SdpSerialize(jdesc_);
3858 // We explicitly test that the serialized SDP string is equal to the hard
3859 // coded SDP string. This is necessary, because in the parser "a=msid" lines
3860 // take priority over "a=ssrc msid" lines. This means if we just used
3861 // TestSerialize(), it could serialize an SDP that omits "a=ssrc msid" lines,
3862 // and still pass, because the deserialized version would be the same.
3863 EXPECT_EQ(kUnifiedPlanSdpFullStringWithSpecialMsid, serialized_sdp);
3864}
3865
3866// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3867// that signal stream IDs) is deserialized appropriately. It tests the case for
3868// no stream ids and multiple stream ids.
3869TEST_F(WebRtcSdpTest, UnifiedPlanDeserializeSessionDescriptionSpecialMsid) {
3870 // Only create a=msid lines for strictly Unified Plan stream ID support.
3871 MakeUnifiedPlanDescriptionMultipleStreamIds(
3872 cricket::kMsidSignalingMediaSection);
3873
3874 JsepSessionDescription deserialized_description(kDummyType);
3875 std::string unified_plan_sdp_string =
3876 kUnifiedPlanSdpFullStringWithSpecialMsid;
3877 RemoveSsrcMsidLinesFromSdpString(&unified_plan_sdp_string);
3878 EXPECT_TRUE(
3879 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3880
3881 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3882}
3883
3884// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3885// that signal stream IDs) is serialized appropriately. It tests the case for no
3886// stream ids and multiple stream ids.
3887TEST_F(WebRtcSdpTest, UnifiedPlanSerializeSessionDescriptionSpecialMsid) {
3888 // Only create a=msid lines for strictly Unified Plan stream ID support.
3889 MakeUnifiedPlanDescriptionMultipleStreamIds(
3890 cricket::kMsidSignalingMediaSection);
3891
Seth Hampson5b4f0752018-04-02 16:31:36 -07003892 TestSerialize(jdesc_);
3893}
3894
Seth Hampson5897a6e2018-04-03 11:16:33 -07003895// This tests that a Unified Plan SDP with no a=ssrc lines is
3896// serialized/deserialized appropriately. In this case the
3897// MediaContentDescription will contain a StreamParams object that doesn't have
3898// any SSRCs. Vice versa, this will be created upon deserializing an SDP with no
3899// SSRC lines.
3900TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3901 MakeUnifiedPlanDescription();
3902 RemoveSsrcSignalingFromStreamParams();
3903 std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString;
3904 RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string);
3905
3906 JsepSessionDescription deserialized_description(kDummyType);
3907 EXPECT_TRUE(
3908 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3909 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3910}
3911
3912TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3913 MakeUnifiedPlanDescription();
3914 RemoveSsrcSignalingFromStreamParams();
3915
3916 TestSerialize(jdesc_);
3917}
3918
Steve Antone831b8c2018-02-01 12:22:16 -08003919TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
3920 JsepSessionDescription jsep_desc(kDummyType);
3921 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
3922 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3923}
3924
3925TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
3926 JsepSessionDescription jsep_desc(kDummyType);
3927 std::string sdp = kSdpSessionString;
3928 sdp += kSdpSctpDataChannelString;
3929 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3930 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3931}
3932
3933TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
3934 JsepSessionDescription jsep_desc(kDummyType);
3935 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
3936 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
3937 jsep_desc.description()->msid_signaling());
3938}
3939
3940TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
3941 JsepSessionDescription jsep_desc(kDummyType);
3942 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
3943 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
3944 jsep_desc.description()->msid_signaling());
3945}
3946
3947const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
3948const char kSsrcAttributeMsidLine[] =
3949 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
3950
3951TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
3952 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
3953 std::string sdp = webrtc::SdpSerialize(jdesc_);
3954
3955 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3956 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3957}
3958
3959TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
3960 jdesc_.description()->set_msid_signaling(
3961 cricket::kMsidSignalingSsrcAttribute);
3962 std::string sdp = webrtc::SdpSerialize(jdesc_);
3963
3964 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
3965 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3966}
3967
3968TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
3969 jdesc_.description()->set_msid_signaling(
3970 cricket::kMsidSignalingMediaSection |
3971 cricket::kMsidSignalingSsrcAttribute);
3972 std::string sdp = webrtc::SdpSerialize(jdesc_);
3973
3974 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3975 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-16 17:54:10 -08003976}
deadbeef7e146cb2016-09-28 10:04:34 -07003977
deadbeefb2362572016-12-13 16:37:06 -08003978// Regression test for integer overflow bug:
3979// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3980TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003981 // Bandwidth attribute is the max signed 32-bit int, which will get
3982 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003983 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003984 "v=0\r\n"
3985 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3986 "s=-\r\n"
3987 "t=0 0\r\n"
3988 "m=video 3457 RTP/SAVPF 120\r\n"
3989 "b=AS:2147483647\r\n"
3990 "foo=fail\r\n";
3991
3992 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3993}
deadbeef7bcdb692017-01-20 12:43:58 -08003994
deadbeefbc88c6b2017-08-02 11:26:34 -07003995// Similar to the above, except that negative values are illegal, not just
3996// error-prone as large values are.
3997// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3998TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3999 static const char kSdpWithNegativeBandwidth[] =
4000 "v=0\r\n"
4001 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4002 "s=-\r\n"
4003 "t=0 0\r\n"
4004 "m=video 3457 RTP/SAVPF 120\r\n"
4005 "b=AS:-1000\r\n";
4006
4007 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
4008}
4009
deadbeef3e8016e2017-08-03 17:49:30 -07004010// An exception to the above rule: a value of -1 for b=AS should just be
4011// ignored, resulting in "kAutoBandwidth" in the deserialized object.
4012// Applications historically may be using "b=AS:-1" to mean "no bandwidth
4013// limit", but this is now what ommitting the attribute entirely will do, so
4014// ignoring it will have the intended effect.
4015TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
4016 static const char kSdpWithBandwidthOfNegativeOne[] =
4017 "v=0\r\n"
4018 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4019 "s=-\r\n"
4020 "t=0 0\r\n"
4021 "m=video 3457 RTP/SAVPF 120\r\n"
4022 "b=AS:-1\r\n";
4023
Steve Antona3a92c22017-12-07 10:27:41 -08004024 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-03 17:49:30 -07004025 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-03 17:49:30 -07004026 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08004027 GetFirstVideoContentDescription(jdesc_output.description());
4028 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-03 17:49:30 -07004029 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
4030}
4031
deadbeef7bcdb692017-01-20 12:43:58 -08004032// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
4033// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
4034// Regression test for:
4035// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
4036TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
4037 // Important piece is "ufrag foo pwd bar".
4038 static const char kSdpWithIceCredentialsInCandidateString[] =
4039 "v=0\r\n"
4040 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4041 "s=-\r\n"
4042 "t=0 0\r\n"
4043 "m=audio 9 RTP/SAVPF 111\r\n"
4044 "c=IN IP4 0.0.0.0\r\n"
4045 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4046 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4047 "a=rtpmap:111 opus/48000/2\r\n"
4048 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
4049 "generation 2 ufrag foo pwd bar\r\n";
4050
Steve Antona3a92c22017-12-07 10:27:41 -08004051 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 12:43:58 -08004052 EXPECT_TRUE(
4053 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
4054 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
4055 ASSERT_NE(nullptr, candidates);
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02004056 ASSERT_EQ(1U, candidates->count());
deadbeef7bcdb692017-01-20 12:43:58 -08004057 cricket::Candidate c = candidates->at(0)->candidate();
4058 EXPECT_EQ("ufrag_voice", c.username());
4059 EXPECT_EQ("pwd_voice", c.password());
4060}
deadbeef90f1e1e2017-02-10 12:35:05 -08004061
Johannes Kron211856b2018-09-06 12:12:28 +02004062// Test that attribute lines "a=ice-ufrag-something"/"a=ice-pwd-something" are
4063// ignored, and only the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
4064// Regression test for:
4065// https://bugs.chromium.org/p/webrtc/issues/detail?id=9712
4066TEST_F(WebRtcSdpTest, AttributeWithPartialMatchingNameIsIgnored) {
4067 static const char kSdpWithFooIceCredentials[] =
4068 "v=0\r\n"
4069 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4070 "s=-\r\n"
4071 "t=0 0\r\n"
4072 "m=audio 9 RTP/SAVPF 111\r\n"
4073 "c=IN IP4 0.0.0.0\r\n"
4074 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4075 "a=ice-ufrag-something:foo\r\na=ice-pwd-something:bar\r\n"
4076 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4077 "a=rtpmap:111 opus/48000/2\r\n"
4078 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
4079 "generation 2\r\n";
4080
4081 JsepSessionDescription jdesc_output(kDummyType);
4082 EXPECT_TRUE(SdpDeserialize(kSdpWithFooIceCredentials, &jdesc_output));
4083 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
4084 ASSERT_NE(nullptr, candidates);
4085 ASSERT_EQ(1U, candidates->count());
4086 cricket::Candidate c = candidates->at(0)->candidate();
4087 EXPECT_EQ("ufrag_voice", c.username());
4088 EXPECT_EQ("pwd_voice", c.password());
4089}
4090
deadbeef90f1e1e2017-02-10 12:35:05 -08004091// Test that SDP with an invalid port number in "a=candidate" lines is
4092// rejected, without crashing.
4093// Regression test for:
4094// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
4095TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
4096 static const char kSdpWithInvalidCandidatePort[] =
4097 "v=0\r\n"
4098 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4099 "s=-\r\n"
4100 "t=0 0\r\n"
4101 "m=audio 9 RTP/SAVPF 111\r\n"
4102 "c=IN IP4 0.0.0.0\r\n"
4103 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4104 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4105 "a=rtpmap:111 opus/48000/2\r\n"
4106 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
4107 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
4108
Steve Antona3a92c22017-12-07 10:27:41 -08004109 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 12:35:05 -08004110 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
4111}
deadbeefa4549d62017-02-10 17:26:22 -08004112
4113// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
4114// Regression test for:
4115// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
4116TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
4117 static const char kSdpWithMissingTrackId[] =
4118 "v=0\r\n"
4119 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4120 "s=-\r\n"
4121 "t=0 0\r\n"
4122 "m=audio 9 RTP/SAVPF 111\r\n"
4123 "c=IN IP4 0.0.0.0\r\n"
4124 "a=rtpmap:111 opus/48000/2\r\n"
4125 "a=msid:stream_id \r\n";
4126
Steve Antona3a92c22017-12-07 10:27:41 -08004127 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08004128 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
4129}
4130
4131TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
4132 static const char kSdpWithMissingStreamId[] =
4133 "v=0\r\n"
4134 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4135 "s=-\r\n"
4136 "t=0 0\r\n"
4137 "m=audio 9 RTP/SAVPF 111\r\n"
4138 "c=IN IP4 0.0.0.0\r\n"
4139 "a=rtpmap:111 opus/48000/2\r\n"
4140 "a=msid: track_id\r\n";
4141
Steve Antona3a92c22017-12-07 10:27:41 -08004142 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08004143 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
4144}
zhihuang38989e52017-03-21 11:04:53 -07004145
4146// Tests that if both session-level address and media-level address exist, use
4147// the media-level address.
4148TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 10:27:41 -08004149 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004150
4151 // Sesssion-level address.
4152 std::string sdp = kSdpFullString;
4153 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
4154 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4155
4156 const auto& content1 = jsep_desc.description()->contents()[0];
4157 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 15:14:30 -08004158 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004159 const auto& content2 = jsep_desc.description()->contents()[1];
4160 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 15:14:30 -08004161 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004162}
4163
4164// Tests that the session-level connection address will be used if the media
4165// level-addresses are not specified.
4166TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 10:27:41 -08004167 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004168
4169 // Sesssion-level address.
4170 std::string sdp = kSdpString;
4171 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
4172 // Remove the media level addresses.
4173 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
4174 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
4175 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4176
4177 const auto& content1 = jsep_desc.description()->contents()[0];
4178 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004179 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004180 const auto& content2 = jsep_desc.description()->contents()[1];
4181 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004182 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004183}
4184
4185TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 10:27:41 -08004186 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004187
4188 std::string sdp = kSdpString;
4189 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4190 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
4191 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
4192 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
4193 &sdp);
4194 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
4195 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
4196 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
4197 &sdp);
4198 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4199 const auto& content1 = jsep_desc.description()->contents()[0];
4200 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004201 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004202 const auto& content2 = jsep_desc.description()->contents()[1];
4203 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004204 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004205}
4206
Qingsi Wang56991422019-02-08 12:53:06 -08004207// Test that a c= line that contains a hostname connection address can be
4208// parsed.
4209TEST_F(WebRtcSdpTest, ParseConnectionDataWithHostnameConnectionAddress) {
4210 JsepSessionDescription jsep_desc(kDummyType);
4211 std::string sdp = kSdpString;
4212 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4213
4214 sdp = kSdpString;
4215 Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp);
4216 Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp);
4217 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4218
4219 ASSERT_NE(nullptr, jsep_desc.description());
4220 const auto& content1 = jsep_desc.description()->contents()[0];
4221 EXPECT_EQ("example.local:9",
4222 content1.media_description()->connection_address().ToString());
4223 const auto& content2 = jsep_desc.description()->contents()[1];
4224 EXPECT_EQ("example.local:9",
4225 content2.media_description()->connection_address().ToString());
4226}
4227
4228// Test that the invalid or unsupported connection data cannot be parsed.
zhihuang38989e52017-03-21 11:04:53 -07004229TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 10:27:41 -08004230 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004231 std::string sdp = kSdpString;
4232 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4233
4234 // Unsupported multicast IPv4 address.
4235 sdp = kSdpFullString;
4236 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
4237 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4238
4239 // Unsupported multicast IPv6 address.
4240 sdp = kSdpFullString;
4241 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
4242 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4243
4244 // Mismatched address type.
4245 sdp = kSdpFullString;
4246 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
4247 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4248
4249 sdp = kSdpFullString;
4250 Replace("c=IN IP4 74.125.224.39\r\n",
4251 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
4252 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4253}
4254
4255TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 10:27:41 -08004256 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004257 MakeDescriptionWithoutCandidates(&expected_jsep);
4258 // Serialization.
Steve Antone831b8c2018-02-01 12:22:16 -08004259 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 11:04:53 -07004260 // Deserialization.
Steve Antona3a92c22017-12-07 10:27:41 -08004261 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004262 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 15:14:30 -08004263 auto audio_desc = jdesc.description()
4264 ->GetContentByName(kAudioContentName)
4265 ->media_description();
4266 auto video_desc = jdesc.description()
4267 ->GetContentByName(kVideoContentName)
4268 ->media_description();
zhihuang38989e52017-03-21 11:04:53 -07004269 EXPECT_EQ(audio_desc_->connection_address().ToString(),
4270 audio_desc->connection_address().ToString());
4271 EXPECT_EQ(video_desc_->connection_address().ToString(),
4272 video_desc->connection_address().ToString());
4273}
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07004274
4275// RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be
4276// used (i.e., a single space as the session name)." So we should accept that.
4277TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) {
4278 JsepSessionDescription jsep_desc(kDummyType);
4279 std::string sdp = kSdpString;
4280 Replace("s=-\r\n", "s= \r\n", &sdp);
4281 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4282}
Amit Hilbucha2012042018-12-03 11:35:05 -08004283
4284// Simulcast malformed input test for invalid format.
4285TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_EmptyAttribute) {
Artem Titovf0a34f22020-03-16 17:52:04 +00004286 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
4287 "a=simulcast:\r\n", "a=simulcast:");
Amit Hilbucha2012042018-12-03 11:35:05 -08004288}
4289
4290// Tests that duplicate simulcast entries in the SDP triggers a parse failure.
4291TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_DuplicateAttribute) {
Artem Titovf0a34f22020-03-16 17:52:04 +00004292 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
4293 "a=simulcast:send 1\r\na=simulcast:recv 2\r\n",
4294 "a=simulcast:");
Amit Hilbucha2012042018-12-03 11:35:05 -08004295}
4296
4297// Validates that deserialization uses the a=simulcast: attribute
4298TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttribute) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004299 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4300 sdp += "a=rid:1 send\r\n";
4301 sdp += "a=rid:2 send\r\n";
4302 sdp += "a=rid:3 send\r\n";
4303 sdp += "a=rid:4 recv\r\n";
4304 sdp += "a=rid:5 recv\r\n";
4305 sdp += "a=rid:6 recv\r\n";
Amit Hilbucha2012042018-12-03 11:35:05 -08004306 sdp += "a=simulcast:send 1,2;3 recv 4;5;6\r\n";
4307 JsepSessionDescription output(kDummyType);
4308 SdpParseError error;
4309 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4310 const cricket::ContentInfos& contents = output.description()->contents();
4311 const cricket::MediaContentDescription* media =
4312 contents.back().media_description();
4313 EXPECT_TRUE(media->HasSimulcast());
4314 EXPECT_EQ(2ul, media->simulcast_description().send_layers().size());
4315 EXPECT_EQ(3ul, media->simulcast_description().receive_layers().size());
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004316 EXPECT_FALSE(media->streams().empty());
4317 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4318 CompareRidDescriptionIds(rids, {"1", "2", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004319}
4320
4321// Validates that deserialization removes rids that do not appear in SDP
4322TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttributeRemovesUnknownRids) {
4323 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4324 sdp += "a=rid:1 send\r\n";
4325 sdp += "a=rid:3 send\r\n";
4326 sdp += "a=rid:4 recv\r\n";
4327 sdp += "a=simulcast:send 1,2;3 recv 4;5,6\r\n";
4328 JsepSessionDescription output(kDummyType);
4329 SdpParseError error;
4330 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4331 const cricket::ContentInfos& contents = output.description()->contents();
4332 const cricket::MediaContentDescription* media =
4333 contents.back().media_description();
4334 EXPECT_TRUE(media->HasSimulcast());
4335 const SimulcastDescription& simulcast = media->simulcast_description();
4336 EXPECT_EQ(2ul, simulcast.send_layers().size());
4337 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4338
4339 std::vector<SimulcastLayer> all_send_layers =
4340 simulcast.send_layers().GetAllLayers();
4341 EXPECT_EQ(2ul, all_send_layers.size());
Steve Anton64b626b2019-01-28 17:25:26 -08004342 EXPECT_EQ(0,
4343 absl::c_count_if(all_send_layers, [](const SimulcastLayer& layer) {
4344 return layer.rid == "2";
4345 }));
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004346
4347 std::vector<SimulcastLayer> all_receive_layers =
4348 simulcast.receive_layers().GetAllLayers();
4349 ASSERT_EQ(1ul, all_receive_layers.size());
4350 EXPECT_EQ("4", all_receive_layers[0].rid);
4351
4352 EXPECT_FALSE(media->streams().empty());
4353 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4354 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004355}
4356
4357// Validates that Simulcast removes rids that appear in both send and receive.
4358TEST_F(WebRtcSdpTest,
4359 TestDeserializeSimulcastAttributeRemovesDuplicateSendReceive) {
4360 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4361 sdp += "a=rid:1 send\r\n";
4362 sdp += "a=rid:2 send\r\n";
4363 sdp += "a=rid:3 send\r\n";
4364 sdp += "a=rid:4 recv\r\n";
4365 sdp += "a=simulcast:send 1;2;3 recv 2;4\r\n";
4366 JsepSessionDescription output(kDummyType);
4367 SdpParseError error;
4368 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4369 const cricket::ContentInfos& contents = output.description()->contents();
4370 const cricket::MediaContentDescription* media =
4371 contents.back().media_description();
4372 EXPECT_TRUE(media->HasSimulcast());
4373 const SimulcastDescription& simulcast = media->simulcast_description();
4374 EXPECT_EQ(2ul, simulcast.send_layers().size());
4375 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4376 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4377 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4378
4379 EXPECT_FALSE(media->streams().empty());
4380 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4381 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004382}
4383
4384// Ignores empty rid line.
4385TEST_F(WebRtcSdpTest, TestDeserializeIgnoresEmptyRidLines) {
4386 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4387 sdp += "a=rid:1 send\r\n";
4388 sdp += "a=rid:2 send\r\n";
4389 sdp += "a=rid\r\n"; // Should ignore this line.
4390 sdp += "a=rid:\r\n"; // Should ignore this line.
4391 sdp += "a=simulcast:send 1;2\r\n";
4392 JsepSessionDescription output(kDummyType);
4393 SdpParseError error;
4394 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4395 const cricket::ContentInfos& contents = output.description()->contents();
4396 const cricket::MediaContentDescription* media =
4397 contents.back().media_description();
4398 EXPECT_TRUE(media->HasSimulcast());
4399 const SimulcastDescription& simulcast = media->simulcast_description();
4400 EXPECT_TRUE(simulcast.receive_layers().empty());
4401 EXPECT_EQ(2ul, simulcast.send_layers().size());
4402 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4403
4404 EXPECT_FALSE(media->streams().empty());
4405 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4406 CompareRidDescriptionIds(rids, {"1", "2"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004407}
4408
4409// Ignores malformed rid lines.
4410TEST_F(WebRtcSdpTest, TestDeserializeIgnoresMalformedRidLines) {
4411 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4412 sdp += "a=rid:1 send pt=\r\n"; // Should ignore this line.
4413 sdp += "a=rid:2 receive\r\n"; // Should ignore this line.
4414 sdp += "a=rid:3 max-width=720;pt=120\r\n"; // Should ignore this line.
4415 sdp += "a=rid:4\r\n"; // Should ignore this line.
4416 sdp += "a=rid:5 send\r\n";
4417 sdp += "a=simulcast:send 1,2,3;4,5\r\n";
4418 JsepSessionDescription output(kDummyType);
4419 SdpParseError error;
4420 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4421 const cricket::ContentInfos& contents = output.description()->contents();
4422 const cricket::MediaContentDescription* media =
4423 contents.back().media_description();
4424 EXPECT_TRUE(media->HasSimulcast());
4425 const SimulcastDescription& simulcast = media->simulcast_description();
4426 EXPECT_TRUE(simulcast.receive_layers().empty());
4427 EXPECT_EQ(1ul, simulcast.send_layers().size());
4428 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4429
4430 EXPECT_FALSE(media->streams().empty());
4431 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4432 CompareRidDescriptionIds(rids, {"5"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004433}
4434
4435// Removes RIDs that specify a different format than the m= section.
4436TEST_F(WebRtcSdpTest, TestDeserializeRemovesRidsWithInvalidCodec) {
4437 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4438 sdp += "a=rid:1 send pt=121,120\r\n"; // Should remove 121 and keep RID.
4439 sdp += "a=rid:2 send pt=121\r\n"; // Should remove RID altogether.
4440 sdp += "a=simulcast:send 1;2\r\n";
4441 JsepSessionDescription output(kDummyType);
4442 SdpParseError error;
4443 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4444 const cricket::ContentInfos& contents = output.description()->contents();
4445 const cricket::MediaContentDescription* media =
4446 contents.back().media_description();
4447 EXPECT_TRUE(media->HasSimulcast());
4448 const SimulcastDescription& simulcast = media->simulcast_description();
4449 EXPECT_TRUE(simulcast.receive_layers().empty());
4450 EXPECT_EQ(1ul, simulcast.send_layers().size());
4451 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4452 EXPECT_EQ("1", simulcast.send_layers()[0][0].rid);
4453 EXPECT_EQ(1ul, media->streams().size());
4454 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4455 EXPECT_EQ(1ul, rids.size());
4456 EXPECT_EQ("1", rids[0].rid);
4457 EXPECT_EQ(1ul, rids[0].payload_types.size());
4458 EXPECT_EQ(120, rids[0].payload_types[0]);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004459}
4460
4461// Ignores duplicate rid lines
4462TEST_F(WebRtcSdpTest, TestDeserializeIgnoresDuplicateRidLines) {
4463 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4464 sdp += "a=rid:1 send\r\n";
4465 sdp += "a=rid:2 send\r\n";
4466 sdp += "a=rid:2 send\r\n";
4467 sdp += "a=rid:3 send\r\n";
4468 sdp += "a=rid:4 recv\r\n";
4469 sdp += "a=simulcast:send 1,2;3 recv 4\r\n";
4470 JsepSessionDescription output(kDummyType);
4471 SdpParseError error;
4472 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4473 const cricket::ContentInfos& contents = output.description()->contents();
4474 const cricket::MediaContentDescription* media =
4475 contents.back().media_description();
4476 EXPECT_TRUE(media->HasSimulcast());
4477 const SimulcastDescription& simulcast = media->simulcast_description();
4478 EXPECT_EQ(2ul, simulcast.send_layers().size());
4479 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4480 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4481 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4482
4483 EXPECT_FALSE(media->streams().empty());
4484 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4485 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbucha2012042018-12-03 11:35:05 -08004486}
4487
Florent Castellic4421972019-07-02 20:27:42 +02004488TEST_F(WebRtcSdpTest, TestDeserializeRidSendDirection) {
4489 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4490 sdp += "a=rid:1 recv\r\n";
4491 sdp += "a=rid:2 recv\r\n";
4492 sdp += "a=simulcast:send 1;2\r\n";
4493 JsepSessionDescription output(kDummyType);
4494 SdpParseError error;
4495 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4496 const cricket::ContentInfos& contents = output.description()->contents();
4497 const cricket::MediaContentDescription* media =
4498 contents.back().media_description();
4499 EXPECT_FALSE(media->HasSimulcast());
4500}
4501
4502TEST_F(WebRtcSdpTest, TestDeserializeRidRecvDirection) {
4503 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4504 sdp += "a=rid:1 send\r\n";
4505 sdp += "a=rid:2 send\r\n";
4506 sdp += "a=simulcast:recv 1;2\r\n";
4507 JsepSessionDescription output(kDummyType);
4508 SdpParseError error;
4509 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4510 const cricket::ContentInfos& contents = output.description()->contents();
4511 const cricket::MediaContentDescription* media =
4512 contents.back().media_description();
4513 EXPECT_FALSE(media->HasSimulcast());
4514}
4515
4516TEST_F(WebRtcSdpTest, TestDeserializeIgnoresWrongRidDirectionLines) {
4517 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4518 sdp += "a=rid:1 send\r\n";
4519 sdp += "a=rid:2 send\r\n";
4520 sdp += "a=rid:3 send\r\n";
4521 sdp += "a=rid:4 recv\r\n";
4522 sdp += "a=rid:5 recv\r\n";
4523 sdp += "a=rid:6 recv\r\n";
4524 sdp += "a=simulcast:send 1;5;3 recv 4;2;6\r\n";
4525 JsepSessionDescription output(kDummyType);
4526 SdpParseError error;
4527 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4528 const cricket::ContentInfos& contents = output.description()->contents();
4529 const cricket::MediaContentDescription* media =
4530 contents.back().media_description();
4531 EXPECT_TRUE(media->HasSimulcast());
4532 const SimulcastDescription& simulcast = media->simulcast_description();
4533 EXPECT_EQ(2ul, simulcast.send_layers().size());
4534 EXPECT_EQ(2ul, simulcast.receive_layers().size());
4535 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4536 EXPECT_EQ(2ul, simulcast.receive_layers().GetAllLayers().size());
4537
4538 EXPECT_FALSE(media->streams().empty());
4539 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4540 CompareRidDescriptionIds(rids, {"1", "3"});
4541}
4542
Amit Hilbucha2012042018-12-03 11:35:05 -08004543// Simulcast serialization integration test.
4544// This test will serialize and deserialize the description and compare.
4545// More detailed tests for parsing simulcast can be found in
4546// unit tests for SdpSerializer.
4547TEST_F(WebRtcSdpTest, SerializeSimulcast_ComplexSerialization) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004548 MakeUnifiedPlanDescription(/* use_ssrcs = */ false);
Amit Hilbucha2012042018-12-03 11:35:05 -08004549 auto description = jdesc_.description();
4550 auto media = description->GetContentDescriptionByName(kVideoContentName3);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004551 ASSERT_EQ(media->streams().size(), 1ul);
4552 StreamParams& send_stream = media->mutable_streams()[0];
4553 std::vector<RidDescription> send_rids;
4554 send_rids.push_back(RidDescription("1", RidDirection::kSend));
4555 send_rids.push_back(RidDescription("2", RidDirection::kSend));
4556 send_rids.push_back(RidDescription("3", RidDirection::kSend));
4557 send_rids.push_back(RidDescription("4", RidDirection::kSend));
4558 send_stream.set_rids(send_rids);
Florent Castellib60141b2019-07-03 12:47:54 +02004559 std::vector<RidDescription> receive_rids;
4560 receive_rids.push_back(RidDescription("5", RidDirection::kReceive));
4561 receive_rids.push_back(RidDescription("6", RidDirection::kReceive));
4562 receive_rids.push_back(RidDescription("7", RidDirection::kReceive));
4563 media->set_receive_rids(receive_rids);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004564
Amit Hilbucha2012042018-12-03 11:35:05 -08004565 SimulcastDescription& simulcast = media->simulcast_description();
4566 simulcast.send_layers().AddLayerWithAlternatives(
4567 {SimulcastLayer("2", false), SimulcastLayer("1", true)});
4568 simulcast.send_layers().AddLayerWithAlternatives(
4569 {SimulcastLayer("4", false), SimulcastLayer("3", false)});
Florent Castellib60141b2019-07-03 12:47:54 +02004570 simulcast.receive_layers().AddLayer({SimulcastLayer("5", false)});
4571 simulcast.receive_layers().AddLayer({SimulcastLayer("6", false)});
4572 simulcast.receive_layers().AddLayer({SimulcastLayer("7", false)});
Amit Hilbucha2012042018-12-03 11:35:05 -08004573
Amit Hilbucha2012042018-12-03 11:35:05 -08004574 TestSerialize(jdesc_);
4575}
Steve Anton06817cd2018-12-18 15:55:30 -08004576
4577// Test that the content name is empty if the media section does not have an
4578// a=mid line.
4579TEST_F(WebRtcSdpTest, ParseNoMid) {
4580 std::string sdp = kSdpString;
4581 Replace("a=mid:audio_content_name\r\n", "", &sdp);
4582 Replace("a=mid:video_content_name\r\n", "", &sdp);
4583
4584 JsepSessionDescription output(kDummyType);
4585 SdpParseError error;
4586 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4587
4588 EXPECT_THAT(output.description()->contents(),
4589 ElementsAre(Field("name", &cricket::ContentInfo::name, ""),
4590 Field("name", &cricket::ContentInfo::name, "")));
4591}
Piotr (Peter) Slatala13e570f2019-02-27 11:34:26 -08004592
Guido Urdanetacecf87f2019-05-31 10:17:38 +00004593TEST_F(WebRtcSdpTest, SerializeWithDefaultSctpProtocol) {
4594 AddSctpDataChannel(false); // Don't use sctpmap
4595 JsepSessionDescription jsep_desc(kDummyType);
4596 MakeDescriptionWithoutCandidates(&jsep_desc);
4597 std::string message = webrtc::SdpSerialize(jsep_desc);
4598 EXPECT_NE(std::string::npos,
4599 message.find(cricket::kMediaProtocolUdpDtlsSctp));
4600}
4601
4602TEST_F(WebRtcSdpTest, DeserializeWithAllSctpProtocols) {
4603 AddSctpDataChannel(false);
4604 std::string protocols[] = {cricket::kMediaProtocolDtlsSctp,
4605 cricket::kMediaProtocolUdpDtlsSctp,
4606 cricket::kMediaProtocolTcpDtlsSctp};
4607 for (const auto& protocol : protocols) {
4608 sctp_desc_->set_protocol(protocol);
4609 JsepSessionDescription jsep_desc(kDummyType);
4610 MakeDescriptionWithoutCandidates(&jsep_desc);
4611 std::string message = webrtc::SdpSerialize(jsep_desc);
4612 EXPECT_NE(std::string::npos, message.find(protocol));
4613 JsepSessionDescription jsep_output(kDummyType);
4614 SdpParseError error;
4615 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jsep_output, &error));
4616 }
4617}
Taylor Brandstetter4256df02020-02-18 14:05:07 -08004618
4619// According to https://tools.ietf.org/html/rfc5576#section-6.1, the CNAME
4620// attribute is mandatory, but we relax that restriction.
4621TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCname) {
4622 std::string sdp_without_cname = kSdpFullString;
4623 Replace("a=ssrc:1 cname:stream_1_cname\r\n", "", &sdp_without_cname);
4624 JsepSessionDescription new_jdesc(kDummyType);
4625 EXPECT_TRUE(SdpDeserialize(sdp_without_cname, &new_jdesc));
4626
4627 audio_desc_->mutable_streams()[0].cname = "";
4628 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
4629 jdesc_.session_version()));
4630 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
4631}
Philipp Hanckeefc55b02020-06-26 10:17:05 +02004632
4633TEST_F(WebRtcSdpTest, DeserializeSdpWithUnsupportedMediaType) {
Philipp Hanckeefc55b02020-06-26 10:17:05 +02004634 std::string sdp = kSdpSessionString;
4635 sdp +=
4636 "m=bogus 9 RTP/SAVPF 0 8\r\n"
Philipp Hancke4e8c1152020-10-13 12:43:15 +02004637 "c=IN IP4 0.0.0.0\r\n"
4638 "a=mid:bogusmid\r\n";
Philipp Hanckeefc55b02020-06-26 10:17:05 +02004639 sdp +=
4640 "m=audio/something 9 RTP/SAVPF 0 8\r\n"
Philipp Hancke4e8c1152020-10-13 12:43:15 +02004641 "c=IN IP4 0.0.0.0\r\n"
4642 "a=mid:somethingmid\r\n";
Philipp Hanckeefc55b02020-06-26 10:17:05 +02004643
4644 JsepSessionDescription jdesc_output(kDummyType);
4645 EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output));
4646
Philipp Hancke4e8c1152020-10-13 12:43:15 +02004647 ASSERT_EQ(2u, jdesc_output.description()->contents().size());
4648 ASSERT_NE(nullptr, jdesc_output.description()
4649 ->contents()[0]
4650 .media_description()
4651 ->as_unsupported());
4652 ASSERT_NE(nullptr, jdesc_output.description()
4653 ->contents()[1]
4654 .media_description()
4655 ->as_unsupported());
4656
4657 EXPECT_TRUE(jdesc_output.description()->contents()[0].rejected);
4658 EXPECT_TRUE(jdesc_output.description()->contents()[1].rejected);
4659
4660 EXPECT_EQ(jdesc_output.description()->contents()[0].name, "bogusmid");
4661 EXPECT_EQ(jdesc_output.description()->contents()[1].name, "somethingmid");
Philipp Hanckeefc55b02020-06-26 10:17:05 +02004662}
Philipp Hanckeb70c9532021-01-13 10:40:06 +01004663
4664TEST_F(WebRtcSdpTest, MediaTypeProtocolMismatch) {
4665 std::string sdp =
4666 "v=0\r\n"
4667 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4668 "s=-\r\n"
4669 "t=0 0\r\n";
4670
4671 ExpectParseFailure(std::string(sdp + "m=audio 9 UDP/DTLS/SCTP 120\r\n"),
4672 "m=audio");
4673 ExpectParseFailure(std::string(sdp + "m=video 9 UDP/DTLS/SCTP 120\r\n"),
4674 "m=video");
4675 ExpectParseFailure(std::string(sdp + "m=video 9 SOMETHING 120\r\n"),
4676 "m=video");
4677 ExpectParseFailure(std::string(sdp + "m=application 9 SOMETHING 120\r\n"),
4678 "m=application");
4679}
Philipp Hanckecd467b52021-01-29 09:29:47 +01004680
4681// Regression test for:
4682// https://bugs.chromium.org/p/chromium/issues/detail?id=1171965
4683TEST_F(WebRtcSdpTest, SctpPortInUnsupportedContent) {
4684 std::string sdp =
4685 "v=0\r\n"
4686 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4687 "s=-\r\n"
4688 "t=0 0\r\n"
4689 "m=o 1 DTLS/SCTP 5000\r\n"
4690 "a=sctp-port\r\n";
4691
4692 JsepSessionDescription jdesc_output(kDummyType);
4693 EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output));
4694}
Harald Alvestrand99bcf602021-03-03 07:44:39 +00004695
4696TEST_F(WebRtcSdpTest, IllegalMidCharacterValue) {
4697 std::string sdp = kSdpString;
4698 // [ is an illegal token value.
4699 Replace("a=mid:", "a=mid:[]", &sdp);
4700 ExpectParseFailure(std::string(sdp), "a=mid:[]");
4701}
Philipp Hancked58ac5a2021-11-25 08:57:54 +01004702
4703TEST_F(WebRtcSdpTest, MaxChannels) {
4704 std::string sdp =
4705 "v=0\r\n"
4706 "o=- 11 22 IN IP4 127.0.0.1\r\n"
4707 "s=-\r\n"
4708 "t=0 0\r\n"
4709 "m=audio 49232 RTP/AVP 108\r\n"
4710 "a=rtpmap:108 ISAC/16000/512\r\n";
4711
4712 ExpectParseFailure(sdp, "a=rtpmap:108 ISAC/16000/512");
4713}