blob: 7c435f64df8490c77ae10f507d2f044363d18f1f [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
910// Add some extra |newlines| to the |message| after |line|.
911static 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
Philipp Hanckeb70c9532021-01-13 10:40:06 +0100923// 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
935// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
936static 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
942// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
943static 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
1586 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1587 // 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
1594 // 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.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001909 os << "m=video 9 RTP/SAVPF 99 95\r\n"
Jonas Olssonb2b20312020-01-14 12:11:31 +01001910 "a=rtpmap:99 VP8/90000\r\n"
1911 "a=rtpmap:95 RTX/90000\r\n"
1912 "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001913 sdp += os.str();
1914
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001915 // Deserialize
1916 SdpParseError error;
1917 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1918
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001919 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001920 GetFirstAudioContentDescription(jdesc_output->description());
1921 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001922 ASSERT_FALSE(acd->codecs().empty());
1923 cricket::AudioCodec opus = acd->codecs()[0];
1924 EXPECT_EQ("opus", opus.name);
1925 EXPECT_EQ(111, opus.id);
1926 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1927 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1928 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1929 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001930 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1931 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001932 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1933 cricket::AudioCodec codec = acd->codecs()[i];
1934 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1935 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001936 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001937
Philipp Hanckef2a4ec12020-07-01 21:07:32 +02001938 cricket::AudioCodec dtmf = acd->codecs()[3];
1939 EXPECT_EQ("telephone-event", dtmf.name);
1940 EXPECT_EQ(105, dtmf.id);
1941 EXPECT_EQ(3u,
1942 dtmf.params.size()); // ptime and max_ptime count as parameters.
1943 EXPECT_EQ(dtmf.params.begin()->first, "");
1944 EXPECT_EQ(dtmf.params.begin()->second, "0-15,66,70");
1945
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001946 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001947 GetFirstVideoContentDescription(jdesc_output->description());
1948 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001949 ASSERT_FALSE(vcd->codecs().empty());
1950 cricket::VideoCodec vp8 = vcd->codecs()[0];
1951 EXPECT_EQ("VP8", vp8.name);
1952 EXPECT_EQ(99, vp8.id);
1953 cricket::VideoCodec rtx = vcd->codecs()[1];
1954 EXPECT_EQ("RTX", rtx.name);
1955 EXPECT_EQ(95, rtx.id);
1956 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001957 }
1958
1959 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1960 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001961 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001962 "v=0\r\n"
1963 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1964 "s=-\r\n"
1965 "t=0 0\r\n"
1966 // Include semantics for WebRTC Media Streams since it is supported by
1967 // this parser, and will be added to the SDP when serializing a session
1968 // description.
1969 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001970 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001971 "a=rtpmap:111 opus/48000/2\r\n";
1972 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001973 "m=video 3457 RTP/SAVPF 101\r\n"
1974 "a=rtpmap:101 VP8/90000\r\n"
Elad Alonfadb1812019-05-24 13:40:02 +02001975 "a=rtcp-fb:101 goog-lntf\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001976 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001977 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001978 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001979 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001980 os << sdp_session_and_audio;
Yves Gerey665174f2018-06-19 15:03:05 +02001981 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001982 os << sdp_video;
Yves Gerey665174f2018-06-19 15:03:05 +02001983 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001984 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001985 // Deserialize
1986 SdpParseError error;
1987 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001988 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001989 GetFirstAudioContentDescription(jdesc_output->description());
1990 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001991 ASSERT_FALSE(acd->codecs().empty());
1992 cricket::AudioCodec opus = acd->codecs()[0];
1993 EXPECT_EQ(111, opus.id);
Yves Gerey665174f2018-06-19 15:03:05 +02001994 EXPECT_TRUE(opus.HasFeedbackParam(cricket::FeedbackParam(
1995 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001996
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001997 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001998 GetFirstVideoContentDescription(jdesc_output->description());
1999 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002000 ASSERT_FALSE(vcd->codecs().empty());
2001 cricket::VideoCodec vp8 = vcd->codecs()[0];
2002 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
2003 vp8.name.c_str());
2004 EXPECT_EQ(101, vp8.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002005 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
Elad Alonfadb1812019-05-24 13:40:02 +02002006 cricket::kRtcpFbParamLntf, cricket::kParamValueEmpty)));
2007 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
Yves Gerey665174f2018-06-19 15:03:05 +02002008 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
2009 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2010 cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli)));
2011 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2012 cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty)));
2013 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2014 cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002015 }
2016
2017 // Two SDP messages can mean the same thing but be different strings, e.g.
2018 // some of the lines can be serialized in different order.
2019 // However, a deserialized description can be compared field by field and has
2020 // no order. If deserializer has already been tested, serializing then
2021 // deserializing and comparing JsepSessionDescription will test
2022 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 12:22:16 -08002023 void TestSerialize(const JsepSessionDescription& jdesc) {
2024 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 10:27:41 -08002025 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002026 SdpParseError error;
2027 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
2028 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
2029 }
2030
zhihuang38989e52017-03-21 11:04:53 -07002031 // Calling 'Initialize' with a copy of the inner SessionDescription will
2032 // create a copy of the JsepSessionDescription without candidates. The
2033 // 'connection address' field, previously set from the candidates, must also
2034 // be reset.
2035 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
2036 rtc::SocketAddress audio_addr("0.0.0.0", 9);
2037 rtc::SocketAddress video_addr("0.0.0.0", 9);
2038 audio_desc_->set_connection_address(audio_addr);
2039 video_desc_->set_connection_address(video_addr);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002040 ASSERT_TRUE(jdesc->Initialize(desc_.Clone(), kSessionId, kSessionVersion));
zhihuang38989e52017-03-21 11:04:53 -07002041 }
2042
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002043 protected:
2044 SessionDescription desc_;
2045 AudioContentDescription* audio_desc_;
2046 VideoContentDescription* video_desc_;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002047 SctpDataContentDescription* sctp_desc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002048 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07002049 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002050 JsepSessionDescription jdesc_;
2051};
2052
2053void TestMismatch(const std::string& string1, const std::string& string2) {
2054 int position = 0;
2055 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
2056 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002057 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002058 break;
2059 }
2060 }
2061 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
2062 << " character\n"
Jonas Olssonb2b20312020-01-14 12:11:31 +01002063 " 1: "
2064 << string1.substr(position, 20)
2065 << "\n"
2066 " 2: "
2067 << string2.substr(position, 20) << "\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002068}
2069
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002070TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
2071 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 12:22:16 -08002072 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002073 TestMismatch(std::string(kSdpFullString), message);
2074}
2075
2076TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 10:27:41 -08002077 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 12:22:16 -08002078 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002079}
2080
2081// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
2082// the case in a DTLS offer.
2083TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
2084 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002085 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002086 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08002087 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002088
2089 std::string sdp_with_fingerprint = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002090 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2091 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002092
2093 EXPECT_EQ(sdp_with_fingerprint, message);
2094}
2095
2096// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
2097// be the case in a DTLS answer.
2098TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
2099 AddFingerprint();
2100 RemoveCryptos();
Steve Antona3a92c22017-12-07 10:27:41 -08002101 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002102 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08002103 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002104
2105 std::string sdp_with_fingerprint = kSdpString;
2106 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
2107 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
Yves Gerey665174f2018-06-19 15:03:05 +02002108 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2109 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002110
2111 EXPECT_EQ(sdp_with_fingerprint, message);
2112}
2113
2114TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
2115 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002116 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002117 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08002118 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002119 EXPECT_EQ(std::string(kSdpString), message);
2120}
2121
2122TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
2123 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2124 group.AddContentName(kAudioContentName);
2125 group.AddContentName(kVideoContentName);
2126 desc_.AddGroup(group);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002127 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002128 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002129 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002130 std::string sdp_with_bundle = kSdpFullString;
2131 InjectAfter(kSessionTime,
2132 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2133 &sdp_with_bundle);
2134 EXPECT_EQ(sdp_with_bundle, message);
2135}
2136
2137TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 15:14:30 -08002138 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
Taylor Brandstetteree8c2462020-07-27 15:52:02 -07002139 vcd->set_bandwidth(100 * 1000 + 755); // Integer division will drop the 755.
2140 vcd->set_bandwidth_type("AS");
Steve Antonb1c1de12017-12-21 15:14:30 -08002141 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
Taylor Brandstetteree8c2462020-07-27 15:52:02 -07002142 acd->set_bandwidth(555);
2143 acd->set_bandwidth_type("TIAS");
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002144 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002145 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002146 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002147 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002148 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002149 &sdp_with_bandwidth);
Taylor Brandstetteree8c2462020-07-27 15:52:02 -07002150 InjectAfter("c=IN IP4 74.125.127.126\r\n", "b=TIAS:555\r\n",
2151 &sdp_with_bandwidth);
2152 EXPECT_EQ(sdp_with_bandwidth, message);
2153}
2154
2155// Should default to b=AS if bandwidth_type isn't set.
2156TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithMissingBandwidthType) {
2157 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
2158 vcd->set_bandwidth(100 * 1000);
2159 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2160 jdesc_.session_version()));
2161 std::string message = webrtc::SdpSerialize(jdesc_);
2162 std::string sdp_with_bandwidth = kSdpFullString;
2163 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002164 &sdp_with_bandwidth);
2165 EXPECT_EQ(sdp_with_bandwidth, message);
2166}
2167
2168TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
2169 std::vector<std::string> transport_options;
2170 transport_options.push_back(kIceOption1);
2171 transport_options.push_back(kIceOption3);
2172 AddIceOptions(kAudioContentName, transport_options);
2173 transport_options.clear();
2174 transport_options.push_back(kIceOption2);
2175 transport_options.push_back(kIceOption3);
2176 AddIceOptions(kVideoContentName, transport_options);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002177 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002178 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002179 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002180 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002181 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002182 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002183 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002184 &sdp_with_ice_options);
2185 EXPECT_EQ(sdp_with_ice_options, message);
2186}
2187
2188TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002189 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002190}
2191
2192TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002193 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002194}
2195
2196TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002197 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002198}
2199
2200TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2201 EXPECT_TRUE(TestSerializeRejected(true, false));
2202}
2203
2204TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2205 EXPECT_TRUE(TestSerializeRejected(false, true));
2206}
2207
2208TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2209 EXPECT_TRUE(TestSerializeRejected(true, true));
2210}
2211
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002212TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08002213 bool use_sctpmap = true;
2214 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002215 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002216
zhihuang38989e52017-03-21 11:04:53 -07002217 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002218 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002219
2220 std::string expected_sdp = kSdpString;
2221 expected_sdp.append(kSdpSctpDataChannelString);
2222 EXPECT_EQ(message, expected_sdp);
2223}
2224
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002225void MutateJsepSctpPort(JsepSessionDescription* jdesc,
2226 const SessionDescription& desc,
2227 int port) {
2228 // Take our pre-built session description and change the SCTP port.
2229 std::unique_ptr<cricket::SessionDescription> mutant = desc.Clone();
2230 SctpDataContentDescription* dcdesc =
2231 mutant->GetContentDescriptionByName(kDataContentName)->as_sctp();
2232 dcdesc->set_port(port);
2233 ASSERT_TRUE(
2234 jdesc->Initialize(std::move(mutant), kSessionId, kSessionVersion));
2235}
2236
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002237TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08002238 bool use_sctpmap = true;
2239 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002240 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002241 MakeDescriptionWithoutCandidates(&jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002242
2243 const int kNewPort = 1234;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002244 MutateJsepSctpPort(&jsep_desc, desc_, kNewPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002245
Steve Antone831b8c2018-02-01 12:22:16 -08002246 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002247
2248 std::string expected_sdp = kSdpString;
2249 expected_sdp.append(kSdpSctpDataChannelString);
2250
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002251 absl::StrReplaceAll(
2252 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kNewPort)}},
2253 &expected_sdp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002254
2255 EXPECT_EQ(expected_sdp, message);
2256}
2257
Johannes Kron0854eb62018-10-10 22:33:20 +02002258TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002259 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002260 TestSerialize(jdesc_);
2261}
2262
2263TEST_F(WebRtcSdpTest, SerializeMediaContentDescriptionWithExtmapAllowMixed) {
2264 cricket::MediaContentDescription* video_desc =
2265 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2266 ASSERT_TRUE(video_desc);
2267 cricket::MediaContentDescription* audio_desc =
2268 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2269 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002270 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002271 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002272 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002273 cricket::MediaContentDescription::kMedia);
2274 TestSerialize(jdesc_);
2275}
2276
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002277TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002278 bool encrypted = false;
2279 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002280 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002281 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 12:22:16 -08002282 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002283
2284 std::string sdp_with_extmap = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002285 InjectAfter("a=mid:audio_content_name\r\n", kExtmap, &sdp_with_extmap);
2286 InjectAfter("a=mid:video_content_name\r\n", kExtmap, &sdp_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002287
2288 EXPECT_EQ(sdp_with_extmap, message);
2289}
2290
jbauch5869f502017-06-29 12:31:36 -07002291TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2292 bool encrypted = true;
2293 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002294 JsepSessionDescription desc_with_extmap(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002295 ASSERT_TRUE(
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002296 desc_with_extmap.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 12:22:16 -08002297 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07002298}
2299
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002300TEST_F(WebRtcSdpTest, SerializeCandidates) {
2301 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002302 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002303
2304 Candidate candidate_with_ufrag(candidates_.front());
2305 candidate_with_ufrag.set_username("ABC");
2306 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2307 candidate_with_ufrag));
2308 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2309 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002310
2311 Candidate candidate_with_network_info(candidates_.front());
2312 candidate_with_network_info.set_network_id(1);
2313 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2314 candidate_with_network_info));
2315 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2316 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2317 candidate_with_network_info.set_network_cost(999);
2318 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2319 candidate_with_network_info));
2320 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2321 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2322 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002323}
2324
Zach Steinb336c272018-08-09 01:16:13 -07002325TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) {
2326 rtc::SocketAddress address("a.test", 1234);
2327 cricket::Candidate candidate(
2328 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
2329 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
2330 JsepIceCandidate jcandidate(std::string("audio_content_name"), 0, candidate);
2331 std::string message = webrtc::SdpSerializeCandidate(jcandidate);
2332 EXPECT_EQ(std::string(kRawHostnameCandidate), message);
2333}
2334
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002335TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002336 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002337 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2338 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2339 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002340 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002341 std::unique_ptr<IceCandidateInterface> jcandidate(
2342 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002343
2344 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2345 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2346}
2347
Taylor Brandstetter8206bc02020-04-02 12:36:38 -07002348// Test serializing a TCP candidate that came in with a missing tcptype. This
2349// shouldn't happen according to the spec, but our implementation has been
2350// accepting this for quite some time, treating it as a passive candidate.
2351//
2352// So, we should be able to at least convert such candidates to and from SDP.
2353// See: bugs.webrtc.org/11423
2354TEST_F(WebRtcSdpTest, ParseTcpCandidateWithoutTcptype) {
2355 std::string missing_tcptype =
2356 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9999 typ host";
2357 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2358 EXPECT_TRUE(SdpDeserializeCandidate(missing_tcptype, &jcandidate));
2359
2360 EXPECT_EQ(std::string(cricket::TCPTYPE_PASSIVE_STR),
2361 jcandidate.candidate().tcptype());
2362}
2363
2364TEST_F(WebRtcSdpTest, ParseSslTcpCandidate) {
2365 std::string ssltcp =
2366 "candidate:a0+B/1 1 ssltcp 2130706432 192.168.1.5 9999 typ host tcptype "
2367 "passive";
2368 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2369 EXPECT_TRUE(SdpDeserializeCandidate(ssltcp, &jcandidate));
2370
2371 EXPECT_EQ(std::string("ssltcp"), jcandidate.candidate().protocol());
2372}
2373
htaa6b99442016-04-12 10:29:17 -07002374TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002375 cricket::VideoCodec h264_codec("H264");
2376 h264_codec.SetParam("profile-level-id", "42e01f");
2377 h264_codec.SetParam("level-asymmetry-allowed", "1");
2378 h264_codec.SetParam("packetization-mode", "1");
2379 video_desc_->AddCodec(h264_codec);
2380
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002381 jdesc_.Initialize(desc_.Clone(), kSessionId, kSessionVersion);
htaa6b99442016-04-12 10:29:17 -07002382
Steve Antone831b8c2018-02-01 12:22:16 -08002383 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 10:29:17 -07002384 size_t after_pt = message.find(" H264/90000");
2385 ASSERT_NE(after_pt, std::string::npos);
2386 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2387 ASSERT_NE(before_pt, std::string::npos);
2388 before_pt += strlen("a=rtpmap:");
2389 std::string pt = message.substr(before_pt, after_pt - before_pt);
2390 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2391 std::string to_find = "a=fmtp:" + pt + " ";
2392 size_t fmtp_pos = message.find(to_find);
2393 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
Mirko Bonadei37ec55e2019-01-28 11:43:52 +01002394 size_t fmtp_endpos = message.find('\n', fmtp_pos);
htaa6b99442016-04-12 10:29:17 -07002395 ASSERT_NE(std::string::npos, fmtp_endpos);
2396 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2397 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2398 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2399 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002400 // Check that there are no spaces after semicolons.
2401 // https://bugs.webrtc.org/5793
2402 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002403}
2404
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002405TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 10:27:41 -08002406 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002407 // Deserialize
2408 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2409 // Verify
2410 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2411}
2412
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002413TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 10:27:41 -08002414 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002415 const char kSdpWithoutMline[] =
Yves Gerey665174f2018-06-19 15:03:05 +02002416 "v=0\r\n"
2417 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2418 "s=-\r\n"
2419 "t=0 0\r\n"
2420 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002421 // Deserialize
2422 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2423 EXPECT_EQ(0u, jdesc.description()->contents().size());
2424}
2425
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002426TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 10:27:41 -08002427 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002428 std::string sdp_without_carriage_return = kSdpFullString;
2429 Replace("\r\n", "\n", &sdp_without_carriage_return);
2430 // Deserialize
2431 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2432 // Verify
2433 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2434}
2435
2436TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2437 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002438 JsepSessionDescription jdesc_no_candidates(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002439 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Clone(), kSessionId,
Yves Gerey665174f2018-06-19 15:03:05 +02002440 kSessionVersion));
Steve Antona3a92c22017-12-07 10:27:41 -08002441 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002442 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2443 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2444}
2445
2446TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2447 static const char kSdpNoRtpmapString[] =
2448 "v=0\r\n"
2449 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2450 "s=-\r\n"
2451 "t=0 0\r\n"
2452 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2453 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002454 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002455 // The rtpmap line for static payload codec is optional.
2456 "a=rtpmap:18 G729/16000\r\n"
2457 "a=rtpmap:103 ISAC/16000\r\n";
2458
Steve Antona3a92c22017-12-07 10:27:41 -08002459 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002460 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2461 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08002462 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002463 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002464 // The codecs in the AudioContentDescription should be in the same order as
2465 // the payload types (<fmt>s) on the m= line.
2466 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2467 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002468 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002469 EXPECT_EQ(ref_codecs, audio->codecs());
2470}
2471
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002472TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2473 static const char kSdpNoRtpmapString[] =
2474 "v=0\r\n"
2475 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2476 "s=-\r\n"
2477 "t=0 0\r\n"
2478 "m=audio 49232 RTP/AVP 18 103\r\n"
2479 "a=fmtp:18 annexb=yes\r\n"
2480 "a=rtpmap:103 ISAC/16000\r\n";
2481
Steve Antona3a92c22017-12-07 10:27:41 -08002482 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002483 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2484 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08002485 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002486
2487 cricket::AudioCodec g729 = audio->codecs()[0];
2488 EXPECT_EQ("G729", g729.name);
2489 EXPECT_EQ(8000, g729.clockrate);
2490 EXPECT_EQ(18, g729.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002491 cricket::CodecParameterMap::iterator found = g729.params.find("annexb");
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002492 ASSERT_TRUE(found != g729.params.end());
2493 EXPECT_EQ(found->second, "yes");
2494
2495 cricket::AudioCodec isac = audio->codecs()[1];
2496 EXPECT_EQ("ISAC", isac.name);
2497 EXPECT_EQ(103, isac.id);
2498 EXPECT_EQ(16000, isac.clockrate);
2499}
2500
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002501// Ensure that we can deserialize SDP with a=fingerprint properly.
2502TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2503 // Add a DTLS a=fingerprint attribute to our session description.
2504 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002505 JsepSessionDescription new_jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002506 ASSERT_TRUE(new_jdesc.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002507 jdesc_.session_version()));
2508
Steve Antona3a92c22017-12-07 10:27:41 -08002509 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002510 std::string sdp_with_fingerprint = kSdpString;
2511 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2512 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2513 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2514 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2515}
2516
2517TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 10:27:41 -08002518 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002519 std::string sdp_with_bundle = kSdpFullString;
2520 InjectAfter(kSessionTime,
2521 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2522 &sdp_with_bundle);
2523 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2524 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2525 group.AddContentName(kAudioContentName);
2526 group.AddContentName(kVideoContentName);
2527 desc_.AddGroup(group);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002528 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002529 jdesc_.session_version()));
2530 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2531}
2532
2533TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002534 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002535 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002536 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002537 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002538 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002539 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002540 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 15:14:30 -08002541 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002542 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002543 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002544 acd->set_bandwidth(50 * 1000);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002545 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002546 jdesc_.session_version()));
2547 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2548}
2549
Taylor Brandstetteree8c2462020-07-27 15:52:02 -07002550TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithTiasBandwidth) {
2551 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
2552 std::string sdp_with_bandwidth = kSdpFullString;
2553 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=TIAS:100000\r\n",
2554 &sdp_with_bandwidth);
2555 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=TIAS:50000\r\n",
2556 &sdp_with_bandwidth);
2557 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2558 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
2559 vcd->set_bandwidth(100 * 1000);
2560 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
2561 acd->set_bandwidth(50 * 1000);
2562 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2563 jdesc_.session_version()));
2564 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2565}
2566
Philipp Hanckefbbfc022020-07-31 08:30:50 +02002567TEST_F(WebRtcSdpTest,
2568 DeserializeSessionDescriptionWithUnknownBandwidthModifier) {
2569 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
2570 std::string sdp_with_bandwidth = kSdpFullString;
2571 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
2572 "b=unknown:100000\r\n", &sdp_with_bandwidth);
2573 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
2574 "b=unknown:50000\r\n", &sdp_with_bandwidth);
2575 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2576 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
2577 vcd->set_bandwidth(-1);
2578 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
2579 acd->set_bandwidth(-1);
2580 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2581 jdesc_.session_version()));
2582 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2583}
2584
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002585TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 10:27:41 -08002586 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002587 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002588 InjectAfter(kSessionTime, "a=ice-options:iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002589 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002590 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002591 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002592 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002593 &sdp_with_ice_options);
2594 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2595 std::vector<std::string> transport_options;
2596 transport_options.push_back(kIceOption3);
2597 transport_options.push_back(kIceOption1);
2598 AddIceOptions(kAudioContentName, transport_options);
2599 transport_options.clear();
2600 transport_options.push_back(kIceOption3);
2601 transport_options.push_back(kIceOption2);
2602 AddIceOptions(kVideoContentName, transport_options);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002603 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002604 jdesc_.session_version()));
2605 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2606}
2607
2608TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2609 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 10:27:41 -08002610 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002611 std::string sdp_with_ufrag_pwd = kSdpFullString;
2612 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2613 // Add session level ufrag and pwd
2614 InjectAfter(kSessionTime,
Yves Gerey665174f2018-06-19 15:03:05 +02002615 "a=ice-pwd:session+level+icepwd\r\n"
2616 "a=ice-ufrag:session+level+iceufrag\r\n",
2617 &sdp_with_ufrag_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002618 // Add media level ufrag and pwd for audio
Yves Gerey665174f2018-06-19 15:03:05 +02002619 InjectAfter(
2620 "a=mid:audio_content_name\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002621 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2622 &sdp_with_ufrag_pwd);
2623 // Update the candidate ufrag and pwd to the expected ones.
Yves Gerey665174f2018-06-19 15:03:05 +02002624 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, "media+level+iceufrag",
2625 "media+level+icepwd"));
2626 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, "session+level+iceufrag",
2627 "session+level+icepwd"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002628 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2629 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2630}
2631
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002632TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002633 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002634}
2635
2636TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002637 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002638}
2639
2640TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002641 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002642}
2643
2644TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2645 EXPECT_TRUE(TestDeserializeRejected(true, false));
2646}
2647
2648TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2649 EXPECT_TRUE(TestDeserializeRejected(false, true));
2650}
2651
2652TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2653 EXPECT_TRUE(TestDeserializeRejected(true, true));
2654}
2655
Artem Titovf0a34f22020-03-16 17:52:04 +00002656// Tests that we can still handle the sdp uses mslabel and label instead of
2657// msid for backward compatibility.
2658TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
2659 jdesc_.description()->set_msid_supported(false);
2660 JsepSessionDescription jdesc(kDummyType);
2661 std::string sdp_without_msid = kSdpFullString;
2662 Replace("msid", "xmsid", &sdp_without_msid);
2663 // Deserialize
2664 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2665 // Verify
2666 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2667 EXPECT_FALSE(jdesc.description()->msid_signaling() &
2668 ~cricket::kMsidSignalingSsrcAttribute);
2669}
2670
Johannes Kron0854eb62018-10-10 22:33:20 +02002671TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002672 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002673 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
Johannes Kron0854eb62018-10-10 22:33:20 +02002674 // Deserialize
2675 JsepSessionDescription jdesc_deserialized(kDummyType);
Emil Lundmark801c9992021-01-19 13:06:32 +01002676 ASSERT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
Johannes Kron0854eb62018-10-10 22:33:20 +02002677 // Verify
2678 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2679}
2680
2681TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002682 jdesc_.description()->set_extmap_allow_mixed(false);
Johannes Kron0854eb62018-10-10 22:33:20 +02002683 std::string sdp_without_extmap_allow_mixed = kSdpFullString;
Emil Lundmark801c9992021-01-19 13:06:32 +01002684 Replace(kExtmapAllowMixed, "", &sdp_without_extmap_allow_mixed);
Johannes Kron0854eb62018-10-10 22:33:20 +02002685 // Deserialize
2686 JsepSessionDescription jdesc_deserialized(kDummyType);
Emil Lundmark801c9992021-01-19 13:06:32 +01002687 ASSERT_TRUE(
Johannes Kron0854eb62018-10-10 22:33:20 +02002688 SdpDeserialize(sdp_without_extmap_allow_mixed, &jdesc_deserialized));
2689 // Verify
2690 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2691}
2692
2693TEST_F(WebRtcSdpTest, DeserializeMediaContentDescriptionWithExtmapAllowMixed) {
2694 cricket::MediaContentDescription* video_desc =
2695 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2696 ASSERT_TRUE(video_desc);
2697 cricket::MediaContentDescription* audio_desc =
2698 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2699 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002700 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002701 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002702 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002703 cricket::MediaContentDescription::kMedia);
2704
2705 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2706 InjectAfter("a=mid:audio_content_name\r\n", kExtmapAllowMixed,
2707 &sdp_with_extmap_allow_mixed);
2708 InjectAfter("a=mid:video_content_name\r\n", kExtmapAllowMixed,
2709 &sdp_with_extmap_allow_mixed);
2710
2711 // Deserialize
2712 JsepSessionDescription jdesc_deserialized(kDummyType);
2713 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2714 // Verify
2715 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2716}
2717
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002718TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2719 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2720
2721 std::string sdp = kSdpOneCandidate;
2722 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2723 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2724 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2725 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002726 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002727
2728 // Candidate line without generation extension.
2729 sdp = kSdpOneCandidate;
2730 Replace(" generation 2", "", &sdp);
2731 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2732 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2733 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2734 Candidate expected = jcandidate_->candidate();
2735 expected.set_generation(0);
2736 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2737
honghaiza0c44ea2016-03-23 16:07:48 -07002738 // Candidate with network id and/or cost.
2739 sdp = kSdpOneCandidate;
2740 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2741 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2742 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2743 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2744 expected = jcandidate_->candidate();
2745 expected.set_network_id(2);
2746 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2747 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2748 // Add network cost
2749 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2750 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2751 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2752 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2753
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002754 sdp = kSdpTcpActiveCandidate;
2755 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2756 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002757 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002758 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2759 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2760 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002761 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2762 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
Yves Gerey665174f2018-06-19 15:03:05 +02002763 EXPECT_TRUE(
2764 jcandidate.candidate().IsEquivalent(jcandidate_template->candidate()));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002765 sdp = kSdpTcpPassiveCandidate;
2766 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2767 sdp = kSdpTcpSOCandidate;
2768 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002769}
2770
2771// This test verifies the deserialization of candidate-attribute
2772// as per RFC 5245. Candiate-attribute will be of the format
2773// candidate:<blah>. This format will be used when candidates
2774// are trickled.
2775TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2776 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2777
2778 std::string candidate_attribute = kRawCandidate;
2779 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2780 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2781 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2782 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2783 EXPECT_EQ(2u, jcandidate.candidate().generation());
2784
2785 // Candidate line without generation extension.
2786 candidate_attribute = kRawCandidate;
2787 Replace(" generation 2", "", &candidate_attribute);
2788 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2789 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2790 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2791 Candidate expected = jcandidate_->candidate();
2792 expected.set_generation(0);
2793 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2794
2795 // Candidate line without candidate:
2796 candidate_attribute = kRawCandidate;
2797 Replace("candidate:", "", &candidate_attribute);
2798 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2799
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002800 // Candidate line with IPV6 address.
2801 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
Zach Steinb336c272018-08-09 01:16:13 -07002802
2803 // Candidate line with hostname address.
2804 EXPECT_TRUE(SdpDeserializeCandidate(kRawHostnameCandidate, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002805}
2806
2807// This test verifies that the deserialization of an invalid candidate string
2808// fails.
2809TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
Yves Gerey665174f2018-06-19 15:03:05 +02002810 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002811
2812 std::string candidate_attribute = kRawCandidate;
2813 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002814 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002815
2816 candidate_attribute = kSdpOneCandidate;
2817 candidate_attribute.replace(0, 1, "x");
2818 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2819
2820 candidate_attribute = kRawCandidate;
2821 candidate_attribute.append("\r\n");
2822 candidate_attribute.append(kRawCandidate);
2823 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2824
2825 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002826}
2827
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002828TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002829 bool use_sctpmap = true;
2830 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002831 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002832 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002833
2834 std::string sdp_with_data = kSdpString;
2835 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002836 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002837
Guido Urdanetacecf87f2019-05-31 10:17:38 +00002838 // Verify with UDP/DTLS/SCTP (already in kSdpSctpDataChannelString).
lally@webrtc.org36300852015-02-24 20:19:35 +00002839 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2840 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2841
Guido Urdanetacecf87f2019-05-31 10:17:38 +00002842 // Verify with DTLS/SCTP.
2843 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2844 kDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002845 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2846 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2847
2848 // Verify with TCP/DTLS/SCTP.
Guido Urdanetacecf87f2019-05-31 10:17:38 +00002849 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
Yves Gerey665174f2018-06-19 15:03:05 +02002850 kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002851 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2852 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2853}
2854
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002855TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002856 bool use_sctpmap = false;
2857 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002858 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002859 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002860
2861 std::string sdp_with_data = kSdpString;
2862 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002863 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002864
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002865 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2866 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2867}
2868
lally69f57602015-10-08 10:15:04 -07002869TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002870 bool use_sctpmap = false;
2871 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002872 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002873 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
lally69f57602015-10-08 10:15:04 -07002874
2875 std::string sdp_with_data = kSdpString;
2876 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002877 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 10:15:04 -07002878
lally69f57602015-10-08 10:15:04 -07002879 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2880 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2881}
2882
Philipp Hanckeefc55b02020-06-26 10:17:05 +02002883TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsButWrongMediaType) {
2884 bool use_sctpmap = true;
2885 AddSctpDataChannel(use_sctpmap);
2886 JsepSessionDescription jdesc(kDummyType);
2887 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
2888
2889 std::string sdp = kSdpSessionString;
2890 sdp += kSdpSctpDataChannelString;
2891
2892 const char needle[] = "m=application ";
2893 sdp.replace(sdp.find(needle), strlen(needle), "m=application:bogus ");
2894
2895 JsepSessionDescription jdesc_output(kDummyType);
2896 EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output));
2897
Philipp Hancke4e8c1152020-10-13 12:43:15 +02002898 EXPECT_EQ(1u, jdesc_output.description()->contents().size());
2899 EXPECT_TRUE(jdesc_output.description()->contents()[0].rejected);
Philipp Hanckeefc55b02020-06-26 10:17:05 +02002900}
2901
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002902// Helper function to set the max-message-size parameter in the
2903// SCTP data codec.
2904void MutateJsepSctpMaxMessageSize(const SessionDescription& desc,
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002905 int new_value,
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002906 JsepSessionDescription* jdesc) {
Harald Alvestrand8da35a62019-05-10 09:31:04 +02002907 std::unique_ptr<cricket::SessionDescription> mutant = desc.Clone();
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002908 SctpDataContentDescription* dcdesc =
2909 mutant->GetContentDescriptionByName(kDataContentName)->as_sctp();
2910 dcdesc->set_max_message_size(new_value);
Harald Alvestrand8da35a62019-05-10 09:31:04 +02002911 jdesc->Initialize(std::move(mutant), kSessionId, kSessionVersion);
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002912}
2913
2914TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithMaxMessageSize) {
2915 bool use_sctpmap = false;
2916 AddSctpDataChannel(use_sctpmap);
2917 JsepSessionDescription jdesc(kDummyType);
2918 std::string sdp_with_data = kSdpString;
2919
2920 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
2921 sdp_with_data.append("a=max-message-size:12345\r\n");
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002922 MutateJsepSctpMaxMessageSize(desc_, 12345, &jdesc);
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002923 JsepSessionDescription jdesc_output(kDummyType);
2924
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002925 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2926 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2927}
2928
Harald Alvestrandfbb45bd2019-05-15 08:07:47 +02002929TEST_F(WebRtcSdpTest, SerializeSdpWithSctpDataChannelWithMaxMessageSize) {
2930 bool use_sctpmap = false;
2931 AddSctpDataChannel(use_sctpmap);
2932 JsepSessionDescription jdesc(kDummyType);
2933 MutateJsepSctpMaxMessageSize(desc_, 12345, &jdesc);
2934 std::string message = webrtc::SdpSerialize(jdesc);
2935 EXPECT_NE(std::string::npos,
2936 message.find("\r\na=max-message-size:12345\r\n"));
2937 JsepSessionDescription jdesc_output(kDummyType);
2938 EXPECT_TRUE(SdpDeserialize(message, &jdesc_output));
2939 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2940}
2941
2942TEST_F(WebRtcSdpTest,
2943 SerializeSdpWithSctpDataChannelWithDefaultMaxMessageSize) {
2944 // https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-26#section-6
2945 // The default max message size is 64K.
2946 bool use_sctpmap = false;
2947 AddSctpDataChannel(use_sctpmap);
2948 JsepSessionDescription jdesc(kDummyType);
2949 MutateJsepSctpMaxMessageSize(desc_, 65536, &jdesc);
2950 std::string message = webrtc::SdpSerialize(jdesc);
2951 EXPECT_EQ(std::string::npos, message.find("\r\na=max-message-size:"));
2952 JsepSessionDescription jdesc_output(kDummyType);
2953 EXPECT_TRUE(SdpDeserialize(message, &jdesc_output));
2954 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2955}
2956
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002957// Test to check the behaviour if sctp-port is specified
2958// on the m= line and in a=sctp-port.
2959TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002960 bool use_sctpmap = true;
2961 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002962 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002963 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002964
2965 std::string sdp_with_data = kSdpString;
2966 // Append m= attributes
2967 sdp_with_data.append(kSdpSctpDataChannelString);
2968 // Append a=sctp-port attribute
2969 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 10:27:41 -08002970 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002971
2972 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2973}
2974
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002975// Test behavior if a=rtpmap occurs in an SCTP section.
2976TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpmapAttribute) {
2977 std::string sdp_with_data = kSdpString;
2978 // Append m= attributes
2979 sdp_with_data.append(kSdpSctpDataChannelString);
2980 // Append a=rtpmap attribute
2981 sdp_with_data.append("a=rtpmap:111 opus/48000/2\r\n");
2982 JsepSessionDescription jdesc_output(kDummyType);
2983 // Correct behavior is to ignore the extra attribute.
2984 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2985}
2986
2987TEST_F(WebRtcSdpTest, DeserializeSdpWithStrangeApplicationProtocolNames) {
Harald Alvestrand7af57c62021-04-16 11:12:14 +00002988 static const char* bad_strings[] = {
2989 "DTLS/SCTPRTP/", "obviously-bogus", "UDP/TL/RTSP/SAVPF",
2990 "UDP/TL/RTSP/S", "DTLS/SCTP/RTP/FOO", "obviously-bogus/RTP/"};
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002991 for (auto proto : bad_strings) {
2992 std::string sdp_with_data = kSdpString;
2993 sdp_with_data.append("m=application 9 ");
2994 sdp_with_data.append(proto);
2995 sdp_with_data.append(" 47\r\n");
2996 JsepSessionDescription jdesc_output(kDummyType);
2997 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output))
2998 << "Parsing should have failed on " << proto;
2999 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003000}
3001
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00003002// For crbug/344475.
3003TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
3004 std::string sdp_with_data = kSdpString;
3005 sdp_with_data.append(kSdpSctpDataChannelString);
3006 // Remove the "\n" at the end.
3007 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 10:27:41 -08003008 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00003009
3010 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
3011 // No crash is a pass.
3012}
3013
zstein4b2e0822017-02-17 19:48:38 -08003014TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
3015 bool use_sctpmap = true;
3016 AddSctpDataChannel(use_sctpmap);
3017
3018 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 10:27:41 -08003019 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003020 MutateJsepSctpPort(&jdesc, desc_, kUnusualSctpPort);
wu@webrtc.org78187522013-10-07 23:32:02 +00003021
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00003022 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00003023 std::string sdp_with_data = kSdpString;
3024 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Anton1c9c9fc2019-02-14 15:13:09 -08003025 absl::StrReplaceAll(
3026 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}},
3027 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08003028 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:02 +00003029
3030 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3031 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08003032}
3033
3034TEST_F(WebRtcSdpTest,
3035 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
3036 bool use_sctpmap = false;
3037 AddSctpDataChannel(use_sctpmap);
3038
Steve Antona3a92c22017-12-07 10:27:41 -08003039 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003040 MutateJsepSctpPort(&jdesc, desc_, kUnusualSctpPort);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003041
3042 // We need to test the deserialized JsepSessionDescription from
3043 // kSdpSctpDataChannelStringWithSctpPort for
3044 // draft-ietf-mmusic-sctp-sdp-07
3045 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08003046 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003047 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Anton1c9c9fc2019-02-14 15:13:09 -08003048 absl::StrReplaceAll(
3049 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}},
3050 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08003051 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003052
3053 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3054 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00003055}
3056
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003057TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08003058 bool use_sctpmap = true;
3059 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08003060 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003061 SctpDataContentDescription* dcd = GetFirstSctpDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003062 dcd->set_bandwidth(100 * 1000);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003063 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003064
3065 std::string sdp_with_bandwidth = kSdpString;
3066 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02003067 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003068 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08003069 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003070
3071 // SCTP has congestion control, so we shouldn't limit the bandwidth
3072 // as we do for RTP.
3073 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003074 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
3075}
3076
Yves Gerey665174f2018-06-19 15:03:05 +02003077class WebRtcSdpExtmapTest : public WebRtcSdpTest,
Mirko Bonadei6a489f22019-04-09 15:11:12 +02003078 public ::testing::WithParamInterface<bool> {};
jbauch5869f502017-06-29 12:31:36 -07003079
3080TEST_P(WebRtcSdpExtmapTest,
Yves Gerey665174f2018-06-19 15:03:05 +02003081 DeserializeSessionDescriptionWithSessionLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003082 bool encrypted = GetParam();
3083 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003084}
3085
Yves Gerey665174f2018-06-19 15:03:05 +02003086TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003087 bool encrypted = GetParam();
3088 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003089}
3090
Yves Gerey665174f2018-06-19 15:03:05 +02003091TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithInvalidExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003092 bool encrypted = GetParam();
3093 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003094}
3095
Mirko Bonadeic84f6612019-01-31 12:20:57 +01003096INSTANTIATE_TEST_SUITE_P(Encrypted,
3097 WebRtcSdpExtmapTest,
3098 ::testing::Values(false, true));
jbauch5869f502017-06-29 12:31:36 -07003099
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003100TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 10:27:41 -08003101 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003102 std::string sdp = kSdpFullString;
3103 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
3104 // Deserialize
3105 SdpParseError error;
3106 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
Artem Titovf0a34f22020-03-16 17:52:04 +00003107 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003108 EXPECT_EQ(lastline, error.line);
3109 EXPECT_EQ("Invalid SDP line.", error.description);
3110}
3111
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003112TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
3113 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
3114 std::string new_sdp = kSdpOneCandidate;
3115 Replace("udp", "unsupported_transport", &new_sdp);
3116 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3117 new_sdp = kSdpOneCandidate;
3118 Replace("udp", "uDP", &new_sdp);
3119 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3120 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3121 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3122 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
3123}
3124
honghaiza54a0802015-12-16 18:37:23 -08003125TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003126 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08003127 EXPECT_TRUE(
3128 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003129 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3130 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3131 Candidate ref_candidate = jcandidate_->candidate();
3132 ref_candidate.set_username("user_rtp");
3133 ref_candidate.set_password("password_rtp");
3134 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
3135}
3136
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003137TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08003138 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003139
3140 // Deserialize
3141 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
3142
3143 // Verify
3144 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08003145 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003146 EXPECT_TRUE(audio->conference_mode());
3147
3148 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 15:55:30 -08003149 cricket::GetFirstVideoContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003150 EXPECT_TRUE(video->conference_mode());
3151}
3152
deadbeefd45aea82017-09-16 01:24:29 -07003153TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08003154 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 01:24:29 -07003155
3156 // We tested deserialization already above, so just test that if we serialize
3157 // and deserialize the flag doesn't disappear.
3158 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 12:22:16 -08003159 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 01:24:29 -07003160 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
3161
3162 // Verify.
3163 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08003164 cricket::GetFirstAudioContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 01:24:29 -07003165 EXPECT_TRUE(audio->conference_mode());
3166
3167 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 15:55:30 -08003168 cricket::GetFirstVideoContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 01:24:29 -07003169 EXPECT_TRUE(video->conference_mode());
3170}
3171
Sebastian Jansson97321b62019-07-24 14:01:18 +02003172TEST_F(WebRtcSdpTest, SerializeAndDeserializeRemoteNetEstimate) {
3173 {
3174 // By default remote estimates are disabled.
3175 JsepSessionDescription dst(kDummyType);
3176 SdpDeserialize(webrtc::SdpSerialize(jdesc_), &dst);
3177 EXPECT_FALSE(cricket::GetFirstVideoContentDescription(dst.description())
3178 ->remote_estimate());
3179 }
3180 {
3181 // When remote estimate is enabled, the setting is propagated via SDP.
3182 cricket::GetFirstVideoContentDescription(jdesc_.description())
3183 ->set_remote_estimate(true);
3184 JsepSessionDescription dst(kDummyType);
3185 SdpDeserialize(webrtc::SdpSerialize(jdesc_), &dst);
3186 EXPECT_TRUE(cricket::GetFirstVideoContentDescription(dst.description())
3187 ->remote_estimate());
3188 }
3189}
3190
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003191TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
3192 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003193 const char kSdpEmptyType[] = " =candidate";
3194 const char kSdpEqualAsPlus[] = "a+candidate";
3195 const char kSdpSpaceAfterEqual[] = "a= candidate";
3196 const char kSdpUpperType[] = "A=candidate";
3197 const char kSdpEmptyLine[] = "";
3198 const char kSdpMissingValue[] = "a=";
3199
Yves Gerey665174f2018-06-19 15:03:05 +02003200 const char kSdpBrokenFingerprint[] =
3201 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003202 "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 +02003203 const char kSdpExtraField[] =
3204 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003205 "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 +02003206 const char kSdpMissingSpace[] =
3207 "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003208 "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 +00003209 // MD5 is not allowed in fingerprints.
Yves Gerey665174f2018-06-19 15:03:05 +02003210 const char kSdpMd5[] =
3211 "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003212 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003213
3214 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003215 ExpectParseFailure("v=", kSdpDestroyer);
3216 ExpectParseFailure("o=", kSdpDestroyer);
3217 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003218 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003219 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003220
3221 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003222 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
3223 ExpectParseFailure("m=video", kSdpDestroyer);
Philipp Hanckeefc55b02020-06-26 10:17:05 +02003224 ExpectParseFailure("m=", "c=IN IP4 74.125.224.39");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003225
3226 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003227 ExpectParseFailure("a=candidate", kSdpEmptyType);
3228 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
3229 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
3230 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003231
3232 // Bogus fingerprint replacing a=sendrev. We selected this attribute
3233 // because it's orthogonal to what we are replacing and hence
3234 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003235 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
3236 ExpectParseFailure("a=sendrecv", kSdpExtraField);
3237 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
3238 ExpectParseFailure("a=sendrecv", kSdpMd5);
3239
3240 // Empty Line
3241 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
3242 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003243}
3244
3245TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
3246 // ssrc
3247 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08003248 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003249 // crypto
3250 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
3251 // rtpmap
3252 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
3253 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
3254 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
3255 // candidate
3256 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
3257 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
3258 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
3259 ExpectParseFailure("rport 2346", "rport badvalue");
3260 ExpectParseFailure("rport 2346 generation 2",
3261 "rport 2346 generation badvalue");
3262 // m line
3263 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
3264 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
3265
3266 // bandwidth
3267 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003268 "b=AS:badvalue\r\n", "b=AS:badvalue");
Philipp Hanckefbbfc022020-07-31 08:30:50 +02003269 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", "b=AS\r\n",
3270 "b=AS");
3271 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", "b=AS:\r\n",
3272 "b=AS:");
3273 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3274 "b=AS:12:34\r\n", "b=AS:12:34");
3275
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003276 // rtcp-fb
3277 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3278 "a=rtcp-fb:badvalue nack\r\n",
3279 "a=rtcp-fb:badvalue nack");
3280 // extmap
3281 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3282 "a=extmap:badvalue http://example.com\r\n",
3283 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003284}
3285
3286TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 10:27:41 -08003287 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003288
3289 const char kSdpWithReorderedPlTypesString[] =
3290 "v=0\r\n"
3291 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3292 "s=-\r\n"
3293 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00003294 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
Yves Gerey665174f2018-06-19 15:03:05 +02003295 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
3296 // in the map.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003297 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003298 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003299
3300 // Deserialize
3301 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
3302
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003303 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003304 GetFirstAudioContentDescription(jdesc_output.description());
3305 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003306 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003307 EXPECT_EQ("ISAC", acd->codecs()[0].name);
3308 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003309 EXPECT_EQ(104, acd->codecs()[0].id);
3310}
3311
3312TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 10:27:41 -08003313 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003314 CodecParams params;
3315 params.max_ptime = 40;
3316 params.ptime = 30;
3317 params.min_ptime = 10;
3318 params.sprop_stereo = 1;
3319 params.stereo = 1;
3320 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003321 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003322 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 12:22:16 -08003323 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003324}
3325
3326TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
3327 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 10:27:41 -08003328 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003329 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003330 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003331}
3332
3333TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
3334 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 10:27:41 -08003335 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003336 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003337 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003338}
3339
3340TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 10:27:41 -08003341 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003342
3343 const char kSdpWithFmtpString[] =
3344 "v=0\r\n"
3345 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3346 "s=-\r\n"
3347 "t=0 0\r\n"
3348 "m=video 3457 RTP/SAVPF 120\r\n"
3349 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07003350 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3351
3352 // Deserialize
3353 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07003354 EXPECT_TRUE(
3355 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07003356
Donald Curtis0e07f922015-05-15 09:21:23 -07003357 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003358 GetFirstVideoContentDescription(jdesc_output.description());
3359 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 09:21:23 -07003360 ASSERT_FALSE(vcd->codecs().empty());
3361 cricket::VideoCodec vp8 = vcd->codecs()[0];
3362 EXPECT_EQ("VP8", vp8.name);
3363 EXPECT_EQ(120, vp8.id);
3364 cricket::CodecParameterMap::iterator found =
3365 vp8.params.find("x-google-min-bitrate");
3366 ASSERT_TRUE(found != vp8.params.end());
3367 EXPECT_EQ(found->second, "10");
3368 found = vp8.params.find("x-google-max-quantization");
3369 ASSERT_TRUE(found != vp8.params.end());
3370 EXPECT_EQ(found->second, "40");
3371}
3372
johan2d8d23e2016-06-03 01:22:42 -07003373TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 10:27:41 -08003374 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 01:22:42 -07003375
3376 const char kSdpWithFmtpString[] =
3377 "v=0\r\n"
3378 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3379 "s=-\r\n"
3380 "t=0 0\r\n"
3381 "m=video 49170 RTP/AVP 98\r\n"
3382 "a=rtpmap:98 H264/90000\r\n"
3383 "a=fmtp:98 profile-level-id=42A01E; "
3384 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3385
3386 // Deserialize.
3387 SdpParseError error;
3388 EXPECT_TRUE(
3389 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3390
johan2d8d23e2016-06-03 01:22:42 -07003391 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003392 GetFirstVideoContentDescription(jdesc_output.description());
3393 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 01:22:42 -07003394 ASSERT_FALSE(vcd->codecs().empty());
3395 cricket::VideoCodec h264 = vcd->codecs()[0];
3396 EXPECT_EQ("H264", h264.name);
3397 EXPECT_EQ(98, h264.id);
3398 cricket::CodecParameterMap::const_iterator found =
3399 h264.params.find("profile-level-id");
3400 ASSERT_TRUE(found != h264.params.end());
3401 EXPECT_EQ(found->second, "42A01E");
3402 found = h264.params.find("sprop-parameter-sets");
3403 ASSERT_TRUE(found != h264.params.end());
3404 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3405}
3406
Donald Curtis0e07f922015-05-15 09:21:23 -07003407TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 10:27:41 -08003408 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 09:21:23 -07003409
3410 const char kSdpWithFmtpString[] =
3411 "v=0\r\n"
3412 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3413 "s=-\r\n"
3414 "t=0 0\r\n"
3415 "m=video 3457 RTP/SAVPF 120\r\n"
3416 "a=rtpmap:120 VP8/90000\r\n"
3417 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003418
3419 // Deserialize
3420 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02003421 EXPECT_TRUE(
3422 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003423
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003424 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003425 GetFirstVideoContentDescription(jdesc_output.description());
3426 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003427 ASSERT_FALSE(vcd->codecs().empty());
3428 cricket::VideoCodec vp8 = vcd->codecs()[0];
3429 EXPECT_EQ("VP8", vp8.name);
3430 EXPECT_EQ(120, vp8.id);
3431 cricket::CodecParameterMap::iterator found =
3432 vp8.params.find("x-google-min-bitrate");
3433 ASSERT_TRUE(found != vp8.params.end());
3434 EXPECT_EQ(found->second, "10");
3435 found = vp8.params.find("x-google-max-quantization");
3436 ASSERT_TRUE(found != vp8.params.end());
3437 EXPECT_EQ(found->second, "40");
3438}
3439
Mirta Dvornicic479a3c02019-06-04 15:38:50 +02003440TEST_F(WebRtcSdpTest, DeserializePacketizationAttributeWithIllegalValue) {
3441 JsepSessionDescription jdesc_output(kDummyType);
3442
3443 const char kSdpWithPacketizationString[] =
3444 "v=0\r\n"
3445 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3446 "s=-\r\n"
3447 "t=0 0\r\n"
3448 "m=audio 9 RTP/SAVPF 111\r\n"
3449 "a=rtpmap:111 opus/48000/2\r\n"
3450 "a=packetization:111 unknownpacketizationattributeforaudio\r\n"
3451 "m=video 3457 RTP/SAVPF 120 121 122\r\n"
3452 "a=rtpmap:120 VP8/90000\r\n"
3453 "a=packetization:120 raw\r\n"
3454 "a=rtpmap:121 VP9/90000\r\n"
3455 "a=rtpmap:122 H264/90000\r\n"
3456 "a=packetization:122 unknownpacketizationattributevalue\r\n";
3457
3458 SdpParseError error;
3459 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithPacketizationString, &jdesc_output,
3460 &error));
3461
3462 AudioContentDescription* acd =
3463 GetFirstAudioContentDescription(jdesc_output.description());
3464 ASSERT_TRUE(acd);
3465 ASSERT_THAT(acd->codecs(), testing::SizeIs(1));
3466 cricket::AudioCodec opus = acd->codecs()[0];
3467 EXPECT_EQ(opus.name, "opus");
3468 EXPECT_EQ(opus.id, 111);
3469
3470 const VideoContentDescription* vcd =
3471 GetFirstVideoContentDescription(jdesc_output.description());
3472 ASSERT_TRUE(vcd);
3473 ASSERT_THAT(vcd->codecs(), testing::SizeIs(3));
3474 cricket::VideoCodec vp8 = vcd->codecs()[0];
3475 EXPECT_EQ(vp8.name, "VP8");
3476 EXPECT_EQ(vp8.id, 120);
3477 EXPECT_EQ(vp8.packetization, "raw");
3478 cricket::VideoCodec vp9 = vcd->codecs()[1];
3479 EXPECT_EQ(vp9.name, "VP9");
3480 EXPECT_EQ(vp9.id, 121);
3481 EXPECT_EQ(vp9.packetization, absl::nullopt);
3482 cricket::VideoCodec h264 = vcd->codecs()[2];
3483 EXPECT_EQ(h264.name, "H264");
3484 EXPECT_EQ(h264.id, 122);
3485 EXPECT_EQ(h264.packetization, absl::nullopt);
3486}
3487
ossuaa4b0772017-01-30 07:41:18 -08003488TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003489 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003490
3491 cricket::AudioCodecs codecs = acd->codecs();
3492 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3493 acd->set_codecs(codecs);
3494
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003495 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003496 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003497 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003498 std::string sdp_with_fmtp = kSdpFullString;
3499 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3500 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3501 &sdp_with_fmtp);
3502 EXPECT_EQ(sdp_with_fmtp, message);
3503}
3504
3505TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003506 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003507
3508 cricket::AudioCodecs codecs = acd->codecs();
3509 codecs[0].params["stereo"] = "1";
3510 acd->set_codecs(codecs);
3511
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003512 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003513 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003514 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003515 std::string sdp_with_fmtp = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003516 InjectAfter("a=rtpmap:111 opus/48000/2\r\n", "a=fmtp:111 stereo=1\r\n",
ossuaa4b0772017-01-30 07:41:18 -08003517 &sdp_with_fmtp);
3518 EXPECT_EQ(sdp_with_fmtp, message);
3519}
3520
3521TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003522 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003523
3524 cricket::AudioCodecs codecs = acd->codecs();
3525 codecs[0].params["ptime"] = "20";
3526 codecs[0].params["maxptime"] = "120";
3527 acd->set_codecs(codecs);
3528
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003529 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003530 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003531 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003532 std::string sdp_with_fmtp = kSdpFullString;
3533 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3534 "a=maxptime:120\r\n" // No comma here. String merging!
3535 "a=ptime:20\r\n",
3536 &sdp_with_fmtp);
3537 EXPECT_EQ(sdp_with_fmtp, message);
3538}
3539
Philipp Hanckef2a4ec12020-07-01 21:07:32 +02003540TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithTelephoneEvent) {
3541 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
3542
3543 cricket::AudioCodecs codecs = acd->codecs();
3544 cricket::AudioCodec dtmf(105, "telephone-event", 8000, 0, 1);
3545 dtmf.params[""] = "0-15";
3546 codecs.push_back(dtmf);
3547 acd->set_codecs(codecs);
3548
3549 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
3550 jdesc_.session_version()));
3551 std::string message = webrtc::SdpSerialize(jdesc_);
3552 std::string sdp_with_fmtp = kSdpFullString;
3553 InjectAfter("m=audio 2345 RTP/SAVPF 111 103 104", " 105", &sdp_with_fmtp);
3554 InjectAfter(
3555 "a=rtpmap:104 ISAC/32000\r\n",
3556 "a=rtpmap:105 telephone-event/8000\r\n" // No comma here. String merging!
3557 "a=fmtp:105 0-15\r\n",
3558 &sdp_with_fmtp);
3559 EXPECT_EQ(sdp_with_fmtp, message);
3560}
3561
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003562TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003563 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003564
3565 cricket::VideoCodecs codecs = vcd->codecs();
3566 codecs[0].params["x-google-min-bitrate"] = "10";
3567 vcd->set_codecs(codecs);
3568
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003569 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003570 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003571 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003572 std::string sdp_with_fmtp = kSdpFullString;
3573 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003574 "a=fmtp:120 x-google-min-bitrate=10\r\n", &sdp_with_fmtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003575 EXPECT_EQ(sdp_with_fmtp, message);
3576}
3577
Mirta Dvornicic479a3c02019-06-04 15:38:50 +02003578TEST_F(WebRtcSdpTest, SerializeVideoPacketizationAttribute) {
3579 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
3580
3581 cricket::VideoCodecs codecs = vcd->codecs();
3582 codecs[0].packetization = "raw";
3583 vcd->set_codecs(codecs);
3584
3585 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
3586 jdesc_.session_version()));
3587 std::string message = webrtc::SdpSerialize(jdesc_);
3588 std::string sdp_with_packetization = kSdpFullString;
3589 InjectAfter("a=rtpmap:120 VP8/90000\r\n", "a=packetization:120 raw\r\n",
3590 &sdp_with_packetization);
3591 EXPECT_EQ(sdp_with_packetization, message);
3592}
3593
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003594TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) {
3595 // Deserialize the baseline description, making sure it's ICE full.
Steve Antona3a92c22017-12-07 10:27:41 -08003596 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003597 std::string sdp_with_icelite = kSdpFullString;
3598 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3599 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3600 const cricket::TransportInfo* tinfo1 =
3601 desc->GetTransportInfoByName("audio_content_name");
3602 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3603 const cricket::TransportInfo* tinfo2 =
3604 desc->GetTransportInfoByName("video_content_name");
3605 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003606
3607 // Add "a=ice-lite" and deserialize, making sure it's ICE lite.
Yves Gerey665174f2018-06-19 15:03:05 +02003608 InjectAfter(kSessionTime, "a=ice-lite\r\n", &sdp_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003609 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3610 desc = jdesc_with_icelite.description();
3611 const cricket::TransportInfo* atinfo =
3612 desc->GetTransportInfoByName("audio_content_name");
3613 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3614 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003615 desc->GetTransportInfoByName("video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003616 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003617
3618 // Now that we know deserialization works, we can use TestSerialize to test
3619 // serialization.
3620 TestSerialize(jdesc_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003621}
3622
3623// Verifies that the candidates in the input SDP are parsed and serialized
3624// correctly in the output SDP.
3625TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3626 std::string sdp_with_data = kSdpString;
3627 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 10:27:41 -08003628 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003629
3630 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 12:22:16 -08003631 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003632}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003633
3634TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3635 AddFingerprint();
3636 TransportInfo audio_transport_info =
3637 *(desc_.GetTransportInfoByName(kAudioContentName));
3638 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3639 audio_transport_info.description.connection_role);
3640 audio_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003641 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003642
3643 TransportInfo video_transport_info =
3644 *(desc_.GetTransportInfoByName(kVideoContentName));
3645 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3646 video_transport_info.description.connection_role);
3647 video_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003648 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003649
3650 desc_.RemoveTransportInfoByName(kAudioContentName);
3651 desc_.RemoveTransportInfoByName(kVideoContentName);
3652
3653 desc_.AddTransportInfo(audio_transport_info);
3654 desc_.AddTransportInfo(video_transport_info);
3655
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003656 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003657 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003658 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003659 std::string sdp_with_dtlssetup = kSdpFullString;
3660
3661 // Fingerprint attribute is necessary to add DTLS setup attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003662 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_dtlssetup);
3663 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003664 // Now adding |setup| attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003665 InjectAfter(kFingerprint, "a=setup:active\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003666 EXPECT_EQ(sdp_with_dtlssetup, message);
3667}
3668
3669TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
Steve Antona3a92c22017-12-07 10:27:41 -08003670 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003671 std::string sdp_with_dtlssetup = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003672 InjectAfter(kSessionTime, "a=setup:actpass\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003673 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3674 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3675 const cricket::TransportInfo* atinfo =
3676 desc->GetTransportInfoByName("audio_content_name");
3677 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3678 atinfo->description.connection_role);
3679 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003680 desc->GetTransportInfoByName("video_content_name");
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003681 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3682 vtinfo->description.connection_role);
3683}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003684
3685// Verifies that the order of the serialized m-lines follows the order of the
3686// ContentInfo in SessionDescription, and vise versa for deserialization.
3687TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 10:27:41 -08003688 JsepSessionDescription jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02003689 const std::string media_content_sdps[3] = {kSdpAudioString, kSdpVideoString,
3690 kSdpSctpDataChannelString};
3691 const cricket::MediaType media_types[3] = {cricket::MEDIA_TYPE_AUDIO,
3692 cricket::MEDIA_TYPE_VIDEO,
3693 cricket::MEDIA_TYPE_DATA};
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003694
3695 // Verifies all 6 permutations.
3696 for (size_t i = 0; i < 6; ++i) {
3697 size_t media_content_in_sdp[3];
3698 // The index of the first media content.
3699 media_content_in_sdp[0] = i / 2;
3700 // The index of the second media content.
3701 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3702 // The index of the third media content.
3703 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3704
3705 std::string sdp_string = kSdpSessionString;
3706 for (size_t i = 0; i < 3; ++i)
3707 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3708
3709 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3710 cricket::SessionDescription* desc = jdesc.description();
3711 EXPECT_EQ(3u, desc->contents().size());
3712
3713 for (size_t i = 0; i < 3; ++i) {
3714 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 15:14:30 -08003715 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003716 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3717 }
3718
Steve Antone831b8c2018-02-01 12:22:16 -08003719 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003720 EXPECT_EQ(sdp_string, serialized_sdp);
3721 }
3722}
deadbeef9d3584c2016-02-16 17:54:10 -08003723
deadbeef25ed4352016-12-12 18:37:36 -08003724TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3725 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 10:27:41 -08003726 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003727 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003728 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3729 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3730}
3731
deadbeef12771a12017-01-03 13:53:47 -08003732// The semantics of "a=bundle-only" are only defined when it's used in
3733// combination with a 0 port on the m= line. We should ignore it if used with a
3734// nonzero port.
3735TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3736 // Make the base bundle-only description but unset the bundle-only flag.
3737 MakeBundleOnlyDescription();
3738 jdesc_.description()->contents()[1].bundle_only = false;
3739
3740 std::string modified_sdp = kBundleOnlySdpFullString;
3741 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08003742 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003743 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3744 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003745}
3746
3747TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3748 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003749 TestSerialize(jdesc_);
deadbeef25ed4352016-12-12 18:37:36 -08003750}
3751
deadbeef9d3584c2016-02-16 17:54:10 -08003752TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3753 MakePlanBDescription();
3754
Steve Antona3a92c22017-12-07 10:27:41 -08003755 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003756 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3757
3758 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3759}
3760
3761TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3762 MakePlanBDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003763 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-16 17:54:10 -08003764}
3765
3766TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3767 MakeUnifiedPlanDescription();
3768
Steve Antona3a92c22017-12-07 10:27:41 -08003769 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003770 EXPECT_TRUE(
3771 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3772
3773 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3774}
3775
3776TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3777 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003778 TestSerialize(jdesc_);
3779}
3780
Seth Hampson5b4f0752018-04-02 16:31:36 -07003781// This tests deserializing a Unified Plan SDP that is compatible with both
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003782// Unified Plan and Plan B style SDP, meaning that it contains both "a=ssrc
3783// msid" lines and "a=msid " lines. It tests the case for audio/video tracks
Seth Hampson5b4f0752018-04-02 16:31:36 -07003784// with no stream ids and multiple stream ids. For parsing this, the Unified
3785// Plan a=msid lines should take priority, because the Plan B style a=ssrc msid
3786// lines do not support multiple stream ids and no stream ids.
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003787TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionSpecialMsid) {
3788 // Create both msid lines for Plan B and Unified Plan support.
3789 MakeUnifiedPlanDescriptionMultipleStreamIds(
3790 cricket::kMsidSignalingMediaSection |
3791 cricket::kMsidSignalingSsrcAttribute);
Seth Hampson5b4f0752018-04-02 16:31:36 -07003792
3793 JsepSessionDescription deserialized_description(kDummyType);
3794 EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid,
3795 &deserialized_description));
3796
3797 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
Henrik Boström5b147782018-12-04 11:25:05 +01003798 EXPECT_EQ(cricket::kMsidSignalingMediaSection |
3799 cricket::kMsidSignalingSsrcAttribute,
3800 deserialized_description.description()->msid_signaling());
Seth Hampson5b4f0752018-04-02 16:31:36 -07003801}
3802
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003803// Tests the serialization of a Unified Plan SDP that is compatible for both
3804// Unified Plan and Plan B style SDPs, meaning that it contains both "a=ssrc
3805// msid" lines and "a=msid " lines. It tests the case for no stream ids and
3806// multiple stream ids.
3807TEST_F(WebRtcSdpTest, SerializeSessionDescriptionSpecialMsid) {
3808 // Create both msid lines for Plan B and Unified Plan support.
3809 MakeUnifiedPlanDescriptionMultipleStreamIds(
3810 cricket::kMsidSignalingMediaSection |
3811 cricket::kMsidSignalingSsrcAttribute);
3812 std::string serialized_sdp = webrtc::SdpSerialize(jdesc_);
3813 // We explicitly test that the serialized SDP string is equal to the hard
3814 // coded SDP string. This is necessary, because in the parser "a=msid" lines
3815 // take priority over "a=ssrc msid" lines. This means if we just used
3816 // TestSerialize(), it could serialize an SDP that omits "a=ssrc msid" lines,
3817 // and still pass, because the deserialized version would be the same.
3818 EXPECT_EQ(kUnifiedPlanSdpFullStringWithSpecialMsid, serialized_sdp);
3819}
3820
3821// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3822// that signal stream IDs) is deserialized appropriately. It tests the case for
3823// no stream ids and multiple stream ids.
3824TEST_F(WebRtcSdpTest, UnifiedPlanDeserializeSessionDescriptionSpecialMsid) {
3825 // Only create a=msid lines for strictly Unified Plan stream ID support.
3826 MakeUnifiedPlanDescriptionMultipleStreamIds(
3827 cricket::kMsidSignalingMediaSection);
3828
3829 JsepSessionDescription deserialized_description(kDummyType);
3830 std::string unified_plan_sdp_string =
3831 kUnifiedPlanSdpFullStringWithSpecialMsid;
3832 RemoveSsrcMsidLinesFromSdpString(&unified_plan_sdp_string);
3833 EXPECT_TRUE(
3834 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3835
3836 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3837}
3838
3839// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3840// that signal stream IDs) is serialized appropriately. It tests the case for no
3841// stream ids and multiple stream ids.
3842TEST_F(WebRtcSdpTest, UnifiedPlanSerializeSessionDescriptionSpecialMsid) {
3843 // Only create a=msid lines for strictly Unified Plan stream ID support.
3844 MakeUnifiedPlanDescriptionMultipleStreamIds(
3845 cricket::kMsidSignalingMediaSection);
3846
Seth Hampson5b4f0752018-04-02 16:31:36 -07003847 TestSerialize(jdesc_);
3848}
3849
Seth Hampson5897a6e2018-04-03 11:16:33 -07003850// This tests that a Unified Plan SDP with no a=ssrc lines is
3851// serialized/deserialized appropriately. In this case the
3852// MediaContentDescription will contain a StreamParams object that doesn't have
3853// any SSRCs. Vice versa, this will be created upon deserializing an SDP with no
3854// SSRC lines.
3855TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3856 MakeUnifiedPlanDescription();
3857 RemoveSsrcSignalingFromStreamParams();
3858 std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString;
3859 RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string);
3860
3861 JsepSessionDescription deserialized_description(kDummyType);
3862 EXPECT_TRUE(
3863 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3864 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3865}
3866
3867TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3868 MakeUnifiedPlanDescription();
3869 RemoveSsrcSignalingFromStreamParams();
3870
3871 TestSerialize(jdesc_);
3872}
3873
Steve Antone831b8c2018-02-01 12:22:16 -08003874TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
3875 JsepSessionDescription jsep_desc(kDummyType);
3876 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
3877 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3878}
3879
3880TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
3881 JsepSessionDescription jsep_desc(kDummyType);
3882 std::string sdp = kSdpSessionString;
3883 sdp += kSdpSctpDataChannelString;
3884 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3885 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3886}
3887
3888TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
3889 JsepSessionDescription jsep_desc(kDummyType);
3890 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
3891 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
3892 jsep_desc.description()->msid_signaling());
3893}
3894
3895TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
3896 JsepSessionDescription jsep_desc(kDummyType);
3897 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
3898 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
3899 jsep_desc.description()->msid_signaling());
3900}
3901
3902const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
3903const char kSsrcAttributeMsidLine[] =
3904 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
3905
3906TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
3907 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
3908 std::string sdp = webrtc::SdpSerialize(jdesc_);
3909
3910 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3911 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3912}
3913
3914TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
3915 jdesc_.description()->set_msid_signaling(
3916 cricket::kMsidSignalingSsrcAttribute);
3917 std::string sdp = webrtc::SdpSerialize(jdesc_);
3918
3919 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
3920 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3921}
3922
3923TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
3924 jdesc_.description()->set_msid_signaling(
3925 cricket::kMsidSignalingMediaSection |
3926 cricket::kMsidSignalingSsrcAttribute);
3927 std::string sdp = webrtc::SdpSerialize(jdesc_);
3928
3929 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3930 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-16 17:54:10 -08003931}
deadbeef7e146cb2016-09-28 10:04:34 -07003932
deadbeefb2362572016-12-13 16:37:06 -08003933// Regression test for integer overflow bug:
3934// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3935TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003936 // Bandwidth attribute is the max signed 32-bit int, which will get
3937 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003938 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003939 "v=0\r\n"
3940 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3941 "s=-\r\n"
3942 "t=0 0\r\n"
3943 "m=video 3457 RTP/SAVPF 120\r\n"
3944 "b=AS:2147483647\r\n"
3945 "foo=fail\r\n";
3946
3947 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3948}
deadbeef7bcdb692017-01-20 12:43:58 -08003949
deadbeefbc88c6b2017-08-02 11:26:34 -07003950// Similar to the above, except that negative values are illegal, not just
3951// error-prone as large values are.
3952// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3953TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3954 static const char kSdpWithNegativeBandwidth[] =
3955 "v=0\r\n"
3956 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3957 "s=-\r\n"
3958 "t=0 0\r\n"
3959 "m=video 3457 RTP/SAVPF 120\r\n"
3960 "b=AS:-1000\r\n";
3961
3962 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3963}
3964
deadbeef3e8016e2017-08-03 17:49:30 -07003965// An exception to the above rule: a value of -1 for b=AS should just be
3966// ignored, resulting in "kAutoBandwidth" in the deserialized object.
3967// Applications historically may be using "b=AS:-1" to mean "no bandwidth
3968// limit", but this is now what ommitting the attribute entirely will do, so
3969// ignoring it will have the intended effect.
3970TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
3971 static const char kSdpWithBandwidthOfNegativeOne[] =
3972 "v=0\r\n"
3973 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3974 "s=-\r\n"
3975 "t=0 0\r\n"
3976 "m=video 3457 RTP/SAVPF 120\r\n"
3977 "b=AS:-1\r\n";
3978
Steve Antona3a92c22017-12-07 10:27:41 -08003979 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-03 17:49:30 -07003980 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-03 17:49:30 -07003981 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003982 GetFirstVideoContentDescription(jdesc_output.description());
3983 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-03 17:49:30 -07003984 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
3985}
3986
deadbeef7bcdb692017-01-20 12:43:58 -08003987// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3988// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3989// Regression test for:
3990// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3991TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3992 // Important piece is "ufrag foo pwd bar".
3993 static const char kSdpWithIceCredentialsInCandidateString[] =
3994 "v=0\r\n"
3995 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3996 "s=-\r\n"
3997 "t=0 0\r\n"
3998 "m=audio 9 RTP/SAVPF 111\r\n"
3999 "c=IN IP4 0.0.0.0\r\n"
4000 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4001 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4002 "a=rtpmap:111 opus/48000/2\r\n"
4003 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
4004 "generation 2 ufrag foo pwd bar\r\n";
4005
Steve Antona3a92c22017-12-07 10:27:41 -08004006 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 12:43:58 -08004007 EXPECT_TRUE(
4008 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
4009 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
4010 ASSERT_NE(nullptr, candidates);
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02004011 ASSERT_EQ(1U, candidates->count());
deadbeef7bcdb692017-01-20 12:43:58 -08004012 cricket::Candidate c = candidates->at(0)->candidate();
4013 EXPECT_EQ("ufrag_voice", c.username());
4014 EXPECT_EQ("pwd_voice", c.password());
4015}
deadbeef90f1e1e2017-02-10 12:35:05 -08004016
Johannes Kron211856b2018-09-06 12:12:28 +02004017// Test that attribute lines "a=ice-ufrag-something"/"a=ice-pwd-something" are
4018// ignored, and only the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
4019// Regression test for:
4020// https://bugs.chromium.org/p/webrtc/issues/detail?id=9712
4021TEST_F(WebRtcSdpTest, AttributeWithPartialMatchingNameIsIgnored) {
4022 static const char kSdpWithFooIceCredentials[] =
4023 "v=0\r\n"
4024 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4025 "s=-\r\n"
4026 "t=0 0\r\n"
4027 "m=audio 9 RTP/SAVPF 111\r\n"
4028 "c=IN IP4 0.0.0.0\r\n"
4029 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4030 "a=ice-ufrag-something:foo\r\na=ice-pwd-something:bar\r\n"
4031 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4032 "a=rtpmap:111 opus/48000/2\r\n"
4033 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
4034 "generation 2\r\n";
4035
4036 JsepSessionDescription jdesc_output(kDummyType);
4037 EXPECT_TRUE(SdpDeserialize(kSdpWithFooIceCredentials, &jdesc_output));
4038 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
4039 ASSERT_NE(nullptr, candidates);
4040 ASSERT_EQ(1U, candidates->count());
4041 cricket::Candidate c = candidates->at(0)->candidate();
4042 EXPECT_EQ("ufrag_voice", c.username());
4043 EXPECT_EQ("pwd_voice", c.password());
4044}
4045
deadbeef90f1e1e2017-02-10 12:35:05 -08004046// Test that SDP with an invalid port number in "a=candidate" lines is
4047// rejected, without crashing.
4048// Regression test for:
4049// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
4050TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
4051 static const char kSdpWithInvalidCandidatePort[] =
4052 "v=0\r\n"
4053 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4054 "s=-\r\n"
4055 "t=0 0\r\n"
4056 "m=audio 9 RTP/SAVPF 111\r\n"
4057 "c=IN IP4 0.0.0.0\r\n"
4058 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4059 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4060 "a=rtpmap:111 opus/48000/2\r\n"
4061 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
4062 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
4063
Steve Antona3a92c22017-12-07 10:27:41 -08004064 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 12:35:05 -08004065 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
4066}
deadbeefa4549d62017-02-10 17:26:22 -08004067
4068// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
4069// Regression test for:
4070// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
4071TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
4072 static const char kSdpWithMissingTrackId[] =
4073 "v=0\r\n"
4074 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4075 "s=-\r\n"
4076 "t=0 0\r\n"
4077 "m=audio 9 RTP/SAVPF 111\r\n"
4078 "c=IN IP4 0.0.0.0\r\n"
4079 "a=rtpmap:111 opus/48000/2\r\n"
4080 "a=msid:stream_id \r\n";
4081
Steve Antona3a92c22017-12-07 10:27:41 -08004082 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08004083 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
4084}
4085
4086TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
4087 static const char kSdpWithMissingStreamId[] =
4088 "v=0\r\n"
4089 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4090 "s=-\r\n"
4091 "t=0 0\r\n"
4092 "m=audio 9 RTP/SAVPF 111\r\n"
4093 "c=IN IP4 0.0.0.0\r\n"
4094 "a=rtpmap:111 opus/48000/2\r\n"
4095 "a=msid: track_id\r\n";
4096
Steve Antona3a92c22017-12-07 10:27:41 -08004097 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08004098 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
4099}
zhihuang38989e52017-03-21 11:04:53 -07004100
4101// Tests that if both session-level address and media-level address exist, use
4102// the media-level address.
4103TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 10:27:41 -08004104 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004105
4106 // Sesssion-level address.
4107 std::string sdp = kSdpFullString;
4108 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
4109 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4110
4111 const auto& content1 = jsep_desc.description()->contents()[0];
4112 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 15:14:30 -08004113 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004114 const auto& content2 = jsep_desc.description()->contents()[1];
4115 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 15:14:30 -08004116 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004117}
4118
4119// Tests that the session-level connection address will be used if the media
4120// level-addresses are not specified.
4121TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 10:27:41 -08004122 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004123
4124 // Sesssion-level address.
4125 std::string sdp = kSdpString;
4126 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
4127 // Remove the media level addresses.
4128 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
4129 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
4130 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4131
4132 const auto& content1 = jsep_desc.description()->contents()[0];
4133 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004134 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004135 const auto& content2 = jsep_desc.description()->contents()[1];
4136 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004137 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004138}
4139
4140TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 10:27:41 -08004141 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004142
4143 std::string sdp = kSdpString;
4144 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4145 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
4146 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
4147 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
4148 &sdp);
4149 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
4150 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
4151 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
4152 &sdp);
4153 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4154 const auto& content1 = jsep_desc.description()->contents()[0];
4155 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004156 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004157 const auto& content2 = jsep_desc.description()->contents()[1];
4158 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004159 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004160}
4161
Qingsi Wang56991422019-02-08 12:53:06 -08004162// Test that a c= line that contains a hostname connection address can be
4163// parsed.
4164TEST_F(WebRtcSdpTest, ParseConnectionDataWithHostnameConnectionAddress) {
4165 JsepSessionDescription jsep_desc(kDummyType);
4166 std::string sdp = kSdpString;
4167 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4168
4169 sdp = kSdpString;
4170 Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp);
4171 Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp);
4172 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4173
4174 ASSERT_NE(nullptr, jsep_desc.description());
4175 const auto& content1 = jsep_desc.description()->contents()[0];
4176 EXPECT_EQ("example.local:9",
4177 content1.media_description()->connection_address().ToString());
4178 const auto& content2 = jsep_desc.description()->contents()[1];
4179 EXPECT_EQ("example.local:9",
4180 content2.media_description()->connection_address().ToString());
4181}
4182
4183// Test that the invalid or unsupported connection data cannot be parsed.
zhihuang38989e52017-03-21 11:04:53 -07004184TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 10:27:41 -08004185 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004186 std::string sdp = kSdpString;
4187 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4188
4189 // Unsupported multicast IPv4 address.
4190 sdp = kSdpFullString;
4191 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
4192 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4193
4194 // Unsupported multicast IPv6 address.
4195 sdp = kSdpFullString;
4196 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
4197 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4198
4199 // Mismatched address type.
4200 sdp = kSdpFullString;
4201 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
4202 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4203
4204 sdp = kSdpFullString;
4205 Replace("c=IN IP4 74.125.224.39\r\n",
4206 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
4207 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4208}
4209
4210TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 10:27:41 -08004211 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004212 MakeDescriptionWithoutCandidates(&expected_jsep);
4213 // Serialization.
Steve Antone831b8c2018-02-01 12:22:16 -08004214 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 11:04:53 -07004215 // Deserialization.
Steve Antona3a92c22017-12-07 10:27:41 -08004216 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004217 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 15:14:30 -08004218 auto audio_desc = jdesc.description()
4219 ->GetContentByName(kAudioContentName)
4220 ->media_description();
4221 auto video_desc = jdesc.description()
4222 ->GetContentByName(kVideoContentName)
4223 ->media_description();
zhihuang38989e52017-03-21 11:04:53 -07004224 EXPECT_EQ(audio_desc_->connection_address().ToString(),
4225 audio_desc->connection_address().ToString());
4226 EXPECT_EQ(video_desc_->connection_address().ToString(),
4227 video_desc->connection_address().ToString());
4228}
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07004229
4230// RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be
4231// used (i.e., a single space as the session name)." So we should accept that.
4232TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) {
4233 JsepSessionDescription jsep_desc(kDummyType);
4234 std::string sdp = kSdpString;
4235 Replace("s=-\r\n", "s= \r\n", &sdp);
4236 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4237}
Amit Hilbucha2012042018-12-03 11:35:05 -08004238
4239// Simulcast malformed input test for invalid format.
4240TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_EmptyAttribute) {
Artem Titovf0a34f22020-03-16 17:52:04 +00004241 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
4242 "a=simulcast:\r\n", "a=simulcast:");
Amit Hilbucha2012042018-12-03 11:35:05 -08004243}
4244
4245// Tests that duplicate simulcast entries in the SDP triggers a parse failure.
4246TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_DuplicateAttribute) {
Artem Titovf0a34f22020-03-16 17:52:04 +00004247 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
4248 "a=simulcast:send 1\r\na=simulcast:recv 2\r\n",
4249 "a=simulcast:");
Amit Hilbucha2012042018-12-03 11:35:05 -08004250}
4251
4252// Validates that deserialization uses the a=simulcast: attribute
4253TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttribute) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004254 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4255 sdp += "a=rid:1 send\r\n";
4256 sdp += "a=rid:2 send\r\n";
4257 sdp += "a=rid:3 send\r\n";
4258 sdp += "a=rid:4 recv\r\n";
4259 sdp += "a=rid:5 recv\r\n";
4260 sdp += "a=rid:6 recv\r\n";
Amit Hilbucha2012042018-12-03 11:35:05 -08004261 sdp += "a=simulcast:send 1,2;3 recv 4;5;6\r\n";
4262 JsepSessionDescription output(kDummyType);
4263 SdpParseError error;
4264 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4265 const cricket::ContentInfos& contents = output.description()->contents();
4266 const cricket::MediaContentDescription* media =
4267 contents.back().media_description();
4268 EXPECT_TRUE(media->HasSimulcast());
4269 EXPECT_EQ(2ul, media->simulcast_description().send_layers().size());
4270 EXPECT_EQ(3ul, media->simulcast_description().receive_layers().size());
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004271 EXPECT_FALSE(media->streams().empty());
4272 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4273 CompareRidDescriptionIds(rids, {"1", "2", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004274}
4275
4276// Validates that deserialization removes rids that do not appear in SDP
4277TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttributeRemovesUnknownRids) {
4278 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4279 sdp += "a=rid:1 send\r\n";
4280 sdp += "a=rid:3 send\r\n";
4281 sdp += "a=rid:4 recv\r\n";
4282 sdp += "a=simulcast:send 1,2;3 recv 4;5,6\r\n";
4283 JsepSessionDescription output(kDummyType);
4284 SdpParseError error;
4285 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4286 const cricket::ContentInfos& contents = output.description()->contents();
4287 const cricket::MediaContentDescription* media =
4288 contents.back().media_description();
4289 EXPECT_TRUE(media->HasSimulcast());
4290 const SimulcastDescription& simulcast = media->simulcast_description();
4291 EXPECT_EQ(2ul, simulcast.send_layers().size());
4292 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4293
4294 std::vector<SimulcastLayer> all_send_layers =
4295 simulcast.send_layers().GetAllLayers();
4296 EXPECT_EQ(2ul, all_send_layers.size());
Steve Anton64b626b2019-01-28 17:25:26 -08004297 EXPECT_EQ(0,
4298 absl::c_count_if(all_send_layers, [](const SimulcastLayer& layer) {
4299 return layer.rid == "2";
4300 }));
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004301
4302 std::vector<SimulcastLayer> all_receive_layers =
4303 simulcast.receive_layers().GetAllLayers();
4304 ASSERT_EQ(1ul, all_receive_layers.size());
4305 EXPECT_EQ("4", all_receive_layers[0].rid);
4306
4307 EXPECT_FALSE(media->streams().empty());
4308 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4309 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004310}
4311
4312// Validates that Simulcast removes rids that appear in both send and receive.
4313TEST_F(WebRtcSdpTest,
4314 TestDeserializeSimulcastAttributeRemovesDuplicateSendReceive) {
4315 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4316 sdp += "a=rid:1 send\r\n";
4317 sdp += "a=rid:2 send\r\n";
4318 sdp += "a=rid:3 send\r\n";
4319 sdp += "a=rid:4 recv\r\n";
4320 sdp += "a=simulcast:send 1;2;3 recv 2;4\r\n";
4321 JsepSessionDescription output(kDummyType);
4322 SdpParseError error;
4323 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4324 const cricket::ContentInfos& contents = output.description()->contents();
4325 const cricket::MediaContentDescription* media =
4326 contents.back().media_description();
4327 EXPECT_TRUE(media->HasSimulcast());
4328 const SimulcastDescription& simulcast = media->simulcast_description();
4329 EXPECT_EQ(2ul, simulcast.send_layers().size());
4330 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4331 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4332 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4333
4334 EXPECT_FALSE(media->streams().empty());
4335 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4336 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004337}
4338
4339// Ignores empty rid line.
4340TEST_F(WebRtcSdpTest, TestDeserializeIgnoresEmptyRidLines) {
4341 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4342 sdp += "a=rid:1 send\r\n";
4343 sdp += "a=rid:2 send\r\n";
4344 sdp += "a=rid\r\n"; // Should ignore this line.
4345 sdp += "a=rid:\r\n"; // Should ignore this line.
4346 sdp += "a=simulcast:send 1;2\r\n";
4347 JsepSessionDescription output(kDummyType);
4348 SdpParseError error;
4349 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4350 const cricket::ContentInfos& contents = output.description()->contents();
4351 const cricket::MediaContentDescription* media =
4352 contents.back().media_description();
4353 EXPECT_TRUE(media->HasSimulcast());
4354 const SimulcastDescription& simulcast = media->simulcast_description();
4355 EXPECT_TRUE(simulcast.receive_layers().empty());
4356 EXPECT_EQ(2ul, simulcast.send_layers().size());
4357 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4358
4359 EXPECT_FALSE(media->streams().empty());
4360 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4361 CompareRidDescriptionIds(rids, {"1", "2"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004362}
4363
4364// Ignores malformed rid lines.
4365TEST_F(WebRtcSdpTest, TestDeserializeIgnoresMalformedRidLines) {
4366 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4367 sdp += "a=rid:1 send pt=\r\n"; // Should ignore this line.
4368 sdp += "a=rid:2 receive\r\n"; // Should ignore this line.
4369 sdp += "a=rid:3 max-width=720;pt=120\r\n"; // Should ignore this line.
4370 sdp += "a=rid:4\r\n"; // Should ignore this line.
4371 sdp += "a=rid:5 send\r\n";
4372 sdp += "a=simulcast:send 1,2,3;4,5\r\n";
4373 JsepSessionDescription output(kDummyType);
4374 SdpParseError error;
4375 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4376 const cricket::ContentInfos& contents = output.description()->contents();
4377 const cricket::MediaContentDescription* media =
4378 contents.back().media_description();
4379 EXPECT_TRUE(media->HasSimulcast());
4380 const SimulcastDescription& simulcast = media->simulcast_description();
4381 EXPECT_TRUE(simulcast.receive_layers().empty());
4382 EXPECT_EQ(1ul, simulcast.send_layers().size());
4383 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4384
4385 EXPECT_FALSE(media->streams().empty());
4386 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4387 CompareRidDescriptionIds(rids, {"5"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004388}
4389
4390// Removes RIDs that specify a different format than the m= section.
4391TEST_F(WebRtcSdpTest, TestDeserializeRemovesRidsWithInvalidCodec) {
4392 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4393 sdp += "a=rid:1 send pt=121,120\r\n"; // Should remove 121 and keep RID.
4394 sdp += "a=rid:2 send pt=121\r\n"; // Should remove RID altogether.
4395 sdp += "a=simulcast:send 1;2\r\n";
4396 JsepSessionDescription output(kDummyType);
4397 SdpParseError error;
4398 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4399 const cricket::ContentInfos& contents = output.description()->contents();
4400 const cricket::MediaContentDescription* media =
4401 contents.back().media_description();
4402 EXPECT_TRUE(media->HasSimulcast());
4403 const SimulcastDescription& simulcast = media->simulcast_description();
4404 EXPECT_TRUE(simulcast.receive_layers().empty());
4405 EXPECT_EQ(1ul, simulcast.send_layers().size());
4406 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4407 EXPECT_EQ("1", simulcast.send_layers()[0][0].rid);
4408 EXPECT_EQ(1ul, media->streams().size());
4409 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4410 EXPECT_EQ(1ul, rids.size());
4411 EXPECT_EQ("1", rids[0].rid);
4412 EXPECT_EQ(1ul, rids[0].payload_types.size());
4413 EXPECT_EQ(120, rids[0].payload_types[0]);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004414}
4415
4416// Ignores duplicate rid lines
4417TEST_F(WebRtcSdpTest, TestDeserializeIgnoresDuplicateRidLines) {
4418 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4419 sdp += "a=rid:1 send\r\n";
4420 sdp += "a=rid:2 send\r\n";
4421 sdp += "a=rid:2 send\r\n";
4422 sdp += "a=rid:3 send\r\n";
4423 sdp += "a=rid:4 recv\r\n";
4424 sdp += "a=simulcast:send 1,2;3 recv 4\r\n";
4425 JsepSessionDescription output(kDummyType);
4426 SdpParseError error;
4427 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4428 const cricket::ContentInfos& contents = output.description()->contents();
4429 const cricket::MediaContentDescription* media =
4430 contents.back().media_description();
4431 EXPECT_TRUE(media->HasSimulcast());
4432 const SimulcastDescription& simulcast = media->simulcast_description();
4433 EXPECT_EQ(2ul, simulcast.send_layers().size());
4434 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4435 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4436 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4437
4438 EXPECT_FALSE(media->streams().empty());
4439 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4440 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbucha2012042018-12-03 11:35:05 -08004441}
4442
Florent Castellic4421972019-07-02 20:27:42 +02004443TEST_F(WebRtcSdpTest, TestDeserializeRidSendDirection) {
4444 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4445 sdp += "a=rid:1 recv\r\n";
4446 sdp += "a=rid:2 recv\r\n";
4447 sdp += "a=simulcast:send 1;2\r\n";
4448 JsepSessionDescription output(kDummyType);
4449 SdpParseError error;
4450 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4451 const cricket::ContentInfos& contents = output.description()->contents();
4452 const cricket::MediaContentDescription* media =
4453 contents.back().media_description();
4454 EXPECT_FALSE(media->HasSimulcast());
4455}
4456
4457TEST_F(WebRtcSdpTest, TestDeserializeRidRecvDirection) {
4458 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4459 sdp += "a=rid:1 send\r\n";
4460 sdp += "a=rid:2 send\r\n";
4461 sdp += "a=simulcast:recv 1;2\r\n";
4462 JsepSessionDescription output(kDummyType);
4463 SdpParseError error;
4464 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4465 const cricket::ContentInfos& contents = output.description()->contents();
4466 const cricket::MediaContentDescription* media =
4467 contents.back().media_description();
4468 EXPECT_FALSE(media->HasSimulcast());
4469}
4470
4471TEST_F(WebRtcSdpTest, TestDeserializeIgnoresWrongRidDirectionLines) {
4472 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4473 sdp += "a=rid:1 send\r\n";
4474 sdp += "a=rid:2 send\r\n";
4475 sdp += "a=rid:3 send\r\n";
4476 sdp += "a=rid:4 recv\r\n";
4477 sdp += "a=rid:5 recv\r\n";
4478 sdp += "a=rid:6 recv\r\n";
4479 sdp += "a=simulcast:send 1;5;3 recv 4;2;6\r\n";
4480 JsepSessionDescription output(kDummyType);
4481 SdpParseError error;
4482 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4483 const cricket::ContentInfos& contents = output.description()->contents();
4484 const cricket::MediaContentDescription* media =
4485 contents.back().media_description();
4486 EXPECT_TRUE(media->HasSimulcast());
4487 const SimulcastDescription& simulcast = media->simulcast_description();
4488 EXPECT_EQ(2ul, simulcast.send_layers().size());
4489 EXPECT_EQ(2ul, simulcast.receive_layers().size());
4490 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4491 EXPECT_EQ(2ul, simulcast.receive_layers().GetAllLayers().size());
4492
4493 EXPECT_FALSE(media->streams().empty());
4494 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4495 CompareRidDescriptionIds(rids, {"1", "3"});
4496}
4497
Amit Hilbucha2012042018-12-03 11:35:05 -08004498// Simulcast serialization integration test.
4499// This test will serialize and deserialize the description and compare.
4500// More detailed tests for parsing simulcast can be found in
4501// unit tests for SdpSerializer.
4502TEST_F(WebRtcSdpTest, SerializeSimulcast_ComplexSerialization) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004503 MakeUnifiedPlanDescription(/* use_ssrcs = */ false);
Amit Hilbucha2012042018-12-03 11:35:05 -08004504 auto description = jdesc_.description();
4505 auto media = description->GetContentDescriptionByName(kVideoContentName3);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004506 ASSERT_EQ(media->streams().size(), 1ul);
4507 StreamParams& send_stream = media->mutable_streams()[0];
4508 std::vector<RidDescription> send_rids;
4509 send_rids.push_back(RidDescription("1", RidDirection::kSend));
4510 send_rids.push_back(RidDescription("2", RidDirection::kSend));
4511 send_rids.push_back(RidDescription("3", RidDirection::kSend));
4512 send_rids.push_back(RidDescription("4", RidDirection::kSend));
4513 send_stream.set_rids(send_rids);
Florent Castellib60141b2019-07-03 12:47:54 +02004514 std::vector<RidDescription> receive_rids;
4515 receive_rids.push_back(RidDescription("5", RidDirection::kReceive));
4516 receive_rids.push_back(RidDescription("6", RidDirection::kReceive));
4517 receive_rids.push_back(RidDescription("7", RidDirection::kReceive));
4518 media->set_receive_rids(receive_rids);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004519
Amit Hilbucha2012042018-12-03 11:35:05 -08004520 SimulcastDescription& simulcast = media->simulcast_description();
4521 simulcast.send_layers().AddLayerWithAlternatives(
4522 {SimulcastLayer("2", false), SimulcastLayer("1", true)});
4523 simulcast.send_layers().AddLayerWithAlternatives(
4524 {SimulcastLayer("4", false), SimulcastLayer("3", false)});
Florent Castellib60141b2019-07-03 12:47:54 +02004525 simulcast.receive_layers().AddLayer({SimulcastLayer("5", false)});
4526 simulcast.receive_layers().AddLayer({SimulcastLayer("6", false)});
4527 simulcast.receive_layers().AddLayer({SimulcastLayer("7", false)});
Amit Hilbucha2012042018-12-03 11:35:05 -08004528
Amit Hilbucha2012042018-12-03 11:35:05 -08004529 TestSerialize(jdesc_);
4530}
Steve Anton06817cd2018-12-18 15:55:30 -08004531
4532// Test that the content name is empty if the media section does not have an
4533// a=mid line.
4534TEST_F(WebRtcSdpTest, ParseNoMid) {
4535 std::string sdp = kSdpString;
4536 Replace("a=mid:audio_content_name\r\n", "", &sdp);
4537 Replace("a=mid:video_content_name\r\n", "", &sdp);
4538
4539 JsepSessionDescription output(kDummyType);
4540 SdpParseError error;
4541 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4542
4543 EXPECT_THAT(output.description()->contents(),
4544 ElementsAre(Field("name", &cricket::ContentInfo::name, ""),
4545 Field("name", &cricket::ContentInfo::name, "")));
4546}
Piotr (Peter) Slatala13e570f2019-02-27 11:34:26 -08004547
Guido Urdanetacecf87f2019-05-31 10:17:38 +00004548TEST_F(WebRtcSdpTest, SerializeWithDefaultSctpProtocol) {
4549 AddSctpDataChannel(false); // Don't use sctpmap
4550 JsepSessionDescription jsep_desc(kDummyType);
4551 MakeDescriptionWithoutCandidates(&jsep_desc);
4552 std::string message = webrtc::SdpSerialize(jsep_desc);
4553 EXPECT_NE(std::string::npos,
4554 message.find(cricket::kMediaProtocolUdpDtlsSctp));
4555}
4556
4557TEST_F(WebRtcSdpTest, DeserializeWithAllSctpProtocols) {
4558 AddSctpDataChannel(false);
4559 std::string protocols[] = {cricket::kMediaProtocolDtlsSctp,
4560 cricket::kMediaProtocolUdpDtlsSctp,
4561 cricket::kMediaProtocolTcpDtlsSctp};
4562 for (const auto& protocol : protocols) {
4563 sctp_desc_->set_protocol(protocol);
4564 JsepSessionDescription jsep_desc(kDummyType);
4565 MakeDescriptionWithoutCandidates(&jsep_desc);
4566 std::string message = webrtc::SdpSerialize(jsep_desc);
4567 EXPECT_NE(std::string::npos, message.find(protocol));
4568 JsepSessionDescription jsep_output(kDummyType);
4569 SdpParseError error;
4570 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jsep_output, &error));
4571 }
4572}
Taylor Brandstetter4256df02020-02-18 14:05:07 -08004573
4574// According to https://tools.ietf.org/html/rfc5576#section-6.1, the CNAME
4575// attribute is mandatory, but we relax that restriction.
4576TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCname) {
4577 std::string sdp_without_cname = kSdpFullString;
4578 Replace("a=ssrc:1 cname:stream_1_cname\r\n", "", &sdp_without_cname);
4579 JsepSessionDescription new_jdesc(kDummyType);
4580 EXPECT_TRUE(SdpDeserialize(sdp_without_cname, &new_jdesc));
4581
4582 audio_desc_->mutable_streams()[0].cname = "";
4583 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
4584 jdesc_.session_version()));
4585 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
4586}
Philipp Hanckeefc55b02020-06-26 10:17:05 +02004587
4588TEST_F(WebRtcSdpTest, DeserializeSdpWithUnsupportedMediaType) {
Philipp Hanckeefc55b02020-06-26 10:17:05 +02004589 std::string sdp = kSdpSessionString;
4590 sdp +=
4591 "m=bogus 9 RTP/SAVPF 0 8\r\n"
Philipp Hancke4e8c1152020-10-13 12:43:15 +02004592 "c=IN IP4 0.0.0.0\r\n"
4593 "a=mid:bogusmid\r\n";
Philipp Hanckeefc55b02020-06-26 10:17:05 +02004594 sdp +=
4595 "m=audio/something 9 RTP/SAVPF 0 8\r\n"
Philipp Hancke4e8c1152020-10-13 12:43:15 +02004596 "c=IN IP4 0.0.0.0\r\n"
4597 "a=mid:somethingmid\r\n";
Philipp Hanckeefc55b02020-06-26 10:17:05 +02004598
4599 JsepSessionDescription jdesc_output(kDummyType);
4600 EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output));
4601
Philipp Hancke4e8c1152020-10-13 12:43:15 +02004602 ASSERT_EQ(2u, jdesc_output.description()->contents().size());
4603 ASSERT_NE(nullptr, jdesc_output.description()
4604 ->contents()[0]
4605 .media_description()
4606 ->as_unsupported());
4607 ASSERT_NE(nullptr, jdesc_output.description()
4608 ->contents()[1]
4609 .media_description()
4610 ->as_unsupported());
4611
4612 EXPECT_TRUE(jdesc_output.description()->contents()[0].rejected);
4613 EXPECT_TRUE(jdesc_output.description()->contents()[1].rejected);
4614
4615 EXPECT_EQ(jdesc_output.description()->contents()[0].name, "bogusmid");
4616 EXPECT_EQ(jdesc_output.description()->contents()[1].name, "somethingmid");
Philipp Hanckeefc55b02020-06-26 10:17:05 +02004617}
Philipp Hanckeb70c9532021-01-13 10:40:06 +01004618
4619TEST_F(WebRtcSdpTest, MediaTypeProtocolMismatch) {
4620 std::string sdp =
4621 "v=0\r\n"
4622 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4623 "s=-\r\n"
4624 "t=0 0\r\n";
4625
4626 ExpectParseFailure(std::string(sdp + "m=audio 9 UDP/DTLS/SCTP 120\r\n"),
4627 "m=audio");
4628 ExpectParseFailure(std::string(sdp + "m=video 9 UDP/DTLS/SCTP 120\r\n"),
4629 "m=video");
4630 ExpectParseFailure(std::string(sdp + "m=video 9 SOMETHING 120\r\n"),
4631 "m=video");
4632 ExpectParseFailure(std::string(sdp + "m=application 9 SOMETHING 120\r\n"),
4633 "m=application");
4634}
Philipp Hanckecd467b52021-01-29 09:29:47 +01004635
4636// Regression test for:
4637// https://bugs.chromium.org/p/chromium/issues/detail?id=1171965
4638TEST_F(WebRtcSdpTest, SctpPortInUnsupportedContent) {
4639 std::string sdp =
4640 "v=0\r\n"
4641 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4642 "s=-\r\n"
4643 "t=0 0\r\n"
4644 "m=o 1 DTLS/SCTP 5000\r\n"
4645 "a=sctp-port\r\n";
4646
4647 JsepSessionDescription jdesc_output(kDummyType);
4648 EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output));
4649}
Harald Alvestrand99bcf602021-03-03 07:44:39 +00004650
4651TEST_F(WebRtcSdpTest, IllegalMidCharacterValue) {
4652 std::string sdp = kSdpString;
4653 // [ is an illegal token value.
4654 Replace("a=mid:", "a=mid:[]", &sdp);
4655 ExpectParseFailure(std::string(sdp), "a=mid:[]");
4656}