blob: 310da3831f633bfa0e222b6822914db1fb55eef2 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2011 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
Yves Gerey3e707812018-11-28 16:47:49 +010011#include <stdio.h>
12#include <string.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020013
Harald Alvestrand4d7160e2019-04-12 07:01:29 +020014#include <algorithm>
Yves Gerey3e707812018-11-28 16:47:49 +010015#include <cstdint>
16#include <map>
kwibergd1fe2812016-04-27 06:47:29 -070017#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000018#include <string>
Yves Gerey3e707812018-11-28 16:47:49 +010019#include <utility>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000020#include <vector>
21
Steve Anton64b626b2019-01-28 17:25:26 -080022#include "absl/algorithm/container.h"
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -080023#include "absl/memory/memory.h"
Steve Anton1c9c9fc2019-02-14 15:13:09 -080024#include "absl/strings/str_replace.h"
Yves Gerey3e707812018-11-28 16:47:49 +010025#include "api/array_view.h"
Steve Anton10542f22019-01-11 09:11:00 -080026#include "api/crypto_params.h"
27#include "api/jsep_session_description.h"
28#include "api/media_types.h"
29#include "api/rtp_parameters.h"
30#include "api/rtp_transceiver_interface.h"
Yves Gerey3e707812018-11-28 16:47:49 +010031#include "media/base/codec.h"
Steve Anton10542f22019-01-11 09:11:00 -080032#include "media/base/media_constants.h"
33#include "media/base/stream_params.h"
34#include "p2p/base/p2p_constants.h"
Yves Gerey665174f2018-06-19 15:03:05 +020035#include "p2p/base/port.h"
Steve Anton10542f22019-01-11 09:11:00 -080036#include "p2p/base/transport_description.h"
37#include "p2p/base/transport_info.h"
38#include "pc/media_session.h"
39#include "pc/session_description.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020040#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 09:11:00 -080041#include "rtc_base/message_digest.h"
42#include "rtc_base/socket_address.h"
43#include "rtc_base/ssl_fingerprint.h"
44#include "rtc_base/string_encode.h"
Steve Anton06817cd2018-12-18 15:55:30 -080045#include "test/gmock.h"
Yves Gerey3e707812018-11-28 16:47:49 +010046#include "test/gtest.h"
Patrik Höglund563934e2017-09-15 09:04:28 +020047
ossu7bb87ee2017-01-23 04:56:25 -080048#ifdef WEBRTC_ANDROID
Steve Anton10542f22019-01-11 09:11:00 -080049#include "pc/test/android_test_initializer.h"
ossu7bb87ee2017-01-23 04:56:25 -080050#endif
Steve Anton10542f22019-01-11 09:11:00 -080051#include "pc/webrtc_sdp.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000052
53using cricket::AudioCodec;
54using cricket::AudioContentDescription;
55using cricket::Candidate;
Steve Anton06817cd2018-12-18 15:55:30 -080056using cricket::ContentGroup;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057using cricket::ContentInfo;
58using cricket::CryptoParams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
60using cricket::ICE_CANDIDATE_COMPONENT_RTP;
61using cricket::kFecSsrcGroupSemantics;
62using cricket::LOCAL_PORT_TYPE;
Steve Anton5adfafd2017-12-20 16:34:00 -080063using cricket::MediaProtocolType;
Steve Anton06817cd2018-12-18 15:55:30 -080064using cricket::RELAY_PORT_TYPE;
Amit Hilbuchc57d5732018-12-11 15:30:11 -080065using cricket::RidDescription;
66using cricket::RidDirection;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020067using cricket::SctpDataContentDescription;
Steve Anton06817cd2018-12-18 15:55:30 -080068using cricket::SessionDescription;
Amit Hilbucha2012042018-12-03 11:35:05 -080069using cricket::SimulcastDescription;
70using cricket::SimulcastLayer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071using cricket::StreamParams;
72using cricket::STUN_PORT_TYPE;
73using cricket::TransportDescription;
74using cricket::TransportInfo;
75using cricket::VideoCodec;
76using cricket::VideoContentDescription;
Steve Anton06817cd2018-12-18 15:55:30 -080077using ::testing::ElementsAre;
78using ::testing::Field;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079using webrtc::IceCandidateCollection;
80using webrtc::IceCandidateInterface;
81using webrtc::JsepIceCandidate;
82using webrtc::JsepSessionDescription;
isheriff6f8d6862016-05-26 11:24:55 -070083using webrtc::RtpExtension;
Steve Anton4e70a722017-11-28 14:57:10 -080084using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085using webrtc::SdpParseError;
Steve Antona3a92c22017-12-07 10:27:41 -080086using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087using webrtc::SessionDescriptionInterface;
88
89typedef std::vector<AudioCodec> AudioCodecs;
90typedef std::vector<Candidate> Candidates;
91
Peter Boström0c4e06b2015-10-07 12:23:21 +020092static const uint32_t kDefaultSctpPort = 5000;
zstein4b2e0822017-02-17 19:48:38 -080093static const uint16_t kUnusualSctpPort = 9556;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020095static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 15:17:14 -080096static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000097static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 15:17:14 -080098static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200100static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000101static const char kCandidateFoundation1[] = "a0+B/1";
102static const char kCandidateFoundation2[] = "a0+B/2";
103static const char kCandidateFoundation3[] = "a0+B/3";
104static const char kCandidateFoundation4[] = "a0+B/4";
105static const char kAttributeCryptoVoice[] =
106 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
107 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
108 "dummy_session_params\r\n";
109static const char kAttributeCryptoVideo[] =
110 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
111 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
Yves Gerey665174f2018-06-19 15:03:05 +0200112static const char kFingerprint[] =
113 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000114 "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 +0200115static const char kExtmapAllowMixed[] = "a=extmap-allow-mixed\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116static const int kExtmapId = 1;
117static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
118static const char kExtmap[] =
119 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
120static const char kExtmapWithDirectionAndAttribute[] =
121 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
jbauch5869f502017-06-29 12:31:36 -0700122static const char kExtmapWithDirectionAndAttributeEncrypted[] =
123 "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt "
124 "http://example.com/082005/ext.htm#ttime a1 a2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125
Peter Boström0c4e06b2015-10-07 12:23:21 +0200126static const uint8_t kIdentityDigest[] = {
127 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
128 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000129
lally@webrtc.org34807282015-02-24 20:19:39 +0000130static const char kDtlsSctp[] = "DTLS/SCTP";
131static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
132static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +0000133
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000134struct CodecParams {
135 int max_ptime;
136 int ptime;
137 int min_ptime;
138 int sprop_stereo;
139 int stereo;
140 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000141 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000142};
143
deadbeef9d3584c2016-02-16 17:54:10 -0800144// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
145// instead of "a=crypto", and have an explicit test for adding "a=crypto".
146// Currently it's the other way around.
147
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000148// Reference sdp string
149static const char kSdpFullString[] =
150 "v=0\r\n"
151 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
152 "s=-\r\n"
153 "t=0 0\r\n"
Emil Lundmark801c9992021-01-19 13:06:32 +0100154 "a=extmap-allow-mixed\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800155 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000156 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
157 "c=IN IP4 74.125.127.126\r\n"
158 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
159 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
160 "generation 2\r\n"
161 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
162 "generation 2\r\n"
163 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
164 "generation 2\r\n"
165 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
166 "generation 2\r\n"
167 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
168 "raddr 192.168.1.5 rport 2346 "
169 "generation 2\r\n"
170 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
171 "raddr 192.168.1.5 rport 2348 "
172 "generation 2\r\n"
173 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
174 "a=mid:audio_content_name\r\n"
175 "a=sendrecv\r\n"
176 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800177 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000178 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
179 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
180 "dummy_session_params\r\n"
181 "a=rtpmap:111 opus/48000/2\r\n"
182 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000183 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000184 "a=ssrc:1 cname:stream_1_cname\r\n"
185 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000186 "a=ssrc:1 mslabel:local_stream_1\r\n"
187 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000188 "m=video 3457 RTP/SAVPF 120\r\n"
189 "c=IN IP4 74.125.224.39\r\n"
190 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
191 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
192 "generation 2\r\n"
193 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
194 "generation 2\r\n"
195 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
196 "generation 2\r\n"
197 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
198 "generation 2\r\n"
199 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
200 "generation 2\r\n"
201 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
202 "generation 2\r\n"
203 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
204 "a=mid:video_content_name\r\n"
205 "a=sendrecv\r\n"
206 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
207 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
208 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800209 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000210 "a=ssrc:2 cname:stream_1_cname\r\n"
211 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000212 "a=ssrc:2 mslabel:local_stream_1\r\n"
213 "a=ssrc:2 label:video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000214 "a=ssrc:3 cname:stream_1_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000215 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
216 "a=ssrc:3 mslabel:local_stream_1\r\n"
217 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000218
219// SDP reference string without the candidates.
220static const char kSdpString[] =
221 "v=0\r\n"
222 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
223 "s=-\r\n"
224 "t=0 0\r\n"
Emil Lundmark801c9992021-01-19 13:06:32 +0100225 "a=extmap-allow-mixed\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800226 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000227 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000228 "c=IN IP4 0.0.0.0\r\n"
229 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000230 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
231 "a=mid:audio_content_name\r\n"
232 "a=sendrecv\r\n"
233 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800234 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000235 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
236 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
237 "dummy_session_params\r\n"
238 "a=rtpmap:111 opus/48000/2\r\n"
239 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000240 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000241 "a=ssrc:1 cname:stream_1_cname\r\n"
242 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000243 "a=ssrc:1 mslabel:local_stream_1\r\n"
244 "a=ssrc:1 label:audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000245 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000246 "c=IN IP4 0.0.0.0\r\n"
247 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000248 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
249 "a=mid:video_content_name\r\n"
250 "a=sendrecv\r\n"
251 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
252 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
253 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800254 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000255 "a=ssrc:2 cname:stream_1_cname\r\n"
256 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000257 "a=ssrc:2 mslabel:local_stream_1\r\n"
258 "a=ssrc:2 label:video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000259 "a=ssrc:3 cname:stream_1_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000260 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
261 "a=ssrc:3 mslabel:local_stream_1\r\n"
262 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000263
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200264// draft-ietf-mmusic-sctp-sdp-03
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000265static const char kSdpSctpDataChannelString[] =
Guido Urdanetacecf87f2019-05-31 10:17:38 +0000266 "m=application 9 UDP/DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000267 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000268 "a=ice-ufrag:ufrag_data\r\n"
269 "a=ice-pwd:pwd_data\r\n"
270 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000271 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000272
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000273// draft-ietf-mmusic-sctp-sdp-12
Harald Alvestrand48cce4d2019-04-11 10:41:24 +0200274// Note - this is invalid per draft-ietf-mmusic-sctp-sdp-26,
275// since the separator after "sctp-port" needs to be a colon.
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000276static const char kSdpSctpDataChannelStringWithSctpPort[] =
Guido Urdanetacecf87f2019-05-31 10:17:38 +0000277 "m=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\n"
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000278 "a=sctp-port 5000\r\n"
279 "c=IN IP4 0.0.0.0\r\n"
280 "a=ice-ufrag:ufrag_data\r\n"
281 "a=ice-pwd:pwd_data\r\n"
282 "a=mid:data_content_name\r\n";
283
Harald Alvestrand48cce4d2019-04-11 10:41:24 +0200284// draft-ietf-mmusic-sctp-sdp-26
lally69f57602015-10-08 10:15:04 -0700285static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
Guido Urdanetacecf87f2019-05-31 10:17:38 +0000286 "m=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\n"
lally69f57602015-10-08 10:15:04 -0700287 "a=sctp-port:5000\r\n"
288 "c=IN IP4 0.0.0.0\r\n"
289 "a=ice-ufrag:ufrag_data\r\n"
290 "a=ice-pwd:pwd_data\r\n"
291 "a=mid:data_content_name\r\n";
292
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000293static const char kSdpSctpDataChannelWithCandidatesString[] =
Guido Urdanetacecf87f2019-05-31 10:17:38 +0000294 "m=application 2345 UDP/DTLS/SCTP 5000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000295 "c=IN IP4 74.125.127.126\r\n"
296 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
297 "generation 2\r\n"
298 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
299 "generation 2\r\n"
300 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
301 "raddr 192.168.1.5 rport 2346 "
302 "generation 2\r\n"
303 "a=ice-ufrag:ufrag_data\r\n"
304 "a=ice-pwd:pwd_data\r\n"
305 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000306 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000307
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000308static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000309 "v=0\r\n"
310 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
311 "s=-\r\n"
312 "t=0 0\r\n"
313 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000314 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000315 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000316 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000317 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000318 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000319 "a=x-google-flag:conference\r\n";
320
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000321static const char kSdpSessionString[] =
322 "v=0\r\n"
323 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
324 "s=-\r\n"
325 "t=0 0\r\n"
326 "a=msid-semantic: WMS local_stream\r\n";
327
328static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000329 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000330 "c=IN IP4 0.0.0.0\r\n"
331 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000332 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
333 "a=mid:audio_content_name\r\n"
334 "a=sendrecv\r\n"
335 "a=rtpmap:111 opus/48000/2\r\n"
336 "a=ssrc:1 cname:stream_1_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000337 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
338 "a=ssrc:1 mslabel:local_stream\r\n"
339 "a=ssrc:1 label:audio_track_id_1\r\n";
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000340
341static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000342 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000343 "c=IN IP4 0.0.0.0\r\n"
344 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000345 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
346 "a=mid:video_content_name\r\n"
347 "a=sendrecv\r\n"
348 "a=rtpmap:120 VP8/90000\r\n"
349 "a=ssrc:2 cname:stream_1_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000350 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
351 "a=ssrc:2 mslabel:local_stream\r\n"
352 "a=ssrc:2 label:video_track_id_1\r\n";
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000353
deadbeef25ed4352016-12-12 18:37:36 -0800354// Reference sdp string using bundle-only.
355static const char kBundleOnlySdpFullString[] =
356 "v=0\r\n"
357 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
358 "s=-\r\n"
359 "t=0 0\r\n"
Emil Lundmark801c9992021-01-19 13:06:32 +0100360 "a=extmap-allow-mixed\r\n"
deadbeef25ed4352016-12-12 18:37:36 -0800361 "a=group:BUNDLE audio_content_name video_content_name\r\n"
362 "a=msid-semantic: WMS local_stream_1\r\n"
363 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
364 "c=IN IP4 74.125.127.126\r\n"
365 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
366 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
367 "generation 2\r\n"
368 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
369 "generation 2\r\n"
370 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
371 "generation 2\r\n"
372 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
373 "generation 2\r\n"
374 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
375 "raddr 192.168.1.5 rport 2346 "
376 "generation 2\r\n"
377 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
378 "raddr 192.168.1.5 rport 2348 "
379 "generation 2\r\n"
380 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
381 "a=mid:audio_content_name\r\n"
382 "a=sendrecv\r\n"
383 "a=rtcp-mux\r\n"
384 "a=rtcp-rsize\r\n"
385 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
386 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
387 "dummy_session_params\r\n"
388 "a=rtpmap:111 opus/48000/2\r\n"
389 "a=rtpmap:103 ISAC/16000\r\n"
390 "a=rtpmap:104 ISAC/32000\r\n"
391 "a=ssrc:1 cname:stream_1_cname\r\n"
392 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000393 "a=ssrc:1 mslabel:local_stream_1\r\n"
394 "a=ssrc:1 label:audio_track_id_1\r\n"
deadbeef25ed4352016-12-12 18:37:36 -0800395 "m=video 0 RTP/SAVPF 120\r\n"
396 "c=IN IP4 0.0.0.0\r\n"
397 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
398 "a=bundle-only\r\n"
399 "a=mid:video_content_name\r\n"
400 "a=sendrecv\r\n"
401 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
402 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
403 "a=rtpmap:120 VP8/90000\r\n"
404 "a=ssrc-group:FEC 2 3\r\n"
405 "a=ssrc:2 cname:stream_1_cname\r\n"
406 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000407 "a=ssrc:2 mslabel:local_stream_1\r\n"
408 "a=ssrc:2 label:video_track_id_1\r\n"
deadbeef25ed4352016-12-12 18:37:36 -0800409 "a=ssrc:3 cname:stream_1_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000410 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
411 "a=ssrc:3 mslabel:local_stream_1\r\n"
412 "a=ssrc:3 label:video_track_id_1\r\n";
deadbeef25ed4352016-12-12 18:37:36 -0800413
deadbeef9d3584c2016-02-16 17:54:10 -0800414// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
415// tracks.
416static const char kPlanBSdpFullString[] =
417 "v=0\r\n"
418 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
419 "s=-\r\n"
420 "t=0 0\r\n"
Emil Lundmark801c9992021-01-19 13:06:32 +0100421 "a=extmap-allow-mixed\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800422 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
423 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
424 "c=IN IP4 74.125.127.126\r\n"
425 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
426 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
427 "generation 2\r\n"
428 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
429 "generation 2\r\n"
430 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
431 "generation 2\r\n"
432 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
433 "generation 2\r\n"
434 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
435 "raddr 192.168.1.5 rport 2346 "
436 "generation 2\r\n"
437 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
438 "raddr 192.168.1.5 rport 2348 "
439 "generation 2\r\n"
440 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
441 "a=mid:audio_content_name\r\n"
442 "a=sendrecv\r\n"
443 "a=rtcp-mux\r\n"
444 "a=rtcp-rsize\r\n"
445 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
446 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
447 "dummy_session_params\r\n"
448 "a=rtpmap:111 opus/48000/2\r\n"
449 "a=rtpmap:103 ISAC/16000\r\n"
450 "a=rtpmap:104 ISAC/32000\r\n"
451 "a=ssrc:1 cname:stream_1_cname\r\n"
452 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000453 "a=ssrc:1 mslabel:local_stream_1\r\n"
454 "a=ssrc:1 label:audio_track_id_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800455 "a=ssrc:4 cname:stream_2_cname\r\n"
456 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000457 "a=ssrc:4 mslabel:local_stream_2\r\n"
458 "a=ssrc:4 label:audio_track_id_2\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800459 "m=video 3457 RTP/SAVPF 120\r\n"
460 "c=IN IP4 74.125.224.39\r\n"
461 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
462 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
463 "generation 2\r\n"
464 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
465 "generation 2\r\n"
466 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
467 "generation 2\r\n"
468 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
469 "generation 2\r\n"
470 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
471 "generation 2\r\n"
472 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
473 "generation 2\r\n"
474 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
475 "a=mid:video_content_name\r\n"
476 "a=sendrecv\r\n"
477 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
478 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
479 "a=rtpmap:120 VP8/90000\r\n"
480 "a=ssrc-group:FEC 2 3\r\n"
481 "a=ssrc:2 cname:stream_1_cname\r\n"
482 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000483 "a=ssrc:2 mslabel:local_stream_1\r\n"
484 "a=ssrc:2 label:video_track_id_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800485 "a=ssrc:3 cname:stream_1_cname\r\n"
486 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000487 "a=ssrc:3 mslabel:local_stream_1\r\n"
488 "a=ssrc:3 label:video_track_id_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800489 "a=ssrc:5 cname:stream_2_cname\r\n"
490 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000491 "a=ssrc:5 mslabel:local_stream_2\r\n"
492 "a=ssrc:5 label:video_track_id_2\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800493 "a=ssrc:6 cname:stream_2_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000494 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
495 "a=ssrc:6 mslabel:local_stream_2\r\n"
496 "a=ssrc:6 label:video_track_id_3\r\n";
deadbeef9d3584c2016-02-16 17:54:10 -0800497
498// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
499// tracks.
500static const char kUnifiedPlanSdpFullString[] =
501 "v=0\r\n"
502 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
503 "s=-\r\n"
504 "t=0 0\r\n"
Emil Lundmark801c9992021-01-19 13:06:32 +0100505 "a=extmap-allow-mixed\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800506 "a=msid-semantic: WMS local_stream_1\r\n"
507 // Audio track 1, stream 1 (with candidates).
508 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
509 "c=IN IP4 74.125.127.126\r\n"
510 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
511 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
512 "generation 2\r\n"
513 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
514 "generation 2\r\n"
515 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
516 "generation 2\r\n"
517 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
518 "generation 2\r\n"
519 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
520 "raddr 192.168.1.5 rport 2346 "
521 "generation 2\r\n"
522 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
523 "raddr 192.168.1.5 rport 2348 "
524 "generation 2\r\n"
525 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
526 "a=mid:audio_content_name\r\n"
527 "a=msid:local_stream_1 audio_track_id_1\r\n"
528 "a=sendrecv\r\n"
529 "a=rtcp-mux\r\n"
530 "a=rtcp-rsize\r\n"
531 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
532 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
533 "dummy_session_params\r\n"
534 "a=rtpmap:111 opus/48000/2\r\n"
535 "a=rtpmap:103 ISAC/16000\r\n"
536 "a=rtpmap:104 ISAC/32000\r\n"
537 "a=ssrc:1 cname:stream_1_cname\r\n"
538 // Video track 1, stream 1 (with candidates).
539 "m=video 3457 RTP/SAVPF 120\r\n"
540 "c=IN IP4 74.125.224.39\r\n"
541 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
542 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
543 "generation 2\r\n"
544 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
545 "generation 2\r\n"
546 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
547 "generation 2\r\n"
548 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
549 "generation 2\r\n"
550 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
551 "generation 2\r\n"
552 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
553 "generation 2\r\n"
554 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
555 "a=mid:video_content_name\r\n"
556 "a=msid:local_stream_1 video_track_id_1\r\n"
557 "a=sendrecv\r\n"
558 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
559 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
560 "a=rtpmap:120 VP8/90000\r\n"
561 "a=ssrc-group:FEC 2 3\r\n"
562 "a=ssrc:2 cname:stream_1_cname\r\n"
563 "a=ssrc:3 cname:stream_1_cname\r\n"
564 // Audio track 2, stream 2.
565 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
566 "c=IN IP4 0.0.0.0\r\n"
567 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
568 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
569 "a=mid:audio_content_name_2\r\n"
570 "a=msid:local_stream_2 audio_track_id_2\r\n"
571 "a=sendrecv\r\n"
572 "a=rtcp-mux\r\n"
573 "a=rtcp-rsize\r\n"
574 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
575 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
576 "dummy_session_params\r\n"
577 "a=rtpmap:111 opus/48000/2\r\n"
578 "a=rtpmap:103 ISAC/16000\r\n"
579 "a=rtpmap:104 ISAC/32000\r\n"
580 "a=ssrc:4 cname:stream_2_cname\r\n"
581 // Video track 2, stream 2.
582 "m=video 9 RTP/SAVPF 120\r\n"
583 "c=IN IP4 0.0.0.0\r\n"
584 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
585 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
586 "a=mid:video_content_name_2\r\n"
587 "a=msid:local_stream_2 video_track_id_2\r\n"
588 "a=sendrecv\r\n"
589 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
590 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
591 "a=rtpmap:120 VP8/90000\r\n"
592 "a=ssrc:5 cname:stream_2_cname\r\n"
593 // Video track 3, stream 2.
594 "m=video 9 RTP/SAVPF 120\r\n"
595 "c=IN IP4 0.0.0.0\r\n"
596 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
597 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
598 "a=mid:video_content_name_3\r\n"
599 "a=msid:local_stream_2 video_track_id_3\r\n"
600 "a=sendrecv\r\n"
601 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
602 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
603 "a=rtpmap:120 VP8/90000\r\n"
604 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000605
Seth Hampson5b4f0752018-04-02 16:31:36 -0700606// Unified Plan SDP reference string:
607// - audio track 1 has 1 a=msid lines
608// - audio track 2 has 2 a=msid lines
609// - audio track 3 has 1 a=msid line with the special "-" marker signifying that
610// there are 0 media stream ids.
611// This Unified Plan SDP represents a SDP that signals the msid using both
612// a=msid and a=ssrc msid semantics.
613static const char kUnifiedPlanSdpFullStringWithSpecialMsid[] =
614 "v=0\r\n"
615 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
616 "s=-\r\n"
617 "t=0 0\r\n"
Emil Lundmark801c9992021-01-19 13:06:32 +0100618 "a=extmap-allow-mixed\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700619 "a=msid-semantic: WMS local_stream_1\r\n"
620 // Audio track 1, with 1 stream id.
621 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
622 "c=IN IP4 74.125.127.126\r\n"
623 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
624 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
625 "generation 2\r\n"
626 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
627 "generation 2\r\n"
628 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
629 "generation 2\r\n"
630 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
631 "generation 2\r\n"
632 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
633 "raddr 192.168.1.5 rport 2346 "
634 "generation 2\r\n"
635 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
636 "raddr 192.168.1.5 rport 2348 "
637 "generation 2\r\n"
638 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
639 "a=mid:audio_content_name\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700640 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700641 "a=msid:local_stream_1 audio_track_id_1\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700642 "a=rtcp-mux\r\n"
643 "a=rtcp-rsize\r\n"
644 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
645 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
646 "dummy_session_params\r\n"
647 "a=rtpmap:111 opus/48000/2\r\n"
648 "a=rtpmap:103 ISAC/16000\r\n"
649 "a=rtpmap:104 ISAC/32000\r\n"
650 "a=ssrc:1 cname:stream_1_cname\r\n"
651 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000652 "a=ssrc:1 mslabel:local_stream_1\r\n"
653 "a=ssrc:1 label:audio_track_id_1\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700654 // Audio track 2, with two stream ids.
655 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
656 "c=IN IP4 0.0.0.0\r\n"
657 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
658 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
659 "a=mid:audio_content_name_2\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700660 "a=sendrecv\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700661 "a=msid:local_stream_1 audio_track_id_2\r\n"
662 "a=msid:local_stream_2 audio_track_id_2\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700663 "a=rtcp-mux\r\n"
664 "a=rtcp-rsize\r\n"
665 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
666 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
667 "dummy_session_params\r\n"
668 "a=rtpmap:111 opus/48000/2\r\n"
669 "a=rtpmap:103 ISAC/16000\r\n"
670 "a=rtpmap:104 ISAC/32000\r\n"
671 "a=ssrc:4 cname:stream_1_cname\r\n"
672 // The support for Plan B msid signaling only includes the
673 // first media stream id "local_stream_1."
674 "a=ssrc:4 msid:local_stream_1 audio_track_id_2\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000675 "a=ssrc:4 mslabel:local_stream_1\r\n"
676 "a=ssrc:4 label:audio_track_id_2\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700677 // Audio track 3, with no stream ids.
678 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
679 "c=IN IP4 0.0.0.0\r\n"
680 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
681 "a=ice-ufrag:ufrag_voice_3\r\na=ice-pwd:pwd_voice_3\r\n"
682 "a=mid:audio_content_name_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700683 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700684 "a=msid:- audio_track_id_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700685 "a=rtcp-mux\r\n"
686 "a=rtcp-rsize\r\n"
687 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
688 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
689 "dummy_session_params\r\n"
690 "a=rtpmap:111 opus/48000/2\r\n"
691 "a=rtpmap:103 ISAC/16000\r\n"
692 "a=rtpmap:104 ISAC/32000\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700693 "a=ssrc:7 cname:stream_2_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000694 "a=ssrc:7 msid:- audio_track_id_3\r\n"
695 "a=ssrc:7 mslabel:-\r\n"
696 "a=ssrc:7 label:audio_track_id_3\r\n";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700697
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800698// SDP string for unified plan without SSRCs
699static const char kUnifiedPlanSdpFullStringNoSsrc[] =
700 "v=0\r\n"
701 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
702 "s=-\r\n"
703 "t=0 0\r\n"
704 "a=msid-semantic: WMS local_stream_1\r\n"
705 // Audio track 1, stream 1 (with candidates).
706 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
707 "c=IN IP4 74.125.127.126\r\n"
708 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
709 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
710 "generation 2\r\n"
711 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
712 "generation 2\r\n"
713 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
714 "generation 2\r\n"
715 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
716 "generation 2\r\n"
717 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
718 "raddr 192.168.1.5 rport 2346 "
719 "generation 2\r\n"
720 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
721 "raddr 192.168.1.5 rport 2348 "
722 "generation 2\r\n"
723 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
724 "a=mid:audio_content_name\r\n"
725 "a=msid:local_stream_1 audio_track_id_1\r\n"
726 "a=sendrecv\r\n"
727 "a=rtcp-mux\r\n"
728 "a=rtcp-rsize\r\n"
729 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
730 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
731 "dummy_session_params\r\n"
732 "a=rtpmap:111 opus/48000/2\r\n"
733 "a=rtpmap:103 ISAC/16000\r\n"
734 "a=rtpmap:104 ISAC/32000\r\n"
735 // Video track 1, stream 1 (with candidates).
736 "m=video 3457 RTP/SAVPF 120\r\n"
737 "c=IN IP4 74.125.224.39\r\n"
738 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
739 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
740 "generation 2\r\n"
741 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
742 "generation 2\r\n"
743 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
744 "generation 2\r\n"
745 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
746 "generation 2\r\n"
747 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
748 "generation 2\r\n"
749 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
750 "generation 2\r\n"
751 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
752 "a=mid:video_content_name\r\n"
753 "a=msid:local_stream_1 video_track_id_1\r\n"
754 "a=sendrecv\r\n"
755 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
756 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
757 "a=rtpmap:120 VP8/90000\r\n"
758 // Audio track 2, stream 2.
759 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
760 "c=IN IP4 0.0.0.0\r\n"
761 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
762 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
763 "a=mid:audio_content_name_2\r\n"
764 "a=msid:local_stream_2 audio_track_id_2\r\n"
765 "a=sendrecv\r\n"
766 "a=rtcp-mux\r\n"
767 "a=rtcp-rsize\r\n"
768 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
769 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
770 "dummy_session_params\r\n"
771 "a=rtpmap:111 opus/48000/2\r\n"
772 "a=rtpmap:103 ISAC/16000\r\n"
773 "a=rtpmap:104 ISAC/32000\r\n"
774 // Video track 2, stream 2.
775 "m=video 9 RTP/SAVPF 120\r\n"
776 "c=IN IP4 0.0.0.0\r\n"
777 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
778 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
779 "a=mid:video_content_name_2\r\n"
780 "a=msid:local_stream_2 video_track_id_2\r\n"
781 "a=sendrecv\r\n"
782 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
783 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
784 "a=rtpmap:120 VP8/90000\r\n"
785 // Video track 3, stream 2.
786 "m=video 9 RTP/SAVPF 120\r\n"
787 "c=IN IP4 0.0.0.0\r\n"
788 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
789 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
790 "a=mid:video_content_name_3\r\n"
791 "a=msid:local_stream_2 video_track_id_3\r\n"
792 "a=sendrecv\r\n"
793 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
794 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
795 "a=rtpmap:120 VP8/90000\r\n";
796
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000797// One candidate reference string as per W3c spec.
798// candidate:<blah> not a=candidate:<blah>CRLF
799static const char kRawCandidate[] =
800 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
801// One candidate reference string.
802static const char kSdpOneCandidate[] =
803 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
804 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000805
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000806static const char kSdpTcpActiveCandidate[] =
807 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
808 "tcptype active generation 2";
809static const char kSdpTcpPassiveCandidate[] =
810 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
811 "tcptype passive generation 2";
812static const char kSdpTcpSOCandidate[] =
813 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
814 "tcptype so generation 2";
815static const char kSdpTcpInvalidCandidate[] =
816 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
817 "tcptype invalid generation 2";
818
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000819// One candidate reference string with IPV6 address.
820static const char kRawIPV6Candidate[] =
821 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 12:04:36 -0700822 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000823
824// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800825static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000826 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800827 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000828
Zach Steinb336c272018-08-09 01:16:13 -0700829static const char kRawHostnameCandidate[] =
830 "candidate:a0+B/1 1 udp 2130706432 a.test 1234 typ host generation 2";
831
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000832// Session id and version
833static const char kSessionId[] = "18446744069414584320";
834static const char kSessionVersion[] = "18446462598732840960";
835
deadbeef9d3584c2016-02-16 17:54:10 -0800836// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000837static const char kIceOption1[] = "iceoption1";
838static const char kIceOption2[] = "iceoption2";
839static const char kIceOption3[] = "iceoption3";
840
deadbeef9d3584c2016-02-16 17:54:10 -0800841// ICE ufrags/passwords.
842static const char kUfragVoice[] = "ufrag_voice";
843static const char kPwdVoice[] = "pwd_voice";
844static const char kUfragVideo[] = "ufrag_video";
845static const char kPwdVideo[] = "pwd_video";
846static const char kUfragData[] = "ufrag_data";
847static const char kPwdData[] = "pwd_data";
848
849// Extra ufrags/passwords for extra unified plan m= sections.
850static const char kUfragVoice2[] = "ufrag_voice_2";
851static const char kPwdVoice2[] = "pwd_voice_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700852static const char kUfragVoice3[] = "ufrag_voice_3";
853static const char kPwdVoice3[] = "pwd_voice_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800854static const char kUfragVideo2[] = "ufrag_video_2";
855static const char kPwdVideo2[] = "pwd_video_2";
856static const char kUfragVideo3[] = "ufrag_video_3";
857static const char kPwdVideo3[] = "pwd_video_3";
858
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000859// Content name
860static const char kAudioContentName[] = "audio_content_name";
861static const char kVideoContentName[] = "video_content_name";
862static const char kDataContentName[] = "data_content_name";
863
deadbeef9d3584c2016-02-16 17:54:10 -0800864// Extra content names for extra unified plan m= sections.
865static const char kAudioContentName2[] = "audio_content_name_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700866static const char kAudioContentName3[] = "audio_content_name_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800867static const char kVideoContentName2[] = "video_content_name_2";
868static const char kVideoContentName3[] = "video_content_name_3";
869
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000870// MediaStream 1
Seth Hampson845e8782018-03-02 11:34:10 -0800871static const char kStreamId1[] = "local_stream_1";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000872static const char kStream1Cname[] = "stream_1_cname";
873static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200874static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000875static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800876static const uint32_t kVideoTrack1Ssrc1 = 2;
877static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000878
879// MediaStream 2
Seth Hampson845e8782018-03-02 11:34:10 -0800880static const char kStreamId2[] = "local_stream_2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000881static const char kStream2Cname[] = "stream_2_cname";
882static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200883static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800884static const char kVideoTrackId2[] = "video_track_id_2";
885static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000886static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800887static const uint32_t kVideoTrack3Ssrc = 6;
Seth Hampson5b4f0752018-04-02 16:31:36 -0700888static const char kAudioTrackId3[] = "audio_track_id_3";
889static const uint32_t kAudioTrack3Ssrc = 7;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000891// Candidate
892static const char kDummyMid[] = "dummy_mid";
893static const int kDummyIndex = 123;
894
895// Misc
Steve Antona3a92c22017-12-07 10:27:41 -0800896static SdpType kDummyType = SdpType::kOffer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000897
898// Helper functions
899
900static bool SdpDeserialize(const std::string& message,
901 JsepSessionDescription* jdesc) {
902 return webrtc::SdpDeserialize(message, jdesc, NULL);
903}
904
905static bool SdpDeserializeCandidate(const std::string& message,
906 JsepIceCandidate* candidate) {
907 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
908}
909
Artem Titov880fa812021-07-30 22:30:23 +0200910// Add some extra `newlines` to the `message` after `line`.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000911static void InjectAfter(const std::string& line,
912 const std::string& newlines,
913 std::string* message) {
Steve Anton1c9c9fc2019-02-14 15:13:09 -0800914 absl::StrReplaceAll({{line, line + newlines}}, message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915}
916
917static void Replace(const std::string& line,
918 const std::string& newlines,
919 std::string* message) {
Steve Anton1c9c9fc2019-02-14 15:13:09 -0800920 absl::StrReplaceAll({{line, newlines}}, message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000921}
922
Artem Titov880fa812021-07-30 22:30:23 +0200923// Expect a parse failure on the line containing `bad_part` when attempting to
924// parse `bad_sdp`.
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000925static void ExpectParseFailure(const std::string& bad_sdp,
926 const std::string& bad_part) {
Steve Antona3a92c22017-12-07 10:27:41 -0800927 JsepSessionDescription desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000928 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000929 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
Harald Alvestrand99bcf602021-03-03 07:44:39 +0000930 ASSERT_FALSE(ret);
931 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()))
932 << "Did not find " << bad_part << " in " << error.line;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000933}
934
Artem Titov880fa812021-07-30 22:30:23 +0200935// Expect fail to parse kSdpFullString if replace `good_part` with `bad_part`.
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000936static void ExpectParseFailure(const char* good_part, const char* bad_part) {
937 std::string bad_sdp = kSdpFullString;
938 Replace(good_part, bad_part, &bad_sdp);
939 ExpectParseFailure(bad_sdp, bad_part);
940}
941
Artem Titov880fa812021-07-30 22:30:23 +0200942// Expect fail to parse kSdpFullString if add `newlines` after `injectpoint`.
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000943static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
944 const std::string& newlines,
945 const std::string& bad_part) {
946 std::string bad_sdp = kSdpFullString;
947 InjectAfter(injectpoint, newlines, &bad_sdp);
948 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000949}
950
Steve Anton4e70a722017-11-28 14:57:10 -0800951static void ReplaceDirection(RtpTransceiverDirection direction,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000952 std::string* message) {
953 std::string new_direction;
954 switch (direction) {
Steve Anton4e70a722017-11-28 14:57:10 -0800955 case RtpTransceiverDirection::kInactive:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000956 new_direction = "a=inactive";
957 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800958 case RtpTransceiverDirection::kSendOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000959 new_direction = "a=sendonly";
960 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800961 case RtpTransceiverDirection::kRecvOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000962 new_direction = "a=recvonly";
963 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800964 case RtpTransceiverDirection::kSendRecv:
Markus Handell45c104b2020-03-11 10:51:13 +0100965 new_direction = "a=sendrecv";
966 break;
967 case RtpTransceiverDirection::kStopped:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000968 default:
Markus Handell45c104b2020-03-11 10:51:13 +0100969 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000970 new_direction = "a=sendrecv";
971 break;
972 }
973 Replace("a=sendrecv", new_direction, message);
974}
975
Yves Gerey665174f2018-06-19 15:03:05 +0200976static void ReplaceRejected(bool audio_rejected,
977 bool video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000978 std::string* message) {
979 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800980 Replace("m=audio 9", "m=audio 0", message);
981 Replace(kAttributeIceUfragVoice, "", message);
982 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000983 }
984 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800985 Replace("m=video 9", "m=video 0", message);
986 Replace(kAttributeIceUfragVideo, "", message);
987 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000988 }
989}
990
991// WebRtcSdpTest
992
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200993class WebRtcSdpTest : public ::testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000994 public:
Steve Antona3a92c22017-12-07 10:27:41 -0800995 WebRtcSdpTest() : jdesc_(kDummyType) {
phoglund37ebcf02016-01-08 05:04:57 -0800996#ifdef WEBRTC_ANDROID
997 webrtc::InitializeAndroidObjects();
998#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000999 // AudioContentDescription
1000 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -08001001 StreamParams audio_stream;
1002 audio_stream.id = kAudioTrackId1;
1003 audio_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001004 audio_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -08001005 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
1006 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 11:04:53 -07001007 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
1008 audio_desc_->set_connection_address(audio_addr);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001009 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1010 absl::WrapUnique(audio_desc_));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001011
1012 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -08001013 video_desc_ = CreateVideoContentDescription();
1014 StreamParams video_stream;
1015 video_stream.id = kVideoTrackId1;
1016 video_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001017 video_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -08001018 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
1019 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
1020 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
1021 video_stream.ssrc_groups.push_back(ssrc_group);
1022 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 11:04:53 -07001023 rtc::SocketAddress video_addr("74.125.224.39", 3457);
1024 video_desc_->set_connection_address(video_addr);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001025 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp,
1026 absl::WrapUnique(video_desc_));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001027
1028 // TransportInfo
Steve Anton06817cd2018-12-18 15:55:30 -08001029 desc_.AddTransportInfo(TransportInfo(
1030 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice)));
1031 desc_.AddTransportInfo(TransportInfo(
1032 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001033
1034 // v4 host
1035 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001036 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001037 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001038 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1039 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001040 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001041 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001042 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1043 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001044 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001045 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001046 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1047 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001048 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001049 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001050 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1051 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001052
1053 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001054 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001055 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1056 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001057 cricket::LOCAL_PORT_TYPE,
1058 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001059 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001060 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "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 candidate7(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 candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "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
1075 // stun
1076 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001077 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
1078 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001079 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1080 address_stun, kCandidatePriority, "", "",
1081 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001082 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001083 candidate9.set_related_address(rel_address_stun);
1084
1085 address_stun.SetPort(port_stun++);
1086 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001087 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1088 address_stun, kCandidatePriority, "", "",
1089 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001090 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001091 candidate10.set_related_address(rel_address_stun);
1092
1093 // relay
1094 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001095 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001096 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1097 address_relay, kCandidatePriority, "", "",
1098 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001099 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001100 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001101 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1102 address_relay, kCandidatePriority, "", "",
1103 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001104 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001105
1106 // voice
1107 candidates_.push_back(candidate1);
1108 candidates_.push_back(candidate2);
1109 candidates_.push_back(candidate5);
1110 candidates_.push_back(candidate6);
1111 candidates_.push_back(candidate9);
1112 candidates_.push_back(candidate10);
1113
1114 // video
1115 candidates_.push_back(candidate3);
1116 candidates_.push_back(candidate4);
1117 candidates_.push_back(candidate7);
1118 candidates_.push_back(candidate8);
1119 candidates_.push_back(candidate11);
1120 candidates_.push_back(candidate12);
1121
Yves Gerey665174f2018-06-19 15:03:05 +02001122 jcandidate_.reset(
1123 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001124
1125 // Set up JsepSessionDescription.
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001126 jdesc_.Initialize(desc_.Clone(), kSessionId, kSessionVersion);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001127 std::string mline_id;
1128 int mline_index = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001129 for (size_t i = 0; i < candidates_.size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001130 // In this test, the audio m line index will be 0, and the video m line
1131 // will be 1.
1132 bool is_video = (i > 5);
1133 mline_id = is_video ? "video_content_name" : "audio_content_name";
1134 mline_index = is_video ? 1 : 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001135 JsepIceCandidate jice(mline_id, mline_index, candidates_.at(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001136 jdesc_.AddCandidate(&jice);
1137 }
1138 }
1139
Seth Hampson5b4f0752018-04-02 16:31:36 -07001140 void RemoveVideoCandidates() {
deadbeef25ed4352016-12-12 18:37:36 -08001141 const IceCandidateCollection* video_candidates_collection =
1142 jdesc_.candidates(1);
1143 ASSERT_NE(nullptr, video_candidates_collection);
1144 std::vector<cricket::Candidate> video_candidates;
1145 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1146 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1147 c.set_transport_name("video_content_name");
1148 video_candidates.push_back(c);
1149 }
1150 jdesc_.RemoveCandidates(video_candidates);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001151 }
1152
1153 // Turns the existing reference description into a description using
1154 // a=bundle-only. This means no transport attributes and a 0 port value on
1155 // the m= sections not associated with the BUNDLE-tag.
1156 void MakeBundleOnlyDescription() {
1157 RemoveVideoCandidates();
deadbeef25ed4352016-12-12 18:37:36 -08001158
1159 // And the rest of the transport attributes.
1160 desc_.transport_infos()[1].description.ice_ufrag.clear();
1161 desc_.transport_infos()[1].description.ice_pwd.clear();
1162 desc_.transport_infos()[1].description.connection_role =
1163 cricket::CONNECTIONROLE_NONE;
1164
1165 // Set bundle-only flag.
1166 desc_.contents()[1].bundle_only = true;
1167
1168 // Add BUNDLE group.
1169 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1170 group.AddContentName(kAudioContentName);
1171 group.AddContentName(kVideoContentName);
1172 desc_.AddGroup(group);
1173
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001174 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef25ed4352016-12-12 18:37:36 -08001175 jdesc_.session_version()));
1176 }
1177
deadbeef9d3584c2016-02-16 17:54:10 -08001178 // Turns the existing reference description into a plan B description,
1179 // with 2 audio tracks and 3 video tracks.
1180 void MakePlanBDescription() {
Harald Alvestrandb97d2fe2020-02-28 11:54:40 +01001181 audio_desc_ = new AudioContentDescription(*audio_desc_);
1182 video_desc_ = new VideoContentDescription(*video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001183
1184 StreamParams audio_track_2;
1185 audio_track_2.id = kAudioTrackId2;
1186 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001187 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001188 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1189 audio_desc_->AddStream(audio_track_2);
1190
1191 StreamParams video_track_2;
1192 video_track_2.id = kVideoTrackId2;
1193 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001194 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001195 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1196 video_desc_->AddStream(video_track_2);
1197
1198 StreamParams video_track_3;
1199 video_track_3.id = kVideoTrackId3;
1200 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001201 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001202 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1203 video_desc_->AddStream(video_track_3);
1204
1205 desc_.RemoveContentByName(kAudioContentName);
1206 desc_.RemoveContentByName(kVideoContentName);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001207 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1208 absl::WrapUnique(audio_desc_));
1209 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp,
1210 absl::WrapUnique(video_desc_));
deadbeef9d3584c2016-02-16 17:54:10 -08001211
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001212 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef9d3584c2016-02-16 17:54:10 -08001213 jdesc_.session_version()));
1214 }
1215
1216 // Turns the existing reference description into a unified plan description,
1217 // with 2 audio tracks and 3 video tracks.
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001218 void MakeUnifiedPlanDescription(bool use_ssrcs = true) {
deadbeef9d3584c2016-02-16 17:54:10 -08001219 // Audio track 2.
1220 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1221 StreamParams audio_track_2;
1222 audio_track_2.id = kAudioTrackId2;
Seth Hampson845e8782018-03-02 11:34:10 -08001223 audio_track_2.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001224 if (use_ssrcs) {
1225 audio_track_2.cname = kStream2Cname;
1226 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1227 }
deadbeef9d3584c2016-02-16 17:54:10 -08001228 audio_desc_2->AddStream(audio_track_2);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001229 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp,
1230 absl::WrapUnique(audio_desc_2));
Steve Anton06817cd2018-12-18 15:55:30 -08001231 desc_.AddTransportInfo(TransportInfo(
1232 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2)));
deadbeef9d3584c2016-02-16 17:54:10 -08001233 // Video track 2, in stream 2.
1234 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1235 StreamParams video_track_2;
1236 video_track_2.id = kVideoTrackId2;
Seth Hampson845e8782018-03-02 11:34:10 -08001237 video_track_2.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001238 if (use_ssrcs) {
1239 video_track_2.cname = kStream2Cname;
1240 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1241 }
deadbeef9d3584c2016-02-16 17:54:10 -08001242 video_desc_2->AddStream(video_track_2);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001243 desc_.AddContent(kVideoContentName2, MediaProtocolType::kRtp,
1244 absl::WrapUnique(video_desc_2));
Steve Anton06817cd2018-12-18 15:55:30 -08001245 desc_.AddTransportInfo(TransportInfo(
1246 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2)));
deadbeef9d3584c2016-02-16 17:54:10 -08001247
1248 // Video track 3, in stream 2.
1249 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1250 StreamParams video_track_3;
1251 video_track_3.id = kVideoTrackId3;
Seth Hampson845e8782018-03-02 11:34:10 -08001252 video_track_3.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001253 if (use_ssrcs) {
1254 video_track_3.cname = kStream2Cname;
1255 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1256 }
deadbeef9d3584c2016-02-16 17:54:10 -08001257 video_desc_3->AddStream(video_track_3);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001258 desc_.AddContent(kVideoContentName3, MediaProtocolType::kRtp,
1259 absl::WrapUnique(video_desc_3));
Steve Anton06817cd2018-12-18 15:55:30 -08001260 desc_.AddTransportInfo(TransportInfo(
1261 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3)));
Steve Antone831b8c2018-02-01 12:22:16 -08001262 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
deadbeef9d3584c2016-02-16 17:54:10 -08001263
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001264 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef9d3584c2016-02-16 17:54:10 -08001265 jdesc_.session_version()));
1266 }
1267
1268 // Creates an audio content description with no streams, and some default
1269 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001270 AudioContentDescription* CreateAudioContentDescription() {
1271 AudioContentDescription* audio = new AudioContentDescription();
1272 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -08001273 audio->set_rtcp_reduced_size(true);
Yves Gerey665174f2018-06-19 15:03:05 +02001274 audio->AddCrypto(CryptoParams(
1275 1, "AES_CM_128_HMAC_SHA1_32",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001276 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1277 "dummy_session_params"));
1278 audio->set_protocol(cricket::kMediaProtocolSavpf);
Philipp Hanckef2a4ec12020-07-01 21:07:32 +02001279 audio->AddCodec(AudioCodec(111, "opus", 48000, 0, 2));
ossue1405ad2017-01-23 08:55:48 -08001280 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1281 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001282 return audio;
1283 }
1284
Seth Hampson5b4f0752018-04-02 16:31:36 -07001285 // Turns the existing reference description into a unified plan description,
1286 // with 3 audio MediaContentDescriptions with special StreamParams that
1287 // contain 0 or multiple stream ids: - audio track 1 has 1 media stream id -
1288 // audio track 2 has 2 media stream ids - audio track 3 has 0 media stream ids
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001289 void MakeUnifiedPlanDescriptionMultipleStreamIds(const int msid_signaling) {
Seth Hampson5b4f0752018-04-02 16:31:36 -07001290 desc_.RemoveContentByName(kVideoContentName);
1291 desc_.RemoveTransportInfoByName(kVideoContentName);
1292 RemoveVideoCandidates();
1293
1294 // Audio track 2 has 2 media stream ids.
1295 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1296 StreamParams audio_track_2;
1297 audio_track_2.id = kAudioTrackId2;
1298 audio_track_2.cname = kStream1Cname;
1299 audio_track_2.set_stream_ids({kStreamId1, kStreamId2});
1300 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1301 audio_desc_2->AddStream(audio_track_2);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001302 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp,
1303 absl::WrapUnique(audio_desc_2));
Steve Anton06817cd2018-12-18 15:55:30 -08001304 desc_.AddTransportInfo(TransportInfo(
1305 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2)));
Seth Hampson5b4f0752018-04-02 16:31:36 -07001306
1307 // Audio track 3 has no stream ids.
1308 AudioContentDescription* audio_desc_3 = CreateAudioContentDescription();
1309 StreamParams audio_track_3;
1310 audio_track_3.id = kAudioTrackId3;
1311 audio_track_3.cname = kStream2Cname;
1312 audio_track_3.set_stream_ids({});
1313 audio_track_3.ssrcs.push_back(kAudioTrack3Ssrc);
1314 audio_desc_3->AddStream(audio_track_3);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001315 desc_.AddContent(kAudioContentName3, MediaProtocolType::kRtp,
1316 absl::WrapUnique(audio_desc_3));
Steve Anton06817cd2018-12-18 15:55:30 -08001317 desc_.AddTransportInfo(TransportInfo(
1318 kAudioContentName3, TransportDescription(kUfragVoice3, kPwdVoice3)));
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001319 desc_.set_msid_signaling(msid_signaling);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001320 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
Seth Hampson5b4f0752018-04-02 16:31:36 -07001321 jdesc_.session_version()));
1322 }
1323
Seth Hampson5897a6e2018-04-03 11:16:33 -07001324 // Turns the existing reference description into a unified plan description
1325 // with one audio MediaContentDescription that contains one StreamParams with
1326 // 0 ssrcs.
1327 void MakeUnifiedPlanDescriptionNoSsrcSignaling() {
1328 desc_.RemoveContentByName(kVideoContentName);
1329 desc_.RemoveContentByName(kAudioContentName);
1330 desc_.RemoveTransportInfoByName(kVideoContentName);
1331 RemoveVideoCandidates();
1332
1333 AudioContentDescription* audio_desc = CreateAudioContentDescription();
1334 StreamParams audio_track;
1335 audio_track.id = kAudioTrackId1;
1336 audio_track.set_stream_ids({kStreamId1});
1337 audio_desc->AddStream(audio_track);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001338 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1339 absl::WrapUnique(audio_desc));
Seth Hampson5897a6e2018-04-03 11:16:33 -07001340
1341 // Enable signaling a=msid lines.
1342 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001343 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
Seth Hampson5897a6e2018-04-03 11:16:33 -07001344 jdesc_.session_version()));
1345 }
1346
deadbeef9d3584c2016-02-16 17:54:10 -08001347 // Creates a video content description with no streams, and some default
1348 // configuration.
1349 VideoContentDescription* CreateVideoContentDescription() {
1350 VideoContentDescription* video = new VideoContentDescription();
1351 video->AddCrypto(CryptoParams(
1352 1, "AES_CM_128_HMAC_SHA1_80",
1353 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1354 video->set_protocol(cricket::kMediaProtocolSavpf);
1355 video->AddCodec(
perkj26752742016-10-24 01:21:16 -07001356 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-16 17:54:10 -08001357 return video;
1358 }
1359
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001360 template <class MCD>
Yves Gerey665174f2018-06-19 15:03:05 +02001361 void CompareMediaContentDescription(const MCD* cd1, const MCD* cd2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001362 // type
Harald Alvestrand1716d392019-06-03 20:35:45 +02001363 EXPECT_EQ(cd1->type(), cd2->type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001364
1365 // content direction
1366 EXPECT_EQ(cd1->direction(), cd2->direction());
1367
1368 // rtcp_mux
1369 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1370
deadbeef13871492015-12-09 12:37:51 -08001371 // rtcp_reduced_size
1372 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1373
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001374 // cryptos
1375 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1376 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1377 ADD_FAILURE();
1378 return;
1379 }
Yves Gerey665174f2018-06-19 15:03:05 +02001380 for (size_t i = 0; i < cd1->cryptos().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001381 const CryptoParams c1 = cd1->cryptos().at(i);
1382 const CryptoParams c2 = cd2->cryptos().at(i);
1383 EXPECT_TRUE(c1.Matches(c2));
1384 EXPECT_EQ(c1.key_params, c2.key_params);
1385 EXPECT_EQ(c1.session_params, c2.session_params);
1386 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001387
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001388 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001389 // Use an equivalence class here, for old and new versions of the
1390 // protocol description.
Yves Gerey665174f2018-06-19 15:03:05 +02001391 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp ||
1392 cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1393 cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
lally@webrtc.org36300852015-02-24 20:19:35 +00001394 const bool cd2_is_also_dtls_sctp =
Yves Gerey665174f2018-06-19 15:03:05 +02001395 cd2->protocol() == cricket::kMediaProtocolDtlsSctp ||
1396 cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1397 cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
lally@webrtc.org36300852015-02-24 20:19:35 +00001398 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001399 } else {
1400 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1401 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001402
1403 // codecs
1404 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1405
1406 // bandwidth
1407 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1408
1409 // streams
1410 EXPECT_EQ(cd1->streams(), cd2->streams());
1411
Johannes Kron0854eb62018-10-10 22:33:20 +02001412 // extmap-allow-mixed
Johannes Kron9581bc42018-10-23 10:17:39 +02001413 EXPECT_EQ(cd1->extmap_allow_mixed_enum(), cd2->extmap_allow_mixed_enum());
Johannes Kron0854eb62018-10-10 22:33:20 +02001414
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001415 // extmap
1416 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1417 cd2->rtp_header_extensions().size());
Yves Gerey665174f2018-06-19 15:03:05 +02001418 for (size_t i = 0; i < cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 11:24:55 -07001419 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1420 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001421 EXPECT_EQ(ext1.uri, ext2.uri);
1422 EXPECT_EQ(ext1.id, ext2.id);
jbauch5869f502017-06-29 12:31:36 -07001423 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001424 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001425 }
1426
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001427 void CompareRidDescriptionIds(const std::vector<RidDescription>& rids,
1428 const std::vector<std::string>& ids) {
1429 // Order of elements does not matter, only equivalence of sets.
1430 EXPECT_EQ(rids.size(), ids.size());
1431 for (const std::string& id : ids) {
Steve Anton64b626b2019-01-28 17:25:26 -08001432 EXPECT_EQ(1l, absl::c_count_if(rids, [id](const RidDescription& rid) {
1433 return rid.rid == id;
1434 }));
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001435 }
1436 }
1437
Amit Hilbucha2012042018-12-03 11:35:05 -08001438 void CompareSimulcastDescription(const SimulcastDescription& simulcast1,
1439 const SimulcastDescription& simulcast2) {
1440 EXPECT_EQ(simulcast1.send_layers().size(), simulcast2.send_layers().size());
1441 EXPECT_EQ(simulcast1.receive_layers().size(),
1442 simulcast2.receive_layers().size());
1443 }
1444
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001445 void CompareSctpDataContentDescription(
1446 const SctpDataContentDescription* dcd1,
1447 const SctpDataContentDescription* dcd2) {
Harald Alvestrand26bf7c42019-04-23 05:20:17 +00001448 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001449 EXPECT_EQ(dcd1->port(), dcd2->port());
1450 EXPECT_EQ(dcd1->max_message_size(), dcd2->max_message_size());
Harald Alvestrand26bf7c42019-04-23 05:20:17 +00001451 }
1452
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001453 void CompareSessionDescription(const SessionDescription& desc1,
1454 const SessionDescription& desc2) {
1455 // Compare content descriptions.
1456 if (desc1.contents().size() != desc2.contents().size()) {
1457 ADD_FAILURE();
1458 return;
1459 }
Yves Gerey665174f2018-06-19 15:03:05 +02001460 for (size_t i = 0; i < desc1.contents().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001461 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1462 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-12 18:37:36 -08001463 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001464 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-12 18:37:36 -08001465 EXPECT_EQ(c1.type, c2.type);
1466 EXPECT_EQ(c1.rejected, c2.rejected);
1467 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001468
1469 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1470 if (IsAudioContent(&c1)) {
1471 const AudioContentDescription* acd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001472 c1.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001473 const AudioContentDescription* acd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001474 c2.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001475 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1476 }
1477
1478 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1479 if (IsVideoContent(&c1)) {
1480 const VideoContentDescription* vcd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001481 c1.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001482 const VideoContentDescription* vcd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001483 c2.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001484 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1485 }
1486
1487 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001488 if (c1.media_description()->as_sctp()) {
1489 ASSERT_TRUE(c2.media_description()->as_sctp());
1490 const SctpDataContentDescription* scd1 =
1491 c1.media_description()->as_sctp();
1492 const SctpDataContentDescription* scd2 =
1493 c2.media_description()->as_sctp();
1494 CompareSctpDataContentDescription(scd1, scd2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001495 }
Amit Hilbucha2012042018-12-03 11:35:05 -08001496
1497 CompareSimulcastDescription(
1498 c1.media_description()->simulcast_description(),
1499 c2.media_description()->simulcast_description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001500 }
1501
1502 // group
1503 const cricket::ContentGroups groups1 = desc1.groups();
1504 const cricket::ContentGroups groups2 = desc2.groups();
1505 EXPECT_EQ(groups1.size(), groups1.size());
1506 if (groups1.size() != groups2.size()) {
1507 ADD_FAILURE();
1508 return;
1509 }
1510 for (size_t i = 0; i < groups1.size(); ++i) {
1511 const cricket::ContentGroup group1 = groups1.at(i);
1512 const cricket::ContentGroup group2 = groups2.at(i);
1513 EXPECT_EQ(group1.semantics(), group2.semantics());
1514 const cricket::ContentNames names1 = group1.content_names();
1515 const cricket::ContentNames names2 = group2.content_names();
1516 EXPECT_EQ(names1.size(), names2.size());
1517 if (names1.size() != names2.size()) {
1518 ADD_FAILURE();
1519 return;
1520 }
1521 cricket::ContentNames::const_iterator iter1 = names1.begin();
1522 cricket::ContentNames::const_iterator iter2 = names2.begin();
1523 while (iter1 != names1.end()) {
1524 EXPECT_EQ(*iter1++, *iter2++);
1525 }
1526 }
1527
1528 // transport info
1529 const cricket::TransportInfos transports1 = desc1.transport_infos();
1530 const cricket::TransportInfos transports2 = desc2.transport_infos();
1531 EXPECT_EQ(transports1.size(), transports2.size());
1532 if (transports1.size() != transports2.size()) {
1533 ADD_FAILURE();
1534 return;
1535 }
1536 for (size_t i = 0; i < transports1.size(); ++i) {
1537 const cricket::TransportInfo transport1 = transports1.at(i);
1538 const cricket::TransportInfo transport2 = transports2.at(i);
1539 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001540 EXPECT_EQ(transport1.description.ice_ufrag,
1541 transport2.description.ice_ufrag);
Yves Gerey665174f2018-06-19 15:03:05 +02001542 EXPECT_EQ(transport1.description.ice_pwd, transport2.description.ice_pwd);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07001543 EXPECT_EQ(transport1.description.ice_mode,
1544 transport2.description.ice_mode);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001545 if (transport1.description.identity_fingerprint) {
1546 EXPECT_EQ(*transport1.description.identity_fingerprint,
1547 *transport2.description.identity_fingerprint);
1548 } else {
1549 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1550 transport2.description.identity_fingerprint.get());
1551 }
1552 EXPECT_EQ(transport1.description.transport_options,
1553 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001554 }
deadbeefc80741f2015-10-22 13:14:45 -07001555
1556 // global attributes
1557 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
Johannes Kron9581bc42018-10-23 10:17:39 +02001558 EXPECT_EQ(desc1.extmap_allow_mixed(), desc2.extmap_allow_mixed());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001559 }
1560
Yves Gerey665174f2018-06-19 15:03:05 +02001561 bool CompareSessionDescription(const JsepSessionDescription& desc1,
1562 const JsepSessionDescription& desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001563 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1564 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1565 CompareSessionDescription(*desc1.description(), *desc2.description());
1566 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1567 return false;
1568 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1569 const IceCandidateCollection* cc1 = desc1.candidates(i);
1570 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-12 18:37:36 -08001571 if (cc1->count() != cc2->count()) {
1572 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001573 return false;
deadbeef25ed4352016-12-12 18:37:36 -08001574 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001575 for (size_t j = 0; j < cc1->count(); ++j) {
1576 const IceCandidateInterface* c1 = cc1->at(j);
1577 const IceCandidateInterface* c2 = cc2->at(j);
1578 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1579 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1580 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1581 }
1582 }
1583 return true;
1584 }
1585
Artem Titov880fa812021-07-30 22:30:23 +02001586 // Disable the ice-ufrag and ice-pwd in given `sdp` message by replacing
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001587 // them with invalid keywords so that the parser will just ignore them.
1588 bool RemoveCandidateUfragPwd(std::string* sdp) {
Steve Anton1c9c9fc2019-02-14 15:13:09 -08001589 absl::StrReplaceAll(
1590 {{"a=ice-ufrag", "a=xice-ufrag"}, {"a=ice-pwd", "a=xice-pwd"}}, sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001591 return true;
1592 }
1593
Artem Titov880fa812021-07-30 22:30:23 +02001594 // Update the candidates in `jdesc` to use the given `ufrag` and `pwd`.
Yves Gerey665174f2018-06-19 15:03:05 +02001595 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc,
1596 int mline_index,
1597 const std::string& ufrag,
1598 const std::string& pwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001599 std::string content_name;
1600 if (mline_index == 0) {
1601 content_name = kAudioContentName;
1602 } else if (mline_index == 1) {
1603 content_name = kVideoContentName;
1604 } else {
nissec80e7412017-01-11 05:56:46 -08001605 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001606 }
Yves Gerey665174f2018-06-19 15:03:05 +02001607 TransportInfo transport_info(content_name,
1608 TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001609 SessionDescription* desc =
1610 const_cast<SessionDescription*>(jdesc->description());
1611 desc->RemoveTransportInfoByName(content_name);
Steve Anton06817cd2018-12-18 15:55:30 -08001612 desc->AddTransportInfo(transport_info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001613 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1614 const IceCandidateCollection* cc = jdesc_.candidates(i);
1615 for (size_t j = 0; j < cc->count(); ++j) {
1616 if (cc->at(j)->sdp_mline_index() == mline_index) {
Yves Gerey665174f2018-06-19 15:03:05 +02001617 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(ufrag);
1618 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001619 }
1620 }
1621 }
1622 return true;
1623 }
1624
1625 void AddIceOptions(const std::string& content_name,
1626 const std::vector<std::string>& transport_options) {
1627 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1628 cricket::TransportInfo transport_info =
1629 *(desc_.GetTransportInfoByName(content_name));
1630 desc_.RemoveTransportInfoByName(content_name);
1631 transport_info.description.transport_options = transport_options;
1632 desc_.AddTransportInfo(transport_info);
1633 }
1634
deadbeef3f7219b2015-12-28 15:17:14 -08001635 void SetIceUfragPwd(const std::string& content_name,
1636 const std::string& ice_ufrag,
1637 const std::string& ice_pwd) {
1638 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1639 cricket::TransportInfo transport_info =
1640 *(desc_.GetTransportInfoByName(content_name));
1641 desc_.RemoveTransportInfoByName(content_name);
1642 transport_info.description.ice_ufrag = ice_ufrag;
1643 transport_info.description.ice_pwd = ice_pwd;
1644 desc_.AddTransportInfo(transport_info);
1645 }
1646
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001647 void AddFingerprint() {
1648 desc_.RemoveTransportInfoByName(kAudioContentName);
1649 desc_.RemoveTransportInfoByName(kVideoContentName);
Steve Anton4905edb2018-10-15 19:27:44 -07001650 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, kIdentityDigest);
Steve Anton06817cd2018-12-18 15:55:30 -08001651 desc_.AddTransportInfo(TransportInfo(
deadbeef46eed762016-01-28 13:24:37 -08001652 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001653 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1654 cricket::ICEMODE_FULL,
Steve Anton06817cd2018-12-18 15:55:30 -08001655 cricket::CONNECTIONROLE_NONE, &fingerprint)));
1656 desc_.AddTransportInfo(TransportInfo(
deadbeef46eed762016-01-28 13:24:37 -08001657 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001658 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1659 cricket::ICEMODE_FULL,
Steve Anton06817cd2018-12-18 15:55:30 -08001660 cricket::CONNECTIONROLE_NONE, &fingerprint)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001661 }
1662
jbauch5869f502017-06-29 12:31:36 -07001663 void AddExtmap(bool encrypted) {
Harald Alvestrandb97d2fe2020-02-28 11:54:40 +01001664 audio_desc_ = new AudioContentDescription(*audio_desc_);
1665 video_desc_ = new VideoContentDescription(*video_desc_);
jbauch5869f502017-06-29 12:31:36 -07001666 audio_desc_->AddRtpHeaderExtension(
1667 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1668 video_desc_->AddRtpHeaderExtension(
1669 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001670 desc_.RemoveContentByName(kAudioContentName);
1671 desc_.RemoveContentByName(kVideoContentName);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001672 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1673 absl::WrapUnique(audio_desc_));
1674 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp,
1675 absl::WrapUnique(video_desc_));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001676 }
1677
1678 void RemoveCryptos() {
1679 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1680 video_desc_->set_cryptos(std::vector<CryptoParams>());
1681 }
1682
Seth Hampson5897a6e2018-04-03 11:16:33 -07001683 // Removes everything in StreamParams from the session description that is
1684 // used for a=ssrc lines.
1685 void RemoveSsrcSignalingFromStreamParams() {
Harald Alvestrand1716d392019-06-03 20:35:45 +02001686 for (cricket::ContentInfo& content_info :
1687 jdesc_.description()->contents()) {
Seth Hampson5897a6e2018-04-03 11:16:33 -07001688 // With Unified Plan there should be one StreamParams per m= section.
1689 StreamParams& stream =
1690 content_info.media_description()->mutable_streams()[0];
1691 stream.ssrcs.clear();
1692 stream.ssrc_groups.clear();
1693 stream.cname.clear();
1694 }
1695 }
1696
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001697 // Removes all a=ssrc lines from the SDP string, except for the
1698 // "a=ssrc:... cname:..." lines.
1699 void RemoveSsrcMsidLinesFromSdpString(std::string* sdp_string) {
1700 const char kAttributeSsrc[] = "a=ssrc";
1701 const char kAttributeCname[] = "cname";
1702 size_t ssrc_line_pos = sdp_string->find(kAttributeSsrc);
1703 while (ssrc_line_pos != std::string::npos) {
1704 size_t beg_line_pos = sdp_string->rfind('\n', ssrc_line_pos);
1705 size_t end_line_pos = sdp_string->find('\n', ssrc_line_pos);
1706 size_t cname_pos = sdp_string->find(kAttributeCname, ssrc_line_pos);
1707 if (cname_pos == std::string::npos || cname_pos > end_line_pos) {
1708 // Only erase a=ssrc lines that don't contain "cname".
1709 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1710 ssrc_line_pos = sdp_string->find(kAttributeSsrc, beg_line_pos);
1711 } else {
1712 // Skip the "a=ssrc:... cname" line and find the next "a=ssrc" line.
1713 ssrc_line_pos = sdp_string->find(kAttributeSsrc, end_line_pos);
1714 }
1715 }
1716 }
1717
Seth Hampson5897a6e2018-04-03 11:16:33 -07001718 // Removes all a=ssrc lines from the SDP string.
1719 void RemoveSsrcLinesFromSdpString(std::string* sdp_string) {
1720 const char kAttributeSsrc[] = "a=ssrc";
1721 while (sdp_string->find(kAttributeSsrc) != std::string::npos) {
1722 size_t pos_ssrc_attribute = sdp_string->find(kAttributeSsrc);
1723 size_t beg_line_pos = sdp_string->rfind('\n', pos_ssrc_attribute);
1724 size_t end_line_pos = sdp_string->find('\n', pos_ssrc_attribute);
1725 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1726 }
1727 }
1728
Steve Anton4e70a722017-11-28 14:57:10 -08001729 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001730 audio_desc_->set_direction(direction);
1731 video_desc_->set_direction(direction);
1732 std::string new_sdp = kSdpFullString;
1733 ReplaceDirection(direction, &new_sdp);
1734
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001735 if (!jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001736 jdesc_.session_version())) {
1737 return false;
1738 }
Steve Antone831b8c2018-02-01 12:22:16 -08001739 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001740 EXPECT_EQ(new_sdp, message);
1741 return true;
1742 }
1743
1744 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
Harald Alvestrandb97d2fe2020-02-28 11:54:40 +01001745 audio_desc_ = new AudioContentDescription(*audio_desc_);
1746 video_desc_ = new VideoContentDescription(*video_desc_);
zhihuang38989e52017-03-21 11:04:53 -07001747
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001748 desc_.RemoveContentByName(kAudioContentName);
1749 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001750 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001751 absl::WrapUnique(audio_desc_));
Steve Anton5adfafd2017-12-20 16:34:00 -08001752 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001753 absl::WrapUnique(video_desc_));
deadbeef9d3584c2016-02-16 17:54:10 -08001754 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1755 audio_rejected ? "" : kPwdVoice);
1756 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1757 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001758
1759 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001760 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1761
Steve Antona3a92c22017-12-07 10:27:41 -08001762 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001763 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001764 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765 EXPECT_EQ(new_sdp, message);
1766 return true;
1767 }
1768
zstein4b2e0822017-02-17 19:48:38 -08001769 void AddSctpDataChannel(bool use_sctpmap) {
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001770 std::unique_ptr<SctpDataContentDescription> data(
1771 new SctpDataContentDescription());
1772 sctp_desc_ = data.get();
1773 sctp_desc_->set_use_sctpmap(use_sctpmap);
Guido Urdanetacecf87f2019-05-31 10:17:38 +00001774 sctp_desc_->set_protocol(cricket::kMediaProtocolUdpDtlsSctp);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001775 sctp_desc_->set_port(kDefaultSctpPort);
Steve Anton5adfafd2017-12-20 16:34:00 -08001776 desc_.AddContent(kDataContentName, MediaProtocolType::kSctp,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001777 std::move(data));
Steve Anton06817cd2018-12-18 15:55:30 -08001778 desc_.AddTransportInfo(TransportInfo(
1779 kDataContentName, TransportDescription(kUfragData, kPwdData)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001780 }
1781
Steve Anton4e70a722017-11-28 14:57:10 -08001782 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001783 std::string new_sdp = kSdpFullString;
1784 ReplaceDirection(direction, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001785 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001786
1787 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1788
1789 audio_desc_->set_direction(direction);
1790 video_desc_->set_direction(direction);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001791 if (!jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001792 jdesc_.session_version())) {
1793 return false;
1794 }
1795 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1796 return true;
1797 }
1798
1799 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001800 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001801 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001802 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001803 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001804
Harald Alvestrandb97d2fe2020-02-28 11:54:40 +01001805 audio_desc_ = new AudioContentDescription(*audio_desc_);
1806 video_desc_ = new VideoContentDescription(*video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001807 desc_.RemoveContentByName(kAudioContentName);
1808 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001809 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001810 absl::WrapUnique(audio_desc_));
Steve Anton5adfafd2017-12-20 16:34:00 -08001811 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001812 absl::WrapUnique(video_desc_));
deadbeef9d3584c2016-02-16 17:54:10 -08001813 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1814 audio_rejected ? "" : kPwdVoice);
1815 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1816 video_rejected ? "" : kPwdVideo);
Steve Antona3a92c22017-12-07 10:27:41 -08001817 JsepSessionDescription jdesc_no_candidates(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001818 if (!jdesc_no_candidates.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef3f7219b2015-12-28 15:17:14 -08001819 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001820 return false;
1821 }
deadbeef3f7219b2015-12-28 15:17:14 -08001822 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001823 return true;
1824 }
1825
Yves Gerey665174f2018-06-19 15:03:05 +02001826 void TestDeserializeExtmap(bool session_level,
1827 bool media_level,
1828 bool encrypted) {
jbauch5869f502017-06-29 12:31:36 -07001829 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08001830 JsepSessionDescription new_jdesc(SdpType::kOffer);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001831 ASSERT_TRUE(new_jdesc.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001832 jdesc_.session_version()));
Steve Antona3a92c22017-12-07 10:27:41 -08001833 JsepSessionDescription jdesc_with_extmap(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001834 std::string sdp_with_extmap = kSdpString;
1835 if (session_level) {
jbauch5869f502017-06-29 12:31:36 -07001836 InjectAfter(kSessionTime,
1837 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1838 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001839 &sdp_with_extmap);
1840 }
1841 if (media_level) {
jbauch5869f502017-06-29 12:31:36 -07001842 InjectAfter(kAttributeIcePwdVoice,
1843 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1844 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001845 &sdp_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07001846 InjectAfter(kAttributeIcePwdVideo,
1847 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1848 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001849 &sdp_with_extmap);
1850 }
1851 // The extmap can't be present at the same time in both session level and
1852 // media level.
1853 if (session_level && media_level) {
1854 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02001855 EXPECT_FALSE(
1856 webrtc::SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001857 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1858 } else {
1859 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1860 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1861 }
1862 }
1863
1864 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
Yves Gerey665174f2018-06-19 15:03:05 +02001865 const std::string& name,
1866 int expected_value) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001867 cricket::CodecParameterMap::const_iterator found = params.find(name);
1868 ASSERT_TRUE(found != params.end());
Jonas Olsson6b1985d2018-07-05 11:59:48 +02001869 EXPECT_EQ(found->second, rtc::ToString(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001870 }
1871
1872 void TestDeserializeCodecParams(const CodecParams& params,
1873 JsepSessionDescription* jdesc_output) {
1874 std::string sdp =
1875 "v=0\r\n"
1876 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1877 "s=-\r\n"
1878 "t=0 0\r\n"
1879 // Include semantics for WebRTC Media Streams since it is supported by
1880 // this parser, and will be added to the SDP when serializing a session
1881 // description.
1882 "a=msid-semantic: WMS\r\n"
1883 // Pl type 111 preferred.
Philipp Hanckef2a4ec12020-07-01 21:07:32 +02001884 "m=audio 9 RTP/SAVPF 111 104 103 105\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001885 // Pltype 111 listed before 103 and 104 in the map.
1886 "a=rtpmap:111 opus/48000/2\r\n"
1887 // Pltype 103 listed before 104.
1888 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001889 "a=rtpmap:104 ISAC/32000\r\n"
Philipp Hanckef2a4ec12020-07-01 21:07:32 +02001890 "a=rtpmap:105 telephone-event/8000\r\n"
1891 "a=fmtp:105 0-15,66,70\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001892 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001893 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001894 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001895 << "; sprop-stereo=" << params.sprop_stereo
1896 << "; useinbandfec=" << params.useinband
Jonas Olssonb2b20312020-01-14 12:11:31 +01001897 << "; maxaveragebitrate=" << params.maxaveragebitrate
1898 << "\r\n"
1899 "a=ptime:"
1900 << params.ptime
1901 << "\r\n"
1902 "a=maxptime:"
1903 << params.max_ptime << "\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001904 sdp += os.str();
1905
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001906 os.clear();
1907 os.str("");
1908 // Pl type 100 preferred.
Philipp Hanckeb7bc2432021-03-11 15:28:00 +01001909 os << "m=video 9 RTP/SAVPF 99 95 96\r\n"
1910 "a=rtpmap:96 VP9/90000\r\n" // out-of-order wrt the m= line.
Jonas Olssonb2b20312020-01-14 12:11:31 +01001911 "a=rtpmap:99 VP8/90000\r\n"
1912 "a=rtpmap:95 RTX/90000\r\n"
1913 "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001914 sdp += os.str();
1915
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001916 // Deserialize
1917 SdpParseError error;
1918 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1919
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001920 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001921 GetFirstAudioContentDescription(jdesc_output->description());
1922 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001923 ASSERT_FALSE(acd->codecs().empty());
1924 cricket::AudioCodec opus = acd->codecs()[0];
1925 EXPECT_EQ("opus", opus.name);
1926 EXPECT_EQ(111, opus.id);
1927 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1928 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1929 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1930 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001931 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1932 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001933 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1934 cricket::AudioCodec codec = acd->codecs()[i];
1935 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1936 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001937 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001938
Philipp Hanckef2a4ec12020-07-01 21:07:32 +02001939 cricket::AudioCodec dtmf = acd->codecs()[3];
1940 EXPECT_EQ("telephone-event", dtmf.name);
1941 EXPECT_EQ(105, dtmf.id);
1942 EXPECT_EQ(3u,
1943 dtmf.params.size()); // ptime and max_ptime count as parameters.
1944 EXPECT_EQ(dtmf.params.begin()->first, "");
1945 EXPECT_EQ(dtmf.params.begin()->second, "0-15,66,70");
1946
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001947 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001948 GetFirstVideoContentDescription(jdesc_output->description());
1949 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001950 ASSERT_FALSE(vcd->codecs().empty());
1951 cricket::VideoCodec vp8 = vcd->codecs()[0];
1952 EXPECT_EQ("VP8", vp8.name);
1953 EXPECT_EQ(99, vp8.id);
1954 cricket::VideoCodec rtx = vcd->codecs()[1];
1955 EXPECT_EQ("RTX", rtx.name);
1956 EXPECT_EQ(95, rtx.id);
1957 VerifyCodecParameter(rtx.params, "apt", vp8.id);
Philipp Hanckeb7bc2432021-03-11 15:28:00 +01001958 // VP9 is listed last in the m= line so should come after VP8 and RTX.
1959 cricket::VideoCodec vp9 = vcd->codecs()[2];
1960 EXPECT_EQ("VP9", vp9.name);
1961 EXPECT_EQ(96, vp9.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001962 }
1963
1964 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1965 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001966 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001967 "v=0\r\n"
1968 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1969 "s=-\r\n"
1970 "t=0 0\r\n"
1971 // Include semantics for WebRTC Media Streams since it is supported by
1972 // this parser, and will be added to the SDP when serializing a session
1973 // description.
1974 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001975 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001976 "a=rtpmap:111 opus/48000/2\r\n";
1977 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001978 "m=video 3457 RTP/SAVPF 101\r\n"
1979 "a=rtpmap:101 VP8/90000\r\n"
Elad Alonfadb1812019-05-24 13:40:02 +02001980 "a=rtcp-fb:101 goog-lntf\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001981 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001982 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001983 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001984 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001985 os << sdp_session_and_audio;
Yves Gerey665174f2018-06-19 15:03:05 +02001986 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001987 os << sdp_video;
Yves Gerey665174f2018-06-19 15:03:05 +02001988 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001989 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001990 // Deserialize
1991 SdpParseError error;
1992 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001993 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001994 GetFirstAudioContentDescription(jdesc_output->description());
1995 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001996 ASSERT_FALSE(acd->codecs().empty());
1997 cricket::AudioCodec opus = acd->codecs()[0];
1998 EXPECT_EQ(111, opus.id);
Yves Gerey665174f2018-06-19 15:03:05 +02001999 EXPECT_TRUE(opus.HasFeedbackParam(cricket::FeedbackParam(
2000 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002001
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002002 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08002003 GetFirstVideoContentDescription(jdesc_output->description());
2004 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002005 ASSERT_FALSE(vcd->codecs().empty());
2006 cricket::VideoCodec vp8 = vcd->codecs()[0];
2007 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
2008 vp8.name.c_str());
2009 EXPECT_EQ(101, vp8.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002010 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
Elad Alonfadb1812019-05-24 13:40:02 +02002011 cricket::kRtcpFbParamLntf, cricket::kParamValueEmpty)));
2012 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
Yves Gerey665174f2018-06-19 15:03:05 +02002013 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
2014 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2015 cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli)));
2016 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2017 cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty)));
2018 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2019 cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002020 }
2021
2022 // Two SDP messages can mean the same thing but be different strings, e.g.
2023 // some of the lines can be serialized in different order.
2024 // However, a deserialized description can be compared field by field and has
2025 // no order. If deserializer has already been tested, serializing then
2026 // deserializing and comparing JsepSessionDescription will test
2027 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 12:22:16 -08002028 void TestSerialize(const JsepSessionDescription& jdesc) {
2029 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 10:27:41 -08002030 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002031 SdpParseError error;
2032 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
2033 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
2034 }
2035
zhihuang38989e52017-03-21 11:04:53 -07002036 // Calling 'Initialize' with a copy of the inner SessionDescription will
2037 // create a copy of the JsepSessionDescription without candidates. The
2038 // 'connection address' field, previously set from the candidates, must also
2039 // be reset.
2040 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
2041 rtc::SocketAddress audio_addr("0.0.0.0", 9);
2042 rtc::SocketAddress video_addr("0.0.0.0", 9);
2043 audio_desc_->set_connection_address(audio_addr);
2044 video_desc_->set_connection_address(video_addr);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002045 ASSERT_TRUE(jdesc->Initialize(desc_.Clone(), kSessionId, kSessionVersion));
zhihuang38989e52017-03-21 11:04:53 -07002046 }
2047
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002048 protected:
2049 SessionDescription desc_;
2050 AudioContentDescription* audio_desc_;
2051 VideoContentDescription* video_desc_;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002052 SctpDataContentDescription* sctp_desc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002053 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07002054 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002055 JsepSessionDescription jdesc_;
2056};
2057
2058void TestMismatch(const std::string& string1, const std::string& string2) {
2059 int position = 0;
2060 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
2061 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002062 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002063 break;
2064 }
2065 }
2066 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
2067 << " character\n"
Jonas Olssonb2b20312020-01-14 12:11:31 +01002068 " 1: "
2069 << string1.substr(position, 20)
2070 << "\n"
2071 " 2: "
2072 << string2.substr(position, 20) << "\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002073}
2074
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002075TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
2076 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 12:22:16 -08002077 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002078 TestMismatch(std::string(kSdpFullString), message);
2079}
2080
2081TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 10:27:41 -08002082 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 12:22:16 -08002083 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002084}
2085
2086// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
2087// the case in a DTLS offer.
2088TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
2089 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002090 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002091 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08002092 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002093
2094 std::string sdp_with_fingerprint = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002095 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2096 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002097
2098 EXPECT_EQ(sdp_with_fingerprint, message);
2099}
2100
2101// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
2102// be the case in a DTLS answer.
2103TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
2104 AddFingerprint();
2105 RemoveCryptos();
Steve Antona3a92c22017-12-07 10:27:41 -08002106 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002107 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08002108 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002109
2110 std::string sdp_with_fingerprint = kSdpString;
2111 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
2112 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
Yves Gerey665174f2018-06-19 15:03:05 +02002113 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2114 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002115
2116 EXPECT_EQ(sdp_with_fingerprint, message);
2117}
2118
2119TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
2120 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002121 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002122 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08002123 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002124 EXPECT_EQ(std::string(kSdpString), message);
2125}
2126
Henrik Boströmf8187e02021-04-26 21:04:26 +02002127TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundles) {
2128 ContentGroup group1(cricket::GROUP_TYPE_BUNDLE);
2129 group1.AddContentName(kAudioContentName);
2130 group1.AddContentName(kVideoContentName);
2131 desc_.AddGroup(group1);
2132 ContentGroup group2(cricket::GROUP_TYPE_BUNDLE);
2133 group2.AddContentName(kAudioContentName2);
2134 desc_.AddGroup(group2);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002135 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002136 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002137 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002138 std::string sdp_with_bundle = kSdpFullString;
2139 InjectAfter(kSessionTime,
Henrik Boströmf8187e02021-04-26 21:04:26 +02002140 "a=group:BUNDLE audio_content_name video_content_name\r\n"
2141 "a=group:BUNDLE audio_content_name_2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002142 &sdp_with_bundle);
2143 EXPECT_EQ(sdp_with_bundle, message);
2144}
2145
2146TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 15:14:30 -08002147 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
Taylor Brandstetteree8c2462020-07-27 15:52:02 -07002148 vcd->set_bandwidth(100 * 1000 + 755); // Integer division will drop the 755.
2149 vcd->set_bandwidth_type("AS");
Steve Antonb1c1de12017-12-21 15:14:30 -08002150 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
Taylor Brandstetteree8c2462020-07-27 15:52:02 -07002151 acd->set_bandwidth(555);
2152 acd->set_bandwidth_type("TIAS");
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002153 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002154 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002155 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002156 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002157 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002158 &sdp_with_bandwidth);
Taylor Brandstetteree8c2462020-07-27 15:52:02 -07002159 InjectAfter("c=IN IP4 74.125.127.126\r\n", "b=TIAS:555\r\n",
2160 &sdp_with_bandwidth);
2161 EXPECT_EQ(sdp_with_bandwidth, message);
2162}
2163
2164// Should default to b=AS if bandwidth_type isn't set.
2165TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithMissingBandwidthType) {
2166 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
2167 vcd->set_bandwidth(100 * 1000);
2168 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2169 jdesc_.session_version()));
2170 std::string message = webrtc::SdpSerialize(jdesc_);
2171 std::string sdp_with_bandwidth = kSdpFullString;
2172 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002173 &sdp_with_bandwidth);
2174 EXPECT_EQ(sdp_with_bandwidth, message);
2175}
2176
2177TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
2178 std::vector<std::string> transport_options;
2179 transport_options.push_back(kIceOption1);
2180 transport_options.push_back(kIceOption3);
2181 AddIceOptions(kAudioContentName, transport_options);
2182 transport_options.clear();
2183 transport_options.push_back(kIceOption2);
2184 transport_options.push_back(kIceOption3);
2185 AddIceOptions(kVideoContentName, transport_options);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002186 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002187 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002188 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002189 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002190 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002191 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002192 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002193 &sdp_with_ice_options);
2194 EXPECT_EQ(sdp_with_ice_options, message);
2195}
2196
2197TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002198 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002199}
2200
2201TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002202 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002203}
2204
2205TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002206 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002207}
2208
2209TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2210 EXPECT_TRUE(TestSerializeRejected(true, false));
2211}
2212
2213TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2214 EXPECT_TRUE(TestSerializeRejected(false, true));
2215}
2216
2217TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2218 EXPECT_TRUE(TestSerializeRejected(true, true));
2219}
2220
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002221TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08002222 bool use_sctpmap = true;
2223 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002224 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002225
zhihuang38989e52017-03-21 11:04:53 -07002226 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002227 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002228
2229 std::string expected_sdp = kSdpString;
2230 expected_sdp.append(kSdpSctpDataChannelString);
2231 EXPECT_EQ(message, expected_sdp);
2232}
2233
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002234void MutateJsepSctpPort(JsepSessionDescription* jdesc,
2235 const SessionDescription& desc,
2236 int port) {
2237 // Take our pre-built session description and change the SCTP port.
2238 std::unique_ptr<cricket::SessionDescription> mutant = desc.Clone();
2239 SctpDataContentDescription* dcdesc =
2240 mutant->GetContentDescriptionByName(kDataContentName)->as_sctp();
2241 dcdesc->set_port(port);
2242 ASSERT_TRUE(
2243 jdesc->Initialize(std::move(mutant), kSessionId, kSessionVersion));
2244}
2245
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002246TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08002247 bool use_sctpmap = true;
2248 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002249 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002250 MakeDescriptionWithoutCandidates(&jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002251
2252 const int kNewPort = 1234;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002253 MutateJsepSctpPort(&jsep_desc, desc_, kNewPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002254
Steve Antone831b8c2018-02-01 12:22:16 -08002255 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002256
2257 std::string expected_sdp = kSdpString;
2258 expected_sdp.append(kSdpSctpDataChannelString);
2259
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002260 absl::StrReplaceAll(
2261 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kNewPort)}},
2262 &expected_sdp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002263
2264 EXPECT_EQ(expected_sdp, message);
2265}
2266
Johannes Kron0854eb62018-10-10 22:33:20 +02002267TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002268 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002269 TestSerialize(jdesc_);
2270}
2271
2272TEST_F(WebRtcSdpTest, SerializeMediaContentDescriptionWithExtmapAllowMixed) {
2273 cricket::MediaContentDescription* video_desc =
2274 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2275 ASSERT_TRUE(video_desc);
2276 cricket::MediaContentDescription* audio_desc =
2277 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2278 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002279 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002280 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002281 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002282 cricket::MediaContentDescription::kMedia);
2283 TestSerialize(jdesc_);
2284}
2285
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002286TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002287 bool encrypted = false;
2288 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002289 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002290 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 12:22:16 -08002291 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002292
2293 std::string sdp_with_extmap = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002294 InjectAfter("a=mid:audio_content_name\r\n", kExtmap, &sdp_with_extmap);
2295 InjectAfter("a=mid:video_content_name\r\n", kExtmap, &sdp_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002296
2297 EXPECT_EQ(sdp_with_extmap, message);
2298}
2299
jbauch5869f502017-06-29 12:31:36 -07002300TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2301 bool encrypted = true;
2302 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002303 JsepSessionDescription desc_with_extmap(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002304 ASSERT_TRUE(
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002305 desc_with_extmap.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 12:22:16 -08002306 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07002307}
2308
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002309TEST_F(WebRtcSdpTest, SerializeCandidates) {
2310 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002311 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002312
2313 Candidate candidate_with_ufrag(candidates_.front());
2314 candidate_with_ufrag.set_username("ABC");
2315 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2316 candidate_with_ufrag));
2317 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2318 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002319
2320 Candidate candidate_with_network_info(candidates_.front());
2321 candidate_with_network_info.set_network_id(1);
2322 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2323 candidate_with_network_info));
2324 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2325 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2326 candidate_with_network_info.set_network_cost(999);
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 network-cost 999",
2331 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002332}
2333
Zach Steinb336c272018-08-09 01:16:13 -07002334TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) {
2335 rtc::SocketAddress address("a.test", 1234);
2336 cricket::Candidate candidate(
2337 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
2338 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
2339 JsepIceCandidate jcandidate(std::string("audio_content_name"), 0, candidate);
2340 std::string message = webrtc::SdpSerializeCandidate(jcandidate);
2341 EXPECT_EQ(std::string(kRawHostnameCandidate), message);
2342}
2343
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002344TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002345 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002346 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2347 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2348 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002349 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002350 std::unique_ptr<IceCandidateInterface> jcandidate(
2351 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002352
2353 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2354 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2355}
2356
Taylor Brandstetter8206bc02020-04-02 12:36:38 -07002357// Test serializing a TCP candidate that came in with a missing tcptype. This
2358// shouldn't happen according to the spec, but our implementation has been
2359// accepting this for quite some time, treating it as a passive candidate.
2360//
2361// So, we should be able to at least convert such candidates to and from SDP.
2362// See: bugs.webrtc.org/11423
2363TEST_F(WebRtcSdpTest, ParseTcpCandidateWithoutTcptype) {
2364 std::string missing_tcptype =
2365 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9999 typ host";
2366 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2367 EXPECT_TRUE(SdpDeserializeCandidate(missing_tcptype, &jcandidate));
2368
2369 EXPECT_EQ(std::string(cricket::TCPTYPE_PASSIVE_STR),
2370 jcandidate.candidate().tcptype());
2371}
2372
2373TEST_F(WebRtcSdpTest, ParseSslTcpCandidate) {
2374 std::string ssltcp =
2375 "candidate:a0+B/1 1 ssltcp 2130706432 192.168.1.5 9999 typ host tcptype "
2376 "passive";
2377 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2378 EXPECT_TRUE(SdpDeserializeCandidate(ssltcp, &jcandidate));
2379
2380 EXPECT_EQ(std::string("ssltcp"), jcandidate.candidate().protocol());
2381}
2382
htaa6b99442016-04-12 10:29:17 -07002383TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002384 cricket::VideoCodec h264_codec("H264");
2385 h264_codec.SetParam("profile-level-id", "42e01f");
2386 h264_codec.SetParam("level-asymmetry-allowed", "1");
2387 h264_codec.SetParam("packetization-mode", "1");
2388 video_desc_->AddCodec(h264_codec);
2389
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002390 jdesc_.Initialize(desc_.Clone(), kSessionId, kSessionVersion);
htaa6b99442016-04-12 10:29:17 -07002391
Steve Antone831b8c2018-02-01 12:22:16 -08002392 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 10:29:17 -07002393 size_t after_pt = message.find(" H264/90000");
2394 ASSERT_NE(after_pt, std::string::npos);
2395 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2396 ASSERT_NE(before_pt, std::string::npos);
2397 before_pt += strlen("a=rtpmap:");
2398 std::string pt = message.substr(before_pt, after_pt - before_pt);
Artem Titov880fa812021-07-30 22:30:23 +02002399 // TODO(hta): Check if payload type `pt` occurs in the m=video line.
htaa6b99442016-04-12 10:29:17 -07002400 std::string to_find = "a=fmtp:" + pt + " ";
2401 size_t fmtp_pos = message.find(to_find);
2402 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
Mirko Bonadei37ec55e2019-01-28 11:43:52 +01002403 size_t fmtp_endpos = message.find('\n', fmtp_pos);
htaa6b99442016-04-12 10:29:17 -07002404 ASSERT_NE(std::string::npos, fmtp_endpos);
2405 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2406 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2407 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2408 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002409 // Check that there are no spaces after semicolons.
2410 // https://bugs.webrtc.org/5793
2411 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002412}
2413
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002414TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 10:27:41 -08002415 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002416 // Deserialize
2417 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2418 // Verify
2419 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2420}
2421
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002422TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 10:27:41 -08002423 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002424 const char kSdpWithoutMline[] =
Yves Gerey665174f2018-06-19 15:03:05 +02002425 "v=0\r\n"
2426 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2427 "s=-\r\n"
2428 "t=0 0\r\n"
2429 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002430 // Deserialize
2431 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2432 EXPECT_EQ(0u, jdesc.description()->contents().size());
2433}
2434
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002435TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 10:27:41 -08002436 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002437 std::string sdp_without_carriage_return = kSdpFullString;
2438 Replace("\r\n", "\n", &sdp_without_carriage_return);
2439 // Deserialize
2440 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2441 // Verify
2442 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2443}
2444
2445TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2446 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002447 JsepSessionDescription jdesc_no_candidates(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002448 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Clone(), kSessionId,
Yves Gerey665174f2018-06-19 15:03:05 +02002449 kSessionVersion));
Steve Antona3a92c22017-12-07 10:27:41 -08002450 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002451 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2452 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2453}
2454
2455TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2456 static const char kSdpNoRtpmapString[] =
2457 "v=0\r\n"
2458 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2459 "s=-\r\n"
2460 "t=0 0\r\n"
2461 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2462 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002463 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002464 // The rtpmap line for static payload codec is optional.
2465 "a=rtpmap:18 G729/16000\r\n"
2466 "a=rtpmap:103 ISAC/16000\r\n";
2467
Steve Antona3a92c22017-12-07 10:27:41 -08002468 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002469 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2470 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08002471 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002472 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002473 // The codecs in the AudioContentDescription should be in the same order as
2474 // the payload types (<fmt>s) on the m= line.
2475 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2476 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002477 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002478 EXPECT_EQ(ref_codecs, audio->codecs());
2479}
2480
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002481TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2482 static const char kSdpNoRtpmapString[] =
2483 "v=0\r\n"
2484 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2485 "s=-\r\n"
2486 "t=0 0\r\n"
2487 "m=audio 49232 RTP/AVP 18 103\r\n"
2488 "a=fmtp:18 annexb=yes\r\n"
2489 "a=rtpmap:103 ISAC/16000\r\n";
2490
Steve Antona3a92c22017-12-07 10:27:41 -08002491 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002492 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2493 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08002494 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002495
2496 cricket::AudioCodec g729 = audio->codecs()[0];
2497 EXPECT_EQ("G729", g729.name);
2498 EXPECT_EQ(8000, g729.clockrate);
2499 EXPECT_EQ(18, g729.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002500 cricket::CodecParameterMap::iterator found = g729.params.find("annexb");
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002501 ASSERT_TRUE(found != g729.params.end());
2502 EXPECT_EQ(found->second, "yes");
2503
2504 cricket::AudioCodec isac = audio->codecs()[1];
2505 EXPECT_EQ("ISAC", isac.name);
2506 EXPECT_EQ(103, isac.id);
2507 EXPECT_EQ(16000, isac.clockrate);
2508}
2509
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002510// Ensure that we can deserialize SDP with a=fingerprint properly.
2511TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2512 // Add a DTLS a=fingerprint attribute to our session description.
2513 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002514 JsepSessionDescription new_jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002515 ASSERT_TRUE(new_jdesc.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002516 jdesc_.session_version()));
2517
Steve Antona3a92c22017-12-07 10:27:41 -08002518 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002519 std::string sdp_with_fingerprint = kSdpString;
2520 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2521 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2522 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2523 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2524}
2525
2526TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 10:27:41 -08002527 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002528 std::string sdp_with_bundle = kSdpFullString;
2529 InjectAfter(kSessionTime,
2530 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2531 &sdp_with_bundle);
2532 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2533 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2534 group.AddContentName(kAudioContentName);
2535 group.AddContentName(kVideoContentName);
2536 desc_.AddGroup(group);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002537 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002538 jdesc_.session_version()));
2539 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2540}
2541
2542TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002543 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002544 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002545 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002546 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002547 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002548 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002549 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 15:14:30 -08002550 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002551 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002552 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002553 acd->set_bandwidth(50 * 1000);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002554 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002555 jdesc_.session_version()));
2556 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2557}
2558
Taylor Brandstetteree8c2462020-07-27 15:52:02 -07002559TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithTiasBandwidth) {
2560 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
2561 std::string sdp_with_bandwidth = kSdpFullString;
2562 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=TIAS:100000\r\n",
2563 &sdp_with_bandwidth);
2564 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=TIAS:50000\r\n",
2565 &sdp_with_bandwidth);
2566 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2567 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
2568 vcd->set_bandwidth(100 * 1000);
2569 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
2570 acd->set_bandwidth(50 * 1000);
2571 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2572 jdesc_.session_version()));
2573 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2574}
2575
Philipp Hanckefbbfc022020-07-31 08:30:50 +02002576TEST_F(WebRtcSdpTest,
2577 DeserializeSessionDescriptionWithUnknownBandwidthModifier) {
2578 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
2579 std::string sdp_with_bandwidth = kSdpFullString;
2580 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
2581 "b=unknown:100000\r\n", &sdp_with_bandwidth);
2582 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
2583 "b=unknown:50000\r\n", &sdp_with_bandwidth);
2584 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2585 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
2586 vcd->set_bandwidth(-1);
2587 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
2588 acd->set_bandwidth(-1);
2589 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2590 jdesc_.session_version()));
2591 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2592}
2593
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002594TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 10:27:41 -08002595 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002596 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002597 InjectAfter(kSessionTime, "a=ice-options:iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002598 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002599 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002600 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002601 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002602 &sdp_with_ice_options);
2603 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2604 std::vector<std::string> transport_options;
2605 transport_options.push_back(kIceOption3);
2606 transport_options.push_back(kIceOption1);
2607 AddIceOptions(kAudioContentName, transport_options);
2608 transport_options.clear();
2609 transport_options.push_back(kIceOption3);
2610 transport_options.push_back(kIceOption2);
2611 AddIceOptions(kVideoContentName, transport_options);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002612 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002613 jdesc_.session_version()));
2614 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2615}
2616
2617TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2618 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 10:27:41 -08002619 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002620 std::string sdp_with_ufrag_pwd = kSdpFullString;
2621 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2622 // Add session level ufrag and pwd
2623 InjectAfter(kSessionTime,
Yves Gerey665174f2018-06-19 15:03:05 +02002624 "a=ice-pwd:session+level+icepwd\r\n"
2625 "a=ice-ufrag:session+level+iceufrag\r\n",
2626 &sdp_with_ufrag_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002627 // Add media level ufrag and pwd for audio
Yves Gerey665174f2018-06-19 15:03:05 +02002628 InjectAfter(
2629 "a=mid:audio_content_name\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002630 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2631 &sdp_with_ufrag_pwd);
2632 // Update the candidate ufrag and pwd to the expected ones.
Yves Gerey665174f2018-06-19 15:03:05 +02002633 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, "media+level+iceufrag",
2634 "media+level+icepwd"));
2635 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, "session+level+iceufrag",
2636 "session+level+icepwd"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002637 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2638 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2639}
2640
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002641TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002642 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002643}
2644
2645TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002646 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002647}
2648
2649TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002650 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002651}
2652
2653TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2654 EXPECT_TRUE(TestDeserializeRejected(true, false));
2655}
2656
2657TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2658 EXPECT_TRUE(TestDeserializeRejected(false, true));
2659}
2660
2661TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2662 EXPECT_TRUE(TestDeserializeRejected(true, true));
2663}
2664
Artem Titovf0a34f22020-03-16 17:52:04 +00002665// Tests that we can still handle the sdp uses mslabel and label instead of
2666// msid for backward compatibility.
2667TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
2668 jdesc_.description()->set_msid_supported(false);
2669 JsepSessionDescription jdesc(kDummyType);
2670 std::string sdp_without_msid = kSdpFullString;
2671 Replace("msid", "xmsid", &sdp_without_msid);
2672 // Deserialize
2673 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2674 // Verify
2675 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2676 EXPECT_FALSE(jdesc.description()->msid_signaling() &
2677 ~cricket::kMsidSignalingSsrcAttribute);
2678}
2679
Johannes Kron0854eb62018-10-10 22:33:20 +02002680TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002681 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002682 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
Johannes Kron0854eb62018-10-10 22:33:20 +02002683 // Deserialize
2684 JsepSessionDescription jdesc_deserialized(kDummyType);
Emil Lundmark801c9992021-01-19 13:06:32 +01002685 ASSERT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
Johannes Kron0854eb62018-10-10 22:33:20 +02002686 // Verify
2687 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2688}
2689
2690TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002691 jdesc_.description()->set_extmap_allow_mixed(false);
Johannes Kron0854eb62018-10-10 22:33:20 +02002692 std::string sdp_without_extmap_allow_mixed = kSdpFullString;
Emil Lundmark801c9992021-01-19 13:06:32 +01002693 Replace(kExtmapAllowMixed, "", &sdp_without_extmap_allow_mixed);
Johannes Kron0854eb62018-10-10 22:33:20 +02002694 // Deserialize
2695 JsepSessionDescription jdesc_deserialized(kDummyType);
Emil Lundmark801c9992021-01-19 13:06:32 +01002696 ASSERT_TRUE(
Johannes Kron0854eb62018-10-10 22:33:20 +02002697 SdpDeserialize(sdp_without_extmap_allow_mixed, &jdesc_deserialized));
2698 // Verify
2699 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2700}
2701
2702TEST_F(WebRtcSdpTest, DeserializeMediaContentDescriptionWithExtmapAllowMixed) {
2703 cricket::MediaContentDescription* video_desc =
2704 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2705 ASSERT_TRUE(video_desc);
2706 cricket::MediaContentDescription* audio_desc =
2707 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2708 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002709 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002710 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002711 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002712 cricket::MediaContentDescription::kMedia);
2713
2714 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2715 InjectAfter("a=mid:audio_content_name\r\n", kExtmapAllowMixed,
2716 &sdp_with_extmap_allow_mixed);
2717 InjectAfter("a=mid:video_content_name\r\n", kExtmapAllowMixed,
2718 &sdp_with_extmap_allow_mixed);
2719
2720 // Deserialize
2721 JsepSessionDescription jdesc_deserialized(kDummyType);
2722 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2723 // Verify
2724 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2725}
2726
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002727TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2728 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2729
2730 std::string sdp = kSdpOneCandidate;
2731 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2732 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2733 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2734 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002735 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002736
2737 // Candidate line without generation extension.
2738 sdp = kSdpOneCandidate;
2739 Replace(" generation 2", "", &sdp);
2740 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2741 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2742 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2743 Candidate expected = jcandidate_->candidate();
2744 expected.set_generation(0);
2745 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2746
honghaiza0c44ea2016-03-23 16:07:48 -07002747 // Candidate with network id and/or cost.
2748 sdp = kSdpOneCandidate;
2749 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2750 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2751 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2752 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2753 expected = jcandidate_->candidate();
2754 expected.set_network_id(2);
2755 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2756 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2757 // Add network cost
2758 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2759 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2760 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2761 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2762
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002763 sdp = kSdpTcpActiveCandidate;
2764 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2765 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002766 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002767 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2768 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2769 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002770 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2771 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
Yves Gerey665174f2018-06-19 15:03:05 +02002772 EXPECT_TRUE(
2773 jcandidate.candidate().IsEquivalent(jcandidate_template->candidate()));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002774 sdp = kSdpTcpPassiveCandidate;
2775 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2776 sdp = kSdpTcpSOCandidate;
2777 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002778}
2779
2780// This test verifies the deserialization of candidate-attribute
2781// as per RFC 5245. Candiate-attribute will be of the format
2782// candidate:<blah>. This format will be used when candidates
2783// are trickled.
2784TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2785 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2786
2787 std::string candidate_attribute = kRawCandidate;
2788 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2789 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2790 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2791 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2792 EXPECT_EQ(2u, jcandidate.candidate().generation());
2793
2794 // Candidate line without generation extension.
2795 candidate_attribute = kRawCandidate;
2796 Replace(" generation 2", "", &candidate_attribute);
2797 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2798 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2799 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2800 Candidate expected = jcandidate_->candidate();
2801 expected.set_generation(0);
2802 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2803
2804 // Candidate line without candidate:
2805 candidate_attribute = kRawCandidate;
2806 Replace("candidate:", "", &candidate_attribute);
2807 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2808
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002809 // Candidate line with IPV6 address.
2810 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
Zach Steinb336c272018-08-09 01:16:13 -07002811
2812 // Candidate line with hostname address.
2813 EXPECT_TRUE(SdpDeserializeCandidate(kRawHostnameCandidate, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002814}
2815
2816// This test verifies that the deserialization of an invalid candidate string
2817// fails.
2818TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
Yves Gerey665174f2018-06-19 15:03:05 +02002819 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002820
2821 std::string candidate_attribute = kRawCandidate;
2822 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002823 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002824
2825 candidate_attribute = kSdpOneCandidate;
2826 candidate_attribute.replace(0, 1, "x");
2827 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2828
2829 candidate_attribute = kRawCandidate;
2830 candidate_attribute.append("\r\n");
2831 candidate_attribute.append(kRawCandidate);
2832 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2833
2834 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002835}
2836
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002837TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002838 bool use_sctpmap = true;
2839 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002840 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002841 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002842
2843 std::string sdp_with_data = kSdpString;
2844 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002845 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002846
Guido Urdanetacecf87f2019-05-31 10:17:38 +00002847 // Verify with UDP/DTLS/SCTP (already in kSdpSctpDataChannelString).
lally@webrtc.org36300852015-02-24 20:19:35 +00002848 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2849 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2850
Guido Urdanetacecf87f2019-05-31 10:17:38 +00002851 // Verify with DTLS/SCTP.
2852 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2853 kDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002854 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2855 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2856
2857 // Verify with TCP/DTLS/SCTP.
Guido Urdanetacecf87f2019-05-31 10:17:38 +00002858 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
Yves Gerey665174f2018-06-19 15:03:05 +02002859 kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002860 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2861 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2862}
2863
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002864TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002865 bool use_sctpmap = false;
2866 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002867 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002868 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002869
2870 std::string sdp_with_data = kSdpString;
2871 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002872 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002873
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002874 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2875 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2876}
2877
lally69f57602015-10-08 10:15:04 -07002878TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002879 bool use_sctpmap = false;
2880 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002881 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002882 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
lally69f57602015-10-08 10:15:04 -07002883
2884 std::string sdp_with_data = kSdpString;
2885 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002886 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 10:15:04 -07002887
lally69f57602015-10-08 10:15:04 -07002888 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2889 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2890}
2891
Philipp Hanckeefc55b02020-06-26 10:17:05 +02002892TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsButWrongMediaType) {
2893 bool use_sctpmap = true;
2894 AddSctpDataChannel(use_sctpmap);
2895 JsepSessionDescription jdesc(kDummyType);
2896 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
2897
2898 std::string sdp = kSdpSessionString;
2899 sdp += kSdpSctpDataChannelString;
2900
2901 const char needle[] = "m=application ";
2902 sdp.replace(sdp.find(needle), strlen(needle), "m=application:bogus ");
2903
2904 JsepSessionDescription jdesc_output(kDummyType);
2905 EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output));
2906
Philipp Hancke4e8c1152020-10-13 12:43:15 +02002907 EXPECT_EQ(1u, jdesc_output.description()->contents().size());
2908 EXPECT_TRUE(jdesc_output.description()->contents()[0].rejected);
Philipp Hanckeefc55b02020-06-26 10:17:05 +02002909}
2910
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002911// Helper function to set the max-message-size parameter in the
2912// SCTP data codec.
2913void MutateJsepSctpMaxMessageSize(const SessionDescription& desc,
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002914 int new_value,
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002915 JsepSessionDescription* jdesc) {
Harald Alvestrand8da35a62019-05-10 09:31:04 +02002916 std::unique_ptr<cricket::SessionDescription> mutant = desc.Clone();
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002917 SctpDataContentDescription* dcdesc =
2918 mutant->GetContentDescriptionByName(kDataContentName)->as_sctp();
2919 dcdesc->set_max_message_size(new_value);
Harald Alvestrand8da35a62019-05-10 09:31:04 +02002920 jdesc->Initialize(std::move(mutant), kSessionId, kSessionVersion);
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002921}
2922
2923TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithMaxMessageSize) {
2924 bool use_sctpmap = false;
2925 AddSctpDataChannel(use_sctpmap);
2926 JsepSessionDescription jdesc(kDummyType);
2927 std::string sdp_with_data = kSdpString;
2928
2929 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
2930 sdp_with_data.append("a=max-message-size:12345\r\n");
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002931 MutateJsepSctpMaxMessageSize(desc_, 12345, &jdesc);
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002932 JsepSessionDescription jdesc_output(kDummyType);
2933
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002934 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2935 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2936}
2937
Harald Alvestrandfbb45bd2019-05-15 08:07:47 +02002938TEST_F(WebRtcSdpTest, SerializeSdpWithSctpDataChannelWithMaxMessageSize) {
2939 bool use_sctpmap = false;
2940 AddSctpDataChannel(use_sctpmap);
2941 JsepSessionDescription jdesc(kDummyType);
2942 MutateJsepSctpMaxMessageSize(desc_, 12345, &jdesc);
2943 std::string message = webrtc::SdpSerialize(jdesc);
2944 EXPECT_NE(std::string::npos,
2945 message.find("\r\na=max-message-size:12345\r\n"));
2946 JsepSessionDescription jdesc_output(kDummyType);
2947 EXPECT_TRUE(SdpDeserialize(message, &jdesc_output));
2948 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2949}
2950
2951TEST_F(WebRtcSdpTest,
2952 SerializeSdpWithSctpDataChannelWithDefaultMaxMessageSize) {
2953 // https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-26#section-6
2954 // The default max message size is 64K.
2955 bool use_sctpmap = false;
2956 AddSctpDataChannel(use_sctpmap);
2957 JsepSessionDescription jdesc(kDummyType);
2958 MutateJsepSctpMaxMessageSize(desc_, 65536, &jdesc);
2959 std::string message = webrtc::SdpSerialize(jdesc);
2960 EXPECT_EQ(std::string::npos, message.find("\r\na=max-message-size:"));
2961 JsepSessionDescription jdesc_output(kDummyType);
2962 EXPECT_TRUE(SdpDeserialize(message, &jdesc_output));
2963 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2964}
2965
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002966// Test to check the behaviour if sctp-port is specified
2967// on the m= line and in a=sctp-port.
2968TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002969 bool use_sctpmap = true;
2970 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002971 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002972 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002973
2974 std::string sdp_with_data = kSdpString;
2975 // Append m= attributes
2976 sdp_with_data.append(kSdpSctpDataChannelString);
2977 // Append a=sctp-port attribute
2978 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 10:27:41 -08002979 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002980
2981 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2982}
2983
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002984// Test behavior if a=rtpmap occurs in an SCTP section.
2985TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpmapAttribute) {
2986 std::string sdp_with_data = kSdpString;
2987 // Append m= attributes
2988 sdp_with_data.append(kSdpSctpDataChannelString);
2989 // Append a=rtpmap attribute
2990 sdp_with_data.append("a=rtpmap:111 opus/48000/2\r\n");
2991 JsepSessionDescription jdesc_output(kDummyType);
2992 // Correct behavior is to ignore the extra attribute.
2993 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2994}
2995
2996TEST_F(WebRtcSdpTest, DeserializeSdpWithStrangeApplicationProtocolNames) {
Harald Alvestrand7af57c62021-04-16 11:12:14 +00002997 static const char* bad_strings[] = {
2998 "DTLS/SCTPRTP/", "obviously-bogus", "UDP/TL/RTSP/SAVPF",
2999 "UDP/TL/RTSP/S", "DTLS/SCTP/RTP/FOO", "obviously-bogus/RTP/"};
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003000 for (auto proto : bad_strings) {
3001 std::string sdp_with_data = kSdpString;
3002 sdp_with_data.append("m=application 9 ");
3003 sdp_with_data.append(proto);
3004 sdp_with_data.append(" 47\r\n");
3005 JsepSessionDescription jdesc_output(kDummyType);
3006 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output))
3007 << "Parsing should have failed on " << proto;
3008 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003009}
3010
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00003011// For crbug/344475.
3012TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
3013 std::string sdp_with_data = kSdpString;
3014 sdp_with_data.append(kSdpSctpDataChannelString);
3015 // Remove the "\n" at the end.
3016 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 10:27:41 -08003017 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00003018
3019 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
3020 // No crash is a pass.
3021}
3022
zstein4b2e0822017-02-17 19:48:38 -08003023TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
3024 bool use_sctpmap = true;
3025 AddSctpDataChannel(use_sctpmap);
3026
3027 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 10:27:41 -08003028 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003029 MutateJsepSctpPort(&jdesc, desc_, kUnusualSctpPort);
wu@webrtc.org78187522013-10-07 23:32:02 +00003030
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00003031 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00003032 std::string sdp_with_data = kSdpString;
3033 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Anton1c9c9fc2019-02-14 15:13:09 -08003034 absl::StrReplaceAll(
3035 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}},
3036 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08003037 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:02 +00003038
3039 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3040 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08003041}
3042
3043TEST_F(WebRtcSdpTest,
3044 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
3045 bool use_sctpmap = false;
3046 AddSctpDataChannel(use_sctpmap);
3047
Steve Antona3a92c22017-12-07 10:27:41 -08003048 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003049 MutateJsepSctpPort(&jdesc, desc_, kUnusualSctpPort);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003050
3051 // We need to test the deserialized JsepSessionDescription from
3052 // kSdpSctpDataChannelStringWithSctpPort for
3053 // draft-ietf-mmusic-sctp-sdp-07
3054 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08003055 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003056 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Anton1c9c9fc2019-02-14 15:13:09 -08003057 absl::StrReplaceAll(
3058 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}},
3059 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08003060 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003061
3062 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3063 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00003064}
3065
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003066TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08003067 bool use_sctpmap = true;
3068 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08003069 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003070 SctpDataContentDescription* dcd = GetFirstSctpDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003071 dcd->set_bandwidth(100 * 1000);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003072 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003073
3074 std::string sdp_with_bandwidth = kSdpString;
3075 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02003076 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003077 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08003078 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003079
3080 // SCTP has congestion control, so we shouldn't limit the bandwidth
3081 // as we do for RTP.
3082 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003083 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
3084}
3085
Yves Gerey665174f2018-06-19 15:03:05 +02003086class WebRtcSdpExtmapTest : public WebRtcSdpTest,
Mirko Bonadei6a489f22019-04-09 15:11:12 +02003087 public ::testing::WithParamInterface<bool> {};
jbauch5869f502017-06-29 12:31:36 -07003088
3089TEST_P(WebRtcSdpExtmapTest,
Yves Gerey665174f2018-06-19 15:03:05 +02003090 DeserializeSessionDescriptionWithSessionLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003091 bool encrypted = GetParam();
3092 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003093}
3094
Yves Gerey665174f2018-06-19 15:03:05 +02003095TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003096 bool encrypted = GetParam();
3097 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003098}
3099
Yves Gerey665174f2018-06-19 15:03:05 +02003100TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithInvalidExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003101 bool encrypted = GetParam();
3102 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003103}
3104
Mirko Bonadeic84f6612019-01-31 12:20:57 +01003105INSTANTIATE_TEST_SUITE_P(Encrypted,
3106 WebRtcSdpExtmapTest,
3107 ::testing::Values(false, true));
jbauch5869f502017-06-29 12:31:36 -07003108
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003109TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 10:27:41 -08003110 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003111 std::string sdp = kSdpFullString;
3112 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
3113 // Deserialize
3114 SdpParseError error;
3115 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
Artem Titovf0a34f22020-03-16 17:52:04 +00003116 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003117 EXPECT_EQ(lastline, error.line);
3118 EXPECT_EQ("Invalid SDP line.", error.description);
3119}
3120
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003121TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
3122 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
3123 std::string new_sdp = kSdpOneCandidate;
3124 Replace("udp", "unsupported_transport", &new_sdp);
3125 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3126 new_sdp = kSdpOneCandidate;
3127 Replace("udp", "uDP", &new_sdp);
3128 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3129 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3130 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3131 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
3132}
3133
honghaiza54a0802015-12-16 18:37:23 -08003134TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003135 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08003136 EXPECT_TRUE(
3137 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003138 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3139 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3140 Candidate ref_candidate = jcandidate_->candidate();
3141 ref_candidate.set_username("user_rtp");
3142 ref_candidate.set_password("password_rtp");
3143 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
3144}
3145
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003146TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08003147 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003148
3149 // Deserialize
3150 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
3151
3152 // Verify
3153 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08003154 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003155 EXPECT_TRUE(audio->conference_mode());
3156
3157 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 15:55:30 -08003158 cricket::GetFirstVideoContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003159 EXPECT_TRUE(video->conference_mode());
3160}
3161
deadbeefd45aea82017-09-16 01:24:29 -07003162TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08003163 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 01:24:29 -07003164
3165 // We tested deserialization already above, so just test that if we serialize
3166 // and deserialize the flag doesn't disappear.
3167 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 12:22:16 -08003168 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 01:24:29 -07003169 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
3170
3171 // Verify.
3172 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08003173 cricket::GetFirstAudioContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 01:24:29 -07003174 EXPECT_TRUE(audio->conference_mode());
3175
3176 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 15:55:30 -08003177 cricket::GetFirstVideoContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 01:24:29 -07003178 EXPECT_TRUE(video->conference_mode());
3179}
3180
Sebastian Jansson97321b62019-07-24 14:01:18 +02003181TEST_F(WebRtcSdpTest, SerializeAndDeserializeRemoteNetEstimate) {
3182 {
3183 // By default remote estimates are disabled.
3184 JsepSessionDescription dst(kDummyType);
3185 SdpDeserialize(webrtc::SdpSerialize(jdesc_), &dst);
3186 EXPECT_FALSE(cricket::GetFirstVideoContentDescription(dst.description())
3187 ->remote_estimate());
3188 }
3189 {
3190 // When remote estimate is enabled, the setting is propagated via SDP.
3191 cricket::GetFirstVideoContentDescription(jdesc_.description())
3192 ->set_remote_estimate(true);
3193 JsepSessionDescription dst(kDummyType);
3194 SdpDeserialize(webrtc::SdpSerialize(jdesc_), &dst);
3195 EXPECT_TRUE(cricket::GetFirstVideoContentDescription(dst.description())
3196 ->remote_estimate());
3197 }
3198}
3199
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003200TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
3201 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003202 const char kSdpEmptyType[] = " =candidate";
3203 const char kSdpEqualAsPlus[] = "a+candidate";
3204 const char kSdpSpaceAfterEqual[] = "a= candidate";
3205 const char kSdpUpperType[] = "A=candidate";
3206 const char kSdpEmptyLine[] = "";
3207 const char kSdpMissingValue[] = "a=";
3208
Yves Gerey665174f2018-06-19 15:03:05 +02003209 const char kSdpBrokenFingerprint[] =
3210 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003211 "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 +02003212 const char kSdpExtraField[] =
3213 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003214 "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 +02003215 const char kSdpMissingSpace[] =
3216 "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003217 "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 +00003218 // MD5 is not allowed in fingerprints.
Yves Gerey665174f2018-06-19 15:03:05 +02003219 const char kSdpMd5[] =
3220 "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003221 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003222
3223 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003224 ExpectParseFailure("v=", kSdpDestroyer);
3225 ExpectParseFailure("o=", kSdpDestroyer);
3226 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003227 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003228 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003229
3230 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003231 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
3232 ExpectParseFailure("m=video", kSdpDestroyer);
Philipp Hanckeefc55b02020-06-26 10:17:05 +02003233 ExpectParseFailure("m=", "c=IN IP4 74.125.224.39");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003234
3235 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003236 ExpectParseFailure("a=candidate", kSdpEmptyType);
3237 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
3238 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
3239 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003240
3241 // Bogus fingerprint replacing a=sendrev. We selected this attribute
3242 // because it's orthogonal to what we are replacing and hence
3243 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003244 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
3245 ExpectParseFailure("a=sendrecv", kSdpExtraField);
3246 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
3247 ExpectParseFailure("a=sendrecv", kSdpMd5);
3248
3249 // Empty Line
3250 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
3251 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003252}
3253
3254TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
3255 // ssrc
3256 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08003257 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003258 // crypto
3259 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
3260 // rtpmap
3261 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
3262 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
3263 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
3264 // candidate
3265 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
3266 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
3267 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
3268 ExpectParseFailure("rport 2346", "rport badvalue");
3269 ExpectParseFailure("rport 2346 generation 2",
3270 "rport 2346 generation badvalue");
3271 // m line
3272 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
3273 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
3274
3275 // bandwidth
3276 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003277 "b=AS:badvalue\r\n", "b=AS:badvalue");
Philipp Hanckefbbfc022020-07-31 08:30:50 +02003278 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", "b=AS\r\n",
3279 "b=AS");
3280 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", "b=AS:\r\n",
3281 "b=AS:");
3282 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3283 "b=AS:12:34\r\n", "b=AS:12:34");
3284
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003285 // rtcp-fb
3286 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3287 "a=rtcp-fb:badvalue nack\r\n",
3288 "a=rtcp-fb:badvalue nack");
3289 // extmap
3290 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3291 "a=extmap:badvalue http://example.com\r\n",
3292 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003293}
3294
3295TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 10:27:41 -08003296 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003297
3298 const char kSdpWithReorderedPlTypesString[] =
3299 "v=0\r\n"
3300 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3301 "s=-\r\n"
3302 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00003303 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
Yves Gerey665174f2018-06-19 15:03:05 +02003304 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
3305 // in the map.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003306 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003307 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003308
3309 // Deserialize
3310 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
3311
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003312 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003313 GetFirstAudioContentDescription(jdesc_output.description());
3314 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003315 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003316 EXPECT_EQ("ISAC", acd->codecs()[0].name);
3317 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003318 EXPECT_EQ(104, acd->codecs()[0].id);
3319}
3320
3321TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 10:27:41 -08003322 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003323 CodecParams params;
3324 params.max_ptime = 40;
3325 params.ptime = 30;
3326 params.min_ptime = 10;
3327 params.sprop_stereo = 1;
3328 params.stereo = 1;
3329 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003330 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003331 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 12:22:16 -08003332 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003333}
3334
3335TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
3336 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 10:27:41 -08003337 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003338 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003339 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003340}
3341
3342TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
3343 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 10:27:41 -08003344 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003345 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003346 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003347}
3348
3349TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 10:27:41 -08003350 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003351
3352 const char kSdpWithFmtpString[] =
3353 "v=0\r\n"
3354 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3355 "s=-\r\n"
3356 "t=0 0\r\n"
3357 "m=video 3457 RTP/SAVPF 120\r\n"
3358 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07003359 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3360
3361 // Deserialize
3362 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07003363 EXPECT_TRUE(
3364 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07003365
Donald Curtis0e07f922015-05-15 09:21:23 -07003366 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003367 GetFirstVideoContentDescription(jdesc_output.description());
3368 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 09:21:23 -07003369 ASSERT_FALSE(vcd->codecs().empty());
3370 cricket::VideoCodec vp8 = vcd->codecs()[0];
3371 EXPECT_EQ("VP8", vp8.name);
3372 EXPECT_EQ(120, vp8.id);
3373 cricket::CodecParameterMap::iterator found =
3374 vp8.params.find("x-google-min-bitrate");
3375 ASSERT_TRUE(found != vp8.params.end());
3376 EXPECT_EQ(found->second, "10");
3377 found = vp8.params.find("x-google-max-quantization");
3378 ASSERT_TRUE(found != vp8.params.end());
3379 EXPECT_EQ(found->second, "40");
3380}
3381
johan2d8d23e2016-06-03 01:22:42 -07003382TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 10:27:41 -08003383 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 01:22:42 -07003384
3385 const char kSdpWithFmtpString[] =
3386 "v=0\r\n"
3387 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3388 "s=-\r\n"
3389 "t=0 0\r\n"
3390 "m=video 49170 RTP/AVP 98\r\n"
3391 "a=rtpmap:98 H264/90000\r\n"
3392 "a=fmtp:98 profile-level-id=42A01E; "
3393 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3394
3395 // Deserialize.
3396 SdpParseError error;
3397 EXPECT_TRUE(
3398 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3399
johan2d8d23e2016-06-03 01:22:42 -07003400 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003401 GetFirstVideoContentDescription(jdesc_output.description());
3402 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 01:22:42 -07003403 ASSERT_FALSE(vcd->codecs().empty());
3404 cricket::VideoCodec h264 = vcd->codecs()[0];
3405 EXPECT_EQ("H264", h264.name);
3406 EXPECT_EQ(98, h264.id);
3407 cricket::CodecParameterMap::const_iterator found =
3408 h264.params.find("profile-level-id");
3409 ASSERT_TRUE(found != h264.params.end());
3410 EXPECT_EQ(found->second, "42A01E");
3411 found = h264.params.find("sprop-parameter-sets");
3412 ASSERT_TRUE(found != h264.params.end());
3413 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3414}
3415
Donald Curtis0e07f922015-05-15 09:21:23 -07003416TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 10:27:41 -08003417 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 09:21:23 -07003418
3419 const char kSdpWithFmtpString[] =
3420 "v=0\r\n"
3421 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3422 "s=-\r\n"
3423 "t=0 0\r\n"
3424 "m=video 3457 RTP/SAVPF 120\r\n"
3425 "a=rtpmap:120 VP8/90000\r\n"
3426 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003427
3428 // Deserialize
3429 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02003430 EXPECT_TRUE(
3431 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003432
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003433 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003434 GetFirstVideoContentDescription(jdesc_output.description());
3435 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003436 ASSERT_FALSE(vcd->codecs().empty());
3437 cricket::VideoCodec vp8 = vcd->codecs()[0];
3438 EXPECT_EQ("VP8", vp8.name);
3439 EXPECT_EQ(120, vp8.id);
3440 cricket::CodecParameterMap::iterator found =
3441 vp8.params.find("x-google-min-bitrate");
3442 ASSERT_TRUE(found != vp8.params.end());
3443 EXPECT_EQ(found->second, "10");
3444 found = vp8.params.find("x-google-max-quantization");
3445 ASSERT_TRUE(found != vp8.params.end());
3446 EXPECT_EQ(found->second, "40");
3447}
3448
Mirta Dvornicic479a3c02019-06-04 15:38:50 +02003449TEST_F(WebRtcSdpTest, DeserializePacketizationAttributeWithIllegalValue) {
3450 JsepSessionDescription jdesc_output(kDummyType);
3451
3452 const char kSdpWithPacketizationString[] =
3453 "v=0\r\n"
3454 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3455 "s=-\r\n"
3456 "t=0 0\r\n"
3457 "m=audio 9 RTP/SAVPF 111\r\n"
3458 "a=rtpmap:111 opus/48000/2\r\n"
3459 "a=packetization:111 unknownpacketizationattributeforaudio\r\n"
3460 "m=video 3457 RTP/SAVPF 120 121 122\r\n"
3461 "a=rtpmap:120 VP8/90000\r\n"
3462 "a=packetization:120 raw\r\n"
3463 "a=rtpmap:121 VP9/90000\r\n"
3464 "a=rtpmap:122 H264/90000\r\n"
3465 "a=packetization:122 unknownpacketizationattributevalue\r\n";
3466
3467 SdpParseError error;
3468 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithPacketizationString, &jdesc_output,
3469 &error));
3470
3471 AudioContentDescription* acd =
3472 GetFirstAudioContentDescription(jdesc_output.description());
3473 ASSERT_TRUE(acd);
3474 ASSERT_THAT(acd->codecs(), testing::SizeIs(1));
3475 cricket::AudioCodec opus = acd->codecs()[0];
3476 EXPECT_EQ(opus.name, "opus");
3477 EXPECT_EQ(opus.id, 111);
3478
3479 const VideoContentDescription* vcd =
3480 GetFirstVideoContentDescription(jdesc_output.description());
3481 ASSERT_TRUE(vcd);
3482 ASSERT_THAT(vcd->codecs(), testing::SizeIs(3));
3483 cricket::VideoCodec vp8 = vcd->codecs()[0];
3484 EXPECT_EQ(vp8.name, "VP8");
3485 EXPECT_EQ(vp8.id, 120);
3486 EXPECT_EQ(vp8.packetization, "raw");
3487 cricket::VideoCodec vp9 = vcd->codecs()[1];
3488 EXPECT_EQ(vp9.name, "VP9");
3489 EXPECT_EQ(vp9.id, 121);
3490 EXPECT_EQ(vp9.packetization, absl::nullopt);
3491 cricket::VideoCodec h264 = vcd->codecs()[2];
3492 EXPECT_EQ(h264.name, "H264");
3493 EXPECT_EQ(h264.id, 122);
3494 EXPECT_EQ(h264.packetization, absl::nullopt);
3495}
3496
ossuaa4b0772017-01-30 07:41:18 -08003497TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003498 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003499
3500 cricket::AudioCodecs codecs = acd->codecs();
3501 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3502 acd->set_codecs(codecs);
3503
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003504 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003505 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003506 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003507 std::string sdp_with_fmtp = kSdpFullString;
3508 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3509 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3510 &sdp_with_fmtp);
3511 EXPECT_EQ(sdp_with_fmtp, message);
3512}
3513
3514TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003515 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003516
3517 cricket::AudioCodecs codecs = acd->codecs();
3518 codecs[0].params["stereo"] = "1";
3519 acd->set_codecs(codecs);
3520
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003521 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003522 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003523 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003524 std::string sdp_with_fmtp = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003525 InjectAfter("a=rtpmap:111 opus/48000/2\r\n", "a=fmtp:111 stereo=1\r\n",
ossuaa4b0772017-01-30 07:41:18 -08003526 &sdp_with_fmtp);
3527 EXPECT_EQ(sdp_with_fmtp, message);
3528}
3529
3530TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003531 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003532
3533 cricket::AudioCodecs codecs = acd->codecs();
3534 codecs[0].params["ptime"] = "20";
3535 codecs[0].params["maxptime"] = "120";
3536 acd->set_codecs(codecs);
3537
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003538 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003539 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003540 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003541 std::string sdp_with_fmtp = kSdpFullString;
3542 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3543 "a=maxptime:120\r\n" // No comma here. String merging!
3544 "a=ptime:20\r\n",
3545 &sdp_with_fmtp);
3546 EXPECT_EQ(sdp_with_fmtp, message);
3547}
3548
Philipp Hanckef2a4ec12020-07-01 21:07:32 +02003549TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithTelephoneEvent) {
3550 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
3551
3552 cricket::AudioCodecs codecs = acd->codecs();
3553 cricket::AudioCodec dtmf(105, "telephone-event", 8000, 0, 1);
3554 dtmf.params[""] = "0-15";
3555 codecs.push_back(dtmf);
3556 acd->set_codecs(codecs);
3557
3558 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
3559 jdesc_.session_version()));
3560 std::string message = webrtc::SdpSerialize(jdesc_);
3561 std::string sdp_with_fmtp = kSdpFullString;
3562 InjectAfter("m=audio 2345 RTP/SAVPF 111 103 104", " 105", &sdp_with_fmtp);
3563 InjectAfter(
3564 "a=rtpmap:104 ISAC/32000\r\n",
3565 "a=rtpmap:105 telephone-event/8000\r\n" // No comma here. String merging!
3566 "a=fmtp:105 0-15\r\n",
3567 &sdp_with_fmtp);
3568 EXPECT_EQ(sdp_with_fmtp, message);
3569}
3570
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003571TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003572 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003573
3574 cricket::VideoCodecs codecs = vcd->codecs();
3575 codecs[0].params["x-google-min-bitrate"] = "10";
3576 vcd->set_codecs(codecs);
3577
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003578 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003579 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003580 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003581 std::string sdp_with_fmtp = kSdpFullString;
3582 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003583 "a=fmtp:120 x-google-min-bitrate=10\r\n", &sdp_with_fmtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003584 EXPECT_EQ(sdp_with_fmtp, message);
3585}
3586
Mirta Dvornicic479a3c02019-06-04 15:38:50 +02003587TEST_F(WebRtcSdpTest, SerializeVideoPacketizationAttribute) {
3588 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
3589
3590 cricket::VideoCodecs codecs = vcd->codecs();
3591 codecs[0].packetization = "raw";
3592 vcd->set_codecs(codecs);
3593
3594 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
3595 jdesc_.session_version()));
3596 std::string message = webrtc::SdpSerialize(jdesc_);
3597 std::string sdp_with_packetization = kSdpFullString;
3598 InjectAfter("a=rtpmap:120 VP8/90000\r\n", "a=packetization:120 raw\r\n",
3599 &sdp_with_packetization);
3600 EXPECT_EQ(sdp_with_packetization, message);
3601}
3602
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003603TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) {
3604 // Deserialize the baseline description, making sure it's ICE full.
Steve Antona3a92c22017-12-07 10:27:41 -08003605 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003606 std::string sdp_with_icelite = kSdpFullString;
3607 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3608 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3609 const cricket::TransportInfo* tinfo1 =
3610 desc->GetTransportInfoByName("audio_content_name");
3611 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3612 const cricket::TransportInfo* tinfo2 =
3613 desc->GetTransportInfoByName("video_content_name");
3614 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003615
3616 // Add "a=ice-lite" and deserialize, making sure it's ICE lite.
Yves Gerey665174f2018-06-19 15:03:05 +02003617 InjectAfter(kSessionTime, "a=ice-lite\r\n", &sdp_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003618 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3619 desc = jdesc_with_icelite.description();
3620 const cricket::TransportInfo* atinfo =
3621 desc->GetTransportInfoByName("audio_content_name");
3622 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3623 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003624 desc->GetTransportInfoByName("video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003625 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003626
3627 // Now that we know deserialization works, we can use TestSerialize to test
3628 // serialization.
3629 TestSerialize(jdesc_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003630}
3631
3632// Verifies that the candidates in the input SDP are parsed and serialized
3633// correctly in the output SDP.
3634TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3635 std::string sdp_with_data = kSdpString;
3636 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 10:27:41 -08003637 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003638
3639 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 12:22:16 -08003640 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003641}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003642
3643TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3644 AddFingerprint();
3645 TransportInfo audio_transport_info =
3646 *(desc_.GetTransportInfoByName(kAudioContentName));
3647 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3648 audio_transport_info.description.connection_role);
3649 audio_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003650 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003651
3652 TransportInfo video_transport_info =
3653 *(desc_.GetTransportInfoByName(kVideoContentName));
3654 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3655 video_transport_info.description.connection_role);
3656 video_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003657 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003658
3659 desc_.RemoveTransportInfoByName(kAudioContentName);
3660 desc_.RemoveTransportInfoByName(kVideoContentName);
3661
3662 desc_.AddTransportInfo(audio_transport_info);
3663 desc_.AddTransportInfo(video_transport_info);
3664
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003665 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003666 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003667 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003668 std::string sdp_with_dtlssetup = kSdpFullString;
3669
3670 // Fingerprint attribute is necessary to add DTLS setup attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003671 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_dtlssetup);
3672 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_dtlssetup);
Artem Titov880fa812021-07-30 22:30:23 +02003673 // Now adding `setup` attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003674 InjectAfter(kFingerprint, "a=setup:active\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003675 EXPECT_EQ(sdp_with_dtlssetup, message);
3676}
3677
3678TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
Steve Antona3a92c22017-12-07 10:27:41 -08003679 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003680 std::string sdp_with_dtlssetup = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003681 InjectAfter(kSessionTime, "a=setup:actpass\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003682 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3683 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3684 const cricket::TransportInfo* atinfo =
3685 desc->GetTransportInfoByName("audio_content_name");
3686 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3687 atinfo->description.connection_role);
3688 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003689 desc->GetTransportInfoByName("video_content_name");
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003690 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3691 vtinfo->description.connection_role);
3692}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003693
3694// Verifies that the order of the serialized m-lines follows the order of the
3695// ContentInfo in SessionDescription, and vise versa for deserialization.
3696TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 10:27:41 -08003697 JsepSessionDescription jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02003698 const std::string media_content_sdps[3] = {kSdpAudioString, kSdpVideoString,
3699 kSdpSctpDataChannelString};
3700 const cricket::MediaType media_types[3] = {cricket::MEDIA_TYPE_AUDIO,
3701 cricket::MEDIA_TYPE_VIDEO,
3702 cricket::MEDIA_TYPE_DATA};
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003703
3704 // Verifies all 6 permutations.
3705 for (size_t i = 0; i < 6; ++i) {
3706 size_t media_content_in_sdp[3];
3707 // The index of the first media content.
3708 media_content_in_sdp[0] = i / 2;
3709 // The index of the second media content.
3710 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3711 // The index of the third media content.
3712 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3713
3714 std::string sdp_string = kSdpSessionString;
3715 for (size_t i = 0; i < 3; ++i)
3716 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3717
3718 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3719 cricket::SessionDescription* desc = jdesc.description();
3720 EXPECT_EQ(3u, desc->contents().size());
3721
3722 for (size_t i = 0; i < 3; ++i) {
3723 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 15:14:30 -08003724 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003725 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3726 }
3727
Steve Antone831b8c2018-02-01 12:22:16 -08003728 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003729 EXPECT_EQ(sdp_string, serialized_sdp);
3730 }
3731}
deadbeef9d3584c2016-02-16 17:54:10 -08003732
deadbeef25ed4352016-12-12 18:37:36 -08003733TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3734 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 10:27:41 -08003735 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003736 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003737 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3738 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3739}
3740
deadbeef12771a12017-01-03 13:53:47 -08003741// The semantics of "a=bundle-only" are only defined when it's used in
3742// combination with a 0 port on the m= line. We should ignore it if used with a
3743// nonzero port.
3744TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3745 // Make the base bundle-only description but unset the bundle-only flag.
3746 MakeBundleOnlyDescription();
3747 jdesc_.description()->contents()[1].bundle_only = false;
3748
3749 std::string modified_sdp = kBundleOnlySdpFullString;
3750 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08003751 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003752 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3753 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003754}
3755
3756TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3757 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003758 TestSerialize(jdesc_);
deadbeef25ed4352016-12-12 18:37:36 -08003759}
3760
deadbeef9d3584c2016-02-16 17:54:10 -08003761TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3762 MakePlanBDescription();
3763
Steve Antona3a92c22017-12-07 10:27:41 -08003764 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003765 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3766
3767 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3768}
3769
3770TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3771 MakePlanBDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003772 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-16 17:54:10 -08003773}
3774
3775TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3776 MakeUnifiedPlanDescription();
3777
Steve Antona3a92c22017-12-07 10:27:41 -08003778 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003779 EXPECT_TRUE(
3780 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3781
3782 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3783}
3784
3785TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3786 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003787 TestSerialize(jdesc_);
3788}
3789
Seth Hampson5b4f0752018-04-02 16:31:36 -07003790// This tests deserializing a Unified Plan SDP that is compatible with both
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003791// Unified Plan and Plan B style SDP, meaning that it contains both "a=ssrc
3792// msid" lines and "a=msid " lines. It tests the case for audio/video tracks
Seth Hampson5b4f0752018-04-02 16:31:36 -07003793// with no stream ids and multiple stream ids. For parsing this, the Unified
3794// Plan a=msid lines should take priority, because the Plan B style a=ssrc msid
3795// lines do not support multiple stream ids and no stream ids.
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003796TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionSpecialMsid) {
3797 // Create both msid lines for Plan B and Unified Plan support.
3798 MakeUnifiedPlanDescriptionMultipleStreamIds(
3799 cricket::kMsidSignalingMediaSection |
3800 cricket::kMsidSignalingSsrcAttribute);
Seth Hampson5b4f0752018-04-02 16:31:36 -07003801
3802 JsepSessionDescription deserialized_description(kDummyType);
3803 EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid,
3804 &deserialized_description));
3805
3806 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
Henrik Boström5b147782018-12-04 11:25:05 +01003807 EXPECT_EQ(cricket::kMsidSignalingMediaSection |
3808 cricket::kMsidSignalingSsrcAttribute,
3809 deserialized_description.description()->msid_signaling());
Seth Hampson5b4f0752018-04-02 16:31:36 -07003810}
3811
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003812// Tests the serialization of a Unified Plan SDP that is compatible for both
3813// Unified Plan and Plan B style SDPs, meaning that it contains both "a=ssrc
3814// msid" lines and "a=msid " lines. It tests the case for no stream ids and
3815// multiple stream ids.
3816TEST_F(WebRtcSdpTest, SerializeSessionDescriptionSpecialMsid) {
3817 // Create both msid lines for Plan B and Unified Plan support.
3818 MakeUnifiedPlanDescriptionMultipleStreamIds(
3819 cricket::kMsidSignalingMediaSection |
3820 cricket::kMsidSignalingSsrcAttribute);
3821 std::string serialized_sdp = webrtc::SdpSerialize(jdesc_);
3822 // We explicitly test that the serialized SDP string is equal to the hard
3823 // coded SDP string. This is necessary, because in the parser "a=msid" lines
3824 // take priority over "a=ssrc msid" lines. This means if we just used
3825 // TestSerialize(), it could serialize an SDP that omits "a=ssrc msid" lines,
3826 // and still pass, because the deserialized version would be the same.
3827 EXPECT_EQ(kUnifiedPlanSdpFullStringWithSpecialMsid, serialized_sdp);
3828}
3829
3830// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3831// that signal stream IDs) is deserialized appropriately. It tests the case for
3832// no stream ids and multiple stream ids.
3833TEST_F(WebRtcSdpTest, UnifiedPlanDeserializeSessionDescriptionSpecialMsid) {
3834 // Only create a=msid lines for strictly Unified Plan stream ID support.
3835 MakeUnifiedPlanDescriptionMultipleStreamIds(
3836 cricket::kMsidSignalingMediaSection);
3837
3838 JsepSessionDescription deserialized_description(kDummyType);
3839 std::string unified_plan_sdp_string =
3840 kUnifiedPlanSdpFullStringWithSpecialMsid;
3841 RemoveSsrcMsidLinesFromSdpString(&unified_plan_sdp_string);
3842 EXPECT_TRUE(
3843 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3844
3845 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3846}
3847
3848// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3849// that signal stream IDs) is serialized appropriately. It tests the case for no
3850// stream ids and multiple stream ids.
3851TEST_F(WebRtcSdpTest, UnifiedPlanSerializeSessionDescriptionSpecialMsid) {
3852 // Only create a=msid lines for strictly Unified Plan stream ID support.
3853 MakeUnifiedPlanDescriptionMultipleStreamIds(
3854 cricket::kMsidSignalingMediaSection);
3855
Seth Hampson5b4f0752018-04-02 16:31:36 -07003856 TestSerialize(jdesc_);
3857}
3858
Seth Hampson5897a6e2018-04-03 11:16:33 -07003859// This tests that a Unified Plan SDP with no a=ssrc lines is
3860// serialized/deserialized appropriately. In this case the
3861// MediaContentDescription will contain a StreamParams object that doesn't have
3862// any SSRCs. Vice versa, this will be created upon deserializing an SDP with no
3863// SSRC lines.
3864TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3865 MakeUnifiedPlanDescription();
3866 RemoveSsrcSignalingFromStreamParams();
3867 std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString;
3868 RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string);
3869
3870 JsepSessionDescription deserialized_description(kDummyType);
3871 EXPECT_TRUE(
3872 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3873 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3874}
3875
3876TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3877 MakeUnifiedPlanDescription();
3878 RemoveSsrcSignalingFromStreamParams();
3879
3880 TestSerialize(jdesc_);
3881}
3882
Steve Antone831b8c2018-02-01 12:22:16 -08003883TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
3884 JsepSessionDescription jsep_desc(kDummyType);
3885 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
3886 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3887}
3888
3889TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
3890 JsepSessionDescription jsep_desc(kDummyType);
3891 std::string sdp = kSdpSessionString;
3892 sdp += kSdpSctpDataChannelString;
3893 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3894 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3895}
3896
3897TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
3898 JsepSessionDescription jsep_desc(kDummyType);
3899 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
3900 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
3901 jsep_desc.description()->msid_signaling());
3902}
3903
3904TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
3905 JsepSessionDescription jsep_desc(kDummyType);
3906 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
3907 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
3908 jsep_desc.description()->msid_signaling());
3909}
3910
3911const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
3912const char kSsrcAttributeMsidLine[] =
3913 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
3914
3915TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
3916 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
3917 std::string sdp = webrtc::SdpSerialize(jdesc_);
3918
3919 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3920 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3921}
3922
3923TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
3924 jdesc_.description()->set_msid_signaling(
3925 cricket::kMsidSignalingSsrcAttribute);
3926 std::string sdp = webrtc::SdpSerialize(jdesc_);
3927
3928 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
3929 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3930}
3931
3932TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
3933 jdesc_.description()->set_msid_signaling(
3934 cricket::kMsidSignalingMediaSection |
3935 cricket::kMsidSignalingSsrcAttribute);
3936 std::string sdp = webrtc::SdpSerialize(jdesc_);
3937
3938 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3939 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-16 17:54:10 -08003940}
deadbeef7e146cb2016-09-28 10:04:34 -07003941
deadbeefb2362572016-12-13 16:37:06 -08003942// Regression test for integer overflow bug:
3943// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3944TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003945 // Bandwidth attribute is the max signed 32-bit int, which will get
3946 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003947 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003948 "v=0\r\n"
3949 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3950 "s=-\r\n"
3951 "t=0 0\r\n"
3952 "m=video 3457 RTP/SAVPF 120\r\n"
3953 "b=AS:2147483647\r\n"
3954 "foo=fail\r\n";
3955
3956 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3957}
deadbeef7bcdb692017-01-20 12:43:58 -08003958
deadbeefbc88c6b2017-08-02 11:26:34 -07003959// Similar to the above, except that negative values are illegal, not just
3960// error-prone as large values are.
3961// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3962TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3963 static const char kSdpWithNegativeBandwidth[] =
3964 "v=0\r\n"
3965 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3966 "s=-\r\n"
3967 "t=0 0\r\n"
3968 "m=video 3457 RTP/SAVPF 120\r\n"
3969 "b=AS:-1000\r\n";
3970
3971 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3972}
3973
deadbeef3e8016e2017-08-03 17:49:30 -07003974// An exception to the above rule: a value of -1 for b=AS should just be
3975// ignored, resulting in "kAutoBandwidth" in the deserialized object.
3976// Applications historically may be using "b=AS:-1" to mean "no bandwidth
3977// limit", but this is now what ommitting the attribute entirely will do, so
3978// ignoring it will have the intended effect.
3979TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
3980 static const char kSdpWithBandwidthOfNegativeOne[] =
3981 "v=0\r\n"
3982 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3983 "s=-\r\n"
3984 "t=0 0\r\n"
3985 "m=video 3457 RTP/SAVPF 120\r\n"
3986 "b=AS:-1\r\n";
3987
Steve Antona3a92c22017-12-07 10:27:41 -08003988 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-03 17:49:30 -07003989 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-03 17:49:30 -07003990 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003991 GetFirstVideoContentDescription(jdesc_output.description());
3992 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-03 17:49:30 -07003993 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
3994}
3995
deadbeef7bcdb692017-01-20 12:43:58 -08003996// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3997// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3998// Regression test for:
3999// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
4000TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
4001 // Important piece is "ufrag foo pwd bar".
4002 static const char kSdpWithIceCredentialsInCandidateString[] =
4003 "v=0\r\n"
4004 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4005 "s=-\r\n"
4006 "t=0 0\r\n"
4007 "m=audio 9 RTP/SAVPF 111\r\n"
4008 "c=IN IP4 0.0.0.0\r\n"
4009 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4010 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4011 "a=rtpmap:111 opus/48000/2\r\n"
4012 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
4013 "generation 2 ufrag foo pwd bar\r\n";
4014
Steve Antona3a92c22017-12-07 10:27:41 -08004015 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 12:43:58 -08004016 EXPECT_TRUE(
4017 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
4018 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
4019 ASSERT_NE(nullptr, candidates);
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02004020 ASSERT_EQ(1U, candidates->count());
deadbeef7bcdb692017-01-20 12:43:58 -08004021 cricket::Candidate c = candidates->at(0)->candidate();
4022 EXPECT_EQ("ufrag_voice", c.username());
4023 EXPECT_EQ("pwd_voice", c.password());
4024}
deadbeef90f1e1e2017-02-10 12:35:05 -08004025
Johannes Kron211856b2018-09-06 12:12:28 +02004026// Test that attribute lines "a=ice-ufrag-something"/"a=ice-pwd-something" are
4027// ignored, and only the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
4028// Regression test for:
4029// https://bugs.chromium.org/p/webrtc/issues/detail?id=9712
4030TEST_F(WebRtcSdpTest, AttributeWithPartialMatchingNameIsIgnored) {
4031 static const char kSdpWithFooIceCredentials[] =
4032 "v=0\r\n"
4033 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4034 "s=-\r\n"
4035 "t=0 0\r\n"
4036 "m=audio 9 RTP/SAVPF 111\r\n"
4037 "c=IN IP4 0.0.0.0\r\n"
4038 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4039 "a=ice-ufrag-something:foo\r\na=ice-pwd-something:bar\r\n"
4040 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4041 "a=rtpmap:111 opus/48000/2\r\n"
4042 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
4043 "generation 2\r\n";
4044
4045 JsepSessionDescription jdesc_output(kDummyType);
4046 EXPECT_TRUE(SdpDeserialize(kSdpWithFooIceCredentials, &jdesc_output));
4047 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
4048 ASSERT_NE(nullptr, candidates);
4049 ASSERT_EQ(1U, candidates->count());
4050 cricket::Candidate c = candidates->at(0)->candidate();
4051 EXPECT_EQ("ufrag_voice", c.username());
4052 EXPECT_EQ("pwd_voice", c.password());
4053}
4054
deadbeef90f1e1e2017-02-10 12:35:05 -08004055// Test that SDP with an invalid port number in "a=candidate" lines is
4056// rejected, without crashing.
4057// Regression test for:
4058// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
4059TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
4060 static const char kSdpWithInvalidCandidatePort[] =
4061 "v=0\r\n"
4062 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4063 "s=-\r\n"
4064 "t=0 0\r\n"
4065 "m=audio 9 RTP/SAVPF 111\r\n"
4066 "c=IN IP4 0.0.0.0\r\n"
4067 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4068 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4069 "a=rtpmap:111 opus/48000/2\r\n"
4070 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
4071 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
4072
Steve Antona3a92c22017-12-07 10:27:41 -08004073 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 12:35:05 -08004074 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
4075}
deadbeefa4549d62017-02-10 17:26:22 -08004076
4077// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
4078// Regression test for:
4079// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
4080TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
4081 static const char kSdpWithMissingTrackId[] =
4082 "v=0\r\n"
4083 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4084 "s=-\r\n"
4085 "t=0 0\r\n"
4086 "m=audio 9 RTP/SAVPF 111\r\n"
4087 "c=IN IP4 0.0.0.0\r\n"
4088 "a=rtpmap:111 opus/48000/2\r\n"
4089 "a=msid:stream_id \r\n";
4090
Steve Antona3a92c22017-12-07 10:27:41 -08004091 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08004092 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
4093}
4094
4095TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
4096 static const char kSdpWithMissingStreamId[] =
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=rtpmap:111 opus/48000/2\r\n"
4104 "a=msid: track_id\r\n";
4105
Steve Antona3a92c22017-12-07 10:27:41 -08004106 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08004107 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
4108}
zhihuang38989e52017-03-21 11:04:53 -07004109
4110// Tests that if both session-level address and media-level address exist, use
4111// the media-level address.
4112TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 10:27:41 -08004113 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004114
4115 // Sesssion-level address.
4116 std::string sdp = kSdpFullString;
4117 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
4118 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4119
4120 const auto& content1 = jsep_desc.description()->contents()[0];
4121 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 15:14:30 -08004122 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004123 const auto& content2 = jsep_desc.description()->contents()[1];
4124 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 15:14:30 -08004125 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004126}
4127
4128// Tests that the session-level connection address will be used if the media
4129// level-addresses are not specified.
4130TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 10:27:41 -08004131 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004132
4133 // Sesssion-level address.
4134 std::string sdp = kSdpString;
4135 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
4136 // Remove the media level addresses.
4137 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
4138 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
4139 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4140
4141 const auto& content1 = jsep_desc.description()->contents()[0];
4142 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004143 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004144 const auto& content2 = jsep_desc.description()->contents()[1];
4145 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004146 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004147}
4148
4149TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 10:27:41 -08004150 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004151
4152 std::string sdp = kSdpString;
4153 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4154 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
4155 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
4156 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
4157 &sdp);
4158 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
4159 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
4160 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
4161 &sdp);
4162 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4163 const auto& content1 = jsep_desc.description()->contents()[0];
4164 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004165 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004166 const auto& content2 = jsep_desc.description()->contents()[1];
4167 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004168 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004169}
4170
Qingsi Wang56991422019-02-08 12:53:06 -08004171// Test that a c= line that contains a hostname connection address can be
4172// parsed.
4173TEST_F(WebRtcSdpTest, ParseConnectionDataWithHostnameConnectionAddress) {
4174 JsepSessionDescription jsep_desc(kDummyType);
4175 std::string sdp = kSdpString;
4176 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4177
4178 sdp = kSdpString;
4179 Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp);
4180 Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp);
4181 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4182
4183 ASSERT_NE(nullptr, jsep_desc.description());
4184 const auto& content1 = jsep_desc.description()->contents()[0];
4185 EXPECT_EQ("example.local:9",
4186 content1.media_description()->connection_address().ToString());
4187 const auto& content2 = jsep_desc.description()->contents()[1];
4188 EXPECT_EQ("example.local:9",
4189 content2.media_description()->connection_address().ToString());
4190}
4191
4192// Test that the invalid or unsupported connection data cannot be parsed.
zhihuang38989e52017-03-21 11:04:53 -07004193TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 10:27:41 -08004194 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004195 std::string sdp = kSdpString;
4196 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4197
4198 // Unsupported multicast IPv4 address.
4199 sdp = kSdpFullString;
4200 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
4201 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4202
4203 // Unsupported multicast IPv6 address.
4204 sdp = kSdpFullString;
4205 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
4206 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4207
4208 // Mismatched address type.
4209 sdp = kSdpFullString;
4210 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
4211 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4212
4213 sdp = kSdpFullString;
4214 Replace("c=IN IP4 74.125.224.39\r\n",
4215 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
4216 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4217}
4218
4219TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 10:27:41 -08004220 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004221 MakeDescriptionWithoutCandidates(&expected_jsep);
4222 // Serialization.
Steve Antone831b8c2018-02-01 12:22:16 -08004223 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 11:04:53 -07004224 // Deserialization.
Steve Antona3a92c22017-12-07 10:27:41 -08004225 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004226 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 15:14:30 -08004227 auto audio_desc = jdesc.description()
4228 ->GetContentByName(kAudioContentName)
4229 ->media_description();
4230 auto video_desc = jdesc.description()
4231 ->GetContentByName(kVideoContentName)
4232 ->media_description();
zhihuang38989e52017-03-21 11:04:53 -07004233 EXPECT_EQ(audio_desc_->connection_address().ToString(),
4234 audio_desc->connection_address().ToString());
4235 EXPECT_EQ(video_desc_->connection_address().ToString(),
4236 video_desc->connection_address().ToString());
4237}
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07004238
4239// RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be
4240// used (i.e., a single space as the session name)." So we should accept that.
4241TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) {
4242 JsepSessionDescription jsep_desc(kDummyType);
4243 std::string sdp = kSdpString;
4244 Replace("s=-\r\n", "s= \r\n", &sdp);
4245 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4246}
Amit Hilbucha2012042018-12-03 11:35:05 -08004247
4248// Simulcast malformed input test for invalid format.
4249TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_EmptyAttribute) {
Artem Titovf0a34f22020-03-16 17:52:04 +00004250 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
4251 "a=simulcast:\r\n", "a=simulcast:");
Amit Hilbucha2012042018-12-03 11:35:05 -08004252}
4253
4254// Tests that duplicate simulcast entries in the SDP triggers a parse failure.
4255TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_DuplicateAttribute) {
Artem Titovf0a34f22020-03-16 17:52:04 +00004256 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
4257 "a=simulcast:send 1\r\na=simulcast:recv 2\r\n",
4258 "a=simulcast:");
Amit Hilbucha2012042018-12-03 11:35:05 -08004259}
4260
4261// Validates that deserialization uses the a=simulcast: attribute
4262TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttribute) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004263 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4264 sdp += "a=rid:1 send\r\n";
4265 sdp += "a=rid:2 send\r\n";
4266 sdp += "a=rid:3 send\r\n";
4267 sdp += "a=rid:4 recv\r\n";
4268 sdp += "a=rid:5 recv\r\n";
4269 sdp += "a=rid:6 recv\r\n";
Amit Hilbucha2012042018-12-03 11:35:05 -08004270 sdp += "a=simulcast:send 1,2;3 recv 4;5;6\r\n";
4271 JsepSessionDescription output(kDummyType);
4272 SdpParseError error;
4273 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4274 const cricket::ContentInfos& contents = output.description()->contents();
4275 const cricket::MediaContentDescription* media =
4276 contents.back().media_description();
4277 EXPECT_TRUE(media->HasSimulcast());
4278 EXPECT_EQ(2ul, media->simulcast_description().send_layers().size());
4279 EXPECT_EQ(3ul, media->simulcast_description().receive_layers().size());
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004280 EXPECT_FALSE(media->streams().empty());
4281 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4282 CompareRidDescriptionIds(rids, {"1", "2", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004283}
4284
4285// Validates that deserialization removes rids that do not appear in SDP
4286TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttributeRemovesUnknownRids) {
4287 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4288 sdp += "a=rid:1 send\r\n";
4289 sdp += "a=rid:3 send\r\n";
4290 sdp += "a=rid:4 recv\r\n";
4291 sdp += "a=simulcast:send 1,2;3 recv 4;5,6\r\n";
4292 JsepSessionDescription output(kDummyType);
4293 SdpParseError error;
4294 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4295 const cricket::ContentInfos& contents = output.description()->contents();
4296 const cricket::MediaContentDescription* media =
4297 contents.back().media_description();
4298 EXPECT_TRUE(media->HasSimulcast());
4299 const SimulcastDescription& simulcast = media->simulcast_description();
4300 EXPECT_EQ(2ul, simulcast.send_layers().size());
4301 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4302
4303 std::vector<SimulcastLayer> all_send_layers =
4304 simulcast.send_layers().GetAllLayers();
4305 EXPECT_EQ(2ul, all_send_layers.size());
Steve Anton64b626b2019-01-28 17:25:26 -08004306 EXPECT_EQ(0,
4307 absl::c_count_if(all_send_layers, [](const SimulcastLayer& layer) {
4308 return layer.rid == "2";
4309 }));
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004310
4311 std::vector<SimulcastLayer> all_receive_layers =
4312 simulcast.receive_layers().GetAllLayers();
4313 ASSERT_EQ(1ul, all_receive_layers.size());
4314 EXPECT_EQ("4", all_receive_layers[0].rid);
4315
4316 EXPECT_FALSE(media->streams().empty());
4317 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4318 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004319}
4320
4321// Validates that Simulcast removes rids that appear in both send and receive.
4322TEST_F(WebRtcSdpTest,
4323 TestDeserializeSimulcastAttributeRemovesDuplicateSendReceive) {
4324 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4325 sdp += "a=rid:1 send\r\n";
4326 sdp += "a=rid:2 send\r\n";
4327 sdp += "a=rid:3 send\r\n";
4328 sdp += "a=rid:4 recv\r\n";
4329 sdp += "a=simulcast:send 1;2;3 recv 2;4\r\n";
4330 JsepSessionDescription output(kDummyType);
4331 SdpParseError error;
4332 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4333 const cricket::ContentInfos& contents = output.description()->contents();
4334 const cricket::MediaContentDescription* media =
4335 contents.back().media_description();
4336 EXPECT_TRUE(media->HasSimulcast());
4337 const SimulcastDescription& simulcast = media->simulcast_description();
4338 EXPECT_EQ(2ul, simulcast.send_layers().size());
4339 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4340 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4341 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4342
4343 EXPECT_FALSE(media->streams().empty());
4344 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4345 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004346}
4347
4348// Ignores empty rid line.
4349TEST_F(WebRtcSdpTest, TestDeserializeIgnoresEmptyRidLines) {
4350 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4351 sdp += "a=rid:1 send\r\n";
4352 sdp += "a=rid:2 send\r\n";
4353 sdp += "a=rid\r\n"; // Should ignore this line.
4354 sdp += "a=rid:\r\n"; // Should ignore this line.
4355 sdp += "a=simulcast:send 1;2\r\n";
4356 JsepSessionDescription output(kDummyType);
4357 SdpParseError error;
4358 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4359 const cricket::ContentInfos& contents = output.description()->contents();
4360 const cricket::MediaContentDescription* media =
4361 contents.back().media_description();
4362 EXPECT_TRUE(media->HasSimulcast());
4363 const SimulcastDescription& simulcast = media->simulcast_description();
4364 EXPECT_TRUE(simulcast.receive_layers().empty());
4365 EXPECT_EQ(2ul, simulcast.send_layers().size());
4366 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4367
4368 EXPECT_FALSE(media->streams().empty());
4369 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4370 CompareRidDescriptionIds(rids, {"1", "2"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004371}
4372
4373// Ignores malformed rid lines.
4374TEST_F(WebRtcSdpTest, TestDeserializeIgnoresMalformedRidLines) {
4375 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4376 sdp += "a=rid:1 send pt=\r\n"; // Should ignore this line.
4377 sdp += "a=rid:2 receive\r\n"; // Should ignore this line.
4378 sdp += "a=rid:3 max-width=720;pt=120\r\n"; // Should ignore this line.
4379 sdp += "a=rid:4\r\n"; // Should ignore this line.
4380 sdp += "a=rid:5 send\r\n";
4381 sdp += "a=simulcast:send 1,2,3;4,5\r\n";
4382 JsepSessionDescription output(kDummyType);
4383 SdpParseError error;
4384 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4385 const cricket::ContentInfos& contents = output.description()->contents();
4386 const cricket::MediaContentDescription* media =
4387 contents.back().media_description();
4388 EXPECT_TRUE(media->HasSimulcast());
4389 const SimulcastDescription& simulcast = media->simulcast_description();
4390 EXPECT_TRUE(simulcast.receive_layers().empty());
4391 EXPECT_EQ(1ul, simulcast.send_layers().size());
4392 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4393
4394 EXPECT_FALSE(media->streams().empty());
4395 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4396 CompareRidDescriptionIds(rids, {"5"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004397}
4398
4399// Removes RIDs that specify a different format than the m= section.
4400TEST_F(WebRtcSdpTest, TestDeserializeRemovesRidsWithInvalidCodec) {
4401 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4402 sdp += "a=rid:1 send pt=121,120\r\n"; // Should remove 121 and keep RID.
4403 sdp += "a=rid:2 send pt=121\r\n"; // Should remove RID altogether.
4404 sdp += "a=simulcast:send 1;2\r\n";
4405 JsepSessionDescription output(kDummyType);
4406 SdpParseError error;
4407 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4408 const cricket::ContentInfos& contents = output.description()->contents();
4409 const cricket::MediaContentDescription* media =
4410 contents.back().media_description();
4411 EXPECT_TRUE(media->HasSimulcast());
4412 const SimulcastDescription& simulcast = media->simulcast_description();
4413 EXPECT_TRUE(simulcast.receive_layers().empty());
4414 EXPECT_EQ(1ul, simulcast.send_layers().size());
4415 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4416 EXPECT_EQ("1", simulcast.send_layers()[0][0].rid);
4417 EXPECT_EQ(1ul, media->streams().size());
4418 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4419 EXPECT_EQ(1ul, rids.size());
4420 EXPECT_EQ("1", rids[0].rid);
4421 EXPECT_EQ(1ul, rids[0].payload_types.size());
4422 EXPECT_EQ(120, rids[0].payload_types[0]);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004423}
4424
4425// Ignores duplicate rid lines
4426TEST_F(WebRtcSdpTest, TestDeserializeIgnoresDuplicateRidLines) {
4427 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4428 sdp += "a=rid:1 send\r\n";
4429 sdp += "a=rid:2 send\r\n";
4430 sdp += "a=rid:2 send\r\n";
4431 sdp += "a=rid:3 send\r\n";
4432 sdp += "a=rid:4 recv\r\n";
4433 sdp += "a=simulcast:send 1,2;3 recv 4\r\n";
4434 JsepSessionDescription output(kDummyType);
4435 SdpParseError error;
4436 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4437 const cricket::ContentInfos& contents = output.description()->contents();
4438 const cricket::MediaContentDescription* media =
4439 contents.back().media_description();
4440 EXPECT_TRUE(media->HasSimulcast());
4441 const SimulcastDescription& simulcast = media->simulcast_description();
4442 EXPECT_EQ(2ul, simulcast.send_layers().size());
4443 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4444 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4445 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4446
4447 EXPECT_FALSE(media->streams().empty());
4448 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4449 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbucha2012042018-12-03 11:35:05 -08004450}
4451
Florent Castellic4421972019-07-02 20:27:42 +02004452TEST_F(WebRtcSdpTest, TestDeserializeRidSendDirection) {
4453 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4454 sdp += "a=rid:1 recv\r\n";
4455 sdp += "a=rid:2 recv\r\n";
4456 sdp += "a=simulcast:send 1;2\r\n";
4457 JsepSessionDescription output(kDummyType);
4458 SdpParseError error;
4459 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4460 const cricket::ContentInfos& contents = output.description()->contents();
4461 const cricket::MediaContentDescription* media =
4462 contents.back().media_description();
4463 EXPECT_FALSE(media->HasSimulcast());
4464}
4465
4466TEST_F(WebRtcSdpTest, TestDeserializeRidRecvDirection) {
4467 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4468 sdp += "a=rid:1 send\r\n";
4469 sdp += "a=rid:2 send\r\n";
4470 sdp += "a=simulcast:recv 1;2\r\n";
4471 JsepSessionDescription output(kDummyType);
4472 SdpParseError error;
4473 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4474 const cricket::ContentInfos& contents = output.description()->contents();
4475 const cricket::MediaContentDescription* media =
4476 contents.back().media_description();
4477 EXPECT_FALSE(media->HasSimulcast());
4478}
4479
4480TEST_F(WebRtcSdpTest, TestDeserializeIgnoresWrongRidDirectionLines) {
4481 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4482 sdp += "a=rid:1 send\r\n";
4483 sdp += "a=rid:2 send\r\n";
4484 sdp += "a=rid:3 send\r\n";
4485 sdp += "a=rid:4 recv\r\n";
4486 sdp += "a=rid:5 recv\r\n";
4487 sdp += "a=rid:6 recv\r\n";
4488 sdp += "a=simulcast:send 1;5;3 recv 4;2;6\r\n";
4489 JsepSessionDescription output(kDummyType);
4490 SdpParseError error;
4491 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4492 const cricket::ContentInfos& contents = output.description()->contents();
4493 const cricket::MediaContentDescription* media =
4494 contents.back().media_description();
4495 EXPECT_TRUE(media->HasSimulcast());
4496 const SimulcastDescription& simulcast = media->simulcast_description();
4497 EXPECT_EQ(2ul, simulcast.send_layers().size());
4498 EXPECT_EQ(2ul, simulcast.receive_layers().size());
4499 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4500 EXPECT_EQ(2ul, simulcast.receive_layers().GetAllLayers().size());
4501
4502 EXPECT_FALSE(media->streams().empty());
4503 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4504 CompareRidDescriptionIds(rids, {"1", "3"});
4505}
4506
Amit Hilbucha2012042018-12-03 11:35:05 -08004507// Simulcast serialization integration test.
4508// This test will serialize and deserialize the description and compare.
4509// More detailed tests for parsing simulcast can be found in
4510// unit tests for SdpSerializer.
4511TEST_F(WebRtcSdpTest, SerializeSimulcast_ComplexSerialization) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004512 MakeUnifiedPlanDescription(/* use_ssrcs = */ false);
Amit Hilbucha2012042018-12-03 11:35:05 -08004513 auto description = jdesc_.description();
4514 auto media = description->GetContentDescriptionByName(kVideoContentName3);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004515 ASSERT_EQ(media->streams().size(), 1ul);
4516 StreamParams& send_stream = media->mutable_streams()[0];
4517 std::vector<RidDescription> send_rids;
4518 send_rids.push_back(RidDescription("1", RidDirection::kSend));
4519 send_rids.push_back(RidDescription("2", RidDirection::kSend));
4520 send_rids.push_back(RidDescription("3", RidDirection::kSend));
4521 send_rids.push_back(RidDescription("4", RidDirection::kSend));
4522 send_stream.set_rids(send_rids);
Florent Castellib60141b2019-07-03 12:47:54 +02004523 std::vector<RidDescription> receive_rids;
4524 receive_rids.push_back(RidDescription("5", RidDirection::kReceive));
4525 receive_rids.push_back(RidDescription("6", RidDirection::kReceive));
4526 receive_rids.push_back(RidDescription("7", RidDirection::kReceive));
4527 media->set_receive_rids(receive_rids);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004528
Amit Hilbucha2012042018-12-03 11:35:05 -08004529 SimulcastDescription& simulcast = media->simulcast_description();
4530 simulcast.send_layers().AddLayerWithAlternatives(
4531 {SimulcastLayer("2", false), SimulcastLayer("1", true)});
4532 simulcast.send_layers().AddLayerWithAlternatives(
4533 {SimulcastLayer("4", false), SimulcastLayer("3", false)});
Florent Castellib60141b2019-07-03 12:47:54 +02004534 simulcast.receive_layers().AddLayer({SimulcastLayer("5", false)});
4535 simulcast.receive_layers().AddLayer({SimulcastLayer("6", false)});
4536 simulcast.receive_layers().AddLayer({SimulcastLayer("7", false)});
Amit Hilbucha2012042018-12-03 11:35:05 -08004537
Amit Hilbucha2012042018-12-03 11:35:05 -08004538 TestSerialize(jdesc_);
4539}
Steve Anton06817cd2018-12-18 15:55:30 -08004540
4541// Test that the content name is empty if the media section does not have an
4542// a=mid line.
4543TEST_F(WebRtcSdpTest, ParseNoMid) {
4544 std::string sdp = kSdpString;
4545 Replace("a=mid:audio_content_name\r\n", "", &sdp);
4546 Replace("a=mid:video_content_name\r\n", "", &sdp);
4547
4548 JsepSessionDescription output(kDummyType);
4549 SdpParseError error;
4550 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4551
4552 EXPECT_THAT(output.description()->contents(),
4553 ElementsAre(Field("name", &cricket::ContentInfo::name, ""),
4554 Field("name", &cricket::ContentInfo::name, "")));
4555}
Piotr (Peter) Slatala13e570f2019-02-27 11:34:26 -08004556
Guido Urdanetacecf87f2019-05-31 10:17:38 +00004557TEST_F(WebRtcSdpTest, SerializeWithDefaultSctpProtocol) {
4558 AddSctpDataChannel(false); // Don't use sctpmap
4559 JsepSessionDescription jsep_desc(kDummyType);
4560 MakeDescriptionWithoutCandidates(&jsep_desc);
4561 std::string message = webrtc::SdpSerialize(jsep_desc);
4562 EXPECT_NE(std::string::npos,
4563 message.find(cricket::kMediaProtocolUdpDtlsSctp));
4564}
4565
4566TEST_F(WebRtcSdpTest, DeserializeWithAllSctpProtocols) {
4567 AddSctpDataChannel(false);
4568 std::string protocols[] = {cricket::kMediaProtocolDtlsSctp,
4569 cricket::kMediaProtocolUdpDtlsSctp,
4570 cricket::kMediaProtocolTcpDtlsSctp};
4571 for (const auto& protocol : protocols) {
4572 sctp_desc_->set_protocol(protocol);
4573 JsepSessionDescription jsep_desc(kDummyType);
4574 MakeDescriptionWithoutCandidates(&jsep_desc);
4575 std::string message = webrtc::SdpSerialize(jsep_desc);
4576 EXPECT_NE(std::string::npos, message.find(protocol));
4577 JsepSessionDescription jsep_output(kDummyType);
4578 SdpParseError error;
4579 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jsep_output, &error));
4580 }
4581}
Taylor Brandstetter4256df02020-02-18 14:05:07 -08004582
4583// According to https://tools.ietf.org/html/rfc5576#section-6.1, the CNAME
4584// attribute is mandatory, but we relax that restriction.
4585TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCname) {
4586 std::string sdp_without_cname = kSdpFullString;
4587 Replace("a=ssrc:1 cname:stream_1_cname\r\n", "", &sdp_without_cname);
4588 JsepSessionDescription new_jdesc(kDummyType);
4589 EXPECT_TRUE(SdpDeserialize(sdp_without_cname, &new_jdesc));
4590
4591 audio_desc_->mutable_streams()[0].cname = "";
4592 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
4593 jdesc_.session_version()));
4594 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
4595}
Philipp Hanckeefc55b02020-06-26 10:17:05 +02004596
4597TEST_F(WebRtcSdpTest, DeserializeSdpWithUnsupportedMediaType) {
Philipp Hanckeefc55b02020-06-26 10:17:05 +02004598 std::string sdp = kSdpSessionString;
4599 sdp +=
4600 "m=bogus 9 RTP/SAVPF 0 8\r\n"
Philipp Hancke4e8c1152020-10-13 12:43:15 +02004601 "c=IN IP4 0.0.0.0\r\n"
4602 "a=mid:bogusmid\r\n";
Philipp Hanckeefc55b02020-06-26 10:17:05 +02004603 sdp +=
4604 "m=audio/something 9 RTP/SAVPF 0 8\r\n"
Philipp Hancke4e8c1152020-10-13 12:43:15 +02004605 "c=IN IP4 0.0.0.0\r\n"
4606 "a=mid:somethingmid\r\n";
Philipp Hanckeefc55b02020-06-26 10:17:05 +02004607
4608 JsepSessionDescription jdesc_output(kDummyType);
4609 EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output));
4610
Philipp Hancke4e8c1152020-10-13 12:43:15 +02004611 ASSERT_EQ(2u, jdesc_output.description()->contents().size());
4612 ASSERT_NE(nullptr, jdesc_output.description()
4613 ->contents()[0]
4614 .media_description()
4615 ->as_unsupported());
4616 ASSERT_NE(nullptr, jdesc_output.description()
4617 ->contents()[1]
4618 .media_description()
4619 ->as_unsupported());
4620
4621 EXPECT_TRUE(jdesc_output.description()->contents()[0].rejected);
4622 EXPECT_TRUE(jdesc_output.description()->contents()[1].rejected);
4623
4624 EXPECT_EQ(jdesc_output.description()->contents()[0].name, "bogusmid");
4625 EXPECT_EQ(jdesc_output.description()->contents()[1].name, "somethingmid");
Philipp Hanckeefc55b02020-06-26 10:17:05 +02004626}
Philipp Hanckeb70c9532021-01-13 10:40:06 +01004627
4628TEST_F(WebRtcSdpTest, MediaTypeProtocolMismatch) {
4629 std::string sdp =
4630 "v=0\r\n"
4631 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4632 "s=-\r\n"
4633 "t=0 0\r\n";
4634
4635 ExpectParseFailure(std::string(sdp + "m=audio 9 UDP/DTLS/SCTP 120\r\n"),
4636 "m=audio");
4637 ExpectParseFailure(std::string(sdp + "m=video 9 UDP/DTLS/SCTP 120\r\n"),
4638 "m=video");
4639 ExpectParseFailure(std::string(sdp + "m=video 9 SOMETHING 120\r\n"),
4640 "m=video");
4641 ExpectParseFailure(std::string(sdp + "m=application 9 SOMETHING 120\r\n"),
4642 "m=application");
4643}
Philipp Hanckecd467b52021-01-29 09:29:47 +01004644
4645// Regression test for:
4646// https://bugs.chromium.org/p/chromium/issues/detail?id=1171965
4647TEST_F(WebRtcSdpTest, SctpPortInUnsupportedContent) {
4648 std::string sdp =
4649 "v=0\r\n"
4650 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4651 "s=-\r\n"
4652 "t=0 0\r\n"
4653 "m=o 1 DTLS/SCTP 5000\r\n"
4654 "a=sctp-port\r\n";
4655
4656 JsepSessionDescription jdesc_output(kDummyType);
4657 EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output));
4658}
Harald Alvestrand99bcf602021-03-03 07:44:39 +00004659
4660TEST_F(WebRtcSdpTest, IllegalMidCharacterValue) {
4661 std::string sdp = kSdpString;
4662 // [ is an illegal token value.
4663 Replace("a=mid:", "a=mid:[]", &sdp);
4664 ExpectParseFailure(std::string(sdp), "a=mid:[]");
4665}