blob: 559b981d5992a836c418f920053531bbb4be9ccd [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.
Philipp Hanckeb7bc2432021-03-11 15:28:00 +01001909 os << "m=video 9 RTP/SAVPF 99 95 96\r\n"
1910 "a=rtpmap:96 VP9/90000\r\n" // out-of-order wrt the m= line.
Jonas Olssonb2b20312020-01-14 12:11:31 +01001911 "a=rtpmap:99 VP8/90000\r\n"
1912 "a=rtpmap:95 RTX/90000\r\n"
1913 "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001914 sdp += os.str();
1915
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001916 // Deserialize
1917 SdpParseError error;
1918 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1919
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001920 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001921 GetFirstAudioContentDescription(jdesc_output->description());
1922 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001923 ASSERT_FALSE(acd->codecs().empty());
1924 cricket::AudioCodec opus = acd->codecs()[0];
1925 EXPECT_EQ("opus", opus.name);
1926 EXPECT_EQ(111, opus.id);
1927 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1928 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1929 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1930 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001931 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1932 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001933 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1934 cricket::AudioCodec codec = acd->codecs()[i];
1935 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1936 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001937 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001938
Philipp Hanckef2a4ec12020-07-01 21:07:32 +02001939 cricket::AudioCodec dtmf = acd->codecs()[3];
1940 EXPECT_EQ("telephone-event", dtmf.name);
1941 EXPECT_EQ(105, dtmf.id);
1942 EXPECT_EQ(3u,
1943 dtmf.params.size()); // ptime and max_ptime count as parameters.
1944 EXPECT_EQ(dtmf.params.begin()->first, "");
1945 EXPECT_EQ(dtmf.params.begin()->second, "0-15,66,70");
1946
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001947 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001948 GetFirstVideoContentDescription(jdesc_output->description());
1949 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001950 ASSERT_FALSE(vcd->codecs().empty());
1951 cricket::VideoCodec vp8 = vcd->codecs()[0];
1952 EXPECT_EQ("VP8", vp8.name);
1953 EXPECT_EQ(99, vp8.id);
1954 cricket::VideoCodec rtx = vcd->codecs()[1];
1955 EXPECT_EQ("RTX", rtx.name);
1956 EXPECT_EQ(95, rtx.id);
1957 VerifyCodecParameter(rtx.params, "apt", vp8.id);
Philipp Hanckeb7bc2432021-03-11 15:28:00 +01001958 // VP9 is listed last in the m= line so should come after VP8 and RTX.
1959 cricket::VideoCodec vp9 = vcd->codecs()[2];
1960 EXPECT_EQ("VP9", vp9.name);
1961 EXPECT_EQ(96, vp9.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001962 }
1963
1964 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1965 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001966 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001967 "v=0\r\n"
1968 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1969 "s=-\r\n"
1970 "t=0 0\r\n"
1971 // Include semantics for WebRTC Media Streams since it is supported by
1972 // this parser, and will be added to the SDP when serializing a session
1973 // description.
1974 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001975 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001976 "a=rtpmap:111 opus/48000/2\r\n";
1977 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001978 "m=video 3457 RTP/SAVPF 101\r\n"
1979 "a=rtpmap:101 VP8/90000\r\n"
Elad Alonfadb1812019-05-24 13:40:02 +02001980 "a=rtcp-fb:101 goog-lntf\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001981 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001982 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001983 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001984 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001985 os << sdp_session_and_audio;
Yves Gerey665174f2018-06-19 15:03:05 +02001986 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001987 os << sdp_video;
Yves Gerey665174f2018-06-19 15:03:05 +02001988 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001989 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001990 // Deserialize
1991 SdpParseError error;
1992 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001993 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001994 GetFirstAudioContentDescription(jdesc_output->description());
1995 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001996 ASSERT_FALSE(acd->codecs().empty());
1997 cricket::AudioCodec opus = acd->codecs()[0];
1998 EXPECT_EQ(111, opus.id);
Yves Gerey665174f2018-06-19 15:03:05 +02001999 EXPECT_TRUE(opus.HasFeedbackParam(cricket::FeedbackParam(
2000 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002001
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002002 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08002003 GetFirstVideoContentDescription(jdesc_output->description());
2004 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002005 ASSERT_FALSE(vcd->codecs().empty());
2006 cricket::VideoCodec vp8 = vcd->codecs()[0];
2007 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
2008 vp8.name.c_str());
2009 EXPECT_EQ(101, vp8.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002010 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
Elad Alonfadb1812019-05-24 13:40:02 +02002011 cricket::kRtcpFbParamLntf, cricket::kParamValueEmpty)));
2012 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
Yves Gerey665174f2018-06-19 15:03:05 +02002013 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
2014 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2015 cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli)));
2016 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2017 cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty)));
2018 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2019 cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002020 }
2021
2022 // Two SDP messages can mean the same thing but be different strings, e.g.
2023 // some of the lines can be serialized in different order.
2024 // However, a deserialized description can be compared field by field and has
2025 // no order. If deserializer has already been tested, serializing then
2026 // deserializing and comparing JsepSessionDescription will test
2027 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 12:22:16 -08002028 void TestSerialize(const JsepSessionDescription& jdesc) {
2029 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 10:27:41 -08002030 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002031 SdpParseError error;
2032 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
2033 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
2034 }
2035
zhihuang38989e52017-03-21 11:04:53 -07002036 // Calling 'Initialize' with a copy of the inner SessionDescription will
2037 // create a copy of the JsepSessionDescription without candidates. The
2038 // 'connection address' field, previously set from the candidates, must also
2039 // be reset.
2040 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
2041 rtc::SocketAddress audio_addr("0.0.0.0", 9);
2042 rtc::SocketAddress video_addr("0.0.0.0", 9);
2043 audio_desc_->set_connection_address(audio_addr);
2044 video_desc_->set_connection_address(video_addr);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002045 ASSERT_TRUE(jdesc->Initialize(desc_.Clone(), kSessionId, kSessionVersion));
zhihuang38989e52017-03-21 11:04:53 -07002046 }
2047
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002048 protected:
2049 SessionDescription desc_;
2050 AudioContentDescription* audio_desc_;
2051 VideoContentDescription* video_desc_;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002052 SctpDataContentDescription* sctp_desc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002053 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07002054 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002055 JsepSessionDescription jdesc_;
2056};
2057
2058void TestMismatch(const std::string& string1, const std::string& string2) {
2059 int position = 0;
2060 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
2061 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002062 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002063 break;
2064 }
2065 }
2066 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
2067 << " character\n"
Jonas Olssonb2b20312020-01-14 12:11:31 +01002068 " 1: "
2069 << string1.substr(position, 20)
2070 << "\n"
2071 " 2: "
2072 << string2.substr(position, 20) << "\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002073}
2074
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002075TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
2076 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 12:22:16 -08002077 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002078 TestMismatch(std::string(kSdpFullString), message);
2079}
2080
2081TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 10:27:41 -08002082 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 12:22:16 -08002083 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002084}
2085
2086// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
2087// the case in a DTLS offer.
2088TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
2089 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002090 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002091 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08002092 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002093
2094 std::string sdp_with_fingerprint = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002095 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2096 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002097
2098 EXPECT_EQ(sdp_with_fingerprint, message);
2099}
2100
2101// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
2102// be the case in a DTLS answer.
2103TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
2104 AddFingerprint();
2105 RemoveCryptos();
Steve Antona3a92c22017-12-07 10:27:41 -08002106 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002107 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08002108 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002109
2110 std::string sdp_with_fingerprint = kSdpString;
2111 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
2112 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
Yves Gerey665174f2018-06-19 15:03:05 +02002113 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2114 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002115
2116 EXPECT_EQ(sdp_with_fingerprint, message);
2117}
2118
2119TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
2120 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002121 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002122 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08002123 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002124 EXPECT_EQ(std::string(kSdpString), message);
2125}
2126
2127TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
2128 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2129 group.AddContentName(kAudioContentName);
2130 group.AddContentName(kVideoContentName);
2131 desc_.AddGroup(group);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002132 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002134 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002135 std::string sdp_with_bundle = kSdpFullString;
2136 InjectAfter(kSessionTime,
2137 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2138 &sdp_with_bundle);
2139 EXPECT_EQ(sdp_with_bundle, message);
2140}
2141
2142TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 15:14:30 -08002143 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
Taylor Brandstetteree8c2462020-07-27 15:52:02 -07002144 vcd->set_bandwidth(100 * 1000 + 755); // Integer division will drop the 755.
2145 vcd->set_bandwidth_type("AS");
Steve Antonb1c1de12017-12-21 15:14:30 -08002146 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
Taylor Brandstetteree8c2462020-07-27 15:52:02 -07002147 acd->set_bandwidth(555);
2148 acd->set_bandwidth_type("TIAS");
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002149 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002150 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002151 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002152 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002153 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002154 &sdp_with_bandwidth);
Taylor Brandstetteree8c2462020-07-27 15:52:02 -07002155 InjectAfter("c=IN IP4 74.125.127.126\r\n", "b=TIAS:555\r\n",
2156 &sdp_with_bandwidth);
2157 EXPECT_EQ(sdp_with_bandwidth, message);
2158}
2159
2160// Should default to b=AS if bandwidth_type isn't set.
2161TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithMissingBandwidthType) {
2162 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
2163 vcd->set_bandwidth(100 * 1000);
2164 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2165 jdesc_.session_version()));
2166 std::string message = webrtc::SdpSerialize(jdesc_);
2167 std::string sdp_with_bandwidth = kSdpFullString;
2168 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002169 &sdp_with_bandwidth);
2170 EXPECT_EQ(sdp_with_bandwidth, message);
2171}
2172
2173TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
2174 std::vector<std::string> transport_options;
2175 transport_options.push_back(kIceOption1);
2176 transport_options.push_back(kIceOption3);
2177 AddIceOptions(kAudioContentName, transport_options);
2178 transport_options.clear();
2179 transport_options.push_back(kIceOption2);
2180 transport_options.push_back(kIceOption3);
2181 AddIceOptions(kVideoContentName, transport_options);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002182 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002183 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002184 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002185 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002186 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002187 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002188 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002189 &sdp_with_ice_options);
2190 EXPECT_EQ(sdp_with_ice_options, message);
2191}
2192
2193TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002194 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002195}
2196
2197TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002198 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002199}
2200
2201TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002202 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002203}
2204
2205TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2206 EXPECT_TRUE(TestSerializeRejected(true, false));
2207}
2208
2209TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2210 EXPECT_TRUE(TestSerializeRejected(false, true));
2211}
2212
2213TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2214 EXPECT_TRUE(TestSerializeRejected(true, true));
2215}
2216
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002217TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08002218 bool use_sctpmap = true;
2219 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002220 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002221
zhihuang38989e52017-03-21 11:04:53 -07002222 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002223 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002224
2225 std::string expected_sdp = kSdpString;
2226 expected_sdp.append(kSdpSctpDataChannelString);
2227 EXPECT_EQ(message, expected_sdp);
2228}
2229
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002230void MutateJsepSctpPort(JsepSessionDescription* jdesc,
2231 const SessionDescription& desc,
2232 int port) {
2233 // Take our pre-built session description and change the SCTP port.
2234 std::unique_ptr<cricket::SessionDescription> mutant = desc.Clone();
2235 SctpDataContentDescription* dcdesc =
2236 mutant->GetContentDescriptionByName(kDataContentName)->as_sctp();
2237 dcdesc->set_port(port);
2238 ASSERT_TRUE(
2239 jdesc->Initialize(std::move(mutant), kSessionId, kSessionVersion));
2240}
2241
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002242TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08002243 bool use_sctpmap = true;
2244 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002245 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002246 MakeDescriptionWithoutCandidates(&jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002247
2248 const int kNewPort = 1234;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002249 MutateJsepSctpPort(&jsep_desc, desc_, kNewPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002250
Steve Antone831b8c2018-02-01 12:22:16 -08002251 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002252
2253 std::string expected_sdp = kSdpString;
2254 expected_sdp.append(kSdpSctpDataChannelString);
2255
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002256 absl::StrReplaceAll(
2257 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kNewPort)}},
2258 &expected_sdp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002259
2260 EXPECT_EQ(expected_sdp, message);
2261}
2262
Johannes Kron0854eb62018-10-10 22:33:20 +02002263TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002264 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002265 TestSerialize(jdesc_);
2266}
2267
2268TEST_F(WebRtcSdpTest, SerializeMediaContentDescriptionWithExtmapAllowMixed) {
2269 cricket::MediaContentDescription* video_desc =
2270 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2271 ASSERT_TRUE(video_desc);
2272 cricket::MediaContentDescription* audio_desc =
2273 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2274 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002275 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002276 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002277 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002278 cricket::MediaContentDescription::kMedia);
2279 TestSerialize(jdesc_);
2280}
2281
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002282TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002283 bool encrypted = false;
2284 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002285 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002286 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 12:22:16 -08002287 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002288
2289 std::string sdp_with_extmap = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002290 InjectAfter("a=mid:audio_content_name\r\n", kExtmap, &sdp_with_extmap);
2291 InjectAfter("a=mid:video_content_name\r\n", kExtmap, &sdp_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002292
2293 EXPECT_EQ(sdp_with_extmap, message);
2294}
2295
jbauch5869f502017-06-29 12:31:36 -07002296TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2297 bool encrypted = true;
2298 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002299 JsepSessionDescription desc_with_extmap(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002300 ASSERT_TRUE(
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002301 desc_with_extmap.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 12:22:16 -08002302 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07002303}
2304
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002305TEST_F(WebRtcSdpTest, SerializeCandidates) {
2306 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002307 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002308
2309 Candidate candidate_with_ufrag(candidates_.front());
2310 candidate_with_ufrag.set_username("ABC");
2311 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2312 candidate_with_ufrag));
2313 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2314 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002315
2316 Candidate candidate_with_network_info(candidates_.front());
2317 candidate_with_network_info.set_network_id(1);
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", message);
2322 candidate_with_network_info.set_network_cost(999);
2323 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2324 candidate_with_network_info));
2325 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2326 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2327 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002328}
2329
Zach Steinb336c272018-08-09 01:16:13 -07002330TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) {
2331 rtc::SocketAddress address("a.test", 1234);
2332 cricket::Candidate candidate(
2333 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
2334 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
2335 JsepIceCandidate jcandidate(std::string("audio_content_name"), 0, candidate);
2336 std::string message = webrtc::SdpSerializeCandidate(jcandidate);
2337 EXPECT_EQ(std::string(kRawHostnameCandidate), message);
2338}
2339
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002340TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002341 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002342 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2343 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2344 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002345 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002346 std::unique_ptr<IceCandidateInterface> jcandidate(
2347 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002348
2349 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2350 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2351}
2352
Taylor Brandstetter8206bc02020-04-02 12:36:38 -07002353// Test serializing a TCP candidate that came in with a missing tcptype. This
2354// shouldn't happen according to the spec, but our implementation has been
2355// accepting this for quite some time, treating it as a passive candidate.
2356//
2357// So, we should be able to at least convert such candidates to and from SDP.
2358// See: bugs.webrtc.org/11423
2359TEST_F(WebRtcSdpTest, ParseTcpCandidateWithoutTcptype) {
2360 std::string missing_tcptype =
2361 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9999 typ host";
2362 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2363 EXPECT_TRUE(SdpDeserializeCandidate(missing_tcptype, &jcandidate));
2364
2365 EXPECT_EQ(std::string(cricket::TCPTYPE_PASSIVE_STR),
2366 jcandidate.candidate().tcptype());
2367}
2368
2369TEST_F(WebRtcSdpTest, ParseSslTcpCandidate) {
2370 std::string ssltcp =
2371 "candidate:a0+B/1 1 ssltcp 2130706432 192.168.1.5 9999 typ host tcptype "
2372 "passive";
2373 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2374 EXPECT_TRUE(SdpDeserializeCandidate(ssltcp, &jcandidate));
2375
2376 EXPECT_EQ(std::string("ssltcp"), jcandidate.candidate().protocol());
2377}
2378
htaa6b99442016-04-12 10:29:17 -07002379TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002380 cricket::VideoCodec h264_codec("H264");
2381 h264_codec.SetParam("profile-level-id", "42e01f");
2382 h264_codec.SetParam("level-asymmetry-allowed", "1");
2383 h264_codec.SetParam("packetization-mode", "1");
2384 video_desc_->AddCodec(h264_codec);
2385
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002386 jdesc_.Initialize(desc_.Clone(), kSessionId, kSessionVersion);
htaa6b99442016-04-12 10:29:17 -07002387
Steve Antone831b8c2018-02-01 12:22:16 -08002388 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 10:29:17 -07002389 size_t after_pt = message.find(" H264/90000");
2390 ASSERT_NE(after_pt, std::string::npos);
2391 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2392 ASSERT_NE(before_pt, std::string::npos);
2393 before_pt += strlen("a=rtpmap:");
2394 std::string pt = message.substr(before_pt, after_pt - before_pt);
2395 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2396 std::string to_find = "a=fmtp:" + pt + " ";
2397 size_t fmtp_pos = message.find(to_find);
2398 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
Mirko Bonadei37ec55e2019-01-28 11:43:52 +01002399 size_t fmtp_endpos = message.find('\n', fmtp_pos);
htaa6b99442016-04-12 10:29:17 -07002400 ASSERT_NE(std::string::npos, fmtp_endpos);
2401 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2402 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2403 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2404 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002405 // Check that there are no spaces after semicolons.
2406 // https://bugs.webrtc.org/5793
2407 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002408}
2409
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002410TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 10:27:41 -08002411 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002412 // Deserialize
2413 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2414 // Verify
2415 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2416}
2417
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002418TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 10:27:41 -08002419 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002420 const char kSdpWithoutMline[] =
Yves Gerey665174f2018-06-19 15:03:05 +02002421 "v=0\r\n"
2422 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2423 "s=-\r\n"
2424 "t=0 0\r\n"
2425 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002426 // Deserialize
2427 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2428 EXPECT_EQ(0u, jdesc.description()->contents().size());
2429}
2430
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002431TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 10:27:41 -08002432 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002433 std::string sdp_without_carriage_return = kSdpFullString;
2434 Replace("\r\n", "\n", &sdp_without_carriage_return);
2435 // Deserialize
2436 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2437 // Verify
2438 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2439}
2440
2441TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2442 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002443 JsepSessionDescription jdesc_no_candidates(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002444 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Clone(), kSessionId,
Yves Gerey665174f2018-06-19 15:03:05 +02002445 kSessionVersion));
Steve Antona3a92c22017-12-07 10:27:41 -08002446 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002447 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2448 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2449}
2450
2451TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2452 static const char kSdpNoRtpmapString[] =
2453 "v=0\r\n"
2454 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2455 "s=-\r\n"
2456 "t=0 0\r\n"
2457 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2458 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002459 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002460 // The rtpmap line for static payload codec is optional.
2461 "a=rtpmap:18 G729/16000\r\n"
2462 "a=rtpmap:103 ISAC/16000\r\n";
2463
Steve Antona3a92c22017-12-07 10:27:41 -08002464 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002465 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2466 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08002467 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002468 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002469 // The codecs in the AudioContentDescription should be in the same order as
2470 // the payload types (<fmt>s) on the m= line.
2471 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2472 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002473 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002474 EXPECT_EQ(ref_codecs, audio->codecs());
2475}
2476
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002477TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2478 static const char kSdpNoRtpmapString[] =
2479 "v=0\r\n"
2480 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2481 "s=-\r\n"
2482 "t=0 0\r\n"
2483 "m=audio 49232 RTP/AVP 18 103\r\n"
2484 "a=fmtp:18 annexb=yes\r\n"
2485 "a=rtpmap:103 ISAC/16000\r\n";
2486
Steve Antona3a92c22017-12-07 10:27:41 -08002487 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002488 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2489 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08002490 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002491
2492 cricket::AudioCodec g729 = audio->codecs()[0];
2493 EXPECT_EQ("G729", g729.name);
2494 EXPECT_EQ(8000, g729.clockrate);
2495 EXPECT_EQ(18, g729.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002496 cricket::CodecParameterMap::iterator found = g729.params.find("annexb");
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002497 ASSERT_TRUE(found != g729.params.end());
2498 EXPECT_EQ(found->second, "yes");
2499
2500 cricket::AudioCodec isac = audio->codecs()[1];
2501 EXPECT_EQ("ISAC", isac.name);
2502 EXPECT_EQ(103, isac.id);
2503 EXPECT_EQ(16000, isac.clockrate);
2504}
2505
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002506// Ensure that we can deserialize SDP with a=fingerprint properly.
2507TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2508 // Add a DTLS a=fingerprint attribute to our session description.
2509 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002510 JsepSessionDescription new_jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002511 ASSERT_TRUE(new_jdesc.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002512 jdesc_.session_version()));
2513
Steve Antona3a92c22017-12-07 10:27:41 -08002514 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002515 std::string sdp_with_fingerprint = kSdpString;
2516 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2517 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2518 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2519 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2520}
2521
2522TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 10:27:41 -08002523 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002524 std::string sdp_with_bundle = kSdpFullString;
2525 InjectAfter(kSessionTime,
2526 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2527 &sdp_with_bundle);
2528 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2529 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2530 group.AddContentName(kAudioContentName);
2531 group.AddContentName(kVideoContentName);
2532 desc_.AddGroup(group);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002533 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002534 jdesc_.session_version()));
2535 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2536}
2537
2538TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002539 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002540 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002541 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002542 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002543 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002544 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002545 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 15:14:30 -08002546 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002547 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002548 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002549 acd->set_bandwidth(50 * 1000);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002550 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002551 jdesc_.session_version()));
2552 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2553}
2554
Taylor Brandstetteree8c2462020-07-27 15:52:02 -07002555TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithTiasBandwidth) {
2556 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
2557 std::string sdp_with_bandwidth = kSdpFullString;
2558 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=TIAS:100000\r\n",
2559 &sdp_with_bandwidth);
2560 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=TIAS:50000\r\n",
2561 &sdp_with_bandwidth);
2562 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2563 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
2564 vcd->set_bandwidth(100 * 1000);
2565 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
2566 acd->set_bandwidth(50 * 1000);
2567 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2568 jdesc_.session_version()));
2569 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2570}
2571
Philipp Hanckefbbfc022020-07-31 08:30:50 +02002572TEST_F(WebRtcSdpTest,
2573 DeserializeSessionDescriptionWithUnknownBandwidthModifier) {
2574 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
2575 std::string sdp_with_bandwidth = kSdpFullString;
2576 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
2577 "b=unknown:100000\r\n", &sdp_with_bandwidth);
2578 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
2579 "b=unknown:50000\r\n", &sdp_with_bandwidth);
2580 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2581 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
2582 vcd->set_bandwidth(-1);
2583 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
2584 acd->set_bandwidth(-1);
2585 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2586 jdesc_.session_version()));
2587 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2588}
2589
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002590TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 10:27:41 -08002591 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002592 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002593 InjectAfter(kSessionTime, "a=ice-options:iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002594 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002595 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002596 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002597 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002598 &sdp_with_ice_options);
2599 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2600 std::vector<std::string> transport_options;
2601 transport_options.push_back(kIceOption3);
2602 transport_options.push_back(kIceOption1);
2603 AddIceOptions(kAudioContentName, transport_options);
2604 transport_options.clear();
2605 transport_options.push_back(kIceOption3);
2606 transport_options.push_back(kIceOption2);
2607 AddIceOptions(kVideoContentName, transport_options);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002608 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002609 jdesc_.session_version()));
2610 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2611}
2612
2613TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2614 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 10:27:41 -08002615 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002616 std::string sdp_with_ufrag_pwd = kSdpFullString;
2617 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2618 // Add session level ufrag and pwd
2619 InjectAfter(kSessionTime,
Yves Gerey665174f2018-06-19 15:03:05 +02002620 "a=ice-pwd:session+level+icepwd\r\n"
2621 "a=ice-ufrag:session+level+iceufrag\r\n",
2622 &sdp_with_ufrag_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002623 // Add media level ufrag and pwd for audio
Yves Gerey665174f2018-06-19 15:03:05 +02002624 InjectAfter(
2625 "a=mid:audio_content_name\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002626 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2627 &sdp_with_ufrag_pwd);
2628 // Update the candidate ufrag and pwd to the expected ones.
Yves Gerey665174f2018-06-19 15:03:05 +02002629 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, "media+level+iceufrag",
2630 "media+level+icepwd"));
2631 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, "session+level+iceufrag",
2632 "session+level+icepwd"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002633 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2634 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2635}
2636
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002637TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002638 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002639}
2640
2641TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002642 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002643}
2644
2645TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002646 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002647}
2648
2649TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2650 EXPECT_TRUE(TestDeserializeRejected(true, false));
2651}
2652
2653TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2654 EXPECT_TRUE(TestDeserializeRejected(false, true));
2655}
2656
2657TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2658 EXPECT_TRUE(TestDeserializeRejected(true, true));
2659}
2660
Artem Titovf0a34f22020-03-16 17:52:04 +00002661// Tests that we can still handle the sdp uses mslabel and label instead of
2662// msid for backward compatibility.
2663TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
2664 jdesc_.description()->set_msid_supported(false);
2665 JsepSessionDescription jdesc(kDummyType);
2666 std::string sdp_without_msid = kSdpFullString;
2667 Replace("msid", "xmsid", &sdp_without_msid);
2668 // Deserialize
2669 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2670 // Verify
2671 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2672 EXPECT_FALSE(jdesc.description()->msid_signaling() &
2673 ~cricket::kMsidSignalingSsrcAttribute);
2674}
2675
Johannes Kron0854eb62018-10-10 22:33:20 +02002676TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002677 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002678 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
Johannes Kron0854eb62018-10-10 22:33:20 +02002679 // Deserialize
2680 JsepSessionDescription jdesc_deserialized(kDummyType);
Emil Lundmark801c9992021-01-19 13:06:32 +01002681 ASSERT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
Johannes Kron0854eb62018-10-10 22:33:20 +02002682 // Verify
2683 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2684}
2685
2686TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002687 jdesc_.description()->set_extmap_allow_mixed(false);
Johannes Kron0854eb62018-10-10 22:33:20 +02002688 std::string sdp_without_extmap_allow_mixed = kSdpFullString;
Emil Lundmark801c9992021-01-19 13:06:32 +01002689 Replace(kExtmapAllowMixed, "", &sdp_without_extmap_allow_mixed);
Johannes Kron0854eb62018-10-10 22:33:20 +02002690 // Deserialize
2691 JsepSessionDescription jdesc_deserialized(kDummyType);
Emil Lundmark801c9992021-01-19 13:06:32 +01002692 ASSERT_TRUE(
Johannes Kron0854eb62018-10-10 22:33:20 +02002693 SdpDeserialize(sdp_without_extmap_allow_mixed, &jdesc_deserialized));
2694 // Verify
2695 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2696}
2697
2698TEST_F(WebRtcSdpTest, DeserializeMediaContentDescriptionWithExtmapAllowMixed) {
2699 cricket::MediaContentDescription* video_desc =
2700 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2701 ASSERT_TRUE(video_desc);
2702 cricket::MediaContentDescription* audio_desc =
2703 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2704 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002705 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002706 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002707 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002708 cricket::MediaContentDescription::kMedia);
2709
2710 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2711 InjectAfter("a=mid:audio_content_name\r\n", kExtmapAllowMixed,
2712 &sdp_with_extmap_allow_mixed);
2713 InjectAfter("a=mid:video_content_name\r\n", kExtmapAllowMixed,
2714 &sdp_with_extmap_allow_mixed);
2715
2716 // Deserialize
2717 JsepSessionDescription jdesc_deserialized(kDummyType);
2718 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2719 // Verify
2720 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2721}
2722
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002723TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2724 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2725
2726 std::string sdp = kSdpOneCandidate;
2727 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2728 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2729 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2730 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002731 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002732
2733 // Candidate line without generation extension.
2734 sdp = kSdpOneCandidate;
2735 Replace(" generation 2", "", &sdp);
2736 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2737 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2738 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2739 Candidate expected = jcandidate_->candidate();
2740 expected.set_generation(0);
2741 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2742
honghaiza0c44ea2016-03-23 16:07:48 -07002743 // Candidate with network id and/or cost.
2744 sdp = kSdpOneCandidate;
2745 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2746 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2747 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2748 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2749 expected = jcandidate_->candidate();
2750 expected.set_network_id(2);
2751 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2752 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2753 // Add network cost
2754 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2755 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2756 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2757 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2758
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002759 sdp = kSdpTcpActiveCandidate;
2760 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2761 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002762 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002763 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2764 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2765 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002766 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2767 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
Yves Gerey665174f2018-06-19 15:03:05 +02002768 EXPECT_TRUE(
2769 jcandidate.candidate().IsEquivalent(jcandidate_template->candidate()));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002770 sdp = kSdpTcpPassiveCandidate;
2771 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2772 sdp = kSdpTcpSOCandidate;
2773 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002774}
2775
2776// This test verifies the deserialization of candidate-attribute
2777// as per RFC 5245. Candiate-attribute will be of the format
2778// candidate:<blah>. This format will be used when candidates
2779// are trickled.
2780TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2781 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2782
2783 std::string candidate_attribute = kRawCandidate;
2784 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2785 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2786 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2787 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2788 EXPECT_EQ(2u, jcandidate.candidate().generation());
2789
2790 // Candidate line without generation extension.
2791 candidate_attribute = kRawCandidate;
2792 Replace(" generation 2", "", &candidate_attribute);
2793 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2794 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2795 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2796 Candidate expected = jcandidate_->candidate();
2797 expected.set_generation(0);
2798 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2799
2800 // Candidate line without candidate:
2801 candidate_attribute = kRawCandidate;
2802 Replace("candidate:", "", &candidate_attribute);
2803 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2804
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002805 // Candidate line with IPV6 address.
2806 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
Zach Steinb336c272018-08-09 01:16:13 -07002807
2808 // Candidate line with hostname address.
2809 EXPECT_TRUE(SdpDeserializeCandidate(kRawHostnameCandidate, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002810}
2811
2812// This test verifies that the deserialization of an invalid candidate string
2813// fails.
2814TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
Yves Gerey665174f2018-06-19 15:03:05 +02002815 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002816
2817 std::string candidate_attribute = kRawCandidate;
2818 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002819 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002820
2821 candidate_attribute = kSdpOneCandidate;
2822 candidate_attribute.replace(0, 1, "x");
2823 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2824
2825 candidate_attribute = kRawCandidate;
2826 candidate_attribute.append("\r\n");
2827 candidate_attribute.append(kRawCandidate);
2828 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2829
2830 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002831}
2832
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002833TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002834 bool use_sctpmap = true;
2835 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002836 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002837 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002838
2839 std::string sdp_with_data = kSdpString;
2840 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002841 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002842
Guido Urdanetacecf87f2019-05-31 10:17:38 +00002843 // Verify with UDP/DTLS/SCTP (already in kSdpSctpDataChannelString).
lally@webrtc.org36300852015-02-24 20:19:35 +00002844 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2845 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2846
Guido Urdanetacecf87f2019-05-31 10:17:38 +00002847 // Verify with DTLS/SCTP.
2848 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2849 kDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002850 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2851 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2852
2853 // Verify with TCP/DTLS/SCTP.
Guido Urdanetacecf87f2019-05-31 10:17:38 +00002854 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
Yves Gerey665174f2018-06-19 15:03:05 +02002855 kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002856 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2857 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2858}
2859
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002860TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002861 bool use_sctpmap = false;
2862 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002863 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002864 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002865
2866 std::string sdp_with_data = kSdpString;
2867 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002868 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002869
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002870 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2871 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2872}
2873
lally69f57602015-10-08 10:15:04 -07002874TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002875 bool use_sctpmap = false;
2876 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002877 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002878 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
lally69f57602015-10-08 10:15:04 -07002879
2880 std::string sdp_with_data = kSdpString;
2881 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002882 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 10:15:04 -07002883
lally69f57602015-10-08 10:15:04 -07002884 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2885 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2886}
2887
Philipp Hanckeefc55b02020-06-26 10:17:05 +02002888TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsButWrongMediaType) {
2889 bool use_sctpmap = true;
2890 AddSctpDataChannel(use_sctpmap);
2891 JsepSessionDescription jdesc(kDummyType);
2892 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
2893
2894 std::string sdp = kSdpSessionString;
2895 sdp += kSdpSctpDataChannelString;
2896
2897 const char needle[] = "m=application ";
2898 sdp.replace(sdp.find(needle), strlen(needle), "m=application:bogus ");
2899
2900 JsepSessionDescription jdesc_output(kDummyType);
2901 EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output));
2902
Philipp Hancke4e8c1152020-10-13 12:43:15 +02002903 EXPECT_EQ(1u, jdesc_output.description()->contents().size());
2904 EXPECT_TRUE(jdesc_output.description()->contents()[0].rejected);
Philipp Hanckeefc55b02020-06-26 10:17:05 +02002905}
2906
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002907// Helper function to set the max-message-size parameter in the
2908// SCTP data codec.
2909void MutateJsepSctpMaxMessageSize(const SessionDescription& desc,
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002910 int new_value,
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002911 JsepSessionDescription* jdesc) {
Harald Alvestrand8da35a62019-05-10 09:31:04 +02002912 std::unique_ptr<cricket::SessionDescription> mutant = desc.Clone();
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002913 SctpDataContentDescription* dcdesc =
2914 mutant->GetContentDescriptionByName(kDataContentName)->as_sctp();
2915 dcdesc->set_max_message_size(new_value);
Harald Alvestrand8da35a62019-05-10 09:31:04 +02002916 jdesc->Initialize(std::move(mutant), kSessionId, kSessionVersion);
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002917}
2918
2919TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithMaxMessageSize) {
2920 bool use_sctpmap = false;
2921 AddSctpDataChannel(use_sctpmap);
2922 JsepSessionDescription jdesc(kDummyType);
2923 std::string sdp_with_data = kSdpString;
2924
2925 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
2926 sdp_with_data.append("a=max-message-size:12345\r\n");
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002927 MutateJsepSctpMaxMessageSize(desc_, 12345, &jdesc);
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002928 JsepSessionDescription jdesc_output(kDummyType);
2929
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002930 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2931 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2932}
2933
Harald Alvestrandfbb45bd2019-05-15 08:07:47 +02002934TEST_F(WebRtcSdpTest, SerializeSdpWithSctpDataChannelWithMaxMessageSize) {
2935 bool use_sctpmap = false;
2936 AddSctpDataChannel(use_sctpmap);
2937 JsepSessionDescription jdesc(kDummyType);
2938 MutateJsepSctpMaxMessageSize(desc_, 12345, &jdesc);
2939 std::string message = webrtc::SdpSerialize(jdesc);
2940 EXPECT_NE(std::string::npos,
2941 message.find("\r\na=max-message-size:12345\r\n"));
2942 JsepSessionDescription jdesc_output(kDummyType);
2943 EXPECT_TRUE(SdpDeserialize(message, &jdesc_output));
2944 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2945}
2946
2947TEST_F(WebRtcSdpTest,
2948 SerializeSdpWithSctpDataChannelWithDefaultMaxMessageSize) {
2949 // https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-26#section-6
2950 // The default max message size is 64K.
2951 bool use_sctpmap = false;
2952 AddSctpDataChannel(use_sctpmap);
2953 JsepSessionDescription jdesc(kDummyType);
2954 MutateJsepSctpMaxMessageSize(desc_, 65536, &jdesc);
2955 std::string message = webrtc::SdpSerialize(jdesc);
2956 EXPECT_EQ(std::string::npos, message.find("\r\na=max-message-size:"));
2957 JsepSessionDescription jdesc_output(kDummyType);
2958 EXPECT_TRUE(SdpDeserialize(message, &jdesc_output));
2959 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2960}
2961
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002962// Test to check the behaviour if sctp-port is specified
2963// on the m= line and in a=sctp-port.
2964TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002965 bool use_sctpmap = true;
2966 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002967 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002968 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002969
2970 std::string sdp_with_data = kSdpString;
2971 // Append m= attributes
2972 sdp_with_data.append(kSdpSctpDataChannelString);
2973 // Append a=sctp-port attribute
2974 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 10:27:41 -08002975 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002976
2977 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2978}
2979
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002980// Test behavior if a=rtpmap occurs in an SCTP section.
2981TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpmapAttribute) {
2982 std::string sdp_with_data = kSdpString;
2983 // Append m= attributes
2984 sdp_with_data.append(kSdpSctpDataChannelString);
2985 // Append a=rtpmap attribute
2986 sdp_with_data.append("a=rtpmap:111 opus/48000/2\r\n");
2987 JsepSessionDescription jdesc_output(kDummyType);
2988 // Correct behavior is to ignore the extra attribute.
2989 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2990}
2991
2992TEST_F(WebRtcSdpTest, DeserializeSdpWithStrangeApplicationProtocolNames) {
Harald Alvestrand7af57c62021-04-16 11:12:14 +00002993 static const char* bad_strings[] = {
2994 "DTLS/SCTPRTP/", "obviously-bogus", "UDP/TL/RTSP/SAVPF",
2995 "UDP/TL/RTSP/S", "DTLS/SCTP/RTP/FOO", "obviously-bogus/RTP/"};
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002996 for (auto proto : bad_strings) {
2997 std::string sdp_with_data = kSdpString;
2998 sdp_with_data.append("m=application 9 ");
2999 sdp_with_data.append(proto);
3000 sdp_with_data.append(" 47\r\n");
3001 JsepSessionDescription jdesc_output(kDummyType);
3002 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output))
3003 << "Parsing should have failed on " << proto;
3004 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003005}
3006
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00003007// For crbug/344475.
3008TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
3009 std::string sdp_with_data = kSdpString;
3010 sdp_with_data.append(kSdpSctpDataChannelString);
3011 // Remove the "\n" at the end.
3012 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 10:27:41 -08003013 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00003014
3015 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
3016 // No crash is a pass.
3017}
3018
zstein4b2e0822017-02-17 19:48:38 -08003019TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
3020 bool use_sctpmap = true;
3021 AddSctpDataChannel(use_sctpmap);
3022
3023 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 10:27:41 -08003024 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003025 MutateJsepSctpPort(&jdesc, desc_, kUnusualSctpPort);
wu@webrtc.org78187522013-10-07 23:32:02 +00003026
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00003027 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00003028 std::string sdp_with_data = kSdpString;
3029 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Anton1c9c9fc2019-02-14 15:13:09 -08003030 absl::StrReplaceAll(
3031 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}},
3032 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08003033 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:02 +00003034
3035 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3036 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08003037}
3038
3039TEST_F(WebRtcSdpTest,
3040 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
3041 bool use_sctpmap = false;
3042 AddSctpDataChannel(use_sctpmap);
3043
Steve Antona3a92c22017-12-07 10:27:41 -08003044 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003045 MutateJsepSctpPort(&jdesc, desc_, kUnusualSctpPort);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003046
3047 // We need to test the deserialized JsepSessionDescription from
3048 // kSdpSctpDataChannelStringWithSctpPort for
3049 // draft-ietf-mmusic-sctp-sdp-07
3050 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08003051 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003052 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Anton1c9c9fc2019-02-14 15:13:09 -08003053 absl::StrReplaceAll(
3054 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}},
3055 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08003056 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003057
3058 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3059 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00003060}
3061
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003062TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08003063 bool use_sctpmap = true;
3064 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08003065 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003066 SctpDataContentDescription* dcd = GetFirstSctpDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003067 dcd->set_bandwidth(100 * 1000);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003068 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003069
3070 std::string sdp_with_bandwidth = kSdpString;
3071 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02003072 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003073 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08003074 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003075
3076 // SCTP has congestion control, so we shouldn't limit the bandwidth
3077 // as we do for RTP.
3078 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003079 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
3080}
3081
Yves Gerey665174f2018-06-19 15:03:05 +02003082class WebRtcSdpExtmapTest : public WebRtcSdpTest,
Mirko Bonadei6a489f22019-04-09 15:11:12 +02003083 public ::testing::WithParamInterface<bool> {};
jbauch5869f502017-06-29 12:31:36 -07003084
3085TEST_P(WebRtcSdpExtmapTest,
Yves Gerey665174f2018-06-19 15:03:05 +02003086 DeserializeSessionDescriptionWithSessionLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003087 bool encrypted = GetParam();
3088 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003089}
3090
Yves Gerey665174f2018-06-19 15:03:05 +02003091TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003092 bool encrypted = GetParam();
3093 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003094}
3095
Yves Gerey665174f2018-06-19 15:03:05 +02003096TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithInvalidExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003097 bool encrypted = GetParam();
3098 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003099}
3100
Mirko Bonadeic84f6612019-01-31 12:20:57 +01003101INSTANTIATE_TEST_SUITE_P(Encrypted,
3102 WebRtcSdpExtmapTest,
3103 ::testing::Values(false, true));
jbauch5869f502017-06-29 12:31:36 -07003104
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003105TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 10:27:41 -08003106 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003107 std::string sdp = kSdpFullString;
3108 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
3109 // Deserialize
3110 SdpParseError error;
3111 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
Artem Titovf0a34f22020-03-16 17:52:04 +00003112 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003113 EXPECT_EQ(lastline, error.line);
3114 EXPECT_EQ("Invalid SDP line.", error.description);
3115}
3116
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003117TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
3118 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
3119 std::string new_sdp = kSdpOneCandidate;
3120 Replace("udp", "unsupported_transport", &new_sdp);
3121 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3122 new_sdp = kSdpOneCandidate;
3123 Replace("udp", "uDP", &new_sdp);
3124 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3125 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3126 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3127 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
3128}
3129
honghaiza54a0802015-12-16 18:37:23 -08003130TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003131 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08003132 EXPECT_TRUE(
3133 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003134 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3135 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3136 Candidate ref_candidate = jcandidate_->candidate();
3137 ref_candidate.set_username("user_rtp");
3138 ref_candidate.set_password("password_rtp");
3139 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
3140}
3141
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003142TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08003143 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003144
3145 // Deserialize
3146 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
3147
3148 // Verify
3149 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08003150 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003151 EXPECT_TRUE(audio->conference_mode());
3152
3153 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 15:55:30 -08003154 cricket::GetFirstVideoContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003155 EXPECT_TRUE(video->conference_mode());
3156}
3157
deadbeefd45aea82017-09-16 01:24:29 -07003158TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08003159 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 01:24:29 -07003160
3161 // We tested deserialization already above, so just test that if we serialize
3162 // and deserialize the flag doesn't disappear.
3163 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 12:22:16 -08003164 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 01:24:29 -07003165 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
3166
3167 // Verify.
3168 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08003169 cricket::GetFirstAudioContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 01:24:29 -07003170 EXPECT_TRUE(audio->conference_mode());
3171
3172 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 15:55:30 -08003173 cricket::GetFirstVideoContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 01:24:29 -07003174 EXPECT_TRUE(video->conference_mode());
3175}
3176
Sebastian Jansson97321b62019-07-24 14:01:18 +02003177TEST_F(WebRtcSdpTest, SerializeAndDeserializeRemoteNetEstimate) {
3178 {
3179 // By default remote estimates are disabled.
3180 JsepSessionDescription dst(kDummyType);
3181 SdpDeserialize(webrtc::SdpSerialize(jdesc_), &dst);
3182 EXPECT_FALSE(cricket::GetFirstVideoContentDescription(dst.description())
3183 ->remote_estimate());
3184 }
3185 {
3186 // When remote estimate is enabled, the setting is propagated via SDP.
3187 cricket::GetFirstVideoContentDescription(jdesc_.description())
3188 ->set_remote_estimate(true);
3189 JsepSessionDescription dst(kDummyType);
3190 SdpDeserialize(webrtc::SdpSerialize(jdesc_), &dst);
3191 EXPECT_TRUE(cricket::GetFirstVideoContentDescription(dst.description())
3192 ->remote_estimate());
3193 }
3194}
3195
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003196TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
3197 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003198 const char kSdpEmptyType[] = " =candidate";
3199 const char kSdpEqualAsPlus[] = "a+candidate";
3200 const char kSdpSpaceAfterEqual[] = "a= candidate";
3201 const char kSdpUpperType[] = "A=candidate";
3202 const char kSdpEmptyLine[] = "";
3203 const char kSdpMissingValue[] = "a=";
3204
Yves Gerey665174f2018-06-19 15:03:05 +02003205 const char kSdpBrokenFingerprint[] =
3206 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003207 "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 +02003208 const char kSdpExtraField[] =
3209 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003210 "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 +02003211 const char kSdpMissingSpace[] =
3212 "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003213 "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 +00003214 // MD5 is not allowed in fingerprints.
Yves Gerey665174f2018-06-19 15:03:05 +02003215 const char kSdpMd5[] =
3216 "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003217 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003218
3219 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003220 ExpectParseFailure("v=", kSdpDestroyer);
3221 ExpectParseFailure("o=", kSdpDestroyer);
3222 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003223 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003224 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003225
3226 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003227 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
3228 ExpectParseFailure("m=video", kSdpDestroyer);
Philipp Hanckeefc55b02020-06-26 10:17:05 +02003229 ExpectParseFailure("m=", "c=IN IP4 74.125.224.39");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003230
3231 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003232 ExpectParseFailure("a=candidate", kSdpEmptyType);
3233 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
3234 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
3235 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003236
3237 // Bogus fingerprint replacing a=sendrev. We selected this attribute
3238 // because it's orthogonal to what we are replacing and hence
3239 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003240 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
3241 ExpectParseFailure("a=sendrecv", kSdpExtraField);
3242 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
3243 ExpectParseFailure("a=sendrecv", kSdpMd5);
3244
3245 // Empty Line
3246 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
3247 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003248}
3249
3250TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
3251 // ssrc
3252 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08003253 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003254 // crypto
3255 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
3256 // rtpmap
3257 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
3258 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
3259 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
3260 // candidate
3261 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
3262 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
3263 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
3264 ExpectParseFailure("rport 2346", "rport badvalue");
3265 ExpectParseFailure("rport 2346 generation 2",
3266 "rport 2346 generation badvalue");
3267 // m line
3268 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
3269 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
3270
3271 // bandwidth
3272 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003273 "b=AS:badvalue\r\n", "b=AS:badvalue");
Philipp Hanckefbbfc022020-07-31 08:30:50 +02003274 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", "b=AS\r\n",
3275 "b=AS");
3276 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", "b=AS:\r\n",
3277 "b=AS:");
3278 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3279 "b=AS:12:34\r\n", "b=AS:12:34");
3280
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003281 // rtcp-fb
3282 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3283 "a=rtcp-fb:badvalue nack\r\n",
3284 "a=rtcp-fb:badvalue nack");
3285 // extmap
3286 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3287 "a=extmap:badvalue http://example.com\r\n",
3288 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003289}
3290
3291TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 10:27:41 -08003292 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003293
3294 const char kSdpWithReorderedPlTypesString[] =
3295 "v=0\r\n"
3296 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3297 "s=-\r\n"
3298 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00003299 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
Yves Gerey665174f2018-06-19 15:03:05 +02003300 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
3301 // in the map.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003302 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003303 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003304
3305 // Deserialize
3306 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
3307
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003308 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003309 GetFirstAudioContentDescription(jdesc_output.description());
3310 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003311 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003312 EXPECT_EQ("ISAC", acd->codecs()[0].name);
3313 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003314 EXPECT_EQ(104, acd->codecs()[0].id);
3315}
3316
3317TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 10:27:41 -08003318 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003319 CodecParams params;
3320 params.max_ptime = 40;
3321 params.ptime = 30;
3322 params.min_ptime = 10;
3323 params.sprop_stereo = 1;
3324 params.stereo = 1;
3325 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003326 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003327 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 12:22:16 -08003328 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003329}
3330
3331TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
3332 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 10:27:41 -08003333 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003334 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003335 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003336}
3337
3338TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
3339 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 10:27:41 -08003340 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003341 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003342 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003343}
3344
3345TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 10:27:41 -08003346 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003347
3348 const char kSdpWithFmtpString[] =
3349 "v=0\r\n"
3350 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3351 "s=-\r\n"
3352 "t=0 0\r\n"
3353 "m=video 3457 RTP/SAVPF 120\r\n"
3354 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07003355 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3356
3357 // Deserialize
3358 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07003359 EXPECT_TRUE(
3360 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07003361
Donald Curtis0e07f922015-05-15 09:21:23 -07003362 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003363 GetFirstVideoContentDescription(jdesc_output.description());
3364 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 09:21:23 -07003365 ASSERT_FALSE(vcd->codecs().empty());
3366 cricket::VideoCodec vp8 = vcd->codecs()[0];
3367 EXPECT_EQ("VP8", vp8.name);
3368 EXPECT_EQ(120, vp8.id);
3369 cricket::CodecParameterMap::iterator found =
3370 vp8.params.find("x-google-min-bitrate");
3371 ASSERT_TRUE(found != vp8.params.end());
3372 EXPECT_EQ(found->second, "10");
3373 found = vp8.params.find("x-google-max-quantization");
3374 ASSERT_TRUE(found != vp8.params.end());
3375 EXPECT_EQ(found->second, "40");
3376}
3377
johan2d8d23e2016-06-03 01:22:42 -07003378TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 10:27:41 -08003379 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 01:22:42 -07003380
3381 const char kSdpWithFmtpString[] =
3382 "v=0\r\n"
3383 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3384 "s=-\r\n"
3385 "t=0 0\r\n"
3386 "m=video 49170 RTP/AVP 98\r\n"
3387 "a=rtpmap:98 H264/90000\r\n"
3388 "a=fmtp:98 profile-level-id=42A01E; "
3389 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3390
3391 // Deserialize.
3392 SdpParseError error;
3393 EXPECT_TRUE(
3394 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3395
johan2d8d23e2016-06-03 01:22:42 -07003396 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003397 GetFirstVideoContentDescription(jdesc_output.description());
3398 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 01:22:42 -07003399 ASSERT_FALSE(vcd->codecs().empty());
3400 cricket::VideoCodec h264 = vcd->codecs()[0];
3401 EXPECT_EQ("H264", h264.name);
3402 EXPECT_EQ(98, h264.id);
3403 cricket::CodecParameterMap::const_iterator found =
3404 h264.params.find("profile-level-id");
3405 ASSERT_TRUE(found != h264.params.end());
3406 EXPECT_EQ(found->second, "42A01E");
3407 found = h264.params.find("sprop-parameter-sets");
3408 ASSERT_TRUE(found != h264.params.end());
3409 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3410}
3411
Donald Curtis0e07f922015-05-15 09:21:23 -07003412TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 10:27:41 -08003413 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 09:21:23 -07003414
3415 const char kSdpWithFmtpString[] =
3416 "v=0\r\n"
3417 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3418 "s=-\r\n"
3419 "t=0 0\r\n"
3420 "m=video 3457 RTP/SAVPF 120\r\n"
3421 "a=rtpmap:120 VP8/90000\r\n"
3422 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003423
3424 // Deserialize
3425 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02003426 EXPECT_TRUE(
3427 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003428
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003429 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003430 GetFirstVideoContentDescription(jdesc_output.description());
3431 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003432 ASSERT_FALSE(vcd->codecs().empty());
3433 cricket::VideoCodec vp8 = vcd->codecs()[0];
3434 EXPECT_EQ("VP8", vp8.name);
3435 EXPECT_EQ(120, vp8.id);
3436 cricket::CodecParameterMap::iterator found =
3437 vp8.params.find("x-google-min-bitrate");
3438 ASSERT_TRUE(found != vp8.params.end());
3439 EXPECT_EQ(found->second, "10");
3440 found = vp8.params.find("x-google-max-quantization");
3441 ASSERT_TRUE(found != vp8.params.end());
3442 EXPECT_EQ(found->second, "40");
3443}
3444
Mirta Dvornicic479a3c02019-06-04 15:38:50 +02003445TEST_F(WebRtcSdpTest, DeserializePacketizationAttributeWithIllegalValue) {
3446 JsepSessionDescription jdesc_output(kDummyType);
3447
3448 const char kSdpWithPacketizationString[] =
3449 "v=0\r\n"
3450 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3451 "s=-\r\n"
3452 "t=0 0\r\n"
3453 "m=audio 9 RTP/SAVPF 111\r\n"
3454 "a=rtpmap:111 opus/48000/2\r\n"
3455 "a=packetization:111 unknownpacketizationattributeforaudio\r\n"
3456 "m=video 3457 RTP/SAVPF 120 121 122\r\n"
3457 "a=rtpmap:120 VP8/90000\r\n"
3458 "a=packetization:120 raw\r\n"
3459 "a=rtpmap:121 VP9/90000\r\n"
3460 "a=rtpmap:122 H264/90000\r\n"
3461 "a=packetization:122 unknownpacketizationattributevalue\r\n";
3462
3463 SdpParseError error;
3464 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithPacketizationString, &jdesc_output,
3465 &error));
3466
3467 AudioContentDescription* acd =
3468 GetFirstAudioContentDescription(jdesc_output.description());
3469 ASSERT_TRUE(acd);
3470 ASSERT_THAT(acd->codecs(), testing::SizeIs(1));
3471 cricket::AudioCodec opus = acd->codecs()[0];
3472 EXPECT_EQ(opus.name, "opus");
3473 EXPECT_EQ(opus.id, 111);
3474
3475 const VideoContentDescription* vcd =
3476 GetFirstVideoContentDescription(jdesc_output.description());
3477 ASSERT_TRUE(vcd);
3478 ASSERT_THAT(vcd->codecs(), testing::SizeIs(3));
3479 cricket::VideoCodec vp8 = vcd->codecs()[0];
3480 EXPECT_EQ(vp8.name, "VP8");
3481 EXPECT_EQ(vp8.id, 120);
3482 EXPECT_EQ(vp8.packetization, "raw");
3483 cricket::VideoCodec vp9 = vcd->codecs()[1];
3484 EXPECT_EQ(vp9.name, "VP9");
3485 EXPECT_EQ(vp9.id, 121);
3486 EXPECT_EQ(vp9.packetization, absl::nullopt);
3487 cricket::VideoCodec h264 = vcd->codecs()[2];
3488 EXPECT_EQ(h264.name, "H264");
3489 EXPECT_EQ(h264.id, 122);
3490 EXPECT_EQ(h264.packetization, absl::nullopt);
3491}
3492
ossuaa4b0772017-01-30 07:41:18 -08003493TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003494 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003495
3496 cricket::AudioCodecs codecs = acd->codecs();
3497 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3498 acd->set_codecs(codecs);
3499
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003500 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003501 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003502 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003503 std::string sdp_with_fmtp = kSdpFullString;
3504 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3505 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3506 &sdp_with_fmtp);
3507 EXPECT_EQ(sdp_with_fmtp, message);
3508}
3509
3510TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003511 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003512
3513 cricket::AudioCodecs codecs = acd->codecs();
3514 codecs[0].params["stereo"] = "1";
3515 acd->set_codecs(codecs);
3516
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003517 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003518 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003519 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003520 std::string sdp_with_fmtp = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003521 InjectAfter("a=rtpmap:111 opus/48000/2\r\n", "a=fmtp:111 stereo=1\r\n",
ossuaa4b0772017-01-30 07:41:18 -08003522 &sdp_with_fmtp);
3523 EXPECT_EQ(sdp_with_fmtp, message);
3524}
3525
3526TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003527 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003528
3529 cricket::AudioCodecs codecs = acd->codecs();
3530 codecs[0].params["ptime"] = "20";
3531 codecs[0].params["maxptime"] = "120";
3532 acd->set_codecs(codecs);
3533
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003534 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003535 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003536 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003537 std::string sdp_with_fmtp = kSdpFullString;
3538 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3539 "a=maxptime:120\r\n" // No comma here. String merging!
3540 "a=ptime:20\r\n",
3541 &sdp_with_fmtp);
3542 EXPECT_EQ(sdp_with_fmtp, message);
3543}
3544
Philipp Hanckef2a4ec12020-07-01 21:07:32 +02003545TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithTelephoneEvent) {
3546 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
3547
3548 cricket::AudioCodecs codecs = acd->codecs();
3549 cricket::AudioCodec dtmf(105, "telephone-event", 8000, 0, 1);
3550 dtmf.params[""] = "0-15";
3551 codecs.push_back(dtmf);
3552 acd->set_codecs(codecs);
3553
3554 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
3555 jdesc_.session_version()));
3556 std::string message = webrtc::SdpSerialize(jdesc_);
3557 std::string sdp_with_fmtp = kSdpFullString;
3558 InjectAfter("m=audio 2345 RTP/SAVPF 111 103 104", " 105", &sdp_with_fmtp);
3559 InjectAfter(
3560 "a=rtpmap:104 ISAC/32000\r\n",
3561 "a=rtpmap:105 telephone-event/8000\r\n" // No comma here. String merging!
3562 "a=fmtp:105 0-15\r\n",
3563 &sdp_with_fmtp);
3564 EXPECT_EQ(sdp_with_fmtp, message);
3565}
3566
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003567TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003568 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003569
3570 cricket::VideoCodecs codecs = vcd->codecs();
3571 codecs[0].params["x-google-min-bitrate"] = "10";
3572 vcd->set_codecs(codecs);
3573
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003574 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003575 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003576 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003577 std::string sdp_with_fmtp = kSdpFullString;
3578 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003579 "a=fmtp:120 x-google-min-bitrate=10\r\n", &sdp_with_fmtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003580 EXPECT_EQ(sdp_with_fmtp, message);
3581}
3582
Mirta Dvornicic479a3c02019-06-04 15:38:50 +02003583TEST_F(WebRtcSdpTest, SerializeVideoPacketizationAttribute) {
3584 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
3585
3586 cricket::VideoCodecs codecs = vcd->codecs();
3587 codecs[0].packetization = "raw";
3588 vcd->set_codecs(codecs);
3589
3590 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
3591 jdesc_.session_version()));
3592 std::string message = webrtc::SdpSerialize(jdesc_);
3593 std::string sdp_with_packetization = kSdpFullString;
3594 InjectAfter("a=rtpmap:120 VP8/90000\r\n", "a=packetization:120 raw\r\n",
3595 &sdp_with_packetization);
3596 EXPECT_EQ(sdp_with_packetization, message);
3597}
3598
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003599TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) {
3600 // Deserialize the baseline description, making sure it's ICE full.
Steve Antona3a92c22017-12-07 10:27:41 -08003601 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003602 std::string sdp_with_icelite = kSdpFullString;
3603 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3604 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3605 const cricket::TransportInfo* tinfo1 =
3606 desc->GetTransportInfoByName("audio_content_name");
3607 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3608 const cricket::TransportInfo* tinfo2 =
3609 desc->GetTransportInfoByName("video_content_name");
3610 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003611
3612 // Add "a=ice-lite" and deserialize, making sure it's ICE lite.
Yves Gerey665174f2018-06-19 15:03:05 +02003613 InjectAfter(kSessionTime, "a=ice-lite\r\n", &sdp_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003614 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3615 desc = jdesc_with_icelite.description();
3616 const cricket::TransportInfo* atinfo =
3617 desc->GetTransportInfoByName("audio_content_name");
3618 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3619 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003620 desc->GetTransportInfoByName("video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003621 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003622
3623 // Now that we know deserialization works, we can use TestSerialize to test
3624 // serialization.
3625 TestSerialize(jdesc_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003626}
3627
3628// Verifies that the candidates in the input SDP are parsed and serialized
3629// correctly in the output SDP.
3630TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3631 std::string sdp_with_data = kSdpString;
3632 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 10:27:41 -08003633 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003634
3635 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 12:22:16 -08003636 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003637}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003638
3639TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3640 AddFingerprint();
3641 TransportInfo audio_transport_info =
3642 *(desc_.GetTransportInfoByName(kAudioContentName));
3643 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3644 audio_transport_info.description.connection_role);
3645 audio_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003646 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003647
3648 TransportInfo video_transport_info =
3649 *(desc_.GetTransportInfoByName(kVideoContentName));
3650 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3651 video_transport_info.description.connection_role);
3652 video_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003653 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003654
3655 desc_.RemoveTransportInfoByName(kAudioContentName);
3656 desc_.RemoveTransportInfoByName(kVideoContentName);
3657
3658 desc_.AddTransportInfo(audio_transport_info);
3659 desc_.AddTransportInfo(video_transport_info);
3660
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003661 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003662 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003663 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003664 std::string sdp_with_dtlssetup = kSdpFullString;
3665
3666 // Fingerprint attribute is necessary to add DTLS setup attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003667 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_dtlssetup);
3668 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003669 // Now adding |setup| attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003670 InjectAfter(kFingerprint, "a=setup:active\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003671 EXPECT_EQ(sdp_with_dtlssetup, message);
3672}
3673
3674TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
Steve Antona3a92c22017-12-07 10:27:41 -08003675 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003676 std::string sdp_with_dtlssetup = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003677 InjectAfter(kSessionTime, "a=setup:actpass\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003678 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3679 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3680 const cricket::TransportInfo* atinfo =
3681 desc->GetTransportInfoByName("audio_content_name");
3682 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3683 atinfo->description.connection_role);
3684 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003685 desc->GetTransportInfoByName("video_content_name");
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003686 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3687 vtinfo->description.connection_role);
3688}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003689
3690// Verifies that the order of the serialized m-lines follows the order of the
3691// ContentInfo in SessionDescription, and vise versa for deserialization.
3692TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 10:27:41 -08003693 JsepSessionDescription jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02003694 const std::string media_content_sdps[3] = {kSdpAudioString, kSdpVideoString,
3695 kSdpSctpDataChannelString};
3696 const cricket::MediaType media_types[3] = {cricket::MEDIA_TYPE_AUDIO,
3697 cricket::MEDIA_TYPE_VIDEO,
3698 cricket::MEDIA_TYPE_DATA};
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003699
3700 // Verifies all 6 permutations.
3701 for (size_t i = 0; i < 6; ++i) {
3702 size_t media_content_in_sdp[3];
3703 // The index of the first media content.
3704 media_content_in_sdp[0] = i / 2;
3705 // The index of the second media content.
3706 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3707 // The index of the third media content.
3708 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3709
3710 std::string sdp_string = kSdpSessionString;
3711 for (size_t i = 0; i < 3; ++i)
3712 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3713
3714 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3715 cricket::SessionDescription* desc = jdesc.description();
3716 EXPECT_EQ(3u, desc->contents().size());
3717
3718 for (size_t i = 0; i < 3; ++i) {
3719 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 15:14:30 -08003720 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003721 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3722 }
3723
Steve Antone831b8c2018-02-01 12:22:16 -08003724 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003725 EXPECT_EQ(sdp_string, serialized_sdp);
3726 }
3727}
deadbeef9d3584c2016-02-16 17:54:10 -08003728
deadbeef25ed4352016-12-12 18:37:36 -08003729TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3730 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 10:27:41 -08003731 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003732 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003733 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3734 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3735}
3736
deadbeef12771a12017-01-03 13:53:47 -08003737// The semantics of "a=bundle-only" are only defined when it's used in
3738// combination with a 0 port on the m= line. We should ignore it if used with a
3739// nonzero port.
3740TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3741 // Make the base bundle-only description but unset the bundle-only flag.
3742 MakeBundleOnlyDescription();
3743 jdesc_.description()->contents()[1].bundle_only = false;
3744
3745 std::string modified_sdp = kBundleOnlySdpFullString;
3746 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08003747 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003748 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3749 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003750}
3751
3752TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3753 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003754 TestSerialize(jdesc_);
deadbeef25ed4352016-12-12 18:37:36 -08003755}
3756
deadbeef9d3584c2016-02-16 17:54:10 -08003757TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3758 MakePlanBDescription();
3759
Steve Antona3a92c22017-12-07 10:27:41 -08003760 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003761 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3762
3763 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3764}
3765
3766TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3767 MakePlanBDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003768 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-16 17:54:10 -08003769}
3770
3771TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3772 MakeUnifiedPlanDescription();
3773
Steve Antona3a92c22017-12-07 10:27:41 -08003774 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003775 EXPECT_TRUE(
3776 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3777
3778 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3779}
3780
3781TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3782 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003783 TestSerialize(jdesc_);
3784}
3785
Seth Hampson5b4f0752018-04-02 16:31:36 -07003786// This tests deserializing a Unified Plan SDP that is compatible with both
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003787// Unified Plan and Plan B style SDP, meaning that it contains both "a=ssrc
3788// msid" lines and "a=msid " lines. It tests the case for audio/video tracks
Seth Hampson5b4f0752018-04-02 16:31:36 -07003789// with no stream ids and multiple stream ids. For parsing this, the Unified
3790// Plan a=msid lines should take priority, because the Plan B style a=ssrc msid
3791// lines do not support multiple stream ids and no stream ids.
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003792TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionSpecialMsid) {
3793 // Create both msid lines for Plan B and Unified Plan support.
3794 MakeUnifiedPlanDescriptionMultipleStreamIds(
3795 cricket::kMsidSignalingMediaSection |
3796 cricket::kMsidSignalingSsrcAttribute);
Seth Hampson5b4f0752018-04-02 16:31:36 -07003797
3798 JsepSessionDescription deserialized_description(kDummyType);
3799 EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid,
3800 &deserialized_description));
3801
3802 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
Henrik Boström5b147782018-12-04 11:25:05 +01003803 EXPECT_EQ(cricket::kMsidSignalingMediaSection |
3804 cricket::kMsidSignalingSsrcAttribute,
3805 deserialized_description.description()->msid_signaling());
Seth Hampson5b4f0752018-04-02 16:31:36 -07003806}
3807
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003808// Tests the serialization of a Unified Plan SDP that is compatible for both
3809// Unified Plan and Plan B style SDPs, meaning that it contains both "a=ssrc
3810// msid" lines and "a=msid " lines. It tests the case for no stream ids and
3811// multiple stream ids.
3812TEST_F(WebRtcSdpTest, SerializeSessionDescriptionSpecialMsid) {
3813 // Create both msid lines for Plan B and Unified Plan support.
3814 MakeUnifiedPlanDescriptionMultipleStreamIds(
3815 cricket::kMsidSignalingMediaSection |
3816 cricket::kMsidSignalingSsrcAttribute);
3817 std::string serialized_sdp = webrtc::SdpSerialize(jdesc_);
3818 // We explicitly test that the serialized SDP string is equal to the hard
3819 // coded SDP string. This is necessary, because in the parser "a=msid" lines
3820 // take priority over "a=ssrc msid" lines. This means if we just used
3821 // TestSerialize(), it could serialize an SDP that omits "a=ssrc msid" lines,
3822 // and still pass, because the deserialized version would be the same.
3823 EXPECT_EQ(kUnifiedPlanSdpFullStringWithSpecialMsid, serialized_sdp);
3824}
3825
3826// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3827// that signal stream IDs) is deserialized appropriately. It tests the case for
3828// no stream ids and multiple stream ids.
3829TEST_F(WebRtcSdpTest, UnifiedPlanDeserializeSessionDescriptionSpecialMsid) {
3830 // Only create a=msid lines for strictly Unified Plan stream ID support.
3831 MakeUnifiedPlanDescriptionMultipleStreamIds(
3832 cricket::kMsidSignalingMediaSection);
3833
3834 JsepSessionDescription deserialized_description(kDummyType);
3835 std::string unified_plan_sdp_string =
3836 kUnifiedPlanSdpFullStringWithSpecialMsid;
3837 RemoveSsrcMsidLinesFromSdpString(&unified_plan_sdp_string);
3838 EXPECT_TRUE(
3839 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3840
3841 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3842}
3843
3844// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3845// that signal stream IDs) is serialized appropriately. It tests the case for no
3846// stream ids and multiple stream ids.
3847TEST_F(WebRtcSdpTest, UnifiedPlanSerializeSessionDescriptionSpecialMsid) {
3848 // Only create a=msid lines for strictly Unified Plan stream ID support.
3849 MakeUnifiedPlanDescriptionMultipleStreamIds(
3850 cricket::kMsidSignalingMediaSection);
3851
Seth Hampson5b4f0752018-04-02 16:31:36 -07003852 TestSerialize(jdesc_);
3853}
3854
Seth Hampson5897a6e2018-04-03 11:16:33 -07003855// This tests that a Unified Plan SDP with no a=ssrc lines is
3856// serialized/deserialized appropriately. In this case the
3857// MediaContentDescription will contain a StreamParams object that doesn't have
3858// any SSRCs. Vice versa, this will be created upon deserializing an SDP with no
3859// SSRC lines.
3860TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3861 MakeUnifiedPlanDescription();
3862 RemoveSsrcSignalingFromStreamParams();
3863 std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString;
3864 RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string);
3865
3866 JsepSessionDescription deserialized_description(kDummyType);
3867 EXPECT_TRUE(
3868 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3869 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3870}
3871
3872TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3873 MakeUnifiedPlanDescription();
3874 RemoveSsrcSignalingFromStreamParams();
3875
3876 TestSerialize(jdesc_);
3877}
3878
Steve Antone831b8c2018-02-01 12:22:16 -08003879TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
3880 JsepSessionDescription jsep_desc(kDummyType);
3881 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
3882 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3883}
3884
3885TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
3886 JsepSessionDescription jsep_desc(kDummyType);
3887 std::string sdp = kSdpSessionString;
3888 sdp += kSdpSctpDataChannelString;
3889 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3890 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3891}
3892
3893TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
3894 JsepSessionDescription jsep_desc(kDummyType);
3895 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
3896 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
3897 jsep_desc.description()->msid_signaling());
3898}
3899
3900TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
3901 JsepSessionDescription jsep_desc(kDummyType);
3902 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
3903 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
3904 jsep_desc.description()->msid_signaling());
3905}
3906
3907const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
3908const char kSsrcAttributeMsidLine[] =
3909 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
3910
3911TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
3912 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
3913 std::string sdp = webrtc::SdpSerialize(jdesc_);
3914
3915 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3916 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3917}
3918
3919TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
3920 jdesc_.description()->set_msid_signaling(
3921 cricket::kMsidSignalingSsrcAttribute);
3922 std::string sdp = webrtc::SdpSerialize(jdesc_);
3923
3924 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
3925 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3926}
3927
3928TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
3929 jdesc_.description()->set_msid_signaling(
3930 cricket::kMsidSignalingMediaSection |
3931 cricket::kMsidSignalingSsrcAttribute);
3932 std::string sdp = webrtc::SdpSerialize(jdesc_);
3933
3934 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3935 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-16 17:54:10 -08003936}
deadbeef7e146cb2016-09-28 10:04:34 -07003937
deadbeefb2362572016-12-13 16:37:06 -08003938// Regression test for integer overflow bug:
3939// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3940TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003941 // Bandwidth attribute is the max signed 32-bit int, which will get
3942 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003943 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003944 "v=0\r\n"
3945 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3946 "s=-\r\n"
3947 "t=0 0\r\n"
3948 "m=video 3457 RTP/SAVPF 120\r\n"
3949 "b=AS:2147483647\r\n"
3950 "foo=fail\r\n";
3951
3952 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3953}
deadbeef7bcdb692017-01-20 12:43:58 -08003954
deadbeefbc88c6b2017-08-02 11:26:34 -07003955// Similar to the above, except that negative values are illegal, not just
3956// error-prone as large values are.
3957// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3958TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3959 static const char kSdpWithNegativeBandwidth[] =
3960 "v=0\r\n"
3961 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3962 "s=-\r\n"
3963 "t=0 0\r\n"
3964 "m=video 3457 RTP/SAVPF 120\r\n"
3965 "b=AS:-1000\r\n";
3966
3967 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3968}
3969
deadbeef3e8016e2017-08-03 17:49:30 -07003970// An exception to the above rule: a value of -1 for b=AS should just be
3971// ignored, resulting in "kAutoBandwidth" in the deserialized object.
3972// Applications historically may be using "b=AS:-1" to mean "no bandwidth
3973// limit", but this is now what ommitting the attribute entirely will do, so
3974// ignoring it will have the intended effect.
3975TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
3976 static const char kSdpWithBandwidthOfNegativeOne[] =
3977 "v=0\r\n"
3978 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3979 "s=-\r\n"
3980 "t=0 0\r\n"
3981 "m=video 3457 RTP/SAVPF 120\r\n"
3982 "b=AS:-1\r\n";
3983
Steve Antona3a92c22017-12-07 10:27:41 -08003984 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-03 17:49:30 -07003985 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-03 17:49:30 -07003986 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003987 GetFirstVideoContentDescription(jdesc_output.description());
3988 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-03 17:49:30 -07003989 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
3990}
3991
deadbeef7bcdb692017-01-20 12:43:58 -08003992// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3993// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3994// Regression test for:
3995// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3996TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3997 // Important piece is "ufrag foo pwd bar".
3998 static const char kSdpWithIceCredentialsInCandidateString[] =
3999 "v=0\r\n"
4000 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4001 "s=-\r\n"
4002 "t=0 0\r\n"
4003 "m=audio 9 RTP/SAVPF 111\r\n"
4004 "c=IN IP4 0.0.0.0\r\n"
4005 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4006 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4007 "a=rtpmap:111 opus/48000/2\r\n"
4008 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
4009 "generation 2 ufrag foo pwd bar\r\n";
4010
Steve Antona3a92c22017-12-07 10:27:41 -08004011 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 12:43:58 -08004012 EXPECT_TRUE(
4013 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
4014 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
4015 ASSERT_NE(nullptr, candidates);
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02004016 ASSERT_EQ(1U, candidates->count());
deadbeef7bcdb692017-01-20 12:43:58 -08004017 cricket::Candidate c = candidates->at(0)->candidate();
4018 EXPECT_EQ("ufrag_voice", c.username());
4019 EXPECT_EQ("pwd_voice", c.password());
4020}
deadbeef90f1e1e2017-02-10 12:35:05 -08004021
Johannes Kron211856b2018-09-06 12:12:28 +02004022// Test that attribute lines "a=ice-ufrag-something"/"a=ice-pwd-something" are
4023// ignored, and only the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
4024// Regression test for:
4025// https://bugs.chromium.org/p/webrtc/issues/detail?id=9712
4026TEST_F(WebRtcSdpTest, AttributeWithPartialMatchingNameIsIgnored) {
4027 static const char kSdpWithFooIceCredentials[] =
4028 "v=0\r\n"
4029 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4030 "s=-\r\n"
4031 "t=0 0\r\n"
4032 "m=audio 9 RTP/SAVPF 111\r\n"
4033 "c=IN IP4 0.0.0.0\r\n"
4034 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4035 "a=ice-ufrag-something:foo\r\na=ice-pwd-something:bar\r\n"
4036 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4037 "a=rtpmap:111 opus/48000/2\r\n"
4038 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
4039 "generation 2\r\n";
4040
4041 JsepSessionDescription jdesc_output(kDummyType);
4042 EXPECT_TRUE(SdpDeserialize(kSdpWithFooIceCredentials, &jdesc_output));
4043 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
4044 ASSERT_NE(nullptr, candidates);
4045 ASSERT_EQ(1U, candidates->count());
4046 cricket::Candidate c = candidates->at(0)->candidate();
4047 EXPECT_EQ("ufrag_voice", c.username());
4048 EXPECT_EQ("pwd_voice", c.password());
4049}
4050
deadbeef90f1e1e2017-02-10 12:35:05 -08004051// Test that SDP with an invalid port number in "a=candidate" lines is
4052// rejected, without crashing.
4053// Regression test for:
4054// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
4055TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
4056 static const char kSdpWithInvalidCandidatePort[] =
4057 "v=0\r\n"
4058 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4059 "s=-\r\n"
4060 "t=0 0\r\n"
4061 "m=audio 9 RTP/SAVPF 111\r\n"
4062 "c=IN IP4 0.0.0.0\r\n"
4063 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4064 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4065 "a=rtpmap:111 opus/48000/2\r\n"
4066 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
4067 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
4068
Steve Antona3a92c22017-12-07 10:27:41 -08004069 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 12:35:05 -08004070 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
4071}
deadbeefa4549d62017-02-10 17:26:22 -08004072
4073// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
4074// Regression test for:
4075// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
4076TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
4077 static const char kSdpWithMissingTrackId[] =
4078 "v=0\r\n"
4079 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4080 "s=-\r\n"
4081 "t=0 0\r\n"
4082 "m=audio 9 RTP/SAVPF 111\r\n"
4083 "c=IN IP4 0.0.0.0\r\n"
4084 "a=rtpmap:111 opus/48000/2\r\n"
4085 "a=msid:stream_id \r\n";
4086
Steve Antona3a92c22017-12-07 10:27:41 -08004087 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08004088 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
4089}
4090
4091TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
4092 static const char kSdpWithMissingStreamId[] =
4093 "v=0\r\n"
4094 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4095 "s=-\r\n"
4096 "t=0 0\r\n"
4097 "m=audio 9 RTP/SAVPF 111\r\n"
4098 "c=IN IP4 0.0.0.0\r\n"
4099 "a=rtpmap:111 opus/48000/2\r\n"
4100 "a=msid: track_id\r\n";
4101
Steve Antona3a92c22017-12-07 10:27:41 -08004102 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08004103 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
4104}
zhihuang38989e52017-03-21 11:04:53 -07004105
4106// Tests that if both session-level address and media-level address exist, use
4107// the media-level address.
4108TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 10:27:41 -08004109 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004110
4111 // Sesssion-level address.
4112 std::string sdp = kSdpFullString;
4113 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
4114 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4115
4116 const auto& content1 = jsep_desc.description()->contents()[0];
4117 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 15:14:30 -08004118 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004119 const auto& content2 = jsep_desc.description()->contents()[1];
4120 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 15:14:30 -08004121 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004122}
4123
4124// Tests that the session-level connection address will be used if the media
4125// level-addresses are not specified.
4126TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 10:27:41 -08004127 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004128
4129 // Sesssion-level address.
4130 std::string sdp = kSdpString;
4131 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
4132 // Remove the media level addresses.
4133 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
4134 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
4135 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4136
4137 const auto& content1 = jsep_desc.description()->contents()[0];
4138 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004139 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004140 const auto& content2 = jsep_desc.description()->contents()[1];
4141 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004142 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004143}
4144
4145TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 10:27:41 -08004146 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004147
4148 std::string sdp = kSdpString;
4149 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4150 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
4151 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
4152 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
4153 &sdp);
4154 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
4155 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
4156 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
4157 &sdp);
4158 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4159 const auto& content1 = jsep_desc.description()->contents()[0];
4160 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004161 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004162 const auto& content2 = jsep_desc.description()->contents()[1];
4163 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004164 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004165}
4166
Qingsi Wang56991422019-02-08 12:53:06 -08004167// Test that a c= line that contains a hostname connection address can be
4168// parsed.
4169TEST_F(WebRtcSdpTest, ParseConnectionDataWithHostnameConnectionAddress) {
4170 JsepSessionDescription jsep_desc(kDummyType);
4171 std::string sdp = kSdpString;
4172 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4173
4174 sdp = kSdpString;
4175 Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp);
4176 Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp);
4177 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4178
4179 ASSERT_NE(nullptr, jsep_desc.description());
4180 const auto& content1 = jsep_desc.description()->contents()[0];
4181 EXPECT_EQ("example.local:9",
4182 content1.media_description()->connection_address().ToString());
4183 const auto& content2 = jsep_desc.description()->contents()[1];
4184 EXPECT_EQ("example.local:9",
4185 content2.media_description()->connection_address().ToString());
4186}
4187
4188// Test that the invalid or unsupported connection data cannot be parsed.
zhihuang38989e52017-03-21 11:04:53 -07004189TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 10:27:41 -08004190 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004191 std::string sdp = kSdpString;
4192 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4193
4194 // Unsupported multicast IPv4 address.
4195 sdp = kSdpFullString;
4196 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
4197 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4198
4199 // Unsupported multicast IPv6 address.
4200 sdp = kSdpFullString;
4201 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
4202 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4203
4204 // Mismatched address type.
4205 sdp = kSdpFullString;
4206 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
4207 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4208
4209 sdp = kSdpFullString;
4210 Replace("c=IN IP4 74.125.224.39\r\n",
4211 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
4212 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4213}
4214
4215TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 10:27:41 -08004216 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004217 MakeDescriptionWithoutCandidates(&expected_jsep);
4218 // Serialization.
Steve Antone831b8c2018-02-01 12:22:16 -08004219 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 11:04:53 -07004220 // Deserialization.
Steve Antona3a92c22017-12-07 10:27:41 -08004221 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004222 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 15:14:30 -08004223 auto audio_desc = jdesc.description()
4224 ->GetContentByName(kAudioContentName)
4225 ->media_description();
4226 auto video_desc = jdesc.description()
4227 ->GetContentByName(kVideoContentName)
4228 ->media_description();
zhihuang38989e52017-03-21 11:04:53 -07004229 EXPECT_EQ(audio_desc_->connection_address().ToString(),
4230 audio_desc->connection_address().ToString());
4231 EXPECT_EQ(video_desc_->connection_address().ToString(),
4232 video_desc->connection_address().ToString());
4233}
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07004234
4235// RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be
4236// used (i.e., a single space as the session name)." So we should accept that.
4237TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) {
4238 JsepSessionDescription jsep_desc(kDummyType);
4239 std::string sdp = kSdpString;
4240 Replace("s=-\r\n", "s= \r\n", &sdp);
4241 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4242}
Amit Hilbucha2012042018-12-03 11:35:05 -08004243
4244// Simulcast malformed input test for invalid format.
4245TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_EmptyAttribute) {
Artem Titovf0a34f22020-03-16 17:52:04 +00004246 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
4247 "a=simulcast:\r\n", "a=simulcast:");
Amit Hilbucha2012042018-12-03 11:35:05 -08004248}
4249
4250// Tests that duplicate simulcast entries in the SDP triggers a parse failure.
4251TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_DuplicateAttribute) {
Artem Titovf0a34f22020-03-16 17:52:04 +00004252 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
4253 "a=simulcast:send 1\r\na=simulcast:recv 2\r\n",
4254 "a=simulcast:");
Amit Hilbucha2012042018-12-03 11:35:05 -08004255}
4256
4257// Validates that deserialization uses the a=simulcast: attribute
4258TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttribute) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004259 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4260 sdp += "a=rid:1 send\r\n";
4261 sdp += "a=rid:2 send\r\n";
4262 sdp += "a=rid:3 send\r\n";
4263 sdp += "a=rid:4 recv\r\n";
4264 sdp += "a=rid:5 recv\r\n";
4265 sdp += "a=rid:6 recv\r\n";
Amit Hilbucha2012042018-12-03 11:35:05 -08004266 sdp += "a=simulcast:send 1,2;3 recv 4;5;6\r\n";
4267 JsepSessionDescription output(kDummyType);
4268 SdpParseError error;
4269 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4270 const cricket::ContentInfos& contents = output.description()->contents();
4271 const cricket::MediaContentDescription* media =
4272 contents.back().media_description();
4273 EXPECT_TRUE(media->HasSimulcast());
4274 EXPECT_EQ(2ul, media->simulcast_description().send_layers().size());
4275 EXPECT_EQ(3ul, media->simulcast_description().receive_layers().size());
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004276 EXPECT_FALSE(media->streams().empty());
4277 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4278 CompareRidDescriptionIds(rids, {"1", "2", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004279}
4280
4281// Validates that deserialization removes rids that do not appear in SDP
4282TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttributeRemovesUnknownRids) {
4283 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4284 sdp += "a=rid:1 send\r\n";
4285 sdp += "a=rid:3 send\r\n";
4286 sdp += "a=rid:4 recv\r\n";
4287 sdp += "a=simulcast:send 1,2;3 recv 4;5,6\r\n";
4288 JsepSessionDescription output(kDummyType);
4289 SdpParseError error;
4290 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4291 const cricket::ContentInfos& contents = output.description()->contents();
4292 const cricket::MediaContentDescription* media =
4293 contents.back().media_description();
4294 EXPECT_TRUE(media->HasSimulcast());
4295 const SimulcastDescription& simulcast = media->simulcast_description();
4296 EXPECT_EQ(2ul, simulcast.send_layers().size());
4297 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4298
4299 std::vector<SimulcastLayer> all_send_layers =
4300 simulcast.send_layers().GetAllLayers();
4301 EXPECT_EQ(2ul, all_send_layers.size());
Steve Anton64b626b2019-01-28 17:25:26 -08004302 EXPECT_EQ(0,
4303 absl::c_count_if(all_send_layers, [](const SimulcastLayer& layer) {
4304 return layer.rid == "2";
4305 }));
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004306
4307 std::vector<SimulcastLayer> all_receive_layers =
4308 simulcast.receive_layers().GetAllLayers();
4309 ASSERT_EQ(1ul, all_receive_layers.size());
4310 EXPECT_EQ("4", all_receive_layers[0].rid);
4311
4312 EXPECT_FALSE(media->streams().empty());
4313 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4314 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004315}
4316
4317// Validates that Simulcast removes rids that appear in both send and receive.
4318TEST_F(WebRtcSdpTest,
4319 TestDeserializeSimulcastAttributeRemovesDuplicateSendReceive) {
4320 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4321 sdp += "a=rid:1 send\r\n";
4322 sdp += "a=rid:2 send\r\n";
4323 sdp += "a=rid:3 send\r\n";
4324 sdp += "a=rid:4 recv\r\n";
4325 sdp += "a=simulcast:send 1;2;3 recv 2;4\r\n";
4326 JsepSessionDescription output(kDummyType);
4327 SdpParseError error;
4328 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4329 const cricket::ContentInfos& contents = output.description()->contents();
4330 const cricket::MediaContentDescription* media =
4331 contents.back().media_description();
4332 EXPECT_TRUE(media->HasSimulcast());
4333 const SimulcastDescription& simulcast = media->simulcast_description();
4334 EXPECT_EQ(2ul, simulcast.send_layers().size());
4335 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4336 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4337 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4338
4339 EXPECT_FALSE(media->streams().empty());
4340 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4341 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004342}
4343
4344// Ignores empty rid line.
4345TEST_F(WebRtcSdpTest, TestDeserializeIgnoresEmptyRidLines) {
4346 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4347 sdp += "a=rid:1 send\r\n";
4348 sdp += "a=rid:2 send\r\n";
4349 sdp += "a=rid\r\n"; // Should ignore this line.
4350 sdp += "a=rid:\r\n"; // Should ignore this line.
4351 sdp += "a=simulcast:send 1;2\r\n";
4352 JsepSessionDescription output(kDummyType);
4353 SdpParseError error;
4354 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4355 const cricket::ContentInfos& contents = output.description()->contents();
4356 const cricket::MediaContentDescription* media =
4357 contents.back().media_description();
4358 EXPECT_TRUE(media->HasSimulcast());
4359 const SimulcastDescription& simulcast = media->simulcast_description();
4360 EXPECT_TRUE(simulcast.receive_layers().empty());
4361 EXPECT_EQ(2ul, simulcast.send_layers().size());
4362 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4363
4364 EXPECT_FALSE(media->streams().empty());
4365 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4366 CompareRidDescriptionIds(rids, {"1", "2"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004367}
4368
4369// Ignores malformed rid lines.
4370TEST_F(WebRtcSdpTest, TestDeserializeIgnoresMalformedRidLines) {
4371 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4372 sdp += "a=rid:1 send pt=\r\n"; // Should ignore this line.
4373 sdp += "a=rid:2 receive\r\n"; // Should ignore this line.
4374 sdp += "a=rid:3 max-width=720;pt=120\r\n"; // Should ignore this line.
4375 sdp += "a=rid:4\r\n"; // Should ignore this line.
4376 sdp += "a=rid:5 send\r\n";
4377 sdp += "a=simulcast:send 1,2,3;4,5\r\n";
4378 JsepSessionDescription output(kDummyType);
4379 SdpParseError error;
4380 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4381 const cricket::ContentInfos& contents = output.description()->contents();
4382 const cricket::MediaContentDescription* media =
4383 contents.back().media_description();
4384 EXPECT_TRUE(media->HasSimulcast());
4385 const SimulcastDescription& simulcast = media->simulcast_description();
4386 EXPECT_TRUE(simulcast.receive_layers().empty());
4387 EXPECT_EQ(1ul, simulcast.send_layers().size());
4388 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4389
4390 EXPECT_FALSE(media->streams().empty());
4391 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4392 CompareRidDescriptionIds(rids, {"5"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004393}
4394
4395// Removes RIDs that specify a different format than the m= section.
4396TEST_F(WebRtcSdpTest, TestDeserializeRemovesRidsWithInvalidCodec) {
4397 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4398 sdp += "a=rid:1 send pt=121,120\r\n"; // Should remove 121 and keep RID.
4399 sdp += "a=rid:2 send pt=121\r\n"; // Should remove RID altogether.
4400 sdp += "a=simulcast:send 1;2\r\n";
4401 JsepSessionDescription output(kDummyType);
4402 SdpParseError error;
4403 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4404 const cricket::ContentInfos& contents = output.description()->contents();
4405 const cricket::MediaContentDescription* media =
4406 contents.back().media_description();
4407 EXPECT_TRUE(media->HasSimulcast());
4408 const SimulcastDescription& simulcast = media->simulcast_description();
4409 EXPECT_TRUE(simulcast.receive_layers().empty());
4410 EXPECT_EQ(1ul, simulcast.send_layers().size());
4411 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4412 EXPECT_EQ("1", simulcast.send_layers()[0][0].rid);
4413 EXPECT_EQ(1ul, media->streams().size());
4414 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4415 EXPECT_EQ(1ul, rids.size());
4416 EXPECT_EQ("1", rids[0].rid);
4417 EXPECT_EQ(1ul, rids[0].payload_types.size());
4418 EXPECT_EQ(120, rids[0].payload_types[0]);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004419}
4420
4421// Ignores duplicate rid lines
4422TEST_F(WebRtcSdpTest, TestDeserializeIgnoresDuplicateRidLines) {
4423 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4424 sdp += "a=rid:1 send\r\n";
4425 sdp += "a=rid:2 send\r\n";
4426 sdp += "a=rid:2 send\r\n";
4427 sdp += "a=rid:3 send\r\n";
4428 sdp += "a=rid:4 recv\r\n";
4429 sdp += "a=simulcast:send 1,2;3 recv 4\r\n";
4430 JsepSessionDescription output(kDummyType);
4431 SdpParseError error;
4432 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4433 const cricket::ContentInfos& contents = output.description()->contents();
4434 const cricket::MediaContentDescription* media =
4435 contents.back().media_description();
4436 EXPECT_TRUE(media->HasSimulcast());
4437 const SimulcastDescription& simulcast = media->simulcast_description();
4438 EXPECT_EQ(2ul, simulcast.send_layers().size());
4439 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4440 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4441 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4442
4443 EXPECT_FALSE(media->streams().empty());
4444 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4445 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbucha2012042018-12-03 11:35:05 -08004446}
4447
Florent Castellic4421972019-07-02 20:27:42 +02004448TEST_F(WebRtcSdpTest, TestDeserializeRidSendDirection) {
4449 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4450 sdp += "a=rid:1 recv\r\n";
4451 sdp += "a=rid:2 recv\r\n";
4452 sdp += "a=simulcast:send 1;2\r\n";
4453 JsepSessionDescription output(kDummyType);
4454 SdpParseError error;
4455 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4456 const cricket::ContentInfos& contents = output.description()->contents();
4457 const cricket::MediaContentDescription* media =
4458 contents.back().media_description();
4459 EXPECT_FALSE(media->HasSimulcast());
4460}
4461
4462TEST_F(WebRtcSdpTest, TestDeserializeRidRecvDirection) {
4463 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4464 sdp += "a=rid:1 send\r\n";
4465 sdp += "a=rid:2 send\r\n";
4466 sdp += "a=simulcast:recv 1;2\r\n";
4467 JsepSessionDescription output(kDummyType);
4468 SdpParseError error;
4469 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4470 const cricket::ContentInfos& contents = output.description()->contents();
4471 const cricket::MediaContentDescription* media =
4472 contents.back().media_description();
4473 EXPECT_FALSE(media->HasSimulcast());
4474}
4475
4476TEST_F(WebRtcSdpTest, TestDeserializeIgnoresWrongRidDirectionLines) {
4477 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4478 sdp += "a=rid:1 send\r\n";
4479 sdp += "a=rid:2 send\r\n";
4480 sdp += "a=rid:3 send\r\n";
4481 sdp += "a=rid:4 recv\r\n";
4482 sdp += "a=rid:5 recv\r\n";
4483 sdp += "a=rid:6 recv\r\n";
4484 sdp += "a=simulcast:send 1;5;3 recv 4;2;6\r\n";
4485 JsepSessionDescription output(kDummyType);
4486 SdpParseError error;
4487 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4488 const cricket::ContentInfos& contents = output.description()->contents();
4489 const cricket::MediaContentDescription* media =
4490 contents.back().media_description();
4491 EXPECT_TRUE(media->HasSimulcast());
4492 const SimulcastDescription& simulcast = media->simulcast_description();
4493 EXPECT_EQ(2ul, simulcast.send_layers().size());
4494 EXPECT_EQ(2ul, simulcast.receive_layers().size());
4495 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4496 EXPECT_EQ(2ul, simulcast.receive_layers().GetAllLayers().size());
4497
4498 EXPECT_FALSE(media->streams().empty());
4499 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4500 CompareRidDescriptionIds(rids, {"1", "3"});
4501}
4502
Amit Hilbucha2012042018-12-03 11:35:05 -08004503// Simulcast serialization integration test.
4504// This test will serialize and deserialize the description and compare.
4505// More detailed tests for parsing simulcast can be found in
4506// unit tests for SdpSerializer.
4507TEST_F(WebRtcSdpTest, SerializeSimulcast_ComplexSerialization) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004508 MakeUnifiedPlanDescription(/* use_ssrcs = */ false);
Amit Hilbucha2012042018-12-03 11:35:05 -08004509 auto description = jdesc_.description();
4510 auto media = description->GetContentDescriptionByName(kVideoContentName3);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004511 ASSERT_EQ(media->streams().size(), 1ul);
4512 StreamParams& send_stream = media->mutable_streams()[0];
4513 std::vector<RidDescription> send_rids;
4514 send_rids.push_back(RidDescription("1", RidDirection::kSend));
4515 send_rids.push_back(RidDescription("2", RidDirection::kSend));
4516 send_rids.push_back(RidDescription("3", RidDirection::kSend));
4517 send_rids.push_back(RidDescription("4", RidDirection::kSend));
4518 send_stream.set_rids(send_rids);
Florent Castellib60141b2019-07-03 12:47:54 +02004519 std::vector<RidDescription> receive_rids;
4520 receive_rids.push_back(RidDescription("5", RidDirection::kReceive));
4521 receive_rids.push_back(RidDescription("6", RidDirection::kReceive));
4522 receive_rids.push_back(RidDescription("7", RidDirection::kReceive));
4523 media->set_receive_rids(receive_rids);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004524
Amit Hilbucha2012042018-12-03 11:35:05 -08004525 SimulcastDescription& simulcast = media->simulcast_description();
4526 simulcast.send_layers().AddLayerWithAlternatives(
4527 {SimulcastLayer("2", false), SimulcastLayer("1", true)});
4528 simulcast.send_layers().AddLayerWithAlternatives(
4529 {SimulcastLayer("4", false), SimulcastLayer("3", false)});
Florent Castellib60141b2019-07-03 12:47:54 +02004530 simulcast.receive_layers().AddLayer({SimulcastLayer("5", false)});
4531 simulcast.receive_layers().AddLayer({SimulcastLayer("6", false)});
4532 simulcast.receive_layers().AddLayer({SimulcastLayer("7", false)});
Amit Hilbucha2012042018-12-03 11:35:05 -08004533
Amit Hilbucha2012042018-12-03 11:35:05 -08004534 TestSerialize(jdesc_);
4535}
Steve Anton06817cd2018-12-18 15:55:30 -08004536
4537// Test that the content name is empty if the media section does not have an
4538// a=mid line.
4539TEST_F(WebRtcSdpTest, ParseNoMid) {
4540 std::string sdp = kSdpString;
4541 Replace("a=mid:audio_content_name\r\n", "", &sdp);
4542 Replace("a=mid:video_content_name\r\n", "", &sdp);
4543
4544 JsepSessionDescription output(kDummyType);
4545 SdpParseError error;
4546 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4547
4548 EXPECT_THAT(output.description()->contents(),
4549 ElementsAre(Field("name", &cricket::ContentInfo::name, ""),
4550 Field("name", &cricket::ContentInfo::name, "")));
4551}
Piotr (Peter) Slatala13e570f2019-02-27 11:34:26 -08004552
Guido Urdanetacecf87f2019-05-31 10:17:38 +00004553TEST_F(WebRtcSdpTest, SerializeWithDefaultSctpProtocol) {
4554 AddSctpDataChannel(false); // Don't use sctpmap
4555 JsepSessionDescription jsep_desc(kDummyType);
4556 MakeDescriptionWithoutCandidates(&jsep_desc);
4557 std::string message = webrtc::SdpSerialize(jsep_desc);
4558 EXPECT_NE(std::string::npos,
4559 message.find(cricket::kMediaProtocolUdpDtlsSctp));
4560}
4561
4562TEST_F(WebRtcSdpTest, DeserializeWithAllSctpProtocols) {
4563 AddSctpDataChannel(false);
4564 std::string protocols[] = {cricket::kMediaProtocolDtlsSctp,
4565 cricket::kMediaProtocolUdpDtlsSctp,
4566 cricket::kMediaProtocolTcpDtlsSctp};
4567 for (const auto& protocol : protocols) {
4568 sctp_desc_->set_protocol(protocol);
4569 JsepSessionDescription jsep_desc(kDummyType);
4570 MakeDescriptionWithoutCandidates(&jsep_desc);
4571 std::string message = webrtc::SdpSerialize(jsep_desc);
4572 EXPECT_NE(std::string::npos, message.find(protocol));
4573 JsepSessionDescription jsep_output(kDummyType);
4574 SdpParseError error;
4575 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jsep_output, &error));
4576 }
4577}
Taylor Brandstetter4256df02020-02-18 14:05:07 -08004578
4579// According to https://tools.ietf.org/html/rfc5576#section-6.1, the CNAME
4580// attribute is mandatory, but we relax that restriction.
4581TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCname) {
4582 std::string sdp_without_cname = kSdpFullString;
4583 Replace("a=ssrc:1 cname:stream_1_cname\r\n", "", &sdp_without_cname);
4584 JsepSessionDescription new_jdesc(kDummyType);
4585 EXPECT_TRUE(SdpDeserialize(sdp_without_cname, &new_jdesc));
4586
4587 audio_desc_->mutable_streams()[0].cname = "";
4588 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
4589 jdesc_.session_version()));
4590 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
4591}
Philipp Hanckeefc55b02020-06-26 10:17:05 +02004592
4593TEST_F(WebRtcSdpTest, DeserializeSdpWithUnsupportedMediaType) {
Philipp Hanckeefc55b02020-06-26 10:17:05 +02004594 std::string sdp = kSdpSessionString;
4595 sdp +=
4596 "m=bogus 9 RTP/SAVPF 0 8\r\n"
Philipp Hancke4e8c1152020-10-13 12:43:15 +02004597 "c=IN IP4 0.0.0.0\r\n"
4598 "a=mid:bogusmid\r\n";
Philipp Hanckeefc55b02020-06-26 10:17:05 +02004599 sdp +=
4600 "m=audio/something 9 RTP/SAVPF 0 8\r\n"
Philipp Hancke4e8c1152020-10-13 12:43:15 +02004601 "c=IN IP4 0.0.0.0\r\n"
4602 "a=mid:somethingmid\r\n";
Philipp Hanckeefc55b02020-06-26 10:17:05 +02004603
4604 JsepSessionDescription jdesc_output(kDummyType);
4605 EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output));
4606
Philipp Hancke4e8c1152020-10-13 12:43:15 +02004607 ASSERT_EQ(2u, jdesc_output.description()->contents().size());
4608 ASSERT_NE(nullptr, jdesc_output.description()
4609 ->contents()[0]
4610 .media_description()
4611 ->as_unsupported());
4612 ASSERT_NE(nullptr, jdesc_output.description()
4613 ->contents()[1]
4614 .media_description()
4615 ->as_unsupported());
4616
4617 EXPECT_TRUE(jdesc_output.description()->contents()[0].rejected);
4618 EXPECT_TRUE(jdesc_output.description()->contents()[1].rejected);
4619
4620 EXPECT_EQ(jdesc_output.description()->contents()[0].name, "bogusmid");
4621 EXPECT_EQ(jdesc_output.description()->contents()[1].name, "somethingmid");
Philipp Hanckeefc55b02020-06-26 10:17:05 +02004622}
Philipp Hanckeb70c9532021-01-13 10:40:06 +01004623
4624TEST_F(WebRtcSdpTest, MediaTypeProtocolMismatch) {
4625 std::string sdp =
4626 "v=0\r\n"
4627 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4628 "s=-\r\n"
4629 "t=0 0\r\n";
4630
4631 ExpectParseFailure(std::string(sdp + "m=audio 9 UDP/DTLS/SCTP 120\r\n"),
4632 "m=audio");
4633 ExpectParseFailure(std::string(sdp + "m=video 9 UDP/DTLS/SCTP 120\r\n"),
4634 "m=video");
4635 ExpectParseFailure(std::string(sdp + "m=video 9 SOMETHING 120\r\n"),
4636 "m=video");
4637 ExpectParseFailure(std::string(sdp + "m=application 9 SOMETHING 120\r\n"),
4638 "m=application");
4639}
Philipp Hanckecd467b52021-01-29 09:29:47 +01004640
4641// Regression test for:
4642// https://bugs.chromium.org/p/chromium/issues/detail?id=1171965
4643TEST_F(WebRtcSdpTest, SctpPortInUnsupportedContent) {
4644 std::string sdp =
4645 "v=0\r\n"
4646 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4647 "s=-\r\n"
4648 "t=0 0\r\n"
4649 "m=o 1 DTLS/SCTP 5000\r\n"
4650 "a=sctp-port\r\n";
4651
4652 JsepSessionDescription jdesc_output(kDummyType);
4653 EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output));
4654}
Harald Alvestrand99bcf602021-03-03 07:44:39 +00004655
4656TEST_F(WebRtcSdpTest, IllegalMidCharacterValue) {
4657 std::string sdp = kSdpString;
4658 // [ is an illegal token value.
4659 Replace("a=mid:", "a=mid:[]", &sdp);
4660 ExpectParseFailure(std::string(sdp), "a=mid:[]");
4661}